|
| 1 | +# Copyright 2017 Igalia S.L. All Rights Reserved. |
| 2 | +# |
| 3 | +# Distributed under MIT license. |
| 4 | +# See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
| 5 | + |
| 6 | +# Ubuntu 12.04 LTS has CMake 2.8.7, and is an important target since |
| 7 | +# several CI services, such as Travis and Drone, use it. Solaris 11 |
| 8 | +# has 2.8.6, and it's not difficult to support if you already have to |
| 9 | +# support 2.8.7. |
| 10 | +cmake_minimum_required(VERSION 2.8.6) |
| 11 | + |
| 12 | +project(woff2) |
| 13 | + |
| 14 | +include(GNUInstallDirs) |
| 15 | + |
| 16 | +# Build options |
| 17 | +option(BUILD_SHARED_LIBS "Build shared libraries" ON) |
| 18 | +option(CANONICAL_PREFIXES "Canonical prefixes" OFF) |
| 19 | +option(NOISY_LOGGING "Noisy logging" ON) |
| 20 | + |
| 21 | +# Version information |
| 22 | +set(WOFF2_VERSION 1.0.2) |
| 23 | + |
| 24 | +# When building shared libraries it is important to set the correct rpath |
| 25 | +# See https://cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH |
| 26 | +set(CMAKE_SKIP_BUILD_RPATH FALSE) |
| 27 | +set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) |
| 28 | +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) |
| 29 | +list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_LIBDIR}" isSystemDir) |
| 30 | +if ("${isSystemDir}" STREQUAL "-1") |
| 31 | + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}") |
| 32 | +endif() |
| 33 | + |
| 34 | +# Find Brotli dependencies |
| 35 | +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 36 | +find_package(BrotliDec) |
| 37 | +if (NOT BROTLIDEC_FOUND) |
| 38 | + message(FATAL_ERROR "librotlidec is needed to build woff2.") |
| 39 | +endif () |
| 40 | +find_package(BrotliEnc) |
| 41 | +if (NOT BROTLIENC_FOUND) |
| 42 | + message(FATAL_ERROR "librotlienc is needed to build woff2.") |
| 43 | +endif () |
| 44 | + |
| 45 | +# Set compiler flags |
| 46 | +if (NOT CANONICAL_PREFIXES) |
| 47 | + add_definitions(-no-canonical-prefixes) |
| 48 | + endif () |
| 49 | +if (NOISY_LOGGING) |
| 50 | + add_definitions(-DFONT_COMPRESSION_BIN) |
| 51 | +endif () |
| 52 | +add_definitions(-D__STDC_FORMAT_MACROS) |
| 53 | +set(COMMON_FLAGS -fno-omit-frame-pointer) |
| 54 | + |
| 55 | +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 56 | + add_definitions(-DOS_MACOSX) |
| 57 | +else () |
| 58 | + set(COMMON_FLAGS "${COMMON_FLAG} -fno-omit-frame-pointer") |
| 59 | +endif() |
| 60 | + |
| 61 | +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAG}") |
| 62 | + |
| 63 | +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAG}") |
| 64 | +set(CMAKE_CXX_STANDARD 11) |
| 65 | + |
| 66 | +# Set search path for our private/public headers as well as Brotli headers |
| 67 | +include_directories("src" "include" |
| 68 | + "${BROTLIDEC_INCLUDE_DIRS}" "${BROTLIENC_INCLUDE_DIRS}") |
| 69 | + |
| 70 | +# Common part used by decoder and encoder |
| 71 | +add_library(woff2common |
| 72 | + src/table_tags.cc |
| 73 | + src/variable_length.cc |
| 74 | + src/woff2_common.cc) |
| 75 | + |
| 76 | +# WOFF2 Decoder |
| 77 | +add_library(woff2dec |
| 78 | + src/woff2_dec.cc |
| 79 | + src/woff2_out.cc) |
| 80 | +target_link_libraries(woff2dec woff2common "${BROTLIDEC_LIBRARIES}") |
| 81 | +add_executable(woff2_decompress src/woff2_decompress.cc) |
| 82 | +target_link_libraries(woff2_decompress woff2dec) |
| 83 | + |
| 84 | +# WOFF2 Encoder |
| 85 | +add_library(woff2enc |
| 86 | + src/font.cc |
| 87 | + src/glyph.cc |
| 88 | + src/normalize.cc |
| 89 | + src/transform.cc |
| 90 | + src/woff2_enc.cc) |
| 91 | +target_link_libraries(woff2enc woff2common "${BROTLIENC_LIBRARIES}") |
| 92 | +add_executable(woff2_compress src/woff2_compress.cc) |
| 93 | +target_link_libraries(woff2_compress woff2enc) |
| 94 | + |
| 95 | +# WOFF2 info |
| 96 | +add_executable(woff2_info src/woff2_info.cc) |
| 97 | +target_link_libraries(woff2_info woff2common) |
| 98 | + |
| 99 | +foreach(lib woff2common woff2dec woff2enc) |
| 100 | + set_target_properties(${lib} PROPERTIES |
| 101 | + SOVERSION ${WOFF2_VERSION} |
| 102 | + VERSION ${WOFF2_VERSION} |
| 103 | + POSITION_INDEPENDENT_CODE TRUE) |
| 104 | +endforeach() |
| 105 | + |
| 106 | +# Fuzzer libraries |
| 107 | +add_library(convert_woff2ttf_fuzzer STATIC src/convert_woff2ttf_fuzzer.cc) |
| 108 | +target_link_libraries(convert_woff2ttf_fuzzer woff2dec) |
| 109 | +add_library(convert_woff2ttf_fuzzer_new_entry STATIC src/convert_woff2ttf_fuzzer_new_entry.cc) |
| 110 | +target_link_libraries(convert_woff2ttf_fuzzer_new_entry woff2dec) |
| 111 | + |
| 112 | +# PC files |
| 113 | +include(CMakeParseArguments) |
| 114 | + |
| 115 | +function(generate_pkg_config_path outvar path) |
| 116 | + string(LENGTH "${path}" path_length) |
| 117 | + |
| 118 | + set(path_args ${ARGV}) |
| 119 | + list(REMOVE_AT path_args 0 1) |
| 120 | + list(LENGTH path_args path_args_remaining) |
| 121 | + |
| 122 | + set("${outvar}" "${path}") |
| 123 | + |
| 124 | + while(path_args_remaining GREATER 1) |
| 125 | + list(GET path_args 0 name) |
| 126 | + list(GET path_args 1 value) |
| 127 | + |
| 128 | + get_filename_component(value_full "${value}" ABSOLUTE) |
| 129 | + string(LENGTH "${value}" value_length) |
| 130 | + |
| 131 | + if(path_length EQUAL value_length AND path STREQUAL value) |
| 132 | + set("${outvar}" "\${${name}}") |
| 133 | + break() |
| 134 | + elseif(path_length GREATER value_length) |
| 135 | + # We might be in a subdirectory of the value, but we have to be |
| 136 | + # careful about a prefix matching but not being a subdirectory |
| 137 | + # (for example, /usr/lib64 is not a subdirectory of /usr/lib). |
| 138 | + # We'll do this by making sure the next character is a directory |
| 139 | + # separator. |
| 140 | + string(SUBSTRING "${path}" ${value_length} 1 sep) |
| 141 | + if(sep STREQUAL "/") |
| 142 | + string(SUBSTRING "${path}" 0 ${value_length} s) |
| 143 | + if(s STREQUAL value) |
| 144 | + string(SUBSTRING "${path}" "${value_length}" -1 suffix) |
| 145 | + set("${outvar}" "\${${name}}${suffix}") |
| 146 | + break() |
| 147 | + endif() |
| 148 | + endif() |
| 149 | + endif() |
| 150 | + |
| 151 | + list(REMOVE_AT path_args 0 1) |
| 152 | + list(LENGTH path_args path_args_remaining) |
| 153 | + endwhile() |
| 154 | + |
| 155 | + set("${outvar}" "${${outvar}}" PARENT_SCOPE) |
| 156 | +endfunction(generate_pkg_config_path) |
| 157 | + |
| 158 | +function(generate_pkg_config output_file) |
| 159 | + set (options) |
| 160 | + set (oneValueArgs NAME DESCRIPTION URL VERSION PREFIX LIBDIR INCLUDEDIR) |
| 161 | + set (multiValueArgs DEPENDS DEPENDS_PRIVATE CFLAGS LIBRARIES) |
| 162 | + cmake_parse_arguments(GEN_PKG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
| 163 | + unset (options) |
| 164 | + unset (oneValueArgs) |
| 165 | + unset (multiValueArgs) |
| 166 | + |
| 167 | + if(NOT GEN_PKG_PREFIX) |
| 168 | + set(GEN_PKG_PREFIX "${CMAKE_INSTALL_PREFIX}") |
| 169 | + endif() |
| 170 | + |
| 171 | + if(NOT GEN_PKG_LIBDIR) |
| 172 | + set(GEN_PKG_LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}") |
| 173 | + endif() |
| 174 | + generate_pkg_config_path(GEN_PKG_LIBDIR "${GEN_PKG_LIBDIR}" |
| 175 | + prefix "${GEN_PKG_PREFIX}") |
| 176 | + |
| 177 | + if(NOT GEN_PKG_INCLUDEDIR) |
| 178 | + set(GEN_PKG_INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}") |
| 179 | + endif() |
| 180 | + generate_pkg_config_path(GEN_PKG_INCLUDEDIR "${GEN_PKG_INCLUDEDIR}" |
| 181 | + prefix "${GEN_PKG_PREFIX}") |
| 182 | + |
| 183 | + file(WRITE "${output_file}" "prefix=${GEN_PKG_PREFIX}\n") |
| 184 | + file(APPEND "${output_file}" "libdir=${GEN_PKG_LIBDIR}\n") |
| 185 | + file(APPEND "${output_file}" "includedir=${GEN_PKG_INCLUDEDIR}\n") |
| 186 | + file(APPEND "${output_file}" "\n") |
| 187 | + |
| 188 | + if(GEN_PKG_NAME) |
| 189 | + file(APPEND "${output_file}" "Name: ${GEN_PKG_NAME}\n") |
| 190 | + else() |
| 191 | + file(APPEND "${output_file}" "Name: ${CMAKE_PROJECT_NAME}\n") |
| 192 | + endif() |
| 193 | + |
| 194 | + if(GEN_PKG_DESCRIPTION) |
| 195 | + file(APPEND "${output_file}" "Description: ${GEN_PKG_DESCRIPTION}\n") |
| 196 | + endif() |
| 197 | + |
| 198 | + if(GEN_PKG_URL) |
| 199 | + file(APPEND "${output_file}" "URL: ${GEN_PKG_URL}\n") |
| 200 | + endif() |
| 201 | + |
| 202 | + if(GEN_PKG_VERSION) |
| 203 | + file(APPEND "${output_file}" "Version: ${GEN_PKG_VERSION}\n") |
| 204 | + endif() |
| 205 | + |
| 206 | + if(GEN_PKG_DEPENDS) |
| 207 | + file(APPEND "${output_file}" "Requires: ${GEN_PKG_DEPENDS}\n") |
| 208 | + endif() |
| 209 | + |
| 210 | + if(GEN_PKG_DEPENDS_PRIVATE) |
| 211 | + file(APPEND "${output_file}" "Requires.private:") |
| 212 | + foreach(lib ${GEN_PKG_DEPENDS_PRIVATE}) |
| 213 | + file(APPEND "${output_file}" " ${lib}") |
| 214 | + endforeach() |
| 215 | + file(APPEND "${output_file}" "\n") |
| 216 | + endif() |
| 217 | + |
| 218 | + if(GEN_PKG_LIBRARIES) |
| 219 | + set(libs) |
| 220 | + |
| 221 | + file(APPEND "${output_file}" "Libs: -L\${libdir}") |
| 222 | + foreach(lib ${GEN_PKG_LIBRARIES}) |
| 223 | + file(APPEND "${output_file}" " -l${lib}") |
| 224 | + endforeach() |
| 225 | + file(APPEND "${output_file}" "\n") |
| 226 | + endif() |
| 227 | + |
| 228 | + file(APPEND "${output_file}" "Cflags: -I\${includedir}") |
| 229 | + if(GEN_PKG_CFLAGS) |
| 230 | + foreach(cflag ${GEN_PKG_CFLAGS}) |
| 231 | + file(APPEND "${output_file}" " ${cflag}") |
| 232 | + endforeach() |
| 233 | + endif() |
| 234 | + file(APPEND "${output_file}" "\n") |
| 235 | +endfunction(generate_pkg_config) |
| 236 | + |
| 237 | +generate_pkg_config ("${CMAKE_CURRENT_BINARY_DIR}/libwoff2common.pc" |
| 238 | + NAME libwoff2common |
| 239 | + DESCRIPTION "Shared data used by libwoff2 and libwoff2dec libraries" |
| 240 | + URL "https://github.com/google/woff2" |
| 241 | + VERSION "${WOFF2_VERSION}" |
| 242 | + LIBRARIES woff2common) |
| 243 | + |
| 244 | +generate_pkg_config ("${CMAKE_CURRENT_BINARY_DIR}/libwoff2dec.pc" |
| 245 | + NAME libwoff2dec |
| 246 | + DESCRIPTION "WOFF2 decoder library" |
| 247 | + URL "https://github.com/google/woff2" |
| 248 | + VERSION "${WOFF2_VERSION}" |
| 249 | + DEPENDS libbrotlidec |
| 250 | + DEPENDS_PRIVATE libwoff2common |
| 251 | + LIBRARIES woff2dec) |
| 252 | + |
| 253 | +generate_pkg_config ("${CMAKE_CURRENT_BINARY_DIR}/libwoff2enc.pc" |
| 254 | + NAME libwoff2enc |
| 255 | + DESCRIPTION "WOFF2 encoder library" |
| 256 | + URL "https://github.com/google/woff2" |
| 257 | + VERSION "${WOFF2_VERSION}" |
| 258 | + DEPENDS libbrotlienc |
| 259 | + DEPENDS_PRIVATE libwoff2common |
| 260 | + LIBRARIES woff2enc) |
| 261 | + |
| 262 | +# Installation |
| 263 | +if (NOT BUILD_SHARED_LIBS) |
| 264 | + install( |
| 265 | + TARGETS woff2_decompress woff2_compress woff2_info |
| 266 | + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
| 267 | + ) |
| 268 | +endif() |
| 269 | + |
| 270 | +install( |
| 271 | + TARGETS woff2common woff2dec woff2enc |
| 272 | + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 273 | + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 274 | + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
| 275 | +) |
| 276 | +install( |
| 277 | + DIRECTORY include/woff2 |
| 278 | + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 279 | +) |
| 280 | +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libwoff2common.pc" |
| 281 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 282 | +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libwoff2dec.pc" |
| 283 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 284 | +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libwoff2enc.pc" |
| 285 | + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
0 commit comments