blob: e881dbd1a4d52064e8bf10f4ef389c0cdd15000e [file] [log] [blame]
ebraminio7d64c0e2017-04-04 15:03:51 +04301cmake_minimum_required(VERSION 2.8.0)
2project(harfbuzz)
3
Khaled Hosnyc8609552017-12-06 00:43:28 +02004enable_testing()
Ebrahim Byagowi15273692017-05-13 21:32:56 +04305
6## Limit framework build to Xcode generator
7if (BUILD_FRAMEWORK)
Ebrahim Byagowic97a7ec2018-01-16 14:18:09 +03308 # for a framework build on macOS, use:
9 # cmake -DBUILD_FRAMEWORK=ON -Bbuild -H. -GXcode && cmake --build build
Ebrahim Byagowi15273692017-05-13 21:32:56 +043010 if (NOT "${CMAKE_GENERATOR}" STREQUAL "Xcode")
11 message(FATAL_ERROR
12 "You should use Xcode generator with BUILD_FRAMEWORK enabled")
13 endif ()
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +033014 set (CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_64_BIT)")
15 set (CMAKE_MACOSX_RPATH ON)
16 set (BUILD_SHARED_LIBS ON)
Ebrahim Byagowi15273692017-05-13 21:32:56 +043017endif ()
18
19
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +043020## Disallow in-source builds, as CMake generated make files can collide with autotools ones
21if (NOT MSVC AND "${PROJECT_BINARY_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}")
ebraminio7d64c0e2017-04-04 15:03:51 +043022 message(FATAL_ERROR
23 "
24In-source builds are not permitted! Make a separate folder for"
25 " building, e.g.,"
26 "
27 mkdir build; cd build; cmake .."
28 "
29Before that, remove the files created by this failed run with"
30 "
31 rm -rf CMakeCache.txt CMakeFiles")
32endif ()
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +043033
ebraminio7d64c0e2017-04-04 15:03:51 +043034
35## HarfBuzz build configurations
ebraminioadfd4ae2017-04-11 23:18:18 +043036option(HB_HAVE_FREETYPE "Enable freetype interop helpers" OFF)
37option(HB_HAVE_GRAPHITE2 "Enable Graphite2 complementary shaper" OFF)
ebraminio7d64c0e2017-04-04 15:03:51 +043038option(HB_BUILTIN_UCDN "Use HarfBuzz provided UCDN" ON)
ebraminioadfd4ae2017-04-11 23:18:18 +043039option(HB_HAVE_GLIB "Enable glib unicode functions" OFF)
40option(HB_HAVE_ICU "Enable icu unicode functions" OFF)
ebraminio69664132017-04-19 22:59:46 +043041if (APPLE)
42 option(HB_HAVE_CORETEXT "Enable CoreText shaper backend on macOS" ON)
Ebrahim Byagowi3c7aeb52018-01-09 01:39:42 +033043 set (CMAKE_MACOSX_RPATH ON)
ebraminio69664132017-04-19 22:59:46 +043044endif ()
45if (WIN32)
46 option(HB_HAVE_UNISCRIBE "Enable Uniscribe shaper backend on Windows" OFF)
Chun-wei Fan162575f2017-10-18 22:27:28 +080047 option(HB_HAVE_DIRECTWRITE "Enable DirectWrite shaper backend on Windows" OFF)
ebraminio69664132017-04-19 22:59:46 +043048endif ()
ebraminio3a8bc572017-04-11 21:32:14 +043049option(HB_BUILD_UTILS "Build harfbuzz utils, needs cairo, freetype, and glib properly be installed" OFF)
50if (HB_BUILD_UTILS)
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +033051 set (HB_HAVE_GLIB ON)
52 set (HB_HAVE_FREETYPE ON)
ebraminio3a8bc572017-04-11 21:32:14 +043053endif ()
ebraminio7d64c0e2017-04-04 15:03:51 +043054
Chun-wei Fan53db2212017-10-18 15:43:57 +080055option(HB_HAVE_GOBJECT "Enable GObject Bindings" OFF)
56if (HB_HAVE_GOBJECT)
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +033057 set (HB_HAVE_GLIB ON)
Chun-wei Fan53db2212017-10-18 15:43:57 +080058endif ()
59
Chun-wei Fan41b18252017-10-19 18:36:32 +080060option(HB_HAVE_INTROSPECTION "Enable building introspection (.gir/.typelib) files" OFF)
61if (HB_HAVE_INTROSPECTION)
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +033062 set (HB_HAVE_GOBJECT ON)
63 set (HB_HAVE_GLIB ON)
Chun-wei Fan41b18252017-10-19 18:36:32 +080064endif ()
65
Ebrahim Byagowi72bec1c2018-01-05 12:42:20 +033066option(HB_CHECK OFF "Do a configuration suitable for testing (shared library and enable all options)")
67if (HB_CHECK)
68 set (BUILD_SHARED_LIBS ON)
69 set (HB_BUILD_UTILS ON)
70 set (HB_BUILTIN_UCDN ON)
71 set (HB_HAVE_ICU)
72 set (HB_HAVE_GLIB ON)
73 #set (HB_HAVE_GOBJECT ON)
74 #set (HB_HAVE_INTROSPECTION ON)
75 set (HB_HAVE_FREETYPE ON)
76 set (HB_HAVE_GRAPHITE2 ON)
77 if (WIN32)
78 set (HB_HAVE_UNISCRIBE ON)
79 set (HB_HAVE_DIRECTWRITE ON)
80 elseif (APPLE)
81 set (HB_HAVE_CORETEXT ON)
82 endif ()
83endif ()
84
ebraminio7d64c0e2017-04-04 15:03:51 +043085include_directories(AFTER
ebraminiod2acaf62017-04-05 02:21:23 -070086 ${PROJECT_SOURCE_DIR}/src
ebraminio7d64c0e2017-04-04 15:03:51 +043087 ${PROJECT_BINARY_DIR}/src
Ebrahim Byagowi5ed26fc2018-01-04 10:11:34 +033088)
ebraminio7d64c0e2017-04-04 15:03:51 +043089
ebraminio7d64c0e2017-04-04 15:03:51 +043090add_definitions(-DHAVE_OT)
Chun-wei Fan162575f2017-10-18 22:27:28 +080091add_definitions(-DHAVE_FALLBACK)
ebraminio7d64c0e2017-04-04 15:03:51 +043092
Chun-wei Fan89dbabf2018-03-12 13:27:38 +080093# We need PYTHON_EXECUTABLE to be set for running the tests...
94include (FindPythonInterp)
Ebrahim Byagowi71e0ed92018-01-10 15:45:12 +033095
Ebrahim Byagowi07885e62018-02-03 12:53:48 +033096## Functions and headers
Ebrahim Byagowi71e0ed92018-01-10 15:45:12 +033097include (CheckFunctionExists)
98include (CheckIncludeFile)
99macro (check_funcs) # Similar to AC_CHECK_FUNCS of autotools
100 foreach (func_name ${ARGN})
Ebrahim Byagowie24bea82018-01-10 23:51:56 +0330101 string(TOUPPER ${func_name} definiton_to_add)
102 check_function_exists(${func_name} HAVE_${definiton_to_add})
103 if (${HAVE_${definiton_to_add}})
Ebrahim Byagowi71e0ed92018-01-10 15:45:12 +0330104 add_definitions(-DHAVE_${definiton_to_add})
105 endif ()
106 endforeach ()
107endmacro ()
Chun-wei Fan89dbabf2018-03-12 13:27:38 +0800108if (UNIX)
109 list(APPEND CMAKE_REQUIRED_LIBRARIES m)
110endif ()
111check_funcs(atexit mprotect sysconf getpagesize mmap isatty newlocale strtod_l round)
Ebrahim Byagowi07885e62018-02-03 12:53:48 +0330112check_include_file(unistd.h HAVE_UNISTD_H)
113if (${HAVE_UNISTD_H})
114 add_definitions(-DHAVE_UNISTD_H)
Ebrahim Byagowi71e0ed92018-01-10 15:45:12 +0330115endif ()
Ebrahim Byagowi07885e62018-02-03 12:53:48 +0330116check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
117if (${HAVE_SYS_MMAN_H})
118 add_definitions(-DHAVE_SYS_MMAN_H)
119endif ()
Ebrahim Byagowi71e0ed92018-01-10 15:45:12 +0330120check_include_file(xlocale.h HAVE_XLOCALE_H)
121if (${HAVE_XLOCALE_H})
122 add_definitions(-DHAVE_XLOCALE_H)
123endif ()
Chun-wei Fan89dbabf2018-03-12 13:27:38 +0800124check_include_file(stdbool.h HAVE_STDBOOL_H)
125if (${HAVE_STDBOOL_H})
126 add_definitions(-DHAVE_STDBOOL_H)
127endif ()
Ebrahim Byagowi71e0ed92018-01-10 15:45:12 +0330128
ebraminio7d64c0e2017-04-04 15:03:51 +0430129
130if (MSVC)
131 add_definitions(-wd4244 -wd4267 -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
132endif ()
133
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +0430134
Ebrahim Byagowi15273692017-05-13 21:32:56 +0430135## Detect if we are running inside a distribution or regular repository folder
Ebrahim Byagowi0eec3312018-02-28 11:53:39 +0330136# if (EXISTS "${PROJECT_SOURCE_DIR}/ChangeLog")
137# # perhaps we are on dist directory
138# set (IN_HB_DIST TRUE)
139# #set (HB_VERSION_H "${PROJECT_SOURCE_DIR}/src/hb-version.h")
140# endif ()
ebraminio7d64c0e2017-04-04 15:03:51 +0430141
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +0430142
ebraminio3a8bc572017-04-11 21:32:14 +0430143## Extract variables from Makefile files
Ebrahim Byagowi2dbdeb12017-12-29 23:13:29 +0330144function (extract_make_variable variable makefile_source)
145 string(REGEX MATCH "${variable} = ([^$]+)\\$" temp ${makefile_source})
146 string(REGEX MATCHALL "[^ \n\t\\]+" listVar ${CMAKE_MATCH_1})
147 set (${variable} ${listVar} PARENT_SCOPE)
148endfunction ()
149
150# http://stackoverflow.com/a/27630120
151function (add_prefix_to_list var prefix)
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330152 set (listVar "")
Ebrahim Byagowi2dbdeb12017-12-29 23:13:29 +0330153 foreach (f ${${var}})
ebraminio3a8bc572017-04-11 21:32:14 +0430154 list(APPEND listVar "${prefix}${f}")
ebraminioadfd4ae2017-04-11 23:18:18 +0430155 endforeach ()
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330156 set (${var} "${listVar}" PARENT_SCOPE)
ebraminiod2acaf62017-04-05 02:21:23 -0700157endfunction ()
158
ebraminio3a8bc572017-04-11 21:32:14 +0430159file(READ ${PROJECT_SOURCE_DIR}/src/Makefile.sources SRCSOURCES)
160file(READ ${PROJECT_SOURCE_DIR}/util/Makefile.sources UTILSOURCES)
ebraminioadfd4ae2017-04-11 23:18:18 +0430161file(READ ${PROJECT_SOURCE_DIR}/src/hb-ucdn/Makefile.sources UCDNSOURCES)
162
Ebrahim Byagowi2dbdeb12017-12-29 23:13:29 +0330163extract_make_variable(HB_BASE_sources ${SRCSOURCES})
164add_prefix_to_list(HB_BASE_sources "${PROJECT_SOURCE_DIR}/src/")
165extract_make_variable(HB_BASE_headers ${SRCSOURCES})
166add_prefix_to_list(HB_BASE_headers "${PROJECT_SOURCE_DIR}/src/")
167extract_make_variable(HB_FALLBACK_sources ${SRCSOURCES})
168add_prefix_to_list(HB_FALLBACK_sources "${PROJECT_SOURCE_DIR}/src/")
169extract_make_variable(HB_OT_sources ${SRCSOURCES})
170add_prefix_to_list(HB_OT_sources "${PROJECT_SOURCE_DIR}/src/")
171extract_make_variable(HB_OT_headers ${SRCSOURCES})
172add_prefix_to_list(HB_OT_headers "${PROJECT_SOURCE_DIR}/src/")
ebraminio3a8bc572017-04-11 21:32:14 +0430173
Garret Riegerf83a43b2018-02-02 17:50:45 -0800174extract_make_variable(HB_SUBSET_sources ${SRCSOURCES})
175add_prefix_to_list(HB_SUBSET_sources "${PROJECT_SOURCE_DIR}/src/")
176
177extract_make_variable(HB_SUBSET_headers ${SRCSOURCES})
178add_prefix_to_list(HB_SUBSET_headers "${PROJECT_SOURCE_DIR}/src/")
179
Ebrahim Byagowi2dbdeb12017-12-29 23:13:29 +0330180extract_make_variable(HB_BASE_RAGEL_GENERATED_sources ${SRCSOURCES})
181extract_make_variable(HB_OT_RAGEL_GENERATED_sources ${SRCSOURCES})
Behdad Esfahbodb91e8da2018-02-23 22:51:17 -0800182#if (IN_HB_DIST)
Ebrahim Byagowi2dbdeb12017-12-29 23:13:29 +0330183 add_prefix_to_list(HB_BASE_RAGEL_GENERATED_sources "${PROJECT_SOURCE_DIR}/src/")
184 add_prefix_to_list(HB_OT_RAGEL_GENERATED_sources "${PROJECT_SOURCE_DIR}/src/")
Behdad Esfahbodb91e8da2018-02-23 22:51:17 -0800185#else ()
186# add_prefix_to_list(HB_BASE_RAGEL_GENERATED_sources "${PROJECT_BINARY_DIR}/src/")
187# add_prefix_to_list(HB_OT_RAGEL_GENERATED_sources "${PROJECT_BINARY_DIR}/src/")
188#endif ()
ebraminio3a8bc572017-04-11 21:32:14 +0430189
Ebrahim Byagowi2dbdeb12017-12-29 23:13:29 +0330190extract_make_variable(HB_VIEW_sources ${UTILSOURCES})
191add_prefix_to_list(HB_VIEW_sources "${PROJECT_SOURCE_DIR}/util/")
192extract_make_variable(HB_SHAPE_sources ${UTILSOURCES})
193add_prefix_to_list(HB_SHAPE_sources "${PROJECT_SOURCE_DIR}/util/")
Garret Riegerf83a43b2018-02-02 17:50:45 -0800194extract_make_variable(HB_SUBSET_CLI_sources ${UTILSOURCES})
195add_prefix_to_list(HB_SUBSET_CLI_sources "${PROJECT_SOURCE_DIR}/util/")
Ebrahim Byagowi2dbdeb12017-12-29 23:13:29 +0330196extract_make_variable(HB_OT_SHAPE_CLOSURE_sources ${UTILSOURCES})
197add_prefix_to_list(HB_OT_SHAPE_CLOSURE_sources "${PROJECT_SOURCE_DIR}/util/")
ebraminio69664132017-04-19 22:59:46 +0430198
Ebrahim Byagowi2dbdeb12017-12-29 23:13:29 +0330199extract_make_variable(LIBHB_UCDN_sources ${UCDNSOURCES})
200add_prefix_to_list(LIBHB_UCDN_sources "${PROJECT_SOURCE_DIR}/src/hb-ucdn/")
201
ebraminioadfd4ae2017-04-11 23:18:18 +0430202
ebraminio3a8bc572017-04-11 21:32:14 +0430203file(READ configure.ac CONFIGUREAC)
204string(REGEX MATCH "\\[(([0-9]+)\\.([0-9]+)\\.([0-9]+))\\]" HB_VERSION_MATCH ${CONFIGUREAC})
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330205set (HB_VERSION ${CMAKE_MATCH_1})
206set (HB_VERSION_MAJOR ${CMAKE_MATCH_2})
207set (HB_VERSION_MINOR ${CMAKE_MATCH_3})
208set (HB_VERSION_MICRO ${CMAKE_MATCH_4})
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +0430209
ebraminiod2acaf62017-04-05 02:21:23 -0700210
Ebrahim Byagowi15273692017-05-13 21:32:56 +0430211## Define ragel tasks
Ebrahim Byagowi0eec3312018-02-28 11:53:39 +0330212# if (NOT IN_HB_DIST)
213# foreach (ragel_output IN ITEMS ${HB_BASE_RAGEL_GENERATED_sources} ${HB_OT_RAGEL_GENERATED_sources})
214# string(REGEX MATCH "([^/]+)\\.hh" temp ${ragel_output})
215# set (target_name ${CMAKE_MATCH_1})
216# add_custom_command(OUTPUT ${ragel_output}
217# COMMAND ${RAGEL} -G2 -o ${ragel_output} ${PROJECT_SOURCE_DIR}/src/${target_name}.rl -I ${PROJECT_SOURCE_DIR} ${ARGN}
218# DEPENDS ${PROJECT_SOURCE_DIR}/src/${target_name}.rl
219# )
220# add_custom_target(harfbuzz_${target_name} DEPENDS ${PROJECT_BINARY_DIR}/src/${target_name})
221# endforeach ()
ebraminio7d64c0e2017-04-04 15:03:51 +0430222
Ebrahim Byagowi0eec3312018-02-28 11:53:39 +0330223# mark_as_advanced(RAGEL)
224# endif ()
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +0430225
ebraminio7d64c0e2017-04-04 15:03:51 +0430226
Ebrahim Byagowi15273692017-05-13 21:32:56 +0430227## Generate hb-version.h
Ebrahim Byagowi0eec3312018-02-28 11:53:39 +0330228# if (NOT IN_HB_DIST)
Behdad Esfahbodb91e8da2018-02-23 22:51:17 -0800229# set (HB_VERSION_H_IN "${PROJECT_SOURCE_DIR}/src/hb-version.h.in")
230# set (HB_VERSION_H "${PROJECT_BINARY_DIR}/src/hb-version.h")
231# set_source_files_properties("${HB_VERSION_H}" PROPERTIES GENERATED true)
232# configure_file("${HB_VERSION_H_IN}" "${HB_VERSION_H}.tmp" @ONLY)
233# execute_process(COMMAND "${CMAKE_COMMAND}" -E copy_if_different
234# "${HB_VERSION_H}.tmp"
235# "${HB_VERSION_H}"
236# )
237# file(REMOVE "${HB_VERSION_H}.tmp")
Ebrahim Byagowi0eec3312018-02-28 11:53:39 +0330238# endif ()
ebraminio7d64c0e2017-04-04 15:03:51 +0430239
Ebrahim Byagowi15273692017-05-13 21:32:56 +0430240
ebraminio3a8bc572017-04-11 21:32:14 +0430241## Define sources and headers of the project
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330242set (project_sources
ebraminiod2acaf62017-04-05 02:21:23 -0700243 ${HB_BASE_sources}
244 ${HB_BASE_RAGEL_GENERATED_sources}
ebraminio7d64c0e2017-04-04 15:03:51 +0430245
Chun-wei Fan162575f2017-10-18 22:27:28 +0800246 ${HB_FALLBACK_sources}
ebraminiod2acaf62017-04-05 02:21:23 -0700247 ${HB_OT_sources}
Behdad Esfahbod9682ef12018-02-08 17:35:57 -0600248 ${HB_OT_RAGEL_GENERATED_sources}
Garret Rieger0f3c7562018-02-08 14:59:32 -0800249)
Garret Riegerf83a43b2018-02-02 17:50:45 -0800250
Garret Rieger0f3c7562018-02-08 14:59:32 -0800251set (subset_project_sources
Garret Riegerf83a43b2018-02-02 17:50:45 -0800252 ${HB_SUBSET_sources}
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330253)
ebraminio7d64c0e2017-04-04 15:03:51 +0430254
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330255set (project_extra_sources)
Chun-wei Fan41b18252017-10-19 18:36:32 +0800256
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330257set (project_headers
Behdad Esfahbodb91e8da2018-02-23 22:51:17 -0800258 #${HB_VERSION_H}
ebraminio7d64c0e2017-04-04 15:03:51 +0430259
260 ${HB_BASE_headers}
261 ${HB_OT_headers}
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330262)
ebraminio7d64c0e2017-04-04 15:03:51 +0430263
Garret Rieger0f3c7562018-02-08 14:59:32 -0800264set (subset_project_headers
265 ${HB_SUBSET_headers}
266)
267
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +0430268
269## Find and include needed header folders and libraries
ebraminio7d64c0e2017-04-04 15:03:51 +0430270if (HB_HAVE_FREETYPE)
Ebrahim Byagowi71e0ed92018-01-10 15:45:12 +0330271 include (FindFreetype)
Khaled Hosny67600212017-10-12 12:05:08 +0300272 if (NOT FREETYPE_FOUND)
273 message(FATAL_ERROR "HB_HAVE_FREETYPE was set, but we failed to find it. Maybe add a CMAKE_PREFIX_PATH= to your Freetype2 install prefix")
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330274 endif ()
Khaled Hosny67600212017-10-12 12:05:08 +0300275
276 list(APPEND THIRD_PARTY_LIBS ${FREETYPE_LIBRARIES})
277 include_directories(AFTER ${FREETYPE_INCLUDE_DIRS})
Ebrahim Byagowi3d615762018-01-22 21:23:19 +0330278 add_definitions(-DHAVE_FREETYPE=1)
ebraminio7d64c0e2017-04-04 15:03:51 +0430279
ebraminio3a8bc572017-04-11 21:32:14 +0430280 list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-ft.cc)
281 list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-ft.h)
Ebrahim Byagowi3c7aeb52018-01-09 01:39:42 +0330282
Ebrahim Byagowi29d90122018-01-30 10:01:46 +0330283 # So check_funcs can find its headers
Ebrahim Byagowi71e0ed92018-01-10 15:45:12 +0330284 set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${FREETYPE_INCLUDE_DIRS})
285 set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${FREETYPE_LIBRARIES})
Ebrahim Byagowi29d90122018-01-30 10:01:46 +0330286
Ebrahim Byagowi71e0ed92018-01-10 15:45:12 +0330287 check_funcs(FT_Get_Var_Blend_Coordinates FT_Set_Var_Blend_Coordinates FT_Done_MM_Var)
ebraminio7d64c0e2017-04-04 15:03:51 +0430288endif ()
289
ebraminioadfd4ae2017-04-11 23:18:18 +0430290if (HB_HAVE_GRAPHITE2)
291 add_definitions(-DHAVE_GRAPHITE2)
292
293 find_path(GRAPHITE2_INCLUDE_DIR graphite2/Font.h)
294 find_library(GRAPHITE2_LIBRARY graphite2)
295
296 include_directories(${GRAPHITE2_INCLUDE_DIR})
297
298 list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-graphite2.cc)
299 list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-graphite2.h)
300
301 list(APPEND THIRD_PARTY_LIBS ${GRAPHITE2_LIBRARY})
ebraminio69664132017-04-19 22:59:46 +0430302
303 mark_as_advanced(GRAPHITE2_INCLUDE_DIR GRAPHITE2_LIBRARY)
ebraminioadfd4ae2017-04-11 23:18:18 +0430304endif ()
305
ebraminio7d64c0e2017-04-04 15:03:51 +0430306if (HB_BUILTIN_UCDN)
307 include_directories(src/hb-ucdn)
308 add_definitions(-DHAVE_UCDN)
309
Chun-wei Fan41b18252017-10-19 18:36:32 +0800310 list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-ucdn.cc)
311 list(APPEND project_extra_sources ${LIBHB_UCDN_sources})
ebraminio3a8bc572017-04-11 21:32:14 +0430312endif ()
313
314if (HB_HAVE_GLIB)
315 add_definitions(-DHAVE_GLIB)
316
317 # https://github.com/WebKit/webkit/blob/master/Source/cmake/FindGLIB.cmake
318 find_package(PkgConfig)
319 pkg_check_modules(PC_GLIB QUIET glib-2.0)
320
321 find_library(GLIB_LIBRARIES NAMES glib-2.0 HINTS ${PC_GLIB_LIBDIR} ${PC_GLIB_LIBRARY_DIRS})
322 find_path(GLIBCONFIG_INCLUDE_DIR NAMES glibconfig.h HINTS ${PC_LIBDIR} ${PC_LIBRARY_DIRS} ${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS} PATH_SUFFIXES glib-2.0/include)
323 find_path(GLIB_INCLUDE_DIR NAMES glib.h HINTS ${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS} PATH_SUFFIXES glib-2.0)
324
325 include_directories(${GLIBCONFIG_INCLUDE_DIR} ${GLIB_INCLUDE_DIR})
326
327 list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-glib.cc)
328 list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-glib.h)
329
330 list(APPEND THIRD_PARTY_LIBS ${GLIB_LIBRARIES})
ebraminio69664132017-04-19 22:59:46 +0430331
332 mark_as_advanced(GLIB_LIBRARIES GLIBCONFIG_INCLUDE_DIR GLIB_INCLUDE_DIR)
ebraminio7d64c0e2017-04-04 15:03:51 +0430333endif ()
334
ebraminioadfd4ae2017-04-11 23:18:18 +0430335if (HB_HAVE_ICU)
336 add_definitions(-DHAVE_ICU)
337
338 # https://github.com/WebKit/webkit/blob/master/Source/cmake/FindICU.cmake
339 find_package(PkgConfig)
340 pkg_check_modules(PC_ICU QUIET icu-uc)
341
342 find_path(ICU_INCLUDE_DIR NAMES unicode/utypes.h HINTS ${PC_ICU_INCLUDE_DIRS} ${PC_ICU_INCLUDEDIR})
343 find_library(ICU_LIBRARY NAMES libicuuc cygicuuc cygicuuc32 icuuc HINTS ${PC_ICU_LIBRARY_DIRS} ${PC_ICU_LIBDIR})
344
345 include_directories(${ICU_INCLUDE_DIR})
346
347 list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-icu.cc)
348 list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-icu.h)
349
350 list(APPEND THIRD_PARTY_LIBS ${ICU_LIBRARY})
ebraminio69664132017-04-19 22:59:46 +0430351
352 mark_as_advanced(ICU_INCLUDE_DIR ICU_LIBRARY)
ebraminioadfd4ae2017-04-11 23:18:18 +0430353endif ()
354
ebraminio7d64c0e2017-04-04 15:03:51 +0430355if (APPLE AND HB_HAVE_CORETEXT)
356 # Apple Advanced Typography
357 add_definitions(-DHAVE_CORETEXT)
358
ebraminio3a8bc572017-04-11 21:32:14 +0430359 list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-coretext.cc)
360 list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-coretext.h)
ebraminio7d64c0e2017-04-04 15:03:51 +0430361
362 find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices)
ebraminio7d64c0e2017-04-04 15:03:51 +0430363 if (APPLICATION_SERVICES_FRAMEWORK)
ebraminio3a8bc572017-04-11 21:32:14 +0430364 list(APPEND THIRD_PARTY_LIBS ${APPLICATION_SERVICES_FRAMEWORK})
ebraminio7d64c0e2017-04-04 15:03:51 +0430365 endif (APPLICATION_SERVICES_FRAMEWORK)
Ebrahim Byagowi3d615762018-01-22 21:23:19 +0330366
ebraminio69664132017-04-19 22:59:46 +0430367 mark_as_advanced(APPLICATION_SERVICES_FRAMEWORK)
ebraminio7d64c0e2017-04-04 15:03:51 +0430368endif ()
369
370if (WIN32 AND HB_HAVE_UNISCRIBE)
371 add_definitions(-DHAVE_UNISCRIBE)
372
ebraminio3a8bc572017-04-11 21:32:14 +0430373 list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-uniscribe.cc)
374 list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-uniscribe.h)
ebraminio7d64c0e2017-04-04 15:03:51 +0430375
ebraminio3a8bc572017-04-11 21:32:14 +0430376 list(APPEND THIRD_PARTY_LIBS usp10 gdi32 rpcrt4)
ebraminio7d64c0e2017-04-04 15:03:51 +0430377endif ()
378
379if (WIN32 AND HB_HAVE_DIRECTWRITE)
380 add_definitions(-DHAVE_DIRECTWRITE)
381
ebraminio3a8bc572017-04-11 21:32:14 +0430382 list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-directwrite.cc)
383 list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-directwrite.h)
ebraminio7d64c0e2017-04-04 15:03:51 +0430384
ebraminio3a8bc572017-04-11 21:32:14 +0430385 list(APPEND THIRD_PARTY_LIBS dwrite rpcrt4)
ebraminio7d64c0e2017-04-04 15:03:51 +0430386endif ()
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +0430387
Chun-wei Fan53db2212017-10-18 15:43:57 +0800388if (HB_HAVE_GOBJECT)
Ebrahim Byagowi71e0ed92018-01-10 15:45:12 +0330389 include (FindPerl)
Ebrahim Byagowi3d615762018-01-22 21:23:19 +0330390
Chun-wei Fan53db2212017-10-18 15:43:57 +0800391 # Use the hints from glib-2.0.pc to find glib-mkenums
392 find_package(PkgConfig)
393 pkg_check_modules(PC_GLIB QUIET glib-2.0)
394 find_program(GLIB_MKENUMS glib-mkenums
395 HINTS ${PC_glib_mkenums}
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330396 )
397 set (GLIB_MKENUMS_CMD)
Chun-wei Fan53db2212017-10-18 15:43:57 +0800398
399 if (WIN32 AND NOT MINGW)
400 # In Visual Studio builds, shebang lines are not supported
401 # in the standard cmd.exe shell that we use, so we need to
402 # first determine whether glib-mkenums is a Python or PERL
403 # script
404 execute_process(COMMAND "${PYTHON_EXECUTABLE}" "${GLIB_MKENUMS}" --version
405 RESULT_VARIABLE GLIB_MKENUMS_PYTHON
406 OUTPUT_QUIET ERROR_QUIET
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330407 )
Chun-wei Fan53db2212017-10-18 15:43:57 +0800408 if (GLIB_MKENUMS_PYTHON EQUAL 0)
409 message("${GLIB_MKENUMS} is a Python script.")
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330410 set (GLIB_MKENUMS_CMD "${PYTHON_EXECUTABLE}" "${GLIB_MKENUMS}")
Chun-wei Fan53db2212017-10-18 15:43:57 +0800411 else ()
412 execute_process(COMMAND "${PERL_EXECUTABLE}" "${GLIB_MKENUMS}" --version
413 RESULT_VARIABLE GLIB_MKENUMS_PERL
414 OUTPUT_QUIET ERROR_QUIET
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330415 )
Chun-wei Fan53db2212017-10-18 15:43:57 +0800416 if (GLIB_MKENUMS_PERL EQUAL 0)
417 message("${GLIB_MKENUMS} is a PERL script.")
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330418 set (GLIB_MKENUMS_CMD "${PERL_EXECUTABLE}" "${GLIB_MKENUMS}")
Chun-wei Fan53db2212017-10-18 15:43:57 +0800419 endif ()
420 if (NOT GLIB_MKENUMS_PERL EQUAL 0 AND NOT GLIB_MKENUMS_PYTHON EQUAL 0)
421 message(FATAL_ERROR "Unable to determine type of glib-mkenums script")
422 endif ()
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330423 endif ()
Chun-wei Fan53db2212017-10-18 15:43:57 +0800424 else ()
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330425 set (GLIB_MKENUMS_CMD "${GLIB_MKENUMS}")
Chun-wei Fan53db2212017-10-18 15:43:57 +0800426 endif ()
427 if (NOT GLIB_MKENUMS_CMD)
428 message(FATAL_ERROR "HB_HAVE_GOBJECT was set, but we failed to find glib-mkenums, which is required")
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330429 endif ()
Chun-wei Fan53db2212017-10-18 15:43:57 +0800430
431 pkg_check_modules(PC_GOBJECT QUIET gobject-2.0)
432
433 find_library(GOBJECT_LIBRARIES NAMES gobject-2.0 HINTS ${PC_GLIB_LIBDIR} ${PC_GLIB_LIBRARY_DIRS})
434 find_path(GOBJECT_INCLUDE_DIR NAMES glib-object.h HINTS ${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS} PATH_SUFFIXES glib-2.0)
435
436 include_directories(${GOBJECTCONFIG_INCLUDE_DIR} ${GOBJECT_INCLUDE_DIR})
437 mark_as_advanced(GOBJECT_LIBRARIES GOBJECT_INCLUDE_DIR)
438
439 list(APPEND hb_gobject_sources ${PROJECT_SOURCE_DIR}/src/hb-gobject-structs.cc)
440 list(APPEND hb_gobject_gen_sources
441 ${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.cc
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330442 )
Chun-wei Fan41b18252017-10-19 18:36:32 +0800443 list(APPEND hb_gobject_structs_headers
444 ${PROJECT_SOURCE_DIR}/src/hb-gobject-structs.h
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330445 )
Chun-wei Fan53db2212017-10-18 15:43:57 +0800446 list(APPEND hb_gobject_headers
447 ${PROJECT_SOURCE_DIR}/src/hb-gobject.h
Chun-wei Fan41b18252017-10-19 18:36:32 +0800448 ${hb_gobject_structs_headers}
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330449 )
Chun-wei Fan53db2212017-10-18 15:43:57 +0800450 list(APPEND hb_gobject_gen_headers
451 ${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.h
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330452 )
Chun-wei Fan53db2212017-10-18 15:43:57 +0800453
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330454 add_custom_command(
Chun-wei Fan53db2212017-10-18 15:43:57 +0800455 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.h
456 COMMAND ${GLIB_MKENUMS_CMD}
457 --template=${PROJECT_SOURCE_DIR}/src/hb-gobject-enums.h.tmpl
458 --identifier-prefix hb_
459 --symbol-prefix hb_gobject
Chun-wei Fan41b18252017-10-19 18:36:32 +0800460 ${hb_gobject_structs_headers}
Chun-wei Fan53db2212017-10-18 15:43:57 +0800461 ${project_headers}
462 > ${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.h.tmp
463 COMMAND "${CMAKE_COMMAND}"
464 "-DENUM_INPUT_SRC=${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.h.tmp"
465 "-DENUM_OUTPUT_SRC=${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.h"
466 -P ${PROJECT_SOURCE_DIR}/replace-enum-strings.cmake
467 DEPENDS ${PROJECT_SOURCE_DIR}/src/hb-gobject-enums.h.tmpl
468 ${hb_gobject_header}
469 ${project_headers}
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330470 )
Chun-wei Fan53db2212017-10-18 15:43:57 +0800471
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330472 add_custom_command(
Chun-wei Fan53db2212017-10-18 15:43:57 +0800473 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.cc
474 COMMAND ${GLIB_MKENUMS_CMD}
475 --template=${PROJECT_SOURCE_DIR}/src/hb-gobject-enums.cc.tmpl
476 --identifier-prefix hb_
477 --symbol-prefix hb_gobject
478 ${hb_gobject_header}
479 ${project_headers}
480 > ${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.cc.tmp
481 COMMAND "${CMAKE_COMMAND}"
482 "-DENUM_INPUT_SRC=${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.cc.tmp"
483 "-DENUM_OUTPUT_SRC=${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.cc"
484 -P ${PROJECT_SOURCE_DIR}/replace-enum-strings.cmake
485 DEPENDS ${PROJECT_SOURCE_DIR}/src/hb-gobject-enums.cc.tmpl
486 ${CMAKE_CURRENT_BINARY_DIR}/src/hb-gobject-enums.h
487 ${hb_gobject_header}
488 ${project_headers}
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330489 )
Chun-wei Fan53db2212017-10-18 15:43:57 +0800490endif ()
ebraminio7d64c0e2017-04-04 15:03:51 +0430491
Ebrahim Byagowi5ed26fc2018-01-04 10:11:34 +0330492
ebraminioa41d5ea2017-04-14 04:25:50 +0430493## Atomic ops availability detection
494file(WRITE "${PROJECT_BINARY_DIR}/try_compile_intel_atomic_primitives.c"
495" void memory_barrier (void) { __sync_synchronize (); }
496 int atomic_add (int *i) { return __sync_fetch_and_add (i, 1); }
497 int mutex_trylock (int *m) { return __sync_lock_test_and_set (m, 1); }
498 void mutex_unlock (int *m) { __sync_lock_release (m); }
ebraminio75931422017-04-14 05:08:11 +0430499 int main () { return 0; }
ebraminioa41d5ea2017-04-14 04:25:50 +0430500")
501try_compile(HB_HAVE_INTEL_ATOMIC_PRIMITIVES
502 ${PROJECT_BINARY_DIR}/try_compile_intel_atomic_primitives
rdb5e14e5f2018-01-16 17:04:33 +0100503 ${PROJECT_BINARY_DIR}/try_compile_intel_atomic_primitives.c)
ebraminioa41d5ea2017-04-14 04:25:50 +0430504if (HB_HAVE_INTEL_ATOMIC_PRIMITIVES)
505 add_definitions(-DHAVE_INTEL_ATOMIC_PRIMITIVES)
506endif ()
507
508file(WRITE "${PROJECT_BINARY_DIR}/try_compile_solaris_atomic_ops.c"
509" #include <atomic.h>
510 /* This requires Solaris Studio 12.2 or newer: */
511 #include <mbarrier.h>
512 void memory_barrier (void) { __machine_rw_barrier (); }
513 int atomic_add (volatile unsigned *i) { return atomic_add_int_nv (i, 1); }
514 void *atomic_ptr_cmpxchg (volatile void **target, void *cmp, void *newval) { return atomic_cas_ptr (target, cmp, newval); }
ebraminio75931422017-04-14 05:08:11 +0430515 int main () { return 0; }
ebraminioa41d5ea2017-04-14 04:25:50 +0430516")
517try_compile(HB_HAVE_SOLARIS_ATOMIC_OPS
518 ${PROJECT_BINARY_DIR}/try_compile_solaris_atomic_ops
rdb5e14e5f2018-01-16 17:04:33 +0100519 ${PROJECT_BINARY_DIR}/try_compile_solaris_atomic_ops.c)
ebraminiocb021e12017-04-14 04:31:17 +0430520if (HB_HAVE_SOLARIS_ATOMIC_OPS)
521 add_definitions(-DHAVE_SOLARIS_ATOMIC_OPS)
ebraminioa41d5ea2017-04-14 04:25:50 +0430522endif ()
ebraminioa41d5ea2017-04-14 04:25:50 +0430523
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +0430524
525## Define harfbuzz library
Chun-wei Fan41b18252017-10-19 18:36:32 +0800526add_library(harfbuzz ${project_sources} ${project_extra_sources} ${project_headers})
ebraminio7d64c0e2017-04-04 15:03:51 +0430527target_link_libraries(harfbuzz ${THIRD_PARTY_LIBS})
528
Garret Rieger0f3c7562018-02-08 14:59:32 -0800529## Define harfbuzz-subset library
530add_library(harfbuzz-subset ${subset_project_sources} ${subset_project_headers})
531add_dependencies(harfbuzz-subset harfbuzz)
532target_link_libraries(harfbuzz-subset harfbuzz ${THIRD_PARTY_LIBS})
533
Ebrahim Byagowiac92ed72018-05-08 01:05:15 +0430534if (BUILD_SHARED_LIBS)
535 set_target_properties(harfbuzz harfbuzz-subset PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE)
536endif ()
537
Ebrahim Byagowi90f01ba2018-01-16 22:00:21 +0330538if (UNIX OR MINGW)
539 # Make symbols link locally
Ebrahim Byagowieff36cd2018-03-30 22:25:35 +0430540 include (CheckCXXCompilerFlag)
Joel Winarsked68f00e2018-03-16 12:14:27 -0700541 check_cxx_compiler_flag(-Bsymbolic-functions CXX_SUPPORTS_FLAG_BSYMB_FUNCS)
Ebrahim Byagowieff36cd2018-03-30 22:25:35 +0430542 if (CXX_SUPPORTS_FLAG_BSYMB_FUNCS)
Joel Winarsked68f00e2018-03-16 12:14:27 -0700543 link_libraries(-Bsymbolic-functions)
Ebrahim Byagowieff36cd2018-03-30 22:25:35 +0430544 endif ()
Ebrahim Byagowi90f01ba2018-01-16 22:00:21 +0330545
Ebrahim Byagowi29d90122018-01-30 10:01:46 +0330546 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Ebrahim Byagowi844f48e2018-02-10 23:13:12 +0330547 # Make sure we don't link to libstdc++
Ebrahim Byagowi29d90122018-01-30 10:01:46 +0330548 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
549 set (CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "m") # libm
550 set (CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")
551 set_target_properties(harfbuzz PROPERTIES LINKER_LANGUAGE C)
Garret Rieger0f3c7562018-02-08 14:59:32 -0800552 set_target_properties(harfbuzz-subset PROPERTIES LINKER_LANGUAGE C)
Ebrahim Byagowi00806142018-01-19 01:12:31 +0330553
Ebrahim Byagowi844f48e2018-02-10 23:13:12 +0330554 # No threadsafe statics as we do it ourselves
Ebrahim Byagowi29d90122018-01-30 10:01:46 +0330555 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics")
Ebrahim Byagowi90f01ba2018-01-16 22:00:21 +0330556 endif ()
557endif ()
558
Chun-wei Fan53db2212017-10-18 15:43:57 +0800559## Define harfbuzz-gobject library
560if (HB_HAVE_GOBJECT)
561 add_library(harfbuzz-gobject
562 ${hb_gobject_sources}
563 ${hb_gobject_gen_sources}
564 ${hb_gobject_headers}
565 ${hb_gobject_gen_headers}
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330566 )
Chun-wei Fan53db2212017-10-18 15:43:57 +0800567 include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/src)
568 add_dependencies(harfbuzz-gobject harfbuzz)
569 target_link_libraries(harfbuzz-gobject harfbuzz ${GOBJECT_LIBRARIES} ${THIRD_PARTY_LIBS})
Ebrahim Byagowiac92ed72018-05-08 01:05:15 +0430570
571 if (BUILD_SHARED_LIBS)
572 set_target_properties(harfbuzz-gobject PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE)
573 endif ()
Chun-wei Fan53db2212017-10-18 15:43:57 +0800574endif ()
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +0430575
Ebrahim Byagowi42d32712018-03-16 22:39:58 +0330576if (BUILD_SHARED_LIBS AND WIN32 AND NOT MINGW)
577 add_definitions("-DHB_EXTERN=__declspec(dllexport) extern")
Nikolaus Waxweiler22de9bf2018-03-14 10:29:24 +0000578endif ()
579
Chun-wei Fan41b18252017-10-19 18:36:32 +0800580# On Windows, g-ir-scanner requires a DLL build in order for it to work
581if (WIN32)
582 if (NOT BUILD_SHARED_LIBS)
583 message("Building introspection files on Windows requires BUILD_SHARED_LIBS to be enabled.")
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330584 set (HB_HAVE_INTROSPECTION OFF)
Chun-wei Fan41b18252017-10-19 18:36:32 +0800585 endif ()
586endif ()
587
588if (HB_HAVE_INTROSPECTION)
589
590 find_package(PkgConfig)
591 pkg_check_modules(PC_GI QUIET gobject-introspection-1.0)
592
593 find_program(G_IR_SCANNER g-ir-scanner
594 HINTS ${PC_g_ir_scanner}
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330595 )
Chun-wei Fan41b18252017-10-19 18:36:32 +0800596
597 find_program(G_IR_COMPILER g-ir-compiler
598 HINTS ${PC_g_ir_compiler}
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330599 )
Chun-wei Fan41b18252017-10-19 18:36:32 +0800600
601 if (WIN32 AND NOT MINGW)
602 # Note that since we already enable HB_HAVE_GOBJECT
603 # we would already have PYTHON_EXECUTABLE handy
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330604 set (G_IR_SCANNER_CMD "${PYTHON_EXECUTABLE}" "${G_IR_SCANNER}")
Chun-wei Fan41b18252017-10-19 18:36:32 +0800605 else ()
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330606 set (G_IR_SCANNER_CMD "${G_IR_SCANNER}")
Chun-wei Fan41b18252017-10-19 18:36:32 +0800607 endif ()
608
609 # We need to account for the varying output directories
610 # when we build using Visual Studio projects
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330611 if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio*")
Chun-wei Fan41b18252017-10-19 18:36:32 +0800612 set (hb_libpath "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>")
613 else ()
614 set (hb_libpath "$<TARGET_FILE_DIR:harfbuzz-gobject>")
615 endif ()
616
617 # Get the CFlags that we used to build HarfBuzz/HarfBuzz-GObject
618 set (hb_defines_cflags "")
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330619 foreach (hb_cflag ${hb_cflags})
Chun-wei Fan41b18252017-10-19 18:36:32 +0800620 list(APPEND hb_defines_cflags "-D${hb_cflag}")
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330621 endforeach (hb_cflag)
Chun-wei Fan41b18252017-10-19 18:36:32 +0800622
623 # Get the other dependent libraries we used to build HarfBuzz/HarfBuzz-GObject
624 set (extra_libs "")
625 foreach (extra_lib ${THIRD_PARTY_LIBS})
626 # We don't want the .lib extension here...
627 string(REPLACE ".lib" "" extra_lib_stripped "${extra_lib}")
628 list(APPEND extra_libs "--extra-library=${extra_lib_stripped}")
629 endforeach ()
630
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330631 set (introspected_sources)
Chun-wei Fan41b18252017-10-19 18:36:32 +0800632 foreach (f
633 ${project_headers}
634 ${project_sources}
635 ${hb_gobject_gen_sources}
636 ${hb_gobject_gen_headers}
637 ${hb_gobject_sources}
638 ${hb_gobject_headers}
Ebrahim Byagowi5ed26fc2018-01-04 10:11:34 +0330639 )
Chun-wei Fan41b18252017-10-19 18:36:32 +0800640 if (WIN32)
641 # Nasty issue: We need to make drive letters lower case,
642 # otherwise g-ir-scanner won't like it and give us a bunch
643 # of invalid items and unresolved types...
644 STRING(SUBSTRING "${f}" 0 1 drive)
645 STRING(SUBSTRING "${f}" 1 -1 path)
646 if (drive MATCHES "[A-Z]")
647 STRING(TOLOWER ${drive} drive_lower)
648 list(APPEND introspected_sources "${drive_lower}${path}")
649 else ()
650 list(APPEND introspected_sources "${f}")
651 endif ()
652 else ()
653 list(APPEND introspected_sources "${f}")
654 endif ()
655 endforeach ()
656
Chun-wei Fane9b80022018-03-12 16:23:57 +0800657 file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/src/hb_gir_list)
658 foreach (s ${introspected_sources})
659 file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/src/hb_gir_list "${s}\n")
660 endforeach ()
661
Chun-wei Fan41b18252017-10-19 18:36:32 +0800662 # Finally, build the introspection files...
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330663 add_custom_command(
Chun-wei Fan41b18252017-10-19 18:36:32 +0800664 TARGET harfbuzz-gobject
665 POST_BUILD
666 COMMAND ${G_IR_SCANNER_CMD}
667 --warn-all --no-libtool --verbose
668 -n hb
669 --namespace=HarfBuzz
670 --nsversion=0.0
671 --identifier-prefix=hb_
672 --include GObject-2.0
673 --pkg-export=harfbuzz
674 --cflags-begin
675 -I${PROJECT_SOURCE_DIR}/src
676 -I${PROJECT_BINARY_DIR}/src
677 ${hb_includedir_cflags}
678 ${hb_defines_cflags}
679 -DHB_H
680 -DHB_H_IN
681 -DHB_OT_H
682 -DHB_OT_H_IN
683 -DHB_GOBJECT_H
684 -DHB_GOBJECT_H_IN
685 -DHB_EXTERN=
686 --cflags-end
687 --library=harfbuzz-gobject
688 --library=harfbuzz
689 -L${hb_libpath}
690 ${extra_libs}
Chun-wei Fane9b80022018-03-12 16:23:57 +0800691 --filelist ${CMAKE_CURRENT_BINARY_DIR}/src/hb_gir_list
Chun-wei Fan41b18252017-10-19 18:36:32 +0800692 -o ${hb_libpath}/HarfBuzz-0.0.gir
Chun-wei Fane9b80022018-03-12 16:23:57 +0800693 DEPENDS harfbuzz-gobject harfbuzz ${CMAKE_CURRENT_BINARY_DIR}/src/hb_gir_list
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330694 )
Chun-wei Fan41b18252017-10-19 18:36:32 +0800695
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330696 add_custom_command(
Chun-wei Fan41b18252017-10-19 18:36:32 +0800697 TARGET harfbuzz-gobject
698 POST_BUILD
699 COMMAND "${G_IR_COMPILER}"
700 --verbose --debug
701 --includedir ${CMAKE_CURRENT_BINARY_DIR}
702 ${hb_libpath}/HarfBuzz-0.0.gir
703 -o ${hb_libpath}/HarfBuzz-0.0.typelib
704 DEPENDS ${hb_libpath}/HarfBuzz-0.0.gir harfbuzz-gobject
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330705 )
Chun-wei Fan41b18252017-10-19 18:36:32 +0800706endif ()
707
Ebrahim Byagowi5ed26fc2018-01-04 10:11:34 +0330708
Ebrahim Byagowi15273692017-05-13 21:32:56 +0430709## Additional framework build configs
710if (BUILD_FRAMEWORK)
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330711 set (CMAKE_MACOSX_RPATH ON)
Ebrahim Byagowi15273692017-05-13 21:32:56 +0430712 set_target_properties(harfbuzz PROPERTIES
713 FRAMEWORK TRUE
714 PUBLIC_HEADER "${project_headers}"
715 XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
716 )
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330717 set (MACOSX_FRAMEWORK_IDENTIFIER "harfbuzz")
718 set (MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${HB_VERSION}")
719 set (MACOSX_FRAMEWORK_BUNDLE_VERSION "${HB_VERSION}")
Ebrahim Byagowi15273692017-05-13 21:32:56 +0430720endif ()
721
722
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +0430723## Additional harfbuzz build artifacts
ebraminio3a8bc572017-04-11 21:32:14 +0430724if (HB_BUILD_UTILS)
725 # https://github.com/WebKit/webkit/blob/master/Source/cmake/FindCairo.cmake
726 find_package(PkgConfig)
727 pkg_check_modules(PC_CAIRO QUIET cairo)
728
729 find_path(CAIRO_INCLUDE_DIRS NAMES cairo.h HINTS ${PC_CAIRO_INCLUDEDIR} ${PC_CAIRO_INCLUDE_DIRS} PATH_SUFFIXES cairo)
730 find_library(CAIRO_LIBRARIESNAMES cairo HINTS ${PC_CAIRO_LIBDIR} ${PC_CAIRO_LIBRARY_DIRS})
731
732 add_definitions("-DPACKAGE_NAME=\"HarfBuzz\"")
733 add_definitions("-DPACKAGE_VERSION=\"${HB_VERSION}\"")
734 include_directories(${CAIRO_INCLUDE_DIRS})
735
736 add_executable(hb-view ${HB_VIEW_sources})
737 target_link_libraries(hb-view harfbuzz ${CAIRO_LIBRARIESNAMES})
738
739 add_executable(hb-shape ${HB_SHAPE_sources})
740 target_link_libraries(hb-shape harfbuzz)
741
Garret Riegerf83a43b2018-02-02 17:50:45 -0800742 add_executable(hb-subset ${HB_SUBSET_CLI_sources})
Garret Rieger0f3c7562018-02-08 14:59:32 -0800743 target_link_libraries(hb-subset harfbuzz harfbuzz-subset)
Garret Riegerf83a43b2018-02-02 17:50:45 -0800744
ebraminio3a8bc572017-04-11 21:32:14 +0430745 add_executable(hb-ot-shape-closure ${HB_OT_SHAPE_CLOSURE_sources})
746 target_link_libraries(hb-ot-shape-closure harfbuzz)
ebraminio69664132017-04-19 22:59:46 +0430747
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +0430748 mark_as_advanced(CAIRO_INCLUDE_DIRS CAIRO_LIBRARIESNAMES)
ebraminio3a8bc572017-04-11 21:32:14 +0430749endif ()
750
Ebrahim Byagowibf50dda2017-05-04 20:31:42 +0430751
ebraminio7d64c0e2017-04-04 15:03:51 +0430752## Install
Ebrahim Byagowi71e0ed92018-01-10 15:45:12 +0330753include (GNUInstallDirs)
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330754
ebraminio7d64c0e2017-04-04 15:03:51 +0430755if (NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL)
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330756 install(FILES ${project_headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/harfbuzz)
Chun-wei Fan53db2212017-10-18 15:43:57 +0800757 if (HB_HAVE_GOBJECT)
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330758 install(FILES ${hb_gobject_headers} ${hb_gobject_gen_headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/harfbuzz)
Chun-wei Fan53db2212017-10-18 15:43:57 +0800759 endif ()
ebraminio7d64c0e2017-04-04 15:03:51 +0430760endif ()
761
762if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
763 install(TARGETS harfbuzz
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330764 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
765 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
766 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Ebrahim Byagowi15273692017-05-13 21:32:56 +0430767 FRAMEWORK DESTINATION Library/Frameworks
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330768 )
Chun-wei Fan162575f2017-10-18 22:27:28 +0800769 if (HB_BUILD_UTILS)
770 install(TARGETS hb-view
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330771 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Chun-wei Fan162575f2017-10-18 22:27:28 +0800772 )
Chun-wei Fan7c43ada2018-03-12 16:43:53 +0800773 install(TARGETS hb-subset
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330774 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Chun-wei Fan162575f2017-10-18 22:27:28 +0800775 )
776
777 install(TARGETS hb-shape
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330778 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Chun-wei Fan162575f2017-10-18 22:27:28 +0800779 )
780
781 install(TARGETS hb-ot-shape-closure
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330782 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Chun-wei Fan162575f2017-10-18 22:27:28 +0800783 )
784 endif ()
Chun-wei Fan53db2212017-10-18 15:43:57 +0800785 if (HB_HAVE_GOBJECT)
786 install(TARGETS harfbuzz-gobject
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330787 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
788 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
789 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Chun-wei Fan53db2212017-10-18 15:43:57 +0800790 )
Chun-wei Fan41b18252017-10-19 18:36:32 +0800791 if (HB_HAVE_INTROSPECTION)
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330792 if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio*")
Chun-wei Fan41b18252017-10-19 18:36:32 +0800793 set (hb_libpath "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>")
794 else ()
795 set (hb_libpath "$<TARGET_FILE_DIR:harfbuzz-gobject>")
796 endif ()
797
798 install(FILES "${hb_libpath}/HarfBuzz-0.0.gir"
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330799 DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/gir-1.0
Ebrahim Byagowi5ed26fc2018-01-04 10:11:34 +0330800 )
Chun-wei Fan41b18252017-10-19 18:36:32 +0800801
802 install(FILES "${hb_libpath}/HarfBuzz-0.0.typelib"
Ebrahim Byagowi24b30fa2017-12-25 22:01:28 +0330803 DESTINATION ${CMAKE_INSTALL_LIBDIR}/girepository-1.0
804 )
Chun-wei Fan41b18252017-10-19 18:36:32 +0800805 endif ()
Chun-wei Fan53db2212017-10-18 15:43:57 +0800806 endif ()
ebraminio7d64c0e2017-04-04 15:03:51 +0430807endif ()
Khaled Hosnyc8609552017-12-06 00:43:28 +0200808
Bruce Mitchener4f800782018-01-04 18:37:35 +0700809if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja")
810 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Ebrahim Byagowi29d90122018-01-30 10:01:46 +0330811 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
812 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics")
Bruce Mitchener4f800782018-01-04 18:37:35 +0700813 endif ()
814 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Ebrahim Byagowi29d90122018-01-30 10:01:46 +0330815 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color")
816 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color")
Bruce Mitchener4f800782018-01-04 18:37:35 +0700817 endif ()
818endif ()
Ebrahim Byagowi5ed26fc2018-01-04 10:11:34 +0330819
Ebrahim Byagowi72bec1c2018-01-05 12:42:20 +0330820
Ebrahim Byagowi29d90122018-01-30 10:01:46 +0330821## src/ executables
Ebrahim Byagowi0eec3312018-02-28 11:53:39 +0330822foreach (prog main test test-would-substitute test-size-params test-buffer-serialize hb-ot-tag test-unicode-ranges)
823 set (prog_name ${prog})
824 if (${prog_name} STREQUAL "test")
825 # test can not be used as a valid executable name on cmake, lets special case it
826 set (prog_name test-test)
827 endif ()
828 add_executable(${prog_name} ${PROJECT_SOURCE_DIR}/src/${prog}.cc)
829 target_link_libraries(${prog_name} harfbuzz ${THIRD_PARTY_LIBS})
830endforeach ()
831set_target_properties(hb-ot-tag PROPERTIES COMPILE_FLAGS "-DMAIN")
Ebrahim Byagowi29d90122018-01-30 10:01:46 +0330832
Ebrahim Byagowi5ed26fc2018-01-04 10:11:34 +0330833## Tests
Ebrahim Byagowi90f01ba2018-01-16 22:00:21 +0330834if (UNIX OR MINGW)
Ebrahim Byagowi5ed26fc2018-01-04 10:11:34 +0330835 if (BUILD_SHARED_LIBS)
Ebrahim Byagowi3d615762018-01-22 21:23:19 +0330836 # generate harfbuzz.def after build completion
Ebrahim Byagowi00806142018-01-19 01:12:31 +0330837 add_custom_command(TARGET harfbuzz POST_BUILD
Cosimo Lupo53f73402018-07-09 18:54:23 +0100838 COMMAND "${PYTHON_EXECUTABLE}" ${PROJECT_SOURCE_DIR}/src/gen-def.py ${PROJECT_BINARY_DIR}/harfbuzz.def ${project_headers}
Ebrahim Byagowi00806142018-01-19 01:12:31 +0330839 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src)
Ebrahim Byagowic97a7ec2018-01-16 14:18:09 +0330840
Ebrahim Byagowi00806142018-01-19 01:12:31 +0330841 add_test(NAME check-static-inits.sh
842 COMMAND ${PROJECT_SOURCE_DIR}/src/check-static-inits.sh
843 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/harfbuzz.dir/src # ugly hack
844 )
845 add_test(NAME check-libstdc++.sh COMMAND ${PROJECT_SOURCE_DIR}/src/check-libstdc++.sh)
Ebrahim Byagowi3d615762018-01-22 21:23:19 +0330846 add_test(NAME check-symbols.sh COMMAND ${PROJECT_SOURCE_DIR}/src/check-symbols.sh)
Ebrahim Byagowi8b60e7c2018-01-22 18:37:26 +0330847
Ebrahim Byagowia9b650d2018-02-12 15:10:13 +0330848 set_tests_properties(
Behdad Esfahbode0939d82018-02-23 13:19:34 -0800849 check-static-inits.sh check-libstdc++.sh check-symbols.sh
Ebrahim Byagowia9b650d2018-02-12 15:10:13 +0330850 PROPERTIES
851 ENVIRONMENT "libs=.;srcdir=${PROJECT_SOURCE_DIR}/src"
852 SKIP_RETURN_CODE 77)
Ebrahim Byagowi5ed26fc2018-01-04 10:11:34 +0330853 endif ()
854
Ebrahim Byagowi90f01ba2018-01-16 22:00:21 +0330855 add_test(NAME check-c-linkage-decls.sh COMMAND ./check-c-linkage-decls.sh)
856 add_test(NAME check-header-guards.sh COMMAND ./check-header-guards.sh)
857 add_test(NAME check-externs.sh COMMAND ./check-externs.sh)
858 add_test(NAME check-includes.sh COMMAND ./check-includes.sh)
859 set_tests_properties(
860 check-c-linkage-decls.sh check-header-guards.sh check-externs.sh check-includes.sh
Ebrahim Byagowia9b650d2018-02-12 15:10:13 +0330861 PROPERTIES
862 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src
863 SKIP_RETURN_CODE 77)
Ebrahim Byagowi5ed26fc2018-01-04 10:11:34 +0330864endif ()
865
Khaled Hosnyc8609552017-12-06 00:43:28 +0200866# Needs to come last so that variables defined above are passed to
867# subdirectories.
rdb5e14e5f2018-01-16 17:04:33 +0100868add_subdirectory(test)