Skip to content

Commit

Permalink
Fix statically linking against Freetype
Browse files Browse the repository at this point in the history
Freetype may require other libraries depending on how it was configured.
  • Loading branch information
dscharrer committed May 24, 2014
1 parent 4620044 commit ceb6604
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,6 @@ if(NOT MSVC AND CMAKE_THREAD_LIBS_INIT)
endif()
list(APPEND ARX_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})

# FreeType
use_static_libs(Freetype)
find_package(Freetype REQUIRED)
use_static_libs_restore()
if(NOT MSVC)
check_link_library(Freetype FREETYPE_LIBRARIES)
endif()
include_directories(SYSTEM ${FREETYPE_INCLUDE_DIRS})
list(APPEND ARX_LIBRARIES ${FREETYPE_LIBRARIES})

# zlib
use_static_libs(ZLIB)
find_package(ZLIB REQUIRED)
Expand All @@ -275,6 +265,57 @@ endif()
include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
list(APPEND ARX_LIBRARIES ${ZLIB_LIBRARIES})

# FreeType
use_static_libs(Freetype)
find_package(Freetype REQUIRED)
if(Freetype_USE_STATIC_LIBS)
# Freetype may require other libraries depending on how it was configured
find_package(PkgConfig QUIET)
pkg_check_modules(PC_Freetype freetype2)
foreach(lib IN LISTS PC_Freetype_STATIC_LIBRARIES)
if(lib MATCHES "(^|/|\\\\)(lib)?z(lib)?(\\.so|\\.a||.dll|\\.lib)?$")
if(NOT Freetype_LINKING_ZLIB)
message(STATUS "Freetype: statically linking ZLIB")
set(Freetype_LINKING_ZLIB 1 CACHE INTERNAL "foobar")
endif()
# We always link ZLIB
list(APPEND FREETYPE_LIBRARIES ${ZLIB_LIBRARIES})
elseif(lib MATCHES "(^|/|\\\\)(lib)?freetype")
# The main lib we linked above
elseif(lib MATCHES "(^|/|\\\\)(lib)?bz(ip)?2")
if(NOT Freetype_LINKING_BZip2)
message(STATUS "Freetype: statically linking BZip2")
set(Freetype_LINKING_BZip2 1 CACHE INTERNAL "foobar")
endif()
find_package(BZip2 REQUIRED)
list(APPEND FREETYPE_LIBRARIES ${BZIP2_LIBRARIES})
elseif(lib MATCHES "(^|/|\\\\)(lib)?png")
if(NOT Freetype_LINKING_PNG)
message(STATUS "Freetype: statically linking libpng")
set(Freetype_LINKING_PNG 1 CACHE INTERNAL "foobar")
endif()
find_package(PNG REQUIRED)
list(APPEND FREETYPE_LIBRARIES ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
else()
# We don't know this library so we can't easily search for a static version.
# Just looking for a static library with the same name is generally not enough
# as it too may require other libraries (and naming can differ).
message(WARNING "Freetype: linking unknown library \"${lib}\"")
if(EXISTS "${lib}" OR lib MATCHES "(/|\\\\)")
list(APPEND FREETYPE_LIBRARIES "${lib}")
else()
list(APPEND FREETYPE_LIBRARIES "-l${lib}")
endif()
endif()
endforeach()
endif()
use_static_libs_restore()
if(NOT MSVC)
check_link_library(Freetype FREETYPE_LIBRARIES)
endif()
include_directories(SYSTEM ${FREETYPE_INCLUDE_DIRS})
list(APPEND ARX_LIBRARIES ${FREETYPE_LIBRARIES})

# OpenGL
if(USE_OPENGL)
find_package(OpenGL ${OPTIONAL_DEPENDENCY})
Expand Down

0 comments on commit ceb6604

Please sign in to comment.