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