diff --git a/.gitignore b/.gitignore index b5db9d874..a47f568e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ config.mk objs/vc2010/ +build diff --git a/CMakeLists.txt b/CMakeLists.txt index 32006d3c7..067d1983a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,35 +12,44 @@ # 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 -# -# 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 +# 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 -# -# 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 +# cmake -E chdir build cmake -G Xcode -D IOS_PLATFORM=OS .. # # or # -# cmake -D IOS_PLATFORM=SIMULATOR -G Xcode +# 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 +# +# A source distribution can be made with +# +# cmake --build build --target package_source # # Please refer to the cmake manual for further options, in particular, how # to modify compilation and linking parameters. @@ -74,13 +83,17 @@ # (this is compatible with the same CMake variables in zlib's CMake # support). - -cmake_minimum_required(VERSION 2.6) - +# FreeType is build as part of the Python binding freetype-py. Python +# extensions for Linux are usually compiled against the manylinux1 target (PEP +# 513); the Manylinux1 Docker container provided by PyPa happens to contain a +# CentOS 5.11 with cmake 2.8.11.2 installed. Raising the minimum version makes +# sure this requirement is actually tested. +cmake_minimum_required(VERSION 2.8.11.2) +# Allow symbol visibility settings also on static libraries. +cmake_policy(SET CMP0063 NEW) 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 +129,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 +182,19 @@ 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}") + if (FT_WITH_${D} STREQUAL ON) + find_package(${d} REQUIRED) + else() + find_package(${d}) endif () endforeach () -message(STATUS - "Creating directory ${PROJECT_BINARY_DIR}/include/freetype/config") -file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/include/freetype/config") - - # 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 +204,27 @@ if (UNIX) FTCONFIG_H) if (HAVE_UNISTD_H) string(REGEX REPLACE - "#undef +(HAVE_UNISTD_H)" "#define \\1" + "#undef +HAVE_UNISTD_H" "#define HAVE_UNISTD_H 1" FTCONFIG_H "${FTCONFIG_H}") endif () if (HAVE_FCNTL_H) string(REGEX REPLACE - "#undef +(HAVE_FCNTL_H)" "#define \\1" + "#undef +HAVE_FCNTL_H" "#define HAVE_FCNTL_H 1" FTCONFIG_H "${FTCONFIG_H}") endif () if (HAVE_STDINT_H) string(REGEX REPLACE - "#undef +(HAVE_STDINT_H)" "#define \\1" + "#undef +HAVE_STDINT_H" "#define HAVE_STDINT_H 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 +247,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 +299,23 @@ set(BASE_SRCS ) if (WIN32) - set(BASE_SRCS ${BASE_SRCS} builds/windows/ftdebug.c) + list(APPEND BASE_SRCS builds/windows/ftdebug.c) 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 +323,32 @@ 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") + if (BUILD_FRAMEWORK) set_property(SOURCE ${PUBLIC_CONFIG_HEADERS} @@ -375,78 +375,90 @@ endif () if (ZLIB_FOUND) target_link_libraries(freetype ${MAYBE_PRIVATE} ${ZLIB_LIBRARIES}) - include_directories(${ZLIB_INCLUDE_DIRS}) + target_include_directories(freetype PRIVATE ${ZLIB_INCLUDE_DIRS}) endif () if (BZIP2_FOUND) target_link_libraries(freetype ${MAYBE_PRIVATE} ${BZIP2_LIBRARIES}) - include_directories(${BZIP2_INCLUDE_DIR}) # not BZIP2_INCLUDE_DIRS + target_include_directories(freetype PRIVATE ${BZIP2_INCLUDE_DIR}) # not BZIP2_INCLUDE_DIRS endif () if (PNG_FOUND) add_definitions(${PNG_DEFINITIONS}) target_link_libraries(freetype ${MAYBE_PRIVATE} ${PNG_LIBRARIES}) - include_directories(${PNG_INCLUDE_DIRS}) + target_include_directories(freetype PRIVATE ${PNG_INCLUDE_DIRS}) endif () if (HARFBUZZ_FOUND) target_link_libraries(freetype ${MAYBE_PRIVATE} ${HARFBUZZ_LIBRARIES}) - include_directories(${HARFBUZZ_INCLUDE_DIRS}) + target_include_directories(freetype PRIVATE ${HARFBUZZ_INCLUDE_DIRS}) endif () -# Installations -# Note the trailing slash in the argument to the `DIRECTORY' directive +# Installation +# XXX: Install documentation? +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 + 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_PACKAGE_VERSION_PATCH ${VERSION_PATCH}) +set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") + +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") set(CPACK_SOURCE_IGNORE_FILES - "/CVS/;/.svn/;.swp$;.#;/#;/build/;/serial/;/ser/;/parallel/;/par/;~;/preconfig.out;/autom4te.cache/;/.config") -set(CPACK_GENERATOR TGZ) -include(CPack) + "/[.]git/;.gitignore;.swp$;.#;/#;/build/;/objs/;/serial/;/ser/;/parallel/;/par/;~;/preconfig.out;/autom4te.cache/;/.config") +if (WIN32) + set(CPACK_SOURCE_GENERATOR ZIP) + set(CPACK_GENERATOR ZIP) +else() + set(CPACK_SOURCE_GENERATOR TGZ) + 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/builds/cmake/FindHarfBuzz.cmake b/builds/cmake/FindHarfBuzz.cmake index f394b82bf..04ff47af0 100644 --- a/builds/cmake/FindHarfBuzz.cmake +++ b/builds/cmake/FindHarfBuzz.cmake @@ -31,42 +31,55 @@ # 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 "") +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 () - 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} +endif () + +if ("${Harfbuzz_FIND_VERSION}" VERSION_GREATER "${HARFBUZZ_VERSION}") + message(FATAL_ERROR "Required version (" ${Harfbuzz_FIND_VERSION} ") is higher than found version (" ${CAIRO_VERSION} ")") +endif () + +# HarfBuzz 0.9.18 split ICU support into a separate harfbuzz-icu library. +if ("${HARFBUZZ_VERSION}" VERSION_GREATER "0.9.17") + pkg_check_modules(PC_HARFBUZZ_ICU QUIET harfbuzz-icu) + + find_library(HARFBUZZ_ICU_LIBRARIES harfbuzz-icu + HINTS ${PC_HARFBUZZ_ICU_LIBDIR} + ${PC_HARFBUZZ_ICU_LIBRARY_DIRS} ) - if (HARFBUZZ_ICU_LIBRARIES) - list(APPEND HARFBUZZ_LIBRARIES "${HARFBUZZ_ICU_LIBRARIES}") + + if (NOT HARFBUZZ_ICU_LIBRARIES) + message(FATAL_ERROR "harfbuzz-icu library not found") endif () - set(_HARFBUZZ_EXTRA_REQUIRED_VAR "HARFBUZZ_ICU_LIBRARIES") -else () - set(_HARFBUZZ_EXTRA_REQUIRED_VAR "") + + list(APPEND HARFBUZZ_LIBRARIES "${HARFBUZZ_ICU_LIBRARIES}") 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 + HARFBUZZ_ICU_LIBRARIES )