BUILD: prefer pkg-config for freetype2 detection
authorhasufell <hasufell@posteo.de>
Sun, 8 Dec 2013 20:05:25 +0000 (21:05 +0100)
committerIlya Zhuravlev <zhuravlevilya@ya.ru>
Sun, 5 Jan 2014 16:58:40 +0000 (20:58 +0400)
This can solve numerous problems such as:
http://www.cmake.org/Bug/view.php?id=13959
http://www.cmake.org/Bug/view.php?id=14601

If pkg-config or freetype2.pc is not found, then fall back to the
FindFreetype.cmake module logic.

Restrict to UNIX since I only tested it here.

src/CMakeLists.txt
src/cguittfont/CMakeLists.txt

index 6418b3b26dd15e1f8f4598d4b24dea3b076a6089..f2c1e166a5add05619476a9faa0e43cfe736c366 100644 (file)
@@ -178,7 +178,19 @@ if(ENABLE_GLES)
 endif(ENABLE_GLES)
 
 if(USE_FREETYPE)
-       find_package(Freetype REQUIRED)
+       if(UNIX)
+               include(FindPkgConfig)
+               if(PKG_CONFIG_FOUND)
+                       pkg_check_modules(FREETYPE QUIET freetype2)
+                       if(FREETYPE_FOUND)
+                               SET(FREETYPE_PKGCONFIG_FOUND TRUE)
+                               SET(FREETYPE_LIBRARY ${FREETYPE_LIBRARIES})
+                       endif(FREETYPE_FOUND)
+               endif(PKG_CONFIG_FOUND)
+       endif(UNIX)
+       if(NOT FREETYPE_FOUND)
+               find_package(Freetype REQUIRED)
+       endif(NOT FREETYPE_FOUND)
        set(CGUITTFONT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cguittfont")
        set(CGUITTFONT_LIBRARY cguittfont)
 endif(USE_FREETYPE)
@@ -451,6 +463,12 @@ if(BUILD_CLIENT)
                )
        endif(USE_CURL)
        if(USE_FREETYPE)
+               if(FREETYPE_PKGCONFIG_FOUND)
+                       set_target_properties(${PROJECT_NAME}
+                               PROPERTIES
+                               COMPILE_FLAGS "${FREETYPE_CFLAGS}"
+                       )
+               endif(FREETYPE_PKGCONFIG_FOUND)
                target_link_libraries(
                        ${PROJECT_NAME}
                        ${FREETYPE_LIBRARY}
index 94d06146259058accc2729e2146b91c7b8e3eaf3..d2647ba694da53b97eb0a65a7ad5ec55779783b6 100644 (file)
@@ -1,17 +1,29 @@
-include_directories(
-  ${IRRLICHT_INCLUDE_DIR}
-  ${FREETYPE_INCLUDE_DIRS}
-)
-
 # CGUITTFont authors, y u no include headers you use?
 #   Do not add CGUITTFont.cpp to the line below.
 #   xCGUITTFont.cpp is a wrapper file that includes
 #   additional required headers.
 add_library(cguittfont xCGUITTFont.cpp)
 
+if(FREETYPE_PKGCONFIG_FOUND)
+       set_target_properties(cguittfont
+               PROPERTIES
+               COMPILE_FLAGS "${FREETYPE_CFLAGS}"
+               LINK_FLAGS "${FREETYPE_LDFLAGS}"
+       )
+
+       include_directories(
+         ${IRRLICHT_INCLUDE_DIR}
+       )
+else(FREETYPE_PKGCONFIG_FOUND)
+       include_directories(
+         ${IRRLICHT_INCLUDE_DIR}
+         ${FREETYPE_INCLUDE_DIRS}
+       )
+endif(FREETYPE_PKGCONFIG_FOUND)
+
 target_link_libraries(
-  cguittfont
-  ${IRRLICHT_LIBRARY}
-  ${FREETYPE_LIBRARY}
-  ${ZLIB_LIBRARIES}  # needed by freetype, repeated here for safety
-)
+       cguittfont
+       ${IRRLICHT_LIBRARY}
+       ${FREETYPE_LIBRARY}
+       ${ZLIB_LIBRARIES}  # needed by freetype, repeated here for safety
+       )