Skip to content

Commit cb7bb73

Browse files
hasufellIlya Zhuravlev
authored and
Ilya Zhuravlev
committedJan 5, 2014
BUILD: prefer pkg-config for freetype2 detection
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.
1 parent 160e2b7 commit cb7bb73

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed
 

‎src/CMakeLists.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,19 @@ if(ENABLE_GLES)
178178
endif(ENABLE_GLES)
179179

180180
if(USE_FREETYPE)
181-
find_package(Freetype REQUIRED)
181+
if(UNIX)
182+
include(FindPkgConfig)
183+
if(PKG_CONFIG_FOUND)
184+
pkg_check_modules(FREETYPE QUIET freetype2)
185+
if(FREETYPE_FOUND)
186+
SET(FREETYPE_PKGCONFIG_FOUND TRUE)
187+
SET(FREETYPE_LIBRARY ${FREETYPE_LIBRARIES})
188+
endif(FREETYPE_FOUND)
189+
endif(PKG_CONFIG_FOUND)
190+
endif(UNIX)
191+
if(NOT FREETYPE_FOUND)
192+
find_package(Freetype REQUIRED)
193+
endif(NOT FREETYPE_FOUND)
182194
set(CGUITTFONT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cguittfont")
183195
set(CGUITTFONT_LIBRARY cguittfont)
184196
endif(USE_FREETYPE)
@@ -451,6 +463,12 @@ if(BUILD_CLIENT)
451463
)
452464
endif(USE_CURL)
453465
if(USE_FREETYPE)
466+
if(FREETYPE_PKGCONFIG_FOUND)
467+
set_target_properties(${PROJECT_NAME}
468+
PROPERTIES
469+
COMPILE_FLAGS "${FREETYPE_CFLAGS}"
470+
)
471+
endif(FREETYPE_PKGCONFIG_FOUND)
454472
target_link_libraries(
455473
${PROJECT_NAME}
456474
${FREETYPE_LIBRARY}

‎src/cguittfont/CMakeLists.txt

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
include_directories(
2-
${IRRLICHT_INCLUDE_DIR}
3-
${FREETYPE_INCLUDE_DIRS}
4-
)
5-
61
# CGUITTFont authors, y u no include headers you use?
72
# Do not add CGUITTFont.cpp to the line below.
83
# xCGUITTFont.cpp is a wrapper file that includes
94
# additional required headers.
105
add_library(cguittfont xCGUITTFont.cpp)
116

7+
if(FREETYPE_PKGCONFIG_FOUND)
8+
set_target_properties(cguittfont
9+
PROPERTIES
10+
COMPILE_FLAGS "${FREETYPE_CFLAGS}"
11+
LINK_FLAGS "${FREETYPE_LDFLAGS}"
12+
)
13+
14+
include_directories(
15+
${IRRLICHT_INCLUDE_DIR}
16+
)
17+
else(FREETYPE_PKGCONFIG_FOUND)
18+
include_directories(
19+
${IRRLICHT_INCLUDE_DIR}
20+
${FREETYPE_INCLUDE_DIRS}
21+
)
22+
endif(FREETYPE_PKGCONFIG_FOUND)
23+
1224
target_link_libraries(
13-
cguittfont
14-
${IRRLICHT_LIBRARY}
15-
${FREETYPE_LIBRARY}
16-
${ZLIB_LIBRARIES} # needed by freetype, repeated here for safety
17-
)
25+
cguittfont
26+
${IRRLICHT_LIBRARY}
27+
${FREETYPE_LIBRARY}
28+
${ZLIB_LIBRARIES} # needed by freetype, repeated here for safety
29+
)

0 commit comments

Comments
 (0)
Please sign in to comment.