• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# CMakeLists.txt
2#
3# Copyright (C) 2013-2023 by
4# David Turner, Robert Wilhelm, and Werner Lemberg.
5#
6# Written originally by John Cary <cary@txcorp.com>
7#
8# This file is part of the FreeType project, and may only be used, modified,
9# and distributed under the terms of the FreeType project license,
10# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
11# indicate that you have read the license and understand and accept it
12# fully.
13#
14#
15# The following will (1) create a build directory, and (2) change into it and
16# call cmake to configure the build with default parameters as a static
17# library.  See
18#
19#   https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
20#
21# for information about debug or release builds, for example
22#
23#   cmake -B build -D CMAKE_BUILD_TYPE=Release
24#
25#
26# For a dynamic library, use
27#
28#   cmake -B build -D BUILD_SHARED_LIBS=true -D CMAKE_BUILD_TYPE=Release
29#
30# For a framework on OS X, use
31#
32#   cmake -E chdir build cmake -G Xcode -D BUILD_FRAMEWORK:BOOL=true ..
33#
34# For an iOS static library, use
35#
36#   cmake -E chdir build cmake -G Xcode -D IOS_PLATFORM=OS ..
37#
38# or
39#
40#   cmake -E chdir build cmake -G Xcode -D IOS_PLATFORM=SIMULATOR ..
41#
42# or
43#
44#   cmake -E chdir build cmake -G Xcode -D IOS_PLATFORM=SIMULATOR64 ..
45#
46#
47# Finally, build the project with
48#
49#   cmake --build build
50#
51# Install it with
52#
53#   (sudo) cmake --build build --target install
54#
55# A binary distribution can be made with
56#
57#   cmake --build build --config Release --target package
58#
59# Please refer to the cmake manual for further options, in particular, how
60# to modify compilation and linking parameters.
61#
62# Some notes.
63#
64# - Say `cmake -LAH` to see all configuration options.
65#
66# - `cmake' creates configuration files in
67#
68#     <build-directory>/include/freetype/config
69#
70#   which should be further modified if necessary.
71#
72# - You can use `cmake' directly on a freshly cloned FreeType git
73#   repository.
74#
75# - `CMakeLists.txt' is provided as-is since it is normally not used by the
76#   developer team.
77#
78# - Set the `FT_REQUIRE_ZLIB', `FT_REQUIRE_BZIP2', `FT_REQUIRE_PNG',
79#   `FT_REQUIRE_HARFBUZZ', and `FT_REQUIRE_BROTLI' CMake variables to `ON'
80#   or `TRUE' to force using a dependency.  Leave a variable undefined
81#   (which is the default) to use the dependency only if it is available.
82#   Example:
83#
84#     cmake -B build -D FT_REQUIRE_ZLIB=TRUE \
85#                    -D FT_REQUIRE_BZIP2=TRUE \
86#                    -D FT_REQUIRE_PNG=TRUE \
87#                    -D FT_REQUIRE_HARFBUZZ=TRUE \
88#                    -D FT_REQUIRE_BROTLI=TRUE [...]
89#
90# - Set `FT_DISABLE_XXX=TRUE' to disable a dependency completely (where
91#   `XXX' is a CMake package name like `BZip2').  Example for disabling all
92#   dependencies:
93#
94#     cmake -B build -D FT_DISABLE_ZLIB=TRUE \
95#                    -D FT_DISABLE_BZIP2=TRUE \
96#                    -D FT_DISABLE_PNG=TRUE \
97#                    -D FT_DISABLE_HARFBUZZ=TRUE \
98#                    -D FT_DISABLE_BROTLI=TRUE [...]
99#
100# - NOTE: If a package is set as DISABLED, it cannot be set as REQUIRED
101#   without unsetting the DISABLED value first.  For example, if
102#   `FT_DISABLE_HARFBUZZ=TRUE' has been set (Cache is present), you need to
103#   call `FT_DISABLE_HARFBUZZ=FALSE' before calling
104#   `FT_REQUIRE_HARFBUZZ=TRUE'.
105#
106# - Installation of FreeType can be controlled with the CMake variables
107#   `SKIP_INSTALL_HEADERS', `SKIP_INSTALL_LIBRARIES', and `SKIP_INSTALL_ALL'
108#   (this is compatible with the same CMake variables in zlib's CMake
109#   support).
110
111# To minimize the number of cmake_policy() workarounds,
112# CMake >= 3 is requested.
113cmake_minimum_required(VERSION 3.0)
114
115if (NOT CMAKE_VERSION VERSION_LESS 3.3)
116  # Allow symbol visibility settings also on static libraries. CMake < 3.3
117  # only sets the property on a shared library build.
118  cmake_policy(SET CMP0063 NEW)
119
120  # Support new IN_LIST if() operator.
121  cmake_policy(SET CMP0057 NEW)
122endif ()
123
124include(CheckIncludeFile)
125include(CMakeDependentOption)
126
127# CMAKE_TOOLCHAIN_FILE must be set before `project' is called, which
128# configures the base build environment and references the toolchain file
129if (APPLE)
130  if (DEFINED IOS_PLATFORM)
131    if (NOT "${IOS_PLATFORM}" STREQUAL "OS"
132        AND NOT "${IOS_PLATFORM}" STREQUAL "SIMULATOR"
133        AND NOT "${IOS_PLATFORM}" STREQUAL "SIMULATOR64")
134      message(FATAL_ERROR
135        "IOS_PLATFORM must be set to either OS, SIMULATOR, or SIMULATOR64")
136    endif ()
137    if (NOT "${CMAKE_GENERATOR}" STREQUAL "Xcode")
138      message(AUTHOR_WARNING
139        "You should use Xcode generator with IOS_PLATFORM enabled to get Universal builds.")
140    endif ()
141    if (BUILD_SHARED_LIBS)
142      message(FATAL_ERROR
143        "BUILD_SHARED_LIBS can not be on with IOS_PLATFORM enabled")
144    endif ()
145    if (BUILD_FRAMEWORK)
146      message(FATAL_ERROR
147        "BUILD_FRAMEWORK can not be on with IOS_PLATFORM enabled")
148    endif ()
149
150    # iOS only uses static libraries
151    set(BUILD_SHARED_LIBS OFF)
152
153    set(CMAKE_TOOLCHAIN_FILE
154      ${CMAKE_SOURCE_DIR}/builds/cmake/iOS.cmake)
155  endif ()
156else ()
157  if (DEFINED IOS_PLATFORM)
158    message(FATAL_ERROR "IOS_PLATFORM is not supported on this platform")
159  endif ()
160endif ()
161
162
163project(freetype C)
164
165set(VERSION_MAJOR "2")
166set(VERSION_MINOR "13")
167set(VERSION_PATCH "2")
168
169# Generate LIBRARY_VERSION and LIBRARY_SOVERSION.
170set(LIBTOOL_REGEX "version_info='([0-9]+):([0-9]+):([0-9]+)'")
171file(STRINGS "${PROJECT_SOURCE_DIR}/builds/unix/configure.raw"
172  VERSION_INFO
173  REGEX ${LIBTOOL_REGEX})
174string(REGEX REPLACE
175  ${LIBTOOL_REGEX} "\\1"
176  LIBTOOL_CURRENT "${VERSION_INFO}")
177string(REGEX REPLACE
178  ${LIBTOOL_REGEX} "\\2"
179  LIBTOOL_REVISION "${VERSION_INFO}")
180string(REGEX REPLACE
181  ${LIBTOOL_REGEX} "\\3"
182  LIBTOOL_AGE "${VERSION_INFO}")
183
184# This is what libtool does internally on Unix platforms.
185math(EXPR LIBRARY_SOVERSION "${LIBTOOL_CURRENT} - ${LIBTOOL_AGE}")
186set(LIBRARY_VERSION "${LIBRARY_SOVERSION}.${LIBTOOL_AGE}.${LIBTOOL_REVISION}")
187
188# External dependency library detection is automatic.  See the notes at the
189# top of this file, for how to force or disable dependencies completely.
190option(FT_DISABLE_ZLIB
191  "Disable use of system zlib and use internal zlib library instead." OFF)
192cmake_dependent_option(FT_REQUIRE_ZLIB
193  "Require system zlib instead of internal zlib library." OFF
194  "NOT FT_DISABLE_ZLIB" OFF)
195
196option(FT_DISABLE_BZIP2
197  "Disable support of bzip2 compressed fonts." OFF)
198cmake_dependent_option(FT_REQUIRE_BZIP2
199  "Require support of bzip2 compressed fonts." OFF
200  "NOT FT_DISABLE_BZIP2" OFF)
201
202option(FT_DISABLE_PNG
203  "Disable support of PNG compressed OpenType embedded bitmaps." OFF)
204cmake_dependent_option(FT_REQUIRE_PNG
205  "Require support of PNG compressed OpenType embedded bitmaps." OFF
206  "NOT FT_DISABLE_PNG" OFF)
207
208option(FT_DISABLE_HARFBUZZ
209  "Disable HarfBuzz (used for improving auto-hinting of OpenType fonts)." OFF)
210cmake_dependent_option(FT_REQUIRE_HARFBUZZ
211  "Require HarfBuzz for improving auto-hinting of OpenType fonts." OFF
212  "NOT FT_DISABLE_HARFBUZZ" OFF)
213
214option(FT_DISABLE_BROTLI
215  "Disable support of compressed WOFF2 fonts." OFF)
216cmake_dependent_option(FT_REQUIRE_BROTLI
217  "Require support of compressed WOFF2 fonts." OFF
218  "NOT FT_DISABLE_BROTLI" OFF)
219
220option(FT_ENABLE_ERROR_STRINGS
221  "Enable support for meaningful error descriptions." OFF)
222
223# Disallow in-source builds
224if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
225  message(FATAL_ERROR
226    "In-source builds are not permitted!  Make a separate folder for"
227    " building, e.g.,\n"
228    "  cmake -E make_directory build\n"
229    "  cmake -E chdir build cmake ..\n"
230    "Before that, remove the files created by this failed run with\n"
231    "  cmake -E remove CMakeCache.txt\n"
232    "  cmake -E remove_directory CMakeFiles")
233endif ()
234
235
236# Add local cmake modules
237list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/builds/cmake)
238
239
240if (BUILD_FRAMEWORK)
241  if (NOT "${CMAKE_GENERATOR}" STREQUAL "Xcode")
242    message(FATAL_ERROR
243      "You should use Xcode generator with BUILD_FRAMEWORK enabled")
244  endif ()
245  set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)")
246  set(BUILD_SHARED_LIBS ON)
247endif ()
248
249
250# Find dependencies
251include(FindPkgConfig)
252
253if (NOT FT_DISABLE_HARFBUZZ)
254  set(HARFBUZZ_MIN_VERSION "2.0.0")
255  if (FT_REQUIRE_HARFBUZZ)
256    find_package(HarfBuzz ${HARFBUZZ_MIN_VERSION} REQUIRED)
257  else ()
258    find_package(HarfBuzz ${HARFBUZZ_MIN_VERSION})
259  endif ()
260endif ()
261
262if (NOT FT_DISABLE_PNG)
263  if (FT_REQUIRE_PNG)
264    find_package(PNG REQUIRED)
265  else ()
266    find_package(PNG)
267  endif ()
268endif ()
269
270if (NOT FT_DISABLE_ZLIB)
271  if (FT_REQUIRE_ZLIB)
272    find_package(ZLIB REQUIRED)
273  else ()
274    find_package(ZLIB)
275  endif ()
276endif ()
277
278if (NOT FT_DISABLE_BZIP2)
279  # Genuine BZip2 does not provide bzip2.pc, but some platforms have it.
280  # For better dependency in freetype2.pc, bzip2.pc is searched
281  # regardless of the availability of libbz2. If bzip2.pc is found,
282  # Requires.private is used instead of Libs.private.
283  if (FT_REQUIRE_BZIP2)
284    find_package(BZip2 REQUIRED)
285  else ()
286    find_package(BZip2)
287  endif ()
288  pkg_check_modules(PC_BZIP2 bzip2)
289endif ()
290
291if (NOT FT_DISABLE_BROTLI)
292  if (FT_REQUIRE_BROTLI)
293    find_package(BrotliDec REQUIRED)
294  else ()
295    find_package(BrotliDec)
296  endif ()
297endif ()
298
299# Create the configuration file
300if (UNIX)
301  check_include_file("unistd.h" HAVE_UNISTD_H)
302  check_include_file("fcntl.h" HAVE_FCNTL_H)
303
304  file(READ "${PROJECT_SOURCE_DIR}/builds/unix/ftconfig.h.in"
305    FTCONFIG_H)
306  if (HAVE_UNISTD_H)
307    string(REGEX REPLACE
308      "#undef +(HAVE_UNISTD_H)" "#define \\1 1"
309      FTCONFIG_H "${FTCONFIG_H}")
310  endif ()
311  if (HAVE_FCNTL_H)
312    string(REGEX REPLACE
313      "#undef +(HAVE_FCNTL_H)" "#define \\1 1"
314      FTCONFIG_H "${FTCONFIG_H}")
315  endif ()
316else ()
317  file(READ "${PROJECT_SOURCE_DIR}/include/freetype/config/ftconfig.h"
318    FTCONFIG_H)
319endif ()
320
321set(FTCONFIG_H_NAME "${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h")
322if (EXISTS "${FTCONFIG_H_NAME}")
323  file(READ "${FTCONFIG_H_NAME}" ORIGINAL_FTCONFIG_H)
324else ()
325  set(ORIGINAL_FTCONFIG_H "")
326endif ()
327if (NOT (ORIGINAL_FTCONFIG_H STREQUAL FTCONFIG_H))
328  file(WRITE "${FTCONFIG_H_NAME}" "${FTCONFIG_H}")
329endif ()
330
331
332# Create the options file
333file(READ "${PROJECT_SOURCE_DIR}/include/freetype/config/ftoption.h"
334  FTOPTION_H)
335if (ZLIB_FOUND)
336  string(REGEX REPLACE
337    "/\\* +(#define +FT_CONFIG_OPTION_SYSTEM_ZLIB) +\\*/" "\\1"
338    FTOPTION_H "${FTOPTION_H}")
339endif ()
340if (BZIP2_FOUND)
341  string(REGEX REPLACE
342    "/\\* +(#define +FT_CONFIG_OPTION_USE_BZIP2) +\\*/" "\\1"
343    FTOPTION_H "${FTOPTION_H}")
344endif ()
345if (PNG_FOUND)
346  string(REGEX REPLACE
347    "/\\* +(#define +FT_CONFIG_OPTION_USE_PNG) +\\*/" "\\1"
348    FTOPTION_H "${FTOPTION_H}")
349endif ()
350if (HARFBUZZ_FOUND)
351  string(REGEX REPLACE
352    "/\\* +(#define +FT_CONFIG_OPTION_USE_HARFBUZZ) +\\*/" "\\1"
353    FTOPTION_H "${FTOPTION_H}")
354endif ()
355if (BROTLIDEC_FOUND)
356  string(REGEX REPLACE
357    "/\\* +(#define +FT_CONFIG_OPTION_USE_BROTLI) +\\*/" "\\1"
358    FTOPTION_H "${FTOPTION_H}")
359endif ()
360
361if (FT_ENABLE_ERROR_STRINGS)
362  string(REGEX REPLACE
363    "/\\* +(#define +FT_CONFIG_OPTION_ERROR_STRINGS) +\\*/" "\\1"
364    FTOPTION_H "${FTOPTION_H}")
365endif ()
366
367set(FTOPTION_H_NAME "${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h")
368if (EXISTS "${FTOPTION_H_NAME}")
369  file(READ "${FTOPTION_H_NAME}" ORIGINAL_FTOPTION_H)
370else ()
371  set(ORIGINAL_FTOPTION_H "")
372endif ()
373if (NOT (ORIGINAL_FTOPTION_H STREQUAL FTOPTION_H))
374  file(WRITE "${FTOPTION_H_NAME}" "${FTOPTION_H}")
375endif ()
376
377
378file(GLOB PUBLIC_HEADERS "include/ft2build.h" "include/freetype/*.h")
379file(GLOB PUBLIC_CONFIG_HEADERS "include/freetype/config/*.h")
380file(GLOB PRIVATE_HEADERS "include/freetype/internal/*.h")
381
382
383set(BASE_SRCS
384  src/autofit/autofit.c
385  src/base/ftbase.c
386  src/base/ftbbox.c
387  src/base/ftbdf.c
388  src/base/ftbitmap.c
389  src/base/ftcid.c
390  src/base/ftfstype.c
391  src/base/ftgasp.c
392  src/base/ftglyph.c
393  src/base/ftgxval.c
394  src/base/ftinit.c
395  src/base/ftmm.c
396  src/base/ftotval.c
397  src/base/ftpatent.c
398  src/base/ftpfr.c
399  src/base/ftstroke.c
400  src/base/ftsynth.c
401  src/base/fttype1.c
402  src/base/ftwinfnt.c
403  src/bdf/bdf.c
404  src/bzip2/ftbzip2.c
405  src/cache/ftcache.c
406  src/cff/cff.c
407  src/cid/type1cid.c
408  src/gzip/ftgzip.c
409  src/lzw/ftlzw.c
410  src/pcf/pcf.c
411  src/pfr/pfr.c
412  src/psaux/psaux.c
413  src/pshinter/pshinter.c
414  src/psnames/psnames.c
415  src/raster/raster.c
416  src/sdf/sdf.c
417  src/sfnt/sfnt.c
418  src/smooth/smooth.c
419  src/svg/svg.c
420  src/truetype/truetype.c
421  src/type1/type1.c
422  src/type42/type42.c
423  src/winfonts/winfnt.c
424)
425
426if (UNIX)
427  list(APPEND BASE_SRCS "builds/unix/ftsystem.c")
428elseif (WIN32)
429  list(APPEND BASE_SRCS "builds/windows/ftsystem.c")
430else ()
431  list(APPEND BASE_SRCS "src/base/ftsystem.c")
432endif ()
433
434if (WIN32)
435  enable_language(RC)
436  list(APPEND BASE_SRCS builds/windows/ftdebug.c
437                        src/base/ftver.rc)
438elseif (WINCE)
439  list(APPEND BASE_SRCS builds/wince/ftdebug.c)
440else ()
441  list(APPEND BASE_SRCS src/base/ftdebug.c)
442endif ()
443
444if (BUILD_FRAMEWORK)
445  list(APPEND BASE_SRCS builds/mac/freetype-Info.plist)
446endif ()
447
448
449if (NOT DISABLE_FORCE_DEBUG_POSTFIX)
450  set(CMAKE_DEBUG_POSTFIX d)
451endif ()
452
453
454add_library(freetype
455  ${PUBLIC_HEADERS}
456  ${PUBLIC_CONFIG_HEADERS}
457  ${PRIVATE_HEADERS}
458  ${BASE_SRCS}
459)
460
461set_target_properties(
462  freetype PROPERTIES
463    C_VISIBILITY_PRESET hidden)
464
465target_compile_definitions(
466  freetype PRIVATE FT2_BUILD_LIBRARY)
467
468if (WIN32)
469  target_compile_definitions(
470    freetype PRIVATE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS)
471  if (BUILD_SHARED_LIBS)
472    target_compile_definitions(
473      freetype PRIVATE DLL_EXPORT)
474  endif ()
475endif ()
476
477if (BUILD_SHARED_LIBS)
478  set_target_properties(freetype PROPERTIES
479    VERSION ${LIBRARY_VERSION}
480    SOVERSION ${LIBRARY_SOVERSION})
481endif ()
482
483# Pick up ftconfig.h and ftoption.h generated above, first.
484target_include_directories(
485  freetype
486    PUBLIC
487      $<INSTALL_INTERFACE:include/freetype2>
488      $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
489      $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
490    PRIVATE
491      ${CMAKE_CURRENT_BINARY_DIR}/include
492      ${CMAKE_CURRENT_SOURCE_DIR}/include
493
494      # Make <ftconfig.h> available for builds/unix/ftsystem.c.
495      ${CMAKE_CURRENT_BINARY_DIR}/include/freetype/config
496)
497
498
499if (BUILD_FRAMEWORK)
500  set_property(SOURCE ${PUBLIC_CONFIG_HEADERS}
501    PROPERTY MACOSX_PACKAGE_LOCATION Headers/config
502  )
503  set_target_properties(freetype PROPERTIES
504    FRAMEWORK TRUE
505    MACOSX_FRAMEWORK_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/builds/mac/freetype-Info.plist
506    PUBLIC_HEADER "${PUBLIC_HEADERS}"
507    XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
508  )
509endif ()
510
511# 'freetype-interface' is an interface library, to be accessed with
512# `EXPORT_NAME Freetype::Freetype`.  This is the target name provided by
513# CMake's `FindFreetype.cmake`, so we provide it for compatibility.
514add_library(freetype-interface INTERFACE)
515set_target_properties(freetype-interface PROPERTIES
516  EXPORT_NAME Freetype::Freetype
517  INTERFACE_LINK_LIBRARIES freetype)
518
519set(PKGCONFIG_REQUIRES "")
520set(PKGCONFIG_REQUIRES_PRIVATE "")
521set(PKGCONFIG_LIBS "-L\${libdir} -lfreetype")
522set(PKGCONFIG_LIBS_PRIVATE "")
523
524if (ZLIB_FOUND)
525  target_link_libraries(freetype PRIVATE ${ZLIB_LIBRARIES})
526  target_include_directories(freetype PRIVATE ${ZLIB_INCLUDE_DIRS})
527  list(APPEND PKGCONFIG_REQUIRES_PRIVATE "zlib")
528endif ()
529if (BZIP2_FOUND)
530  target_link_libraries(freetype PRIVATE ${BZIP2_LIBRARIES})
531  target_include_directories(freetype PRIVATE ${BZIP2_INCLUDE_DIR}) # not BZIP2_INCLUDE_DIRS
532  if (PC_BZIP2_FOUND)
533    list(APPEND PKGCONFIG_REQUIRES_PRIVATE "bzip2")
534  else ()
535    list(APPEND PKGCONFIG_LIBS_PRIVATE "-lbz2")
536  endif ()
537endif ()
538if (PNG_FOUND)
539  target_link_libraries(freetype PRIVATE ${PNG_LIBRARIES})
540  target_compile_definitions(freetype PRIVATE ${PNG_DEFINITIONS})
541  target_include_directories(freetype PRIVATE ${PNG_INCLUDE_DIRS})
542  list(APPEND PKGCONFIG_REQUIRES_PRIVATE "libpng")
543endif ()
544if (HarfBuzz_FOUND)
545  target_link_libraries(freetype PRIVATE ${HarfBuzz_LIBRARY})
546  target_include_directories(freetype PRIVATE ${HarfBuzz_INCLUDE_DIRS})
547  list(APPEND PKGCONFIG_REQUIRES_PRIVATE "harfbuzz >= ${HARFBUZZ_MIN_VERSION}")
548endif ()
549if (BROTLIDEC_FOUND)
550  target_link_libraries(freetype PRIVATE ${BROTLIDEC_LIBRARIES})
551  target_compile_definitions(freetype PRIVATE ${BROTLIDEC_DEFINITIONS})
552  target_include_directories(freetype PRIVATE ${BROTLIDEC_INCLUDE_DIRS})
553  list(APPEND PKGCONFIG_REQUIRES_PRIVATE "libbrotlidec")
554endif ()
555
556
557# Installation
558include(GNUInstallDirs)
559
560if (NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL)
561  install(
562    # Note the trailing slash in the argument to `DIRECTORY'!
563    DIRECTORY ${PROJECT_SOURCE_DIR}/include/
564      DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/freetype2
565      COMPONENT headers
566      PATTERN "internal" EXCLUDE
567      PATTERN "ftconfig.h" EXCLUDE
568      PATTERN "ftoption.h" EXCLUDE)
569  install(
570    FILES ${PROJECT_BINARY_DIR}/include/freetype/config/ftconfig.h
571          ${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h
572      DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/freetype2/freetype/config
573      COMPONENT headers)
574endif ()
575
576if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
577  # Generate the pkg-config file
578  file(READ "${PROJECT_SOURCE_DIR}/builds/unix/freetype2.in" FREETYPE2_PC_IN)
579
580  string(REPLACE ";" ", " PKGCONFIG_REQUIRES_PRIVATE "${PKGCONFIG_REQUIRES_PRIVATE}")
581
582  string(REPLACE "%prefix%" ${CMAKE_INSTALL_PREFIX}
583          FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
584  string(REPLACE "%exec_prefix%" "\${prefix}"
585          FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
586  string(REPLACE "%libdir%" "\${prefix}/${CMAKE_INSTALL_LIBDIR}"
587          FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
588  string(REPLACE "%includedir%" "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}"
589          FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
590  string(REPLACE "%ft_version%" "${LIBTOOL_CURRENT}.${LIBTOOL_REVISION}.${LIBTOOL_AGE}"
591          FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
592
593  if (BUILD_SHARED_LIBS)
594    string(REPLACE "%PKGCONFIG_REQUIRES%" "${PKGCONFIG_REQUIRES}"
595            FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
596    string(REPLACE "%PKGCONFIG_REQUIRES_PRIVATE%" "${PKGCONFIG_REQUIRES_PRIVATE}"
597            FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
598    string(REPLACE "%PKGCONFIG_LIBS%" "${PKGCONFIG_LIBS}"
599            FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
600    string(REPLACE "%PKGCONFIG_LIBS_PRIVATE%" "${PKGCONFIG_LIBS_PRIVATE}"
601            FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
602  else ()
603    string(REPLACE "%PKGCONFIG_REQUIRES%" "${PKGCONFIG_REQUIRES} ${PKGCONFIG_REQUIRES_PRIVATE}"
604            FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
605    string(REPLACE "%PKGCONFIG_REQUIRES_PRIVATE%" ""
606            FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
607    string(REPLACE "%PKGCONFIG_LIBS%" "${PKGCONFIG_LIBS} ${PKGCONFIG_LIBS_PRIVATE}"
608            FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
609    string(REPLACE "%PKGCONFIG_LIBS_PRIVATE%" ""
610            FREETYPE2_PC_IN ${FREETYPE2_PC_IN})
611  endif ()
612
613  set(FREETYPE2_PC_IN_NAME "${PROJECT_BINARY_DIR}/freetype2.pc")
614  if (EXISTS "${FREETYPE2_PC_IN_NAME}")
615    file(READ "${FREETYPE2_PC_IN_NAME}" ORIGINAL_FREETYPE2_PC_IN)
616  else ()
617    set(ORIGINAL_FREETYPE2_PC_IN "")
618  endif ()
619  if (NOT (ORIGINAL_FREETYPE2_PC_IN STREQUAL FREETYPE2_PC_IN))
620    file(WRITE "${FREETYPE2_PC_IN_NAME}" ${FREETYPE2_PC_IN})
621  endif ()
622
623  install(
624    FILES ${PROJECT_BINARY_DIR}/freetype2.pc
625    DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
626    COMPONENT pkgconfig)
627
628  include(CMakePackageConfigHelpers)
629  write_basic_package_version_file(
630    ${PROJECT_BINARY_DIR}/freetype-config-version.cmake
631    VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
632    COMPATIBILITY SameMajorVersion)
633
634  install(
635    TARGETS freetype freetype-interface
636      EXPORT freetype-targets
637      LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
638      ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
639      RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
640      FRAMEWORK DESTINATION Library/Frameworks
641      COMPONENT libraries)
642  install(
643    EXPORT freetype-targets
644      DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/freetype
645      FILE freetype-config.cmake
646      COMPONENT headers)
647  install(
648    FILES ${PROJECT_BINARY_DIR}/freetype-config-version.cmake
649    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/freetype
650    COMPONENT headers)
651endif ()
652
653
654# Packaging
655set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
656set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The FreeType font rendering library.")
657set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
658set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
659
660set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
661set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
662set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
663set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
664
665if (WIN32)
666  set(CPACK_GENERATOR ZIP)
667else ()
668  set(CPACK_GENERATOR TGZ)
669endif ()
670
671set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
672set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C/C++ Headers")
673set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
674  "Library used to build programs which use FreeType")
675set(CPACK_COMPONENT_HEADERS_DESCRIPTION
676  "C/C++ header files for use with FreeType")
677set(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
678set(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
679set(CPACK_COMPONENT_HEADERS_GROUP "Development")
680
681include(CPack)
682