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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
diff --git a/.gitignore b/.gitignore
index b5db9d8..a47f568 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
config.mk
objs/vc2010/
+build
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 32006d3..95daeb7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,35 +12,40 @@
# fully.
#
#
-# As a preliminary, create a compilation directory and change into it, for
-# example
+# 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
+# library.
#
-# mkdir ~/freetype2.compiled
-# cd ~/freetype2.compiled
-#
-# Now you can say
-#
-# cmake <path-to-freetype2-src-dir>
-#
-# to create a Makefile that builds a static version of the library.
+# cmake -E make_directory build
+# cmake -E chdir build cmake ..
#
# For a dynamic library, use
#
-# cmake -D BUILD_SHARED_LIBS:BOOL=true <path-to-freetype2-src-dir>
+# cmake -E chdir build cmake -D BUILD_SHARED_LIBS:BOOL=true ..
#
# For a framework on OS X, use
#
-# cmake -D BUILD_FRAMEWORK:BOOL=true -G Xcode <path-to-freetype2-src-dir>
-#
-# instead.
+# cmake -E chdir build cmake -G Xcode -D BUILD_FRAMEWORK:BOOL=true ..
#
# For an iOS static library, use
#
-# cmake -D IOS_PLATFORM=OS -G Xcode <path-to-freetype2-src-dir>
+# cmake -E chdir build cmake -G Xcode -D IOS_PLATFORM=OS ..
#
# or
#
-# cmake -D IOS_PLATFORM=SIMULATOR -G Xcode <path-to-freetype2-src-dir>
+# cmake -E chdir build cmake -G Xcode -D IOS_PLATFORM=SIMULATOR ..
+#
+# Finally, build the project with:
+#
+# cmake --build build
+#
+# Install it with
+#
+# (sudo) cmake --build build --target install
+#
+# A binary distribution can be made with
+#
+# cmake --build build --config Release --target package
#
# Please refer to the cmake manual for further options, in particular, how
# to modify compilation and linking parameters.
@@ -59,28 +64,33 @@
# . `CMakeLists.txt' is provided as-is since it is normally not used by the
# developer team.
#
-# . If you want to disable the automatic generation of the distribution
-# targets, add the `-D FREETYPE_NO_DIST=true' command line argument.
-#
-# . Set the `WITH_ZLIB', `WITH_BZip2', `WITH_PNG', and `WITH_HarfBuzz'
-# CMake variables to `ON' or `OFF' to force or skip using a dependency.
+# . Set the `FT_WITH_ZLIB', `FT_WITH_BZIP2', `FT_WITH_PNG', and
+# `FT_WITH_HARFBUZZ' CMake variables to `ON' to force using a dependency.
# Leave a variable undefined (which is the default) to use the dependency
-# only if it is available. Example:
+# only if it is available. Set `CMAKE_DISABLE_FIND_PACKAGE_HarfBuzz=TRUE' to
+# disable a dependency completely (CMake package name, so `BZip2' instead of
+# `BZIP2'). Example:
#
-# cmake ... -DWITH_ZLIB=ON -DWITH_HarfBuzz=OFF ...
+# cmake -DFT_WITH_ZLIB=ON -DCMAKE_DISABLE_FIND_PACKAGE_HarfBuzz=TRUE [...]
#
# . Installation of FreeType can be controlled with the CMake variables
# `SKIP_INSTALL_HEADERS', `SKIP_INSTALL_LIBRARIES', and `SKIP_INSTALL_ALL'
# (this is compatible with the same CMake variables in zlib's CMake
# support).
+# FreeType explicitly marks the API to be exported and relies on the compiler
+# to hide all other symbols. CMake supports a C_VISBILITY_PRESET property
+# starting with 2.8.12.
+cmake_minimum_required(VERSION 2.8.12)
-cmake_minimum_required(VERSION 2.6)
-
+if (NOT CMAKE_VERSION VERSION_LESS 3.3)
+ # Allow symbol visibility settings also on static libraries. CMake < 3.3
+ # only sets the propery on a shared library build.
+ cmake_policy(SET CMP0063 NEW)
+endif ()
include(CheckIncludeFile)
-
# CMAKE_TOOLCHAIN_FILE must be set before `project' is called, which
# configures the base build environment and references the toolchain file
if (APPLE)
@@ -116,26 +126,47 @@ else ()
endif ()
-project(freetype)
+project(freetype C)
+
+set(VERSION_MAJOR "2")
+set(VERSION_MINOR "9")
+set(VERSION_PATCH "0")
+
+# SOVERSION scheme: CURRENT.AGE.REVISION
+# If there was an incompatible interface change:
+# Increment CURRENT. Set AGE and REVISION to 0
+# If there was a compatible interface change:
+# Increment AGE. Set REVISION to 0
+# If the source code was changed, but there were no interface changes:
+# Increment REVISION.
+set(LIBRARY_VERSION "6.16.0")
+set(LIBRARY_SOVERSION "6")
+
+# These options mean "require x and complain if not found". They'll get
+# optionally found anyway. Use `-DCMAKE_DISABLE_FIND_PACKAGE_x=TRUE` to disable
+# searching for a packge entirely (x is the CMake package name, so "BZip2"
+# instead of "BZIP2").
+option(FT_WITH_ZLIB "Use system zlib instead of internal library." OFF)
+option(FT_WITH_BZIP2 "Support bzip2 compressed fonts." OFF)
+option(FT_WITH_PNG "Support PNG compressed OpenType embedded bitmaps." OFF)
+option(FT_WITH_HARFBUZZ "Improve auto-hinting of OpenType fonts." OFF)
# Disallow in-source builds
if ("${PROJECT_BINARY_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
message(FATAL_ERROR
- "
-In-source builds are not permitted! Make a separate folder for"
- " building, e.g.,"
- "
- mkdir build; cd build; cmake .."
- "
-Before that, remove the files created by this failed run with"
- "
- rm -rf CMakeCache.txt CMakeFiles")
+ "In-source builds are not permitted! Make a separate folder for"
+ " building, e.g.,\n"
+ " cmake -E make_directory build\n"
+ " cmake -E chdir build cmake ..\n"
+ "Before that, remove the files created by this failed run with\n"
+ " cmake -E remove CMakeCache.txt\n"
+ " cmake -E remove_directory CMakeFiles")
endif ()
# Add local cmake modules
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/builds/cmake)
+list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/builds/cmake)
if (BUILD_FRAMEWORK)
@@ -148,49 +179,32 @@ if (BUILD_FRAMEWORK)
endif ()
-set(VERSION_MAJOR "2")
-set(VERSION_MINOR "9")
-set(VERSION_PATCH "0")
-
-set(PROJECT_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
-set(SHARED_LIBRARY_VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
-
-
-# Compiler definitions for building the library
-add_definitions(-DFT2_BUILD_LIBRARY)
-if (WIN32)
- add_definitions(-D_CRT_SECURE_NO_WARNINGS)
- add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
-endif ()
-
-
# Find dependencies
-foreach (d ZLIB BZip2 PNG HarfBuzz)
- string(TOUPPER "${d}" D)
-
- if (DEFINED WITH_${d} OR DEFINED WITH_${D})
- if (WITH_${d} OR WITH_${D})
- find_package(${d} QUIET REQUIRED)
- endif ()
- else ()
- find_package(${d} QUIET)
- endif ()
-
- if (${d}_FOUND OR ${D}_FOUND)
- message(STATUS "Building with ${d}")
- endif ()
-endforeach ()
+if (FT_WITH_HARFBUZZ)
+ find_package(HarfBuzz 1.3.0 REQUIRED)
+else ()
+ find_package(HarfBuzz 1.3.0)
+endif ()
+if (FT_WITH_PNG)
+ find_package(PNG REQUIRED)
+else ()
+ find_package(PNG)
+endif ()
-message(STATUS
- "Creating directory ${PROJECT_BINARY_DIR}/include/freetype/config")
-file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/include/freetype/config")
+if (FT_WITH_ZLIB)
+ find_package(ZLIB REQUIRED)
+else ()
+ find_package(ZLIB)
+endif ()
+if (FT_WITH_BZIP2)
+ find_package(BZip2 REQUIRED)
+else ()
+ find_package(BZip2)
+endif ()
# Create the configuration file
-message(STATUS
- "Creating file ${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h")
-
if (UNIX)
check_include_file("unistd.h" HAVE_UNISTD_H)
check_include_file("fcntl.h" HAVE_FCNTL_H)
@@ -200,38 +214,27 @@ if (UNIX)
FTCONFIG_H)
if (HAVE_UNISTD_H)
string(REGEX REPLACE
- "#undef +(HAVE_UNISTD_H)" "#define \\1"
+ "#undef +(HAVE_UNISTD_H)" "#define \\1 1"
FTCONFIG_H "${FTCONFIG_H}")
endif ()
if (HAVE_FCNTL_H)
string(REGEX REPLACE
- "#undef +(HAVE_FCNTL_H)" "#define \\1"
+ "#undef +(HAVE_FCNTL_H)" "#define \\1 1"
FTCONFIG_H "${FTCONFIG_H}")
endif ()
if (HAVE_STDINT_H)
string(REGEX REPLACE
- "#undef +(HAVE_STDINT_H)" "#define \\1"
+ "#undef +(HAVE_STDINT_H)" "#define \\1 1"
FTCONFIG_H "${FTCONFIG_H}")
endif ()
string(REPLACE "/undef " "#undef "
FTCONFIG_H "${FTCONFIG_H}")
- file(WRITE "${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h-new"
- "${FTCONFIG_H}")
-else ()
- file(READ "${PROJECT_SOURCE_DIR}/include/freetype/config/ftconfig.h"
- FTCONFIG_H)
- file(WRITE "${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h-new"
+ file(WRITE "${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h"
"${FTCONFIG_H}")
endif ()
-execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
- "${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h-new"
- "${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h")
# Create the options file
-message(STATUS
- "Creating file ${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h")
-
file(READ "${PROJECT_SOURCE_DIR}/include/freetype/config/ftoption.h"
FTOPTION_H)
if (ZLIB_FOUND)
@@ -254,16 +257,8 @@ if (HARFBUZZ_FOUND)
"/\\* +(#define +FT_CONFIG_OPTION_USE_HARFBUZZ) +\\*/" "\\1"
FTOPTION_H "${FTOPTION_H}")
endif ()
-file(WRITE "${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h-new"
+file(WRITE "${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h"
"${FTOPTION_H}")
-execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
- "${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h-new"
- "${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h")
-
-
-# Specify library include directories
-include_directories("${PROJECT_SOURCE_DIR}/include")
-include_directories(BEFORE "${PROJECT_BINARY_DIR}/include")
file(GLOB PUBLIC_HEADERS "include/ft2build.h" "include/freetype/*.h")
@@ -314,25 +309,25 @@ set(BASE_SRCS
)
if (WIN32)
- set(BASE_SRCS ${BASE_SRCS} builds/windows/ftdebug.c)
+ enable_language(RC)
+ list(APPEND BASE_SRCS builds/windows/ftdebug.c
+ src/base/ftver.rc)
elseif (WINCE)
- set(BASE_SRCS ${BASE_SRCS} builds/wince/ftdebug.c)
+ list(APPEND BASE_SRCS builds/wince/ftdebug.c)
else ()
- set(BASE_SRCS ${BASE_SRCS} src/base/ftdebug.c)
+ list(APPEND BASE_SRCS src/base/ftdebug.c)
endif ()
-
if (BUILD_FRAMEWORK)
- set(BASE_SRCS
- ${BASE_SRCS}
- builds/mac/freetype-Info.plist
- )
+ list(APPEND BASE_SRCS builds/mac/freetype-Info.plist)
endif ()
+
if (NOT DISABLE_FORCE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX d)
endif()
+
add_library(freetype
${PUBLIC_HEADERS}
${PUBLIC_CONFIG_HEADERS}
@@ -340,15 +335,35 @@ add_library(freetype
${BASE_SRCS}
)
+set_target_properties(
+ freetype PROPERTIES
+ C_VISIBILITY_PRESET hidden)
+
+target_compile_definitions(
+ freetype PRIVATE FT2_BUILD_LIBRARY)
+
+if (WIN32)
+ target_compile_definitions(
+ freetype PRIVATE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS)
+endif ()
if (BUILD_SHARED_LIBS)
set_target_properties(freetype PROPERTIES
- VERSION ${PROJECT_VERSION}
- SOVERSION ${SHARED_LIBRARY_VERSION}
- COMPILE_DEFINITIONS freetype_EXPORTS
- )
+ VERSION ${LIBRARY_VERSION}
+ SOVERSION ${LIBRARY_SOVERSION})
endif ()
+target_include_directories(
+ freetype BEFORE # Pick up ftconfig.h and ftoption.h generated above.
+ PRIVATE "${PROJECT_BINARY_DIR}/include")
+
+target_include_directories(
+ freetype
+ PRIVATE "${PROJECT_SOURCE_DIR}/include")
+
+target_include_directories(
+ freetype
+ PUBLIC $<INSTALL_INTERFACE:include/freetype2>)
if (BUILD_FRAMEWORK)
set_property(SOURCE ${PUBLIC_CONFIG_HEADERS}
@@ -362,91 +377,121 @@ if (BUILD_FRAMEWORK)
)
endif ()
-if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)
- target_include_directories(freetype
- PUBLIC $<INSTALL_INTERFACE:include/freetype2>)
-endif ()
-if (CMAKE_VERSION VERSION_LESS 2.8.12)
- set(MAYBE_PRIVATE "")
-else ()
- set(MAYBE_PRIVATE "PRIVATE")
-endif ()
+set(PKG_CONFIG_REQUIRED_PRIVATE "")
if (ZLIB_FOUND)
- target_link_libraries(freetype ${MAYBE_PRIVATE} ${ZLIB_LIBRARIES})
- include_directories(${ZLIB_INCLUDE_DIRS})
+ target_link_libraries(freetype PRIVATE ${ZLIB_LIBRARIES})
+ target_include_directories(freetype PRIVATE ${ZLIB_INCLUDE_DIRS})
+ list(APPEND PKG_CONFIG_REQUIRED_PRIVATE zlib)
endif ()
if (BZIP2_FOUND)
- target_link_libraries(freetype ${MAYBE_PRIVATE} ${BZIP2_LIBRARIES})
- include_directories(${BZIP2_INCLUDE_DIR}) # not BZIP2_INCLUDE_DIRS
+ target_link_libraries(freetype PRIVATE ${BZIP2_LIBRARIES})
+ target_include_directories(freetype PRIVATE ${BZIP2_INCLUDE_DIR}) # not BZIP2_INCLUDE_DIRS
+ list(APPEND PKG_CONFIG_REQUIRED_PRIVATE bzip2)
endif ()
if (PNG_FOUND)
- add_definitions(${PNG_DEFINITIONS})
- target_link_libraries(freetype ${MAYBE_PRIVATE} ${PNG_LIBRARIES})
- include_directories(${PNG_INCLUDE_DIRS})
+ target_link_libraries(freetype PRIVATE ${PNG_LIBRARIES})
+ target_compile_definitions(freetype PRIVATE ${PNG_DEFINITIONS})
+ target_include_directories(freetype PRIVATE ${PNG_INCLUDE_DIRS})
+ list(APPEND PKG_CONFIG_REQUIRED_PRIVATE libpng)
endif ()
if (HARFBUZZ_FOUND)
- target_link_libraries(freetype ${MAYBE_PRIVATE} ${HARFBUZZ_LIBRARIES})
- include_directories(${HARFBUZZ_INCLUDE_DIRS})
+ target_link_libraries(freetype PRIVATE ${HARFBUZZ_LIBRARIES})
+ target_include_directories(freetype PRIVATE ${HARFBUZZ_INCLUDE_DIRS})
+ list(APPEND PKG_CONFIG_REQUIRED_PRIVATE harfbuzz)
endif ()
-# Installations
-# Note the trailing slash in the argument to the `DIRECTORY' directive
+# Installation
+include(GNUInstallDirs)
+
if (NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL)
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
- DESTINATION include/freetype2
- PATTERN "internal" EXCLUDE
- PATTERN "ftconfig.h" EXCLUDE
- PATTERN "ftoption.h" EXCLUDE
- )
- install(FILES
- ${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h
- ${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h
- DESTINATION include/freetype2/freetype/config
- )
+ install(
+ # Note the trailing slash in the argument to `DIRECTORY'!
+ DIRECTORY ${PROJECT_SOURCE_DIR}/include/
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/freetype2
+ COMPONENT headers
+ PATTERN "internal" EXCLUDE
+ PATTERN "ftconfig.h" EXCLUDE
+ PATTERN "ftoption.h" EXCLUDE)
+ install(
+ FILES ${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h
+ ${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/freetype2/freetype/config
+ COMPONENT headers)
endif ()
if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
- install(TARGETS freetype
+ # Generate the pkg-config file
+ if (UNIX)
+ file(READ ${PROJECT_SOURCE_DIR}/builds/unix/freetype2.in FREETYPE2_PC_IN)
+
+ string(REPLACE ";" ", " PKG_CONFIG_REQUIRED_PRIVATE "${PKG_CONFIG_REQUIRED_PRIVATE}")
+
+ string(REPLACE "%prefix%" ${CMAKE_INSTALL_PREFIX}
+ FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
+ string(REPLACE "%exec_prefix%" "\${prefix}"
+ FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
+ string(REPLACE "%libdir%" "\${prefix}/${CMAKE_INSTALL_LIBDIR}"
+ FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
+ string(REPLACE "%includedir%" "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}"
+ FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
+ string(REPLACE "%ft_version%" "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
+ FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
+ string(REPLACE "%REQUIRES_PRIVATE%" "${PKG_CONFIG_REQUIRED_PRIVATE}"
+ FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
+ string(REPLACE "%LIBS_PRIVATE%" "" # All libs support pkg-config
+ FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
+
+ file(WRITE ${PROJECT_BINARY_DIR}/freetype2.pc ${FREETYPE2_PC_IN})
+
+ install(
+ FILES ${PROJECT_BINARY_DIR}/freetype2.pc
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
+ COMPONENT pkgconfig)
+ endif ()
+
+ install(
+ TARGETS freetype
+ EXPORT freetype-targets
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ FRAMEWORK DESTINATION Library/Frameworks
+ COMPONENT libraries)
+ install(
EXPORT freetype-targets
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION lib
- ARCHIVE DESTINATION lib
- FRAMEWORK DESTINATION Library/Frameworks
- )
- install(EXPORT freetype-targets
- DESTINATION lib/cmake/freetype
- FILE freetype-config.cmake
- )
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/freetype
+ FILE freetype-config.cmake
+ COMPONENT headers)
endif ()
# Packaging
-# CPack version numbers for release tarball name.
+set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The FreeType font rendering library.")
+set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/docs/LICENSE.TXT")
+
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
-set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH}})
-if (NOT DEFINED CPACK_PACKAGE_DESCRIPTION_SUMMARY)
- set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CMAKE_PROJECT_NAME}")
-endif ()
-if (NOT DEFINED CPACK_SOURCE_PACKAGE_FILE_NAME)
- set(CPACK_SOURCE_PACKAGE_FILE_NAME
- "${CMAKE_PROJECT_NAME}-${PROJECT_VERSION}-r${PROJECT_REV}"
- CACHE INTERNAL "tarball basename"
- )
-endif ()
-set(CPACK_SOURCE_GENERATOR TGZ)
-set(CPACK_SOURCE_IGNORE_FILES
- "/CVS/;/.svn/;.swp$;.#;/#;/build/;/serial/;/ser/;/parallel/;/par/;~;/preconfig.out;/autom4te.cache/;/.config")
-set(CPACK_GENERATOR TGZ)
-include(CPack)
+set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
+set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
+if (WIN32)
+ set(CPACK_GENERATOR ZIP)
+else()
+ set(CPACK_GENERATOR TGZ)
+endif()
-# Add `make dist' target if FREETYPE_DIST is set (which is the default)
-if (NOT DEFINED FREETYPE_NO_DIST)
- add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
-endif ()
+set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
+set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C/C++ Headers")
+set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
+ "Library used to build programs which use FreeType")
+set(CPACK_COMPONENT_HEADERS_DESCRIPTION
+ "C/C++ header files for use with FreeType")
+set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
+set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
+set(CPACK_COMPONENT_HEADERS_GROUP "Development")
-# eof
+include(CPack)
diff --git a/ChangeLog b/ChangeLog
index 01ed40e..8a108b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+2018-04-10 Nikolaus Waxweiler <madigens@gmail.com>
+
+ * CMakeLists.txt, builds/cmake/FindHarfBuzz.cmake: Extensive
+ modernization measures.
+
+ 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.
+
2018-04-09 Werner Lemberg <wl@gnu.org>
[truetype] Integer overflow issues.
diff --git a/builds/cmake/FindHarfBuzz.cmake b/builds/cmake/FindHarfBuzz.cmake
index f394b82..ee0d52e 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 ()