From 029721d69c8073fa4b5c78d19f6fa051a7ae3459 Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Sat, 7 Apr 2018 21:34:24 +0100 Subject: Modernize CMake build. * CMakeLists.txt, builds/cmake/FindHarfBuzz.cmake: Extensive modernization measures. * .gitignore: Add build/, as that's the example directory used in CMakeLists.txt. This brings up the minimum required CMake version to 2.8.12. The installation paths follow the GNU defaults now, e.g. installing on a 64 bit host will place binaries into the lib64/ folder on e.g. Fedora. Symbols are hidden by default (e.g. `-fvisibility=hidden' on GCC). CMake will no longer look for a C++ compiler. Library and .so version now match the Autotools build. Comments in the build file and informational messages now use platform agnostic example commands. ftoption.h and ftconfig.h are written directly without a redundant `-new' copy. External dependencies are expressed as option()s and will turn up as such in cmake-gui. Internal: Properties such as dependencies and include directories are now privately set on the freetype library instead of globally. The CPack definitions have been cleaned up, the `make dist' has been removed. Source packages generated with CPack don't contain Autotools files and aren't used by the maintainters anyway. On Windows, src/base/ftver.rc is compiled to decorate the library with version and copyright information. A pkg-config file is now generated and installed. --- builds/cmake/FindHarfBuzz.cmake | 57 ++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'builds') diff --git a/builds/cmake/FindHarfBuzz.cmake b/builds/cmake/FindHarfBuzz.cmake index f394b82bf..ee0d52e36 100644 --- a/builds/cmake/FindHarfBuzz.cmake +++ b/builds/cmake/FindHarfBuzz.cmake @@ -31,42 +31,51 @@ # HARFBUZZ_LIBRARIES - containg the HarfBuzz library include(FindPkgConfig) +pkg_check_modules(PC_HARFBUZZ QUIET harfbuzz) -pkg_check_modules(PC_HARFBUZZ harfbuzz>=0.9.7) - -find_path(HARFBUZZ_INCLUDE_DIRS NAMES hb.h - HINTS ${PC_HARFBUZZ_INCLUDE_DIRS} ${PC_HARFBUZZ_INCLUDEDIR} +find_path(HARFBUZZ_INCLUDE_DIRS + NAMES hb.h + HINTS ${PC_HARFBUZZ_INCLUDEDIR} + ${PC_HARFBUZZ_INCLUDE_DIRS} + PATH_SUFFIXES harfbuzz ) find_library(HARFBUZZ_LIBRARIES NAMES harfbuzz - HINTS ${PC_HARFBUZZ_LIBRARY_DIRS} ${PC_HARFBUZZ_LIBDIR} + HINTS ${PC_HARFBUZZ_LIBDIR} + ${PC_HARFBUZZ_LIBRARY_DIRS} ) -# HarfBuzz 0.9.18 split ICU support into a separate harfbuzz-icu library. -if ("${PC_HARFBUZZ_VERSION}" VERSION_GREATER "0.9.17") - if (HarfBuzz_FIND_REQUIRED) - set(_HARFBUZZ_REQUIRED REQUIRED) - else () - set(_HARFBUZZ_REQUIRED "") - endif () - pkg_check_modules(PC_HARFBUZZ_ICU harfbuzz-icu>=0.9.18 ${_HARFBUZZ_REQUIRED}) - find_library(HARFBUZZ_ICU_LIBRARIES NAMES harfbuzz-icu - HINTS ${PC_HARFBUZZ_ICU_LIBRARY_DIRS} ${PC_HARFBUZZ_ICU_LIBDIR} - ) - if (HARFBUZZ_ICU_LIBRARIES) - list(APPEND HARFBUZZ_LIBRARIES "${HARFBUZZ_ICU_LIBRARIES}") +if (HARFBUZZ_INCLUDE_DIRS) + if (EXISTS "${HARFBUZZ_INCLUDE_DIRS}/hb-version.h") + file(READ "${HARFBUZZ_INCLUDE_DIRS}/hb-version.h" _harfbuzz_version_content) + + string(REGEX MATCH "#define +HB_VERSION_STRING +\"([0-9]+\\.[0-9]+\\.[0-9]+)\"" _dummy "${_harfbuzz_version_content}") + set(HARFBUZZ_VERSION "${CMAKE_MATCH_1}") endif () - set(_HARFBUZZ_EXTRA_REQUIRED_VAR "HARFBUZZ_ICU_LIBRARIES") -else () - set(_HARFBUZZ_EXTRA_REQUIRED_VAR "") +endif () + +if ("${harfbuzz_FIND_VERSION}" VERSION_GREATER "${HARFBUZZ_VERSION}") + message(FATAL_ERROR "Required version (" ${harfbuzz_FIND_VERSION} ") is higher than found version (" ${HARFBUZZ_VERSION} ")") endif () include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(HarfBuzz DEFAULT_MSG HARFBUZZ_INCLUDE_DIRS - HARFBUZZ_LIBRARIES ${_HARFBUZZ_EXTRA_REQUIRED_VAR}) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( + harfbuzz + REQUIRED_VARS HARFBUZZ_INCLUDE_DIRS HARFBUZZ_LIBRARIES + VERSION_VAR HARFBUZZ_VERSION) mark_as_advanced( - HARFBUZZ_ICU_LIBRARIES HARFBUZZ_INCLUDE_DIRS HARFBUZZ_LIBRARIES ) + +# Allows easy linking as in +# target_link_libraries(freetype PRIVATE Harfbuzz::Harfbuzz) +if (NOT CMAKE_VERSION VERSION_LESS 3.1) + if (HARFBUZZ_FOUND AND NOT TARGET Harfbuzz::Harfbuzz) + add_library(Harfbuzz::Harfbuzz INTERFACE IMPORTED) + set_target_properties( + Harfbuzz::Harfbuzz PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HARFBUZZ_INCLUDE_DIRS}") + endif () +endif () -- cgit v1.2.1