ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.0) |
| 2 | project(harfbuzz) |
| 3 | |
Ebrahim Byagowi | 1527369 | 2017-05-13 21:32:56 +0430 | [diff] [blame] | 4 | |
| 5 | ## Limit framework build to Xcode generator |
| 6 | if (BUILD_FRAMEWORK) |
| 7 | # for a framework on macOS, use `cmake .. -DBUILD_FRAMEWORK:BOOL=true -G Xcode` |
| 8 | if (NOT "${CMAKE_GENERATOR}" STREQUAL "Xcode") |
| 9 | message(FATAL_ERROR |
| 10 | "You should use Xcode generator with BUILD_FRAMEWORK enabled") |
| 11 | endif () |
| 12 | set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_64_BIT)") |
| 13 | set(CMAKE_MACOSX_RPATH ON) |
| 14 | set(BUILD_SHARED_LIBS ON) |
| 15 | endif () |
| 16 | |
| 17 | |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 18 | ## Disallow in-source builds, as CMake generated make files can collide with autotools ones |
| 19 | if (NOT MSVC AND "${PROJECT_BINARY_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}") |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 20 | message(FATAL_ERROR |
| 21 | " |
| 22 | In-source builds are not permitted! Make a separate folder for" |
| 23 | " building, e.g.," |
| 24 | " |
| 25 | mkdir build; cd build; cmake .." |
| 26 | " |
| 27 | Before that, remove the files created by this failed run with" |
| 28 | " |
| 29 | rm -rf CMakeCache.txt CMakeFiles") |
| 30 | endif () |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 31 | |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 32 | |
| 33 | ## HarfBuzz build configurations |
ebraminio | adfd4ae | 2017-04-11 23:18:18 +0430 | [diff] [blame] | 34 | option(HB_HAVE_FREETYPE "Enable freetype interop helpers" OFF) |
| 35 | option(HB_HAVE_GRAPHITE2 "Enable Graphite2 complementary shaper" OFF) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 36 | option(HB_BUILTIN_UCDN "Use HarfBuzz provided UCDN" ON) |
ebraminio | adfd4ae | 2017-04-11 23:18:18 +0430 | [diff] [blame] | 37 | option(HB_HAVE_GLIB "Enable glib unicode functions" OFF) |
| 38 | option(HB_HAVE_ICU "Enable icu unicode functions" OFF) |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 39 | if (APPLE) |
| 40 | option(HB_HAVE_CORETEXT "Enable CoreText shaper backend on macOS" ON) |
| 41 | endif () |
| 42 | if (WIN32) |
| 43 | option(HB_HAVE_UNISCRIBE "Enable Uniscribe shaper backend on Windows" OFF) |
| 44 | option(HB_HAVE_DIRECWRITE "Enable DirectWrite shaper backend on Windows" OFF) |
| 45 | endif () |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 46 | option(HB_BUILD_UTILS "Build harfbuzz utils, needs cairo, freetype, and glib properly be installed" OFF) |
| 47 | if (HB_BUILD_UTILS) |
| 48 | set(HB_HAVE_GLIB ON) |
| 49 | set(HB_HAVE_FREETYPE ON) |
| 50 | endif () |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 51 | |
| 52 | include_directories(AFTER |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 53 | ${PROJECT_SOURCE_DIR}/src |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 54 | ${PROJECT_BINARY_DIR}/src |
| 55 | ) |
| 56 | |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 57 | add_definitions(-DHAVE_OT) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 58 | |
| 59 | if (BUILD_SHARED_LIBS) |
| 60 | add_definitions(-DHAVE_ATEXIT) |
| 61 | endif () |
| 62 | |
| 63 | if (MSVC) |
| 64 | add_definitions(-wd4244 -wd4267 -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS) |
| 65 | endif () |
| 66 | |
| 67 | if (WIN32 AND NOT MINGW AND BUILD_SHARED_LIBS) |
| 68 | add_definitions("-DHB_EXTERN=__declspec(dllexport) extern") |
| 69 | endif () |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 70 | |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 71 | |
Ebrahim Byagowi | 1527369 | 2017-05-13 21:32:56 +0430 | [diff] [blame] | 72 | ## Detect if we are running inside a distribution or regular repository folder |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 73 | set(IN_HB_DIST FALSE) |
Ebrahim Byagowi | 3b0e47c | 2017-06-19 14:47:09 +0430 | [diff] [blame] | 74 | if (EXISTS "${PROJECT_SOURCE_DIR}/ChangeLog") |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 75 | # perhaps we are on dist directory |
| 76 | set(IN_HB_DIST TRUE) |
| 77 | set(HB_VERSION_H "${PROJECT_SOURCE_DIR}/src/hb-version.h") |
| 78 | endif () |
| 79 | |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 80 | |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 81 | ## Extract variables from Makefile files |
| 82 | # http://stackoverflow.com/a/27630120/1414809 |
| 83 | function (prepend var prefix) |
| 84 | set(listVar "") |
| 85 | foreach (f ${ARGN}) |
| 86 | list(APPEND listVar "${prefix}${f}") |
ebraminio | adfd4ae | 2017-04-11 23:18:18 +0430 | [diff] [blame] | 87 | endforeach () |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 88 | set(${var} "${listVar}" PARENT_SCOPE) |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 89 | endfunction () |
| 90 | |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 91 | function (extract_make_variable variable file prefix) |
| 92 | string(REGEX MATCH "${variable} = ([^$]+)\\$" temp ${file}) |
| 93 | string(REGEX MATCHALL "[^ \n\t\\]+" list ${CMAKE_MATCH_1}) |
| 94 | prepend(list ${prefix} ${list}) |
| 95 | set(${variable} ${list} PARENT_SCOPE) |
| 96 | endfunction () |
| 97 | |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 98 | file(READ ${PROJECT_SOURCE_DIR}/src/Makefile.sources SRCSOURCES) |
| 99 | file(READ ${PROJECT_SOURCE_DIR}/util/Makefile.sources UTILSOURCES) |
ebraminio | adfd4ae | 2017-04-11 23:18:18 +0430 | [diff] [blame] | 100 | file(READ ${PROJECT_SOURCE_DIR}/src/hb-ucdn/Makefile.sources UCDNSOURCES) |
| 101 | |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 102 | extract_make_variable(HB_BASE_sources ${SRCSOURCES} "${PROJECT_SOURCE_DIR}/src/") |
| 103 | extract_make_variable(HB_BASE_headers ${SRCSOURCES} "${PROJECT_SOURCE_DIR}/src/") |
| 104 | extract_make_variable(HB_OT_sources ${SRCSOURCES} "${PROJECT_SOURCE_DIR}/src/") |
| 105 | extract_make_variable(HB_OT_headers ${SRCSOURCES} "${PROJECT_SOURCE_DIR}/src/") |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 106 | |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 107 | if (IN_HB_DIST) |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 108 | set(RAGEL_GENERATED_DIR "${PROJECT_SOURCE_DIR}/src/") |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 109 | else () |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 110 | set(RAGEL_GENERATED_DIR "${PROJECT_BINARY_DIR}/src/") |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 111 | endif () |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 112 | extract_make_variable(HB_BASE_RAGEL_GENERATED_sources ${SRCSOURCES} ${RAGEL_GENERATED_DIR}) |
| 113 | extract_make_variable(HB_OT_RAGEL_GENERATED_sources ${SRCSOURCES} ${RAGEL_GENERATED_DIR}) |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 114 | |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 115 | extract_make_variable(HB_VIEW_sources ${UTILSOURCES} "${PROJECT_SOURCE_DIR}/util/") |
| 116 | extract_make_variable(HB_SHAPE_sources ${UTILSOURCES} "${PROJECT_SOURCE_DIR}/util/") |
| 117 | extract_make_variable(HB_OT_SHAPE_CLOSURE_sources ${UTILSOURCES} "${PROJECT_SOURCE_DIR}/util/") |
| 118 | |
| 119 | extract_make_variable(LIBHB_UCDN_sources ${UCDNSOURCES} "${PROJECT_SOURCE_DIR}/src/hb-ucdn/") |
ebraminio | adfd4ae | 2017-04-11 23:18:18 +0430 | [diff] [blame] | 120 | |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 121 | file(READ configure.ac CONFIGUREAC) |
| 122 | string(REGEX MATCH "\\[(([0-9]+)\\.([0-9]+)\\.([0-9]+))\\]" HB_VERSION_MATCH ${CONFIGUREAC}) |
| 123 | set(HB_VERSION ${CMAKE_MATCH_1}) |
| 124 | set(HB_VERSION_MAJOR ${CMAKE_MATCH_2}) |
| 125 | set(HB_VERSION_MINOR ${CMAKE_MATCH_3}) |
| 126 | set(HB_VERSION_MICRO ${CMAKE_MATCH_4}) |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 127 | |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 128 | |
Ebrahim Byagowi | 1527369 | 2017-05-13 21:32:56 +0430 | [diff] [blame] | 129 | ## Define ragel tasks |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 130 | if (NOT IN_HB_DIST) |
Ebrahim Byagowi | 3b0e47c | 2017-06-19 14:47:09 +0430 | [diff] [blame] | 131 | find_program(RAGEL "ragel" CMAKE_FIND_ROOT_PATH_BOTH) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 132 | |
| 133 | if (RAGEL) |
| 134 | message(STATUS "ragel found at: ${RAGEL}") |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 135 | else () |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 136 | message(FATAL_ERROR "ragel not found, get it here -- http://www.complang.org/ragel/ or, use harfbuzz releases https://github.com/behdad/harfbuzz/releases") |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 137 | endif () |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 138 | |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 139 | foreach (ragel_output IN ITEMS ${HB_BASE_RAGEL_GENERATED_sources} ${HB_OT_RAGEL_GENERATED_sources}) |
| 140 | string(REGEX MATCH "([^/]+)\\.hh" temp ${ragel_output}) |
| 141 | set(target_name ${CMAKE_MATCH_1}) |
| 142 | add_custom_command(OUTPUT ${ragel_output} |
| 143 | COMMAND ${RAGEL} -G2 -o ${ragel_output} ${PROJECT_SOURCE_DIR}/src/${target_name}.rl -I ${PROJECT_SOURCE_DIR} ${ARGN} |
| 144 | DEPENDS ${PROJECT_SOURCE_DIR}/src/${target_name}.rl |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 145 | ) |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 146 | add_custom_target(harfbuzz_${target_name} DEPENDS ${PROJECT_BINARY_DIR}/src/${target_name}) |
| 147 | endforeach () |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 148 | |
| 149 | mark_as_advanced(RAGEL) |
Ebrahim Byagowi | 1527369 | 2017-05-13 21:32:56 +0430 | [diff] [blame] | 150 | endif () |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 151 | |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 152 | |
Ebrahim Byagowi | 1527369 | 2017-05-13 21:32:56 +0430 | [diff] [blame] | 153 | ## Generate hb-version.h |
| 154 | if (NOT IN_HB_DIST) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 155 | set(HB_VERSION_H_IN "${PROJECT_SOURCE_DIR}/src/hb-version.h.in") |
| 156 | set(HB_VERSION_H "${PROJECT_BINARY_DIR}/src/hb-version.h") |
| 157 | set_source_files_properties("${HB_VERSION_H}" PROPERTIES GENERATED true) |
| 158 | configure_file("${HB_VERSION_H_IN}" "${HB_VERSION_H}.tmp" @ONLY) |
| 159 | execute_process(COMMAND "${CMAKE_COMMAND}" -E copy_if_different |
| 160 | "${HB_VERSION_H}.tmp" |
Ebrahim Byagowi | 1527369 | 2017-05-13 21:32:56 +0430 | [diff] [blame] | 161 | "${HB_VERSION_H}" |
| 162 | ) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 163 | file(REMOVE "${HB_VERSION_H}.tmp") |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 164 | endif () |
| 165 | |
Ebrahim Byagowi | 1527369 | 2017-05-13 21:32:56 +0430 | [diff] [blame] | 166 | |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 167 | ## Define sources and headers of the project |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 168 | set(project_sources |
| 169 | ${HB_BASE_sources} |
| 170 | ${HB_BASE_RAGEL_GENERATED_sources} |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 171 | |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 172 | ${HB_OT_sources} |
| 173 | ${HB_OT_RAGEL_GENERATED_sources} |
| 174 | ) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 175 | |
| 176 | set(project_headers |
| 177 | ${HB_VERSION_H} |
| 178 | |
| 179 | ${HB_BASE_headers} |
| 180 | ${HB_OT_headers} |
| 181 | ) |
| 182 | |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 183 | |
| 184 | ## Find and include needed header folders and libraries |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 185 | if (HB_HAVE_FREETYPE) |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 186 | add_definitions(-DHAVE_FREETYPE=1 -DHAVE_FT_FACE_GETCHARVARIANTINDEX=1) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 187 | |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 188 | # https://github.com/WebKit/webkit/blob/master/Source/cmake/FindFreetype2.cmake |
| 189 | find_package(PkgConfig) |
| 190 | pkg_check_modules(PC_FREETYPE2 QUIET freetype2) |
| 191 | |
| 192 | find_path(FREETYPE2_HEADER_DIR NAMES freetype.h HINTS ${PC_FREETYPE2_INCLUDE_DIRS} ${PC_FREETYPE2_INCLUDEDIR} $ENV{FREETYPE_DIR}/include PATH_SUFFIXES freetype) |
| 193 | find_path(FREETYPE2_ROOT_INCLUDE_DIR NAMES freetype/freetype.h HINTS ${PC_FREETYPE2_INCLUDE_DIRS} ${PC_FREETYPE2_INCLUDEDIR} $ENV{FREETYPE_DIR}/include) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 194 | if (CMAKE_BUILD_TYPE MATCHES Debug) |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 195 | set(FREETYPE2_LIBRARY_NAME freetyped) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 196 | else () |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 197 | set(FREETYPE2_LIBRARY_NAME freetype) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 198 | endif () |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 199 | find_library(FREETYPE2_LIBRARIES ${FREETYPE2_LIBRARY_NAME} HINTS ${PC_FREETYPE2_LIBDIR} ${PC_FREETYPE2_LIBRARY_DIRS} $ENV{FREETYPE_DIR}/lib) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 200 | |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 201 | include_directories(AFTER ${FREETYPE2_HEADER_DIR} ${FREETYPE2_ROOT_INCLUDE_DIR}) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 202 | |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 203 | list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-ft.cc) |
| 204 | list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-ft.h) |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 205 | |
| 206 | list(APPEND THIRD_PARTY_LIBS ${FREETYPE2_LIBRARIES}) |
| 207 | |
| 208 | mark_as_advanced(FREETYPE2_HEADER_DIR FREETYPE2_ROOT_INCLUDE_DIR FREETYPE2_LIBRARIES) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 209 | endif () |
| 210 | |
ebraminio | adfd4ae | 2017-04-11 23:18:18 +0430 | [diff] [blame] | 211 | if (HB_HAVE_GRAPHITE2) |
| 212 | add_definitions(-DHAVE_GRAPHITE2) |
| 213 | |
| 214 | find_path(GRAPHITE2_INCLUDE_DIR graphite2/Font.h) |
| 215 | find_library(GRAPHITE2_LIBRARY graphite2) |
| 216 | |
| 217 | include_directories(${GRAPHITE2_INCLUDE_DIR}) |
| 218 | |
| 219 | list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-graphite2.cc) |
| 220 | list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-graphite2.h) |
| 221 | |
| 222 | list(APPEND THIRD_PARTY_LIBS ${GRAPHITE2_LIBRARY}) |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 223 | |
| 224 | mark_as_advanced(GRAPHITE2_INCLUDE_DIR GRAPHITE2_LIBRARY) |
ebraminio | adfd4ae | 2017-04-11 23:18:18 +0430 | [diff] [blame] | 225 | endif () |
| 226 | |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 227 | if (HB_BUILTIN_UCDN) |
| 228 | include_directories(src/hb-ucdn) |
| 229 | add_definitions(-DHAVE_UCDN) |
| 230 | |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 231 | list(APPEND project_sources |
ebraminio | d2acaf6 | 2017-04-05 02:21:23 -0700 | [diff] [blame] | 232 | ${PROJECT_SOURCE_DIR}/src/hb-ucdn.cc |
Ebrahim Byagowi | 1527369 | 2017-05-13 21:32:56 +0430 | [diff] [blame] | 233 | ${LIBHB_UCDN_sources} |
| 234 | ) |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 235 | endif () |
| 236 | |
| 237 | if (HB_HAVE_GLIB) |
| 238 | add_definitions(-DHAVE_GLIB) |
| 239 | |
| 240 | # https://github.com/WebKit/webkit/blob/master/Source/cmake/FindGLIB.cmake |
| 241 | find_package(PkgConfig) |
| 242 | pkg_check_modules(PC_GLIB QUIET glib-2.0) |
| 243 | |
| 244 | find_library(GLIB_LIBRARIES NAMES glib-2.0 HINTS ${PC_GLIB_LIBDIR} ${PC_GLIB_LIBRARY_DIRS}) |
| 245 | 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) |
| 246 | find_path(GLIB_INCLUDE_DIR NAMES glib.h HINTS ${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS} PATH_SUFFIXES glib-2.0) |
| 247 | |
| 248 | include_directories(${GLIBCONFIG_INCLUDE_DIR} ${GLIB_INCLUDE_DIR}) |
| 249 | |
| 250 | list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-glib.cc) |
| 251 | list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-glib.h) |
| 252 | |
| 253 | list(APPEND THIRD_PARTY_LIBS ${GLIB_LIBRARIES}) |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 254 | |
| 255 | mark_as_advanced(GLIB_LIBRARIES GLIBCONFIG_INCLUDE_DIR GLIB_INCLUDE_DIR) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 256 | endif () |
| 257 | |
ebraminio | adfd4ae | 2017-04-11 23:18:18 +0430 | [diff] [blame] | 258 | if (HB_HAVE_ICU) |
| 259 | add_definitions(-DHAVE_ICU) |
| 260 | |
| 261 | # https://github.com/WebKit/webkit/blob/master/Source/cmake/FindICU.cmake |
| 262 | find_package(PkgConfig) |
| 263 | pkg_check_modules(PC_ICU QUIET icu-uc) |
| 264 | |
| 265 | find_path(ICU_INCLUDE_DIR NAMES unicode/utypes.h HINTS ${PC_ICU_INCLUDE_DIRS} ${PC_ICU_INCLUDEDIR}) |
| 266 | find_library(ICU_LIBRARY NAMES libicuuc cygicuuc cygicuuc32 icuuc HINTS ${PC_ICU_LIBRARY_DIRS} ${PC_ICU_LIBDIR}) |
| 267 | |
| 268 | include_directories(${ICU_INCLUDE_DIR}) |
| 269 | |
| 270 | list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-icu.cc) |
| 271 | list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-icu.h) |
| 272 | |
| 273 | list(APPEND THIRD_PARTY_LIBS ${ICU_LIBRARY}) |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 274 | |
| 275 | mark_as_advanced(ICU_INCLUDE_DIR ICU_LIBRARY) |
ebraminio | adfd4ae | 2017-04-11 23:18:18 +0430 | [diff] [blame] | 276 | endif () |
| 277 | |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 278 | if (APPLE AND HB_HAVE_CORETEXT) |
| 279 | # Apple Advanced Typography |
| 280 | add_definitions(-DHAVE_CORETEXT) |
| 281 | |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 282 | list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-coretext.cc) |
| 283 | list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-coretext.h) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 284 | |
| 285 | find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 286 | if (APPLICATION_SERVICES_FRAMEWORK) |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 287 | list(APPEND THIRD_PARTY_LIBS ${APPLICATION_SERVICES_FRAMEWORK}) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 288 | endif (APPLICATION_SERVICES_FRAMEWORK) |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 289 | |
| 290 | mark_as_advanced(APPLICATION_SERVICES_FRAMEWORK) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 291 | endif () |
| 292 | |
| 293 | if (WIN32 AND HB_HAVE_UNISCRIBE) |
| 294 | add_definitions(-DHAVE_UNISCRIBE) |
| 295 | |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 296 | list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-uniscribe.cc) |
| 297 | list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-uniscribe.h) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 298 | |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 299 | list(APPEND THIRD_PARTY_LIBS usp10 gdi32 rpcrt4) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 300 | endif () |
| 301 | |
| 302 | if (WIN32 AND HB_HAVE_DIRECTWRITE) |
| 303 | add_definitions(-DHAVE_DIRECTWRITE) |
| 304 | |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 305 | list(APPEND project_sources ${PROJECT_SOURCE_DIR}/src/hb-directwrite.cc) |
| 306 | list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-directwrite.h) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 307 | |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 308 | list(APPEND THIRD_PARTY_LIBS dwrite rpcrt4) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 309 | endif () |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 310 | |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 311 | |
ebraminio | a41d5ea | 2017-04-14 04:25:50 +0430 | [diff] [blame] | 312 | ## Atomic ops availability detection |
| 313 | file(WRITE "${PROJECT_BINARY_DIR}/try_compile_intel_atomic_primitives.c" |
| 314 | " void memory_barrier (void) { __sync_synchronize (); } |
| 315 | int atomic_add (int *i) { return __sync_fetch_and_add (i, 1); } |
| 316 | int mutex_trylock (int *m) { return __sync_lock_test_and_set (m, 1); } |
| 317 | void mutex_unlock (int *m) { __sync_lock_release (m); } |
ebraminio | 7593142 | 2017-04-14 05:08:11 +0430 | [diff] [blame] | 318 | int main () { return 0; } |
ebraminio | a41d5ea | 2017-04-14 04:25:50 +0430 | [diff] [blame] | 319 | ") |
| 320 | try_compile(HB_HAVE_INTEL_ATOMIC_PRIMITIVES |
| 321 | ${PROJECT_BINARY_DIR}/try_compile_intel_atomic_primitives |
| 322 | SOURCES ${PROJECT_BINARY_DIR}/try_compile_intel_atomic_primitives.c) |
| 323 | if (HB_HAVE_INTEL_ATOMIC_PRIMITIVES) |
| 324 | add_definitions(-DHAVE_INTEL_ATOMIC_PRIMITIVES) |
| 325 | endif () |
| 326 | |
| 327 | file(WRITE "${PROJECT_BINARY_DIR}/try_compile_solaris_atomic_ops.c" |
| 328 | " #include <atomic.h> |
| 329 | /* This requires Solaris Studio 12.2 or newer: */ |
| 330 | #include <mbarrier.h> |
| 331 | void memory_barrier (void) { __machine_rw_barrier (); } |
| 332 | int atomic_add (volatile unsigned *i) { return atomic_add_int_nv (i, 1); } |
| 333 | void *atomic_ptr_cmpxchg (volatile void **target, void *cmp, void *newval) { return atomic_cas_ptr (target, cmp, newval); } |
ebraminio | 7593142 | 2017-04-14 05:08:11 +0430 | [diff] [blame] | 334 | int main () { return 0; } |
ebraminio | a41d5ea | 2017-04-14 04:25:50 +0430 | [diff] [blame] | 335 | ") |
| 336 | try_compile(HB_HAVE_SOLARIS_ATOMIC_OPS |
| 337 | ${PROJECT_BINARY_DIR}/try_compile_solaris_atomic_ops |
| 338 | SOURCES ${PROJECT_BINARY_DIR}/try_compile_solaris_atomic_ops.c) |
ebraminio | cb021e1 | 2017-04-14 04:31:17 +0430 | [diff] [blame] | 339 | if (HB_HAVE_SOLARIS_ATOMIC_OPS) |
| 340 | add_definitions(-DHAVE_SOLARIS_ATOMIC_OPS) |
ebraminio | a41d5ea | 2017-04-14 04:25:50 +0430 | [diff] [blame] | 341 | endif () |
ebraminio | a41d5ea | 2017-04-14 04:25:50 +0430 | [diff] [blame] | 342 | |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 343 | |
| 344 | ## Define harfbuzz library |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 345 | add_library(harfbuzz ${project_sources} ${project_headers}) |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 346 | target_link_libraries(harfbuzz ${THIRD_PARTY_LIBS}) |
| 347 | |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 348 | |
Ebrahim Byagowi | 1527369 | 2017-05-13 21:32:56 +0430 | [diff] [blame] | 349 | ## Additional framework build configs |
| 350 | if (BUILD_FRAMEWORK) |
| 351 | set(CMAKE_MACOSX_RPATH ON) |
| 352 | set_target_properties(harfbuzz PROPERTIES |
| 353 | FRAMEWORK TRUE |
| 354 | PUBLIC_HEADER "${project_headers}" |
| 355 | XCODE_ATTRIBUTE_INSTALL_PATH "@rpath" |
| 356 | ) |
| 357 | set(MACOSX_FRAMEWORK_IDENTIFIER "harfbuzz") |
| 358 | set(MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${HB_VERSION}") |
| 359 | set(MACOSX_FRAMEWORK_BUNDLE_VERSION "${HB_VERSION}") |
| 360 | endif () |
| 361 | |
| 362 | |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 363 | ## Additional harfbuzz build artifacts |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 364 | if (HB_BUILD_UTILS) |
| 365 | # https://github.com/WebKit/webkit/blob/master/Source/cmake/FindCairo.cmake |
| 366 | find_package(PkgConfig) |
| 367 | pkg_check_modules(PC_CAIRO QUIET cairo) |
| 368 | |
| 369 | find_path(CAIRO_INCLUDE_DIRS NAMES cairo.h HINTS ${PC_CAIRO_INCLUDEDIR} ${PC_CAIRO_INCLUDE_DIRS} PATH_SUFFIXES cairo) |
| 370 | find_library(CAIRO_LIBRARIESNAMES cairo HINTS ${PC_CAIRO_LIBDIR} ${PC_CAIRO_LIBRARY_DIRS}) |
| 371 | |
| 372 | add_definitions("-DPACKAGE_NAME=\"HarfBuzz\"") |
| 373 | add_definitions("-DPACKAGE_VERSION=\"${HB_VERSION}\"") |
| 374 | include_directories(${CAIRO_INCLUDE_DIRS}) |
| 375 | |
| 376 | add_executable(hb-view ${HB_VIEW_sources}) |
| 377 | target_link_libraries(hb-view harfbuzz ${CAIRO_LIBRARIESNAMES}) |
| 378 | |
| 379 | add_executable(hb-shape ${HB_SHAPE_sources}) |
| 380 | target_link_libraries(hb-shape harfbuzz) |
| 381 | |
| 382 | add_executable(hb-ot-shape-closure ${HB_OT_SHAPE_CLOSURE_sources}) |
| 383 | target_link_libraries(hb-ot-shape-closure harfbuzz) |
ebraminio | 6966413 | 2017-04-19 22:59:46 +0430 | [diff] [blame] | 384 | |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 385 | mark_as_advanced(CAIRO_INCLUDE_DIRS CAIRO_LIBRARIESNAMES) |
ebraminio | 3a8bc57 | 2017-04-11 21:32:14 +0430 | [diff] [blame] | 386 | endif () |
| 387 | |
Ebrahim Byagowi | bf50dda | 2017-05-04 20:31:42 +0430 | [diff] [blame] | 388 | |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 389 | ## Install |
| 390 | if (NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL) |
| 391 | install(FILES ${project_headers} DESTINATION include/harfbuzz) |
| 392 | endif () |
| 393 | |
| 394 | if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) |
| 395 | install(TARGETS harfbuzz |
| 396 | ARCHIVE DESTINATION lib |
| 397 | LIBRARY DESTINATION lib |
| 398 | RUNTIME DESTINATION bin |
Ebrahim Byagowi | 1527369 | 2017-05-13 21:32:56 +0430 | [diff] [blame] | 399 | FRAMEWORK DESTINATION Library/Frameworks |
ebraminio | 7d64c0e | 2017-04-04 15:03:51 +0430 | [diff] [blame] | 400 | ) |
| 401 | endif () |