* CMakeLists.txt: Make `cmake` handle disabled dependencies correctly.

Include 'CMakeDependentOption'.

Replace `FT_WITH_XXX` options with `FT_DISABLE_XXX` and `FT_REQUIRE_XXX`
pairs.  Update option logic accordingly.

Fixes #1066.
This commit is contained in:
AnuthaDev 2021-07-20 20:00:10 +05:30 committed by Werner Lemberg
parent 5bcaf51b61
commit 1f742f05bf
1 changed files with 100 additions and 53 deletions

View File

@ -12,13 +12,17 @@
# fully. # fully.
# #
# #
# The following will 1. create a build directory and 2. change into it and # The following will (1) create a build directory, and (2) change into it and
# call cmake to configure the build with default parameters as a static # call cmake to configure the build with default parameters as a static
# library. See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html # library. See
# for information about Debug, Release, etc. builds. #
# https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
#
# for information about debug or release builds, for example
# #
# cmake -B build -D CMAKE_BUILD_TYPE=Release # cmake -B build -D CMAKE_BUILD_TYPE=Release
# #
#
# For a dynamic library, use # For a dynamic library, use
# #
# cmake -B build -D BUILD_SHARED_LIBS=true -D CMAKE_BUILD_TYPE=Release # cmake -B build -D BUILD_SHARED_LIBS=true -D CMAKE_BUILD_TYPE=Release
@ -39,7 +43,8 @@
# #
# cmake -E chdir build cmake -G Xcode -D IOS_PLATFORM=SIMULATOR64 .. # cmake -E chdir build cmake -G Xcode -D IOS_PLATFORM=SIMULATOR64 ..
# #
# Finally, build the project with: #
# Finally, build the project with
# #
# cmake --build build # cmake --build build
# #
@ -56,40 +61,47 @@
# #
# Some notes. # Some notes.
# #
# . `cmake' creates configuration files in # - `cmake' creates configuration files in
# #
# <build-directory>/include/freetype/config # <build-directory>/include/freetype/config
# #
# which should be further modified if necessary. # which should be further modified if necessary.
# #
# . You can use `cmake' directly on a freshly cloned FreeType git # - You can use `cmake' directly on a freshly cloned FreeType git
# repository. # repository.
# #
# . `CMakeLists.txt' is provided as-is since it is normally not used by the # - `CMakeLists.txt' is provided as-is since it is normally not used by the
# developer team. # developer team.
# #
# . Set the `FT_WITH_ZLIB', `FT_WITH_BZIP2', `FT_WITH_PNG', # - Set the `FT_REQUIRE_ZLIB', `FT_REQUIRE_BZIP2', `FT_REQUIRE_PNG',
# `FT_WITH_HARFBUZZ', and `FT_WITH_BROTLI' CMake variables to `ON' to # `FT_REQUIRE_HARFBUZZ', and `FT_REQUIRE_BROTLI' CMake variables to `ON'
# force using a dependency. Leave a variable undefined (which is the # or `TRUE' to force using a dependency. Leave a variable undefined
# default) to use the dependency only if it is available. Example: # (which is the default) to use the dependency only if it is available.
# Example:
# #
# cmake -B build -D FT_WITH_ZLIB=ON \ # cmake -B build -D FT_REQUIRE_ZLIB=TRUE \
# -D FT_WITH_BZIP2=ON \ # -D FT_REQUIRE_BZIP2=TRUE \
# -D FT_WITH_PNG=ON \ # -D FT_REQUIRE_PNG=TRUE \
# -D FT_WITH_HARFBUZZ=ON \ # -D FT_REQUIRE_HARFBUZZ=TRUE \
# -D FT_WITH_BROTLI=ON [...] # -D FT_REQUIRE_BROTLI=TRUE [...]
# #
# Set `CMAKE_DISABLE_FIND_PACKAGE_XXX=TRUE' to disable a dependency completely # - Set `FT_DISABLE_XXX=TRUE' to disable a dependency completely (where
# (where `XXX' is a CMake package name like `BZip2'). Example for disabling all # `XXX' is a CMake package name like `BZip2'). Example for disabling all
# dependencies: # dependencies:
# #
# cmake -B build -D CMAKE_DISABLE_FIND_PACKAGE_ZLIB=TRUE \ # cmake -B build -D FT_DISABLE_ZLIB=TRUE \
# -D CMAKE_DISABLE_FIND_PACKAGE_BZip2=TRUE \ # -D FT_DISABLE_BZIP2=TRUE \
# -D CMAKE_DISABLE_FIND_PACKAGE_PNG=TRUE \ # -D FT_DISABLE_PNG=TRUE \
# -D CMAKE_DISABLE_FIND_PACKAGE_HarfBuzz=TRUE \ # -D FT_DISABLE_HARFBUZZ=TRUE \
# -D CMAKE_DISABLE_FIND_PACKAGE_BrotliDec=TRUE [...] # -D FT_DISABLE_BROTLI=TRUE [...]
# #
# . Installation of FreeType can be controlled with the CMake variables # - NOTE: If a package is set as DISABLED, it cannot be set as REQUIRED
# without unsetting the DISABLED value first. For example, if
# `FT_DISABLE_HARFBUZZ=TRUE' has been set (Cache is present), you need to
# call `FT_DISABLE_HARFBUZZ=FALSE' before calling
# `FT_REQUIRE_HARFBUZZ=TRUE'.
#
# - Installation of FreeType can be controlled with the CMake variables
# `SKIP_INSTALL_HEADERS', `SKIP_INSTALL_LIBRARIES', and `SKIP_INSTALL_ALL' # `SKIP_INSTALL_HEADERS', `SKIP_INSTALL_LIBRARIES', and `SKIP_INSTALL_ALL'
# (this is compatible with the same CMake variables in zlib's CMake # (this is compatible with the same CMake variables in zlib's CMake
# support). # support).
@ -109,6 +121,7 @@ if (NOT CMAKE_VERSION VERSION_LESS 3.3)
endif () endif ()
include(CheckIncludeFile) include(CheckIncludeFile)
include(CMakeDependentOption)
# CMAKE_TOOLCHAIN_FILE must be set before `project' is called, which # CMAKE_TOOLCHAIN_FILE must be set before `project' is called, which
# configures the base build environment and references the toolchain file # configures the base build environment and references the toolchain file
@ -171,13 +184,37 @@ string(REGEX REPLACE
math(EXPR LIBRARY_SOVERSION "${LIBTOOL_CURRENT} - ${LIBTOOL_AGE}") math(EXPR LIBRARY_SOVERSION "${LIBTOOL_CURRENT} - ${LIBTOOL_AGE}")
set(LIBRARY_VERSION "${LIBRARY_SOVERSION}.${LIBTOOL_AGE}.${LIBTOOL_REVISION}") set(LIBRARY_VERSION "${LIBRARY_SOVERSION}.${LIBTOOL_AGE}.${LIBTOOL_REVISION}")
# External dependency library detection is automatic. See the notes at the top # External dependency library detection is automatic. See the notes at the
# of this file, for how to force or disable dependencies completely. # top of this file, for how to force or disable dependencies completely.
option(FT_WITH_ZLIB "Use system zlib instead of internal library." OFF) option(FT_DISABLE_ZLIB
option(FT_WITH_BZIP2 "Support bzip2 compressed fonts." OFF) "Disable use of system zlib and use internal zlib library instead." OFF)
option(FT_WITH_PNG "Support PNG compressed OpenType embedded bitmaps." OFF) cmake_dependent_option(FT_REQUIRE_ZLIB
option(FT_WITH_HARFBUZZ "Improve auto-hinting of OpenType fonts." OFF) "Require system zlib instead of internal zlib library." OFF
option(FT_WITH_BROTLI "Support compressed WOFF2 fonts." OFF) "NOT FT_DISABLE_ZLIB" OFF)
option(FT_DISABLE_BZIP2
"Disable support of bzip2 compressed fonts." OFF)
cmake_dependent_option(FT_REQUIRE_BZIP2
"Require support of bzip2 compressed fonts." OFF
"NOT FT_DISABLE_BZIP2" OFF)
option(FT_DISABLE_PNG
"Disable support of PNG compressed OpenType embedded bitmaps." OFF)
cmake_dependent_option(FT_REQUIRE_PNG
"Require support of PNG compressed OpenType embedded bitmaps." OFF
"NOT FT_DISABLE_PNG" OFF)
option(FT_DISABLE_HARFBUZZ
"Disable HarfBuzz (used for improving auto-hinting of OpenType fonts)." OFF)
cmake_dependent_option(FT_REQUIRE_HARFBUZZ
"Require HarfBuzz for improving auto-hinting of OpenType fonts." OFF
"NOT FT_DISABLE_HARFBUZZ" OFF)
option(FT_DISABLE_BROTLI
"Disable support of compressed WOFF2 fonts." OFF)
cmake_dependent_option(FT_REQUIRE_BROTLI
"Require support of compressed WOFF2 fonts." OFF
"NOT FT_DISABLE_BROTLI" OFF)
# Disallow in-source builds # Disallow in-source builds
@ -208,35 +245,45 @@ endif ()
# Find dependencies # Find dependencies
set(HARFBUZZ_MIN_VERSION "2.0.0") if (NOT FT_DISABLE_HARFBUZZ)
if (FT_WITH_HARFBUZZ) set(HARFBUZZ_MIN_VERSION "2.0.0")
find_package(HarfBuzz ${HARFBUZZ_MIN_VERSION} REQUIRED) if (FT_REQUIRE_HARFBUZZ)
else () find_package(HarfBuzz ${HARFBUZZ_MIN_VERSION} REQUIRED)
find_package(HarfBuzz ${HARFBUZZ_MIN_VERSION}) else ()
find_package(HarfBuzz ${HARFBUZZ_MIN_VERSION})
endif ()
endif () endif ()
if (FT_WITH_PNG) if (NOT FT_DISABLE_PNG)
find_package(PNG REQUIRED) if (FT_REQUIRE_PNG)
else () find_package(PNG REQUIRED)
find_package(PNG) else ()
find_package(PNG)
endif ()
endif () endif ()
if (FT_WITH_ZLIB) if (NOT FT_DISABLE_ZLIB)
find_package(ZLIB REQUIRED) if (FT_REQUIRE_ZLIB)
else () find_package(ZLIB REQUIRED)
find_package(ZLIB) else ()
find_package(ZLIB)
endif ()
endif () endif ()
if (FT_WITH_BZIP2) if (NOT FT_DISABLE_BZIP2)
find_package(BZip2 REQUIRED) if (FT_REQUIRE_BZIP2)
else () find_package(BZip2 REQUIRED)
find_package(BZip2) else ()
find_package(BZip2)
endif ()
endif () endif ()
if (FT_WITH_BROTLI) if (NOT FT_DISABLE_BROTLI)
find_package(BrotliDec REQUIRED) if (FT_REQUIRE_BROTLI)
else () find_package(BrotliDec REQUIRED)
find_package(BrotliDec) else ()
find_package(BrotliDec)
endif ()
endif () endif ()
# Create the configuration file # Create the configuration file
@ -426,7 +473,7 @@ target_include_directories(
PRIVATE PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
# Make <ftconfig.h> available for builds/unix/ftsystem.c. # Make <ftconfig.h> available for builds/unix/ftsystem.c.
${CMAKE_CURRENT_BINARY_DIR}/include/freetype/config ${CMAKE_CURRENT_BINARY_DIR}/include/freetype/config
) )