Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 1 | # Ubuntu 12.04 LTS has CMake 2.8.7, and is an important target since |
| 2 | # several CI services, such as Travis and Drone, use it. Solaris 11 |
| 3 | # has 2.8.6, and it's not difficult to support if you already have to |
| 4 | # support 2.8.7. |
| 5 | cmake_minimum_required(VERSION 2.8.6) |
| 6 | |
| 7 | project(brotli) |
| 8 | |
| 9 | # If Brotli is being bundled in another project, we don't want to |
| 10 | # install anything. However, we want to let people override this, so |
| 11 | # we'll use the BROTLI_BUNDLED_MODE variable to let them do that; just |
| 12 | # set it to OFF in your project before you add_subdirectory(brotli). |
| 13 | get_directory_property(BROTLI_PARENT_DIRECTORY PARENT_DIRECTORY) |
| 14 | if(BROTLI_BUNDLED_MODE STREQUAL "") |
| 15 | # Bundled mode hasn't been set one way or the other, set the default |
| 16 | # depending on whether or not we are the top-level project. |
| 17 | if(BROTLI_PARENT_DIRECTORY) |
| 18 | set(BROTLI_BUNDLED_MODE OFF) |
| 19 | else() |
| 20 | set(BROTLI_BUNDLED_MODE ON) |
| 21 | endif() |
| 22 | endif() |
| 23 | mark_as_advanced(BROTLI_BUNDLED_MODE) |
| 24 | |
Evan Nemerson | 6c47009 | 2016-11-01 02:03:29 -0700 | [diff] [blame] | 25 | include(GNUInstallDirs) |
| 26 | |
Frédéric Wang | 074e4ac | 2016-08-27 12:04:48 +0200 | [diff] [blame] | 27 | # When building shared libraries it is important to set the correct rpath. |
| 28 | # See https://cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH |
Eugene Kliuchnikov | 52f0483 | 2017-09-19 09:40:48 +0200 | [diff] [blame] | 29 | set(CMAKE_SKIP_BUILD_RPATH FALSE) |
| 30 | set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) |
| 31 | set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) |
| 32 | list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_LIBDIR}" isSystemDir) |
| 33 | if ("${isSystemDir}" STREQUAL "-1") |
| 34 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}") |
Frédéric Wang | 074e4ac | 2016-08-27 12:04:48 +0200 | [diff] [blame] | 35 | endif() |
| 36 | |
Eugene Kliuchnikov | b93cb69 | 2016-10-18 17:14:49 +0200 | [diff] [blame] | 37 | # Parse version information from common/version.h. Normally we would |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 38 | # define these values here and write them out to configuration file(s) |
| 39 | # (i.e., config.h), but in this case we parse them from |
Eugene Kliuchnikov | 2c2d557 | 2016-08-22 15:44:12 +0200 | [diff] [blame] | 40 | # common/version.h to be less intrusive. |
| 41 | function(hex_to_dec HEXADECIMAL DECIMAL) |
| 42 | string(TOUPPER "${HEXADECIMAL}" _tail) |
| 43 | set(_decimal 0) |
| 44 | string(LENGTH "${_tail}" _tail_length) |
| 45 | while (_tail_length GREATER 0) |
| 46 | math(EXPR _decimal "${_decimal} * 16") |
| 47 | string(SUBSTRING "${_tail}" 0 1 _digit) |
| 48 | string(SUBSTRING "${_tail}" 1 -1 _tail) |
| 49 | if (_digit STREQUAL "A") |
| 50 | math(EXPR _decimal "${_decimal} + 10") |
| 51 | elseif (_digit STREQUAL "B") |
| 52 | math(EXPR _decimal "${_decimal} + 11") |
| 53 | elseif (_digit STREQUAL "C") |
| 54 | math(EXPR _decimal "${_decimal} + 12") |
| 55 | elseif (_digit STREQUAL "D") |
| 56 | math(EXPR _decimal "${_decimal} + 13") |
| 57 | elseif (_digit STREQUAL "E") |
| 58 | math(EXPR _decimal "${_decimal} + 14") |
| 59 | elseif (_digit STREQUAL "F") |
| 60 | math(EXPR _decimal "${_decimal} + 15") |
| 61 | else() |
| 62 | math(EXPR _decimal "${_decimal} + ${_digit}") |
| 63 | endif() |
| 64 | string(LENGTH "${_tail}" _tail_length) |
| 65 | endwhile() |
| 66 | set(${DECIMAL} ${_decimal} PARENT_SCOPE) |
| 67 | endfunction(hex_to_dec) |
| 68 | |
Evan Nemerson | 6c47009 | 2016-11-01 02:03:29 -0700 | [diff] [blame] | 69 | # Version information |
Eugene Kliuchnikov | 6ece1d8 | 2017-04-23 14:07:08 +0200 | [diff] [blame] | 70 | file(STRINGS "c/common/version.h" _brotli_version_line REGEX "^#define BROTLI_VERSION (0x[0-9a-fA-F]+)$") |
Eugene Kliuchnikov | 2c2d557 | 2016-08-22 15:44:12 +0200 | [diff] [blame] | 71 | string(REGEX REPLACE "^#define BROTLI_VERSION 0x([0-9a-fA-F]+)$" "\\1" _brotli_version_hex "${_brotli_version_line}") |
| 72 | hex_to_dec("${_brotli_version_hex}" _brotli_version) |
| 73 | math(EXPR BROTLI_VERSION_MAJOR "${_brotli_version} >> 24") |
| 74 | math(EXPR BROTLI_VERSION_MINOR "(${_brotli_version} >> 12) & 4095") |
| 75 | math(EXPR BROTLI_VERSION_REVISION "${_brotli_version} & 4095") |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 76 | mark_as_advanced(BROTLI_VERSION_MAJOR BROTLI_VERSION_MINOR BROTLI_VERSION_REVISION) |
| 77 | |
Evan Nemerson | 37be4e3 | 2016-06-28 20:35:16 -0700 | [diff] [blame] | 78 | if (ENABLE_SANITIZER) |
| 79 | set(CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} -fsanitize=${ENABLE_SANITIZER}") |
| 80 | set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fsanitize=${ENABLE_SANITIZER}") |
| 81 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${ENABLE_SANITIZER}") |
Evan Nemerson | 26a5935 | 2016-07-26 08:22:58 -0700 | [diff] [blame] | 82 | |
| 83 | # By default, brotli depends on undefined behavior, but setting |
| 84 | # BROTLI_BUILD_PORTABLE should result in a build which does not. |
| 85 | if(ENABLE_SANITIZER STREQUAL "undefined") |
| 86 | add_definitions(-DBROTLI_BUILD_PORTABLE) |
| 87 | endif() |
Evan Nemerson | 37be4e3 | 2016-06-28 20:35:16 -0700 | [diff] [blame] | 88 | endif () |
| 89 | |
Evan Nemerson | c1ec7ba | 2016-07-29 11:52:15 -0700 | [diff] [blame] | 90 | include(CheckFunctionExists) |
| 91 | set(LIBM_LIBRARY) |
| 92 | CHECK_FUNCTION_EXISTS(log2 LOG2_RES) |
| 93 | if(NOT LOG2_RES) |
Evan Nemerson | c1ec7ba | 2016-07-29 11:52:15 -0700 | [diff] [blame] | 94 | set(orig_req_libs "${CMAKE_REQUIRED_LIBRARIES}") |
| 95 | set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};m") |
Evan Nemerson | fe0e153 | 2016-08-04 18:51:20 -0700 | [diff] [blame] | 96 | CHECK_FUNCTION_EXISTS(log2 LOG2_LIBM_RES) |
| 97 | if(LOG2_LIBM_RES) |
Evan Nemerson | c1ec7ba | 2016-07-29 11:52:15 -0700 | [diff] [blame] | 98 | set(LIBM_LIBRARY "m") |
| 99 | else() |
| 100 | message(FATAL_ERROR "log2() not found") |
| 101 | endif() |
| 102 | |
| 103 | set(CMAKE_REQUIRED_LIBRARIES "${orig_req_libs}") |
Evan Nemerson | fe0e153 | 2016-08-04 18:51:20 -0700 | [diff] [blame] | 104 | unset(LOG2_LIBM_RES) |
Evan Nemerson | c1ec7ba | 2016-07-29 11:52:15 -0700 | [diff] [blame] | 105 | unset(orig_req_libs) |
| 106 | endif() |
| 107 | unset(LOG2_RES) |
| 108 | |
Eugene Kliuchnikov | 6ece1d8 | 2017-04-23 14:07:08 +0200 | [diff] [blame] | 109 | set(BROTLI_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/c/include") |
Eugene Kliuchnikov | 52f0483 | 2017-09-19 09:40:48 +0200 | [diff] [blame] | 110 | mark_as_advanced(BROTLI_INCLUDE_DIRS) |
| 111 | |
Frédéric Wang | ed2748a | 2016-10-12 18:23:34 +0200 | [diff] [blame] | 112 | set(BROTLI_LIBRARIES_CORE brotlienc brotlidec brotlicommon) |
Frédéric Wang | 074e4ac | 2016-08-27 12:04:48 +0200 | [diff] [blame] | 113 | set(BROTLI_LIBRARIES ${BROTLI_LIBRARIES_CORE} ${LIBM_LIBRARY}) |
Eugene Kliuchnikov | 52f0483 | 2017-09-19 09:40:48 +0200 | [diff] [blame] | 114 | mark_as_advanced(BROTLI_LIBRARIES) |
| 115 | |
| 116 | set(BROTLI_LIBRARIES_CORE_STATIC brotlienc-static brotlidec-static brotlicommon-static) |
| 117 | set(BROTLI_LIBRARIES_STATIC ${BROTLI_LIBRARIES_CORE_STATIC} ${LIBM_LIBRARY}) |
| 118 | mark_as_advanced(BROTLI_LIBRARIES_STATIC) |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 119 | |
| 120 | if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 121 | add_definitions(-DOS_LINUX) |
| 122 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") |
| 123 | add_definitions(-DOS_FREEBSD) |
| 124 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 125 | add_definitions(-DOS_MACOSX) |
| 126 | endif() |
| 127 | |
Eugene Kliuchnikov | 52f0483 | 2017-09-19 09:40:48 +0200 | [diff] [blame] | 128 | set(BROTLICOMMON_SOURCES |
Eugene Kliuchnikov | 6ece1d8 | 2017-04-23 14:07:08 +0200 | [diff] [blame] | 129 | c/common/dictionary.c) |
Eugene Kliuchnikov | 52f0483 | 2017-09-19 09:40:48 +0200 | [diff] [blame] | 130 | set(BROTLIDEC_SOURCES |
Eugene Kliuchnikov | 6ece1d8 | 2017-04-23 14:07:08 +0200 | [diff] [blame] | 131 | c/dec/bit_reader.c |
| 132 | c/dec/decode.c |
| 133 | c/dec/huffman.c |
| 134 | c/dec/state.c) |
Eugene Kliuchnikov | 52f0483 | 2017-09-19 09:40:48 +0200 | [diff] [blame] | 135 | set(BROTLIENC_SOURCES |
Eugene Kliuchnikov | 6ece1d8 | 2017-04-23 14:07:08 +0200 | [diff] [blame] | 136 | c/enc/backward_references.c |
| 137 | c/enc/backward_references_hq.c |
| 138 | c/enc/bit_cost.c |
| 139 | c/enc/block_splitter.c |
| 140 | c/enc/brotli_bit_stream.c |
| 141 | c/enc/cluster.c |
| 142 | c/enc/compress_fragment.c |
| 143 | c/enc/compress_fragment_two_pass.c |
| 144 | c/enc/dictionary_hash.c |
| 145 | c/enc/encode.c |
| 146 | c/enc/entropy_encode.c |
| 147 | c/enc/histogram.c |
| 148 | c/enc/literal_cost.c |
| 149 | c/enc/memory.c |
| 150 | c/enc/metablock.c |
| 151 | c/enc/static_dict.c |
| 152 | c/enc/utf8_util.c) |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 153 | |
Eugene Kliuchnikov | 52f0483 | 2017-09-19 09:40:48 +0200 | [diff] [blame] | 154 | add_library(brotlicommon SHARED ${BROTLICOMMON_SOURCES}) |
| 155 | add_library(brotlidec SHARED ${BROTLIDEC_SOURCES}) |
| 156 | add_library(brotlienc SHARED ${BROTLIENC_SOURCES}) |
| 157 | |
| 158 | add_library(brotlicommon-static STATIC ${BROTLICOMMON_SOURCES}) |
| 159 | add_library(brotlidec-static STATIC ${BROTLIDEC_SOURCES}) |
| 160 | add_library(brotlienc-static STATIC ${BROTLIENC_SOURCES}) |
| 161 | |
Eugene Kliuchnikov | 532921b | 2016-08-23 15:35:54 +0200 | [diff] [blame] | 162 | # Older CMake versions does not understand INCLUDE_DIRECTORIES property. |
| 163 | include_directories(${BROTLI_INCLUDE_DIRS}) |
| 164 | |
Frédéric Wang | ed2748a | 2016-10-12 18:23:34 +0200 | [diff] [blame] | 165 | foreach(lib brotlicommon brotlidec brotlienc) |
Eugene Kliuchnikov | 52f0483 | 2017-09-19 09:40:48 +0200 | [diff] [blame] | 166 | target_compile_definitions(${lib} PUBLIC "BROTLI_SHARED_COMPILATION" ) |
| 167 | string(TOUPPER "${lib}" LIB) |
| 168 | set_target_properties (${lib} PROPERTIES DEFINE_SYMBOL "${LIB}_SHARED_COMPILATION" ) |
| 169 | endforeach() |
| 170 | |
| 171 | foreach(lib brotlicommon brotlidec brotlienc brotlicommon-static brotlidec-static brotlienc-static) |
Evan Nemerson | c1ec7ba | 2016-07-29 11:52:15 -0700 | [diff] [blame] | 172 | target_link_libraries(${lib} ${LIBM_LIBRARY}) |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 173 | set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIRS}) |
| 174 | set_target_properties(${lib} PROPERTIES |
Evan Nemerson | 6c47009 | 2016-11-01 02:03:29 -0700 | [diff] [blame] | 175 | SOVERSION "${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_REVISION}" |
| 176 | VERSION "${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_REVISION}" |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 177 | POSITION_INDEPENDENT_CODE TRUE) |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 178 | set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIRS}") |
| 179 | endforeach() |
Eugene Kliuchnikov | 69982c2 | 2016-10-18 16:45:32 +0200 | [diff] [blame] | 180 | |
Evan Nemerson | 6c47009 | 2016-11-01 02:03:29 -0700 | [diff] [blame] | 181 | target_link_libraries(brotlidec brotlicommon) |
| 182 | target_link_libraries(brotlienc brotlicommon) |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 183 | |
Eugene Kliuchnikov | 52f0483 | 2017-09-19 09:40:48 +0200 | [diff] [blame] | 184 | target_link_libraries(brotlidec-static brotlicommon-static) |
| 185 | target_link_libraries(brotlienc-static brotlicommon-static) |
| 186 | |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 187 | # For projects stuck on older versions of CMake, this will set the |
| 188 | # BROTLI_INCLUDE_DIRS and BROTLI_LIBRARIES variables so they still |
| 189 | # have a relatively easy way to use Brotli: |
| 190 | # |
| 191 | # include_directories(${BROTLI_INCLUDE_DIRS}) |
| 192 | # target_link_libraries(foo ${BROTLI_LIBRARIES}) |
| 193 | if(BROTLI_PARENT_DIRECTORY) |
| 194 | set(BROTLI_INCLUDE_DIRS "${BROTLI_INCLUDE_DIRS}" PARENT_SCOPE) |
| 195 | set(BROTLI_LIBRARIES "${BROTLI_LIBRARIES}" PARENT_SCOPE) |
| 196 | endif() |
| 197 | |
Eugene Kliuchnikov | 03739d2 | 2017-05-29 17:55:14 +0200 | [diff] [blame] | 198 | # Build the brotli executable |
| 199 | add_executable(brotli c/tools/brotli.c) |
Eugene Kliuchnikov | 52f0483 | 2017-09-19 09:40:48 +0200 | [diff] [blame] | 200 | target_link_libraries(brotli ${BROTLI_LIBRARIES_STATIC}) |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 201 | |
| 202 | # Installation |
Frédéric Wang | 5e1219a | 2016-08-27 12:14:13 +0200 | [diff] [blame] | 203 | if(NOT BROTLI_BUNDLED_MODE) |
Eugene Kliuchnikov | 2c00101 | 2017-05-24 17:19:34 +0200 | [diff] [blame] | 204 | install( |
Eugene Kliuchnikov | 03739d2 | 2017-05-29 17:55:14 +0200 | [diff] [blame] | 205 | TARGETS brotli |
Eugene Kliuchnikov | 2c00101 | 2017-05-24 17:19:34 +0200 | [diff] [blame] | 206 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
| 207 | ) |
Frédéric Wang | 074e4ac | 2016-08-27 12:04:48 +0200 | [diff] [blame] | 208 | |
Eugene Kliuchnikov | 2c00101 | 2017-05-24 17:19:34 +0200 | [diff] [blame] | 209 | install( |
| 210 | TARGETS ${BROTLI_LIBRARIES_CORE} |
| 211 | ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 212 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 213 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
| 214 | ) |
Frédéric Wang | 074e4ac | 2016-08-27 12:04:48 +0200 | [diff] [blame] | 215 | |
Eugene Kliuchnikov | 2c00101 | 2017-05-24 17:19:34 +0200 | [diff] [blame] | 216 | install( |
Eugene Kliuchnikov | b6a0174 | 2017-09-20 10:04:06 +0200 | [diff] [blame] | 217 | TARGETS ${BROTLI_LIBRARIES_CORE_STATIC} |
| 218 | ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 219 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 220 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
| 221 | ) |
| 222 | |
| 223 | install( |
Eugene Kliuchnikov | 2c00101 | 2017-05-24 17:19:34 +0200 | [diff] [blame] | 224 | DIRECTORY ${BROTLI_INCLUDE_DIRS}/brotli |
| 225 | DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 226 | ) |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 227 | endif() |
| 228 | |
| 229 | # Tests |
Evan Nemerson | 03657e8 | 2016-07-28 13:31:09 -0700 | [diff] [blame] | 230 | |
| 231 | # If we're targeting Windows but not running on Windows, we need Wine |
| 232 | # to run the tests... |
| 233 | if(NOT BROTLI_DISABLE_TESTS) |
| 234 | if(WIN32 AND NOT CMAKE_HOST_WIN32) |
| 235 | find_program(BROTLI_WINE NAMES wine) |
Evan Nemerson | 03657e8 | 2016-07-28 13:31:09 -0700 | [diff] [blame] | 236 | |
Evan Nemerson | c1ec7ba | 2016-07-29 11:52:15 -0700 | [diff] [blame] | 237 | if(NOT BROTLI_WINE) |
| 238 | message(STATUS "wine not found, disabling tests") |
| 239 | set(BROTLI_DISABLE_TESTS TRUE) |
| 240 | endif() |
Evan Nemerson | 03657e8 | 2016-07-28 13:31:09 -0700 | [diff] [blame] | 241 | endif() |
| 242 | endif() |
| 243 | |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 244 | if(NOT BROTLI_DISABLE_TESTS) |
| 245 | include(CTest) |
| 246 | enable_testing() |
| 247 | |
| 248 | set(ROUNDTRIP_INPUTS |
| 249 | tests/testdata/alice29.txt |
| 250 | tests/testdata/asyoulik.txt |
| 251 | tests/testdata/lcet10.txt |
| 252 | tests/testdata/plrabn12.txt |
Eugene Kliuchnikov | 6ece1d8 | 2017-04-23 14:07:08 +0200 | [diff] [blame] | 253 | c/enc/encode.c |
| 254 | c/common/dictionary.h |
| 255 | c/dec/decode.c) |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 256 | |
| 257 | foreach(INPUT ${ROUNDTRIP_INPUTS}) |
Evan Nemerson | 03657e8 | 2016-07-28 13:31:09 -0700 | [diff] [blame] | 258 | get_filename_component(OUTPUT_NAME "${INPUT}" NAME) |
| 259 | |
| 260 | set(OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}") |
| 261 | set(INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${INPUT}") |
| 262 | |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 263 | foreach(quality 1 6 9 11) |
| 264 | add_test(NAME "${BROTLI_TEST_PREFIX}roundtrip/${INPUT}/${quality}" |
| 265 | COMMAND "${CMAKE_COMMAND}" |
Evan Nemerson | 03657e8 | 2016-07-28 13:31:09 -0700 | [diff] [blame] | 266 | -DBROTLI_WRAPPER=${BROTLI_WINE} |
Eugene Kliuchnikov | 03739d2 | 2017-05-29 17:55:14 +0200 | [diff] [blame] | 267 | -DBROTLI_CLI=$<TARGET_FILE:brotli> |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 268 | -DQUALITY=${quality} |
Evan Nemerson | 03657e8 | 2016-07-28 13:31:09 -0700 | [diff] [blame] | 269 | -DINPUT=${INPUT_FILE} |
Eugene Kliuchnikov | b6a0174 | 2017-09-20 10:04:06 +0200 | [diff] [blame] | 270 | -DOUTPUT=${OUTPUT_FILE}.${quality} |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 271 | -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run-roundtrip-test.cmake) |
| 272 | endforeach() |
| 273 | endforeach() |
| 274 | |
| 275 | file(GLOB_RECURSE |
| 276 | COMPATIBILITY_INPUTS |
| 277 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} |
| 278 | tests/testdata/*.compressed*) |
| 279 | |
| 280 | foreach(INPUT ${COMPATIBILITY_INPUTS}) |
| 281 | add_test(NAME "${BROTLI_TEST_PREFIX}compatibility/${INPUT}" |
| 282 | COMMAND "${CMAKE_COMMAND}" |
Evan Nemerson | 03657e8 | 2016-07-28 13:31:09 -0700 | [diff] [blame] | 283 | -DBROTLI_WRAPPER=${BROTLI_WINE} |
Eugene Kliuchnikov | 03739d2 | 2017-05-29 17:55:14 +0200 | [diff] [blame] | 284 | -DBROTLI_CLI=$<TARGET_FILE:brotli> |
Evan Nemerson | 93ef13f | 2016-06-20 13:07:35 -0700 | [diff] [blame] | 285 | -DINPUT=${CMAKE_CURRENT_SOURCE_DIR}/${INPUT} |
| 286 | -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run-compatibility-test.cmake) |
| 287 | endforeach() |
| 288 | endif() |
Evan Nemerson | 6c47009 | 2016-11-01 02:03:29 -0700 | [diff] [blame] | 289 | |
| 290 | # Generate a pkg-config file |
| 291 | |
| 292 | include(CMakeParseArguments) |
| 293 | |
| 294 | function(generate_pkg_config_path outvar path) |
| 295 | string(LENGTH "${path}" path_length) |
| 296 | |
| 297 | set(path_args ${ARGV}) |
| 298 | list(REMOVE_AT path_args 0 1) |
| 299 | list(LENGTH path_args path_args_remaining) |
| 300 | |
| 301 | set("${outvar}" "${path}") |
| 302 | |
| 303 | while(path_args_remaining GREATER 1) |
| 304 | list(GET path_args 0 name) |
| 305 | list(GET path_args 1 value) |
| 306 | |
| 307 | get_filename_component(value_full "${value}" ABSOLUTE) |
| 308 | string(LENGTH "${value}" value_length) |
| 309 | |
| 310 | if(path_length EQUAL value_length AND path STREQUAL value) |
| 311 | set("${outvar}" "\${${name}}") |
| 312 | break() |
| 313 | elseif(path_length GREATER value_length) |
| 314 | # We might be in a subdirectory of the value, but we have to be |
| 315 | # careful about a prefix matching but not being a subdirectory |
| 316 | # (for example, /usr/lib64 is not a subdirectory of /usr/lib). |
| 317 | # We'll do this by making sure the next character is a directory |
| 318 | # separator. |
| 319 | string(SUBSTRING "${path}" ${value_length} 1 sep) |
| 320 | if(sep STREQUAL "/") |
| 321 | string(SUBSTRING "${path}" 0 ${value_length} s) |
| 322 | if(s STREQUAL value) |
| 323 | string(SUBSTRING "${path}" "${value_length}" -1 suffix) |
| 324 | set("${outvar}" "\${${name}}${suffix}") |
| 325 | break() |
| 326 | endif() |
| 327 | endif() |
| 328 | endif() |
| 329 | |
| 330 | list(REMOVE_AT path_args 0 1) |
| 331 | list(LENGTH path_args path_args_remaining) |
| 332 | endwhile() |
| 333 | |
| 334 | set("${outvar}" "${${outvar}}" PARENT_SCOPE) |
| 335 | endfunction(generate_pkg_config_path) |
| 336 | |
| 337 | function(generate_pkg_config output_file) |
| 338 | set (options) |
Eugene Kliuchnikov | fe9f9a9 | 2016-12-22 08:57:44 +0100 | [diff] [blame] | 339 | set (oneValueArgs NAME DESCRIPTION URL VERSION PREFIX LIBDIR INCLUDEDIR) |
| 340 | set (multiValueArgs DEPENDS_PRIVATE CFLAGS LIBRARIES) |
Evan Nemerson | 6c47009 | 2016-11-01 02:03:29 -0700 | [diff] [blame] | 341 | cmake_parse_arguments(GEN_PKG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
| 342 | unset (options) |
| 343 | unset (oneValueArgs) |
| 344 | unset (multiValueArgs) |
| 345 | |
| 346 | if(NOT GEN_PKG_PREFIX) |
| 347 | set(GEN_PKG_PREFIX "${CMAKE_INSTALL_PREFIX}") |
| 348 | endif() |
| 349 | |
| 350 | if(NOT GEN_PKG_LIBDIR) |
| 351 | set(GEN_PKG_LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}") |
| 352 | endif() |
| 353 | generate_pkg_config_path(GEN_PKG_LIBDIR "${GEN_PKG_LIBDIR}" |
| 354 | prefix "${GEN_PKG_PREFIX}") |
| 355 | |
| 356 | if(NOT GEN_PKG_INCLUDEDIR) |
| 357 | set(GEN_PKG_INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}") |
| 358 | endif() |
| 359 | generate_pkg_config_path(GEN_PKG_INCLUDEDIR "${GEN_PKG_INCLUDEDIR}" |
| 360 | prefix "${GEN_PKG_PREFIX}") |
| 361 | |
| 362 | file(WRITE "${output_file}" "prefix=${GEN_PKG_PREFIX}\n") |
| 363 | file(APPEND "${output_file}" "libdir=${GEN_PKG_LIBDIR}\n") |
| 364 | file(APPEND "${output_file}" "includedir=${GEN_PKG_INCLUDEDIR}\n") |
| 365 | file(APPEND "${output_file}" "\n") |
| 366 | |
| 367 | if(GEN_PKG_NAME) |
| 368 | file(APPEND "${output_file}" "Name: ${GEN_PKG_NAME}\n") |
| 369 | else() |
| 370 | file(APPEND "${output_file}" "Name: ${CMAKE_PROJECT_NAME}\n") |
| 371 | endif() |
| 372 | |
| 373 | if(GEN_PKG_DESCRIPTION) |
| 374 | file(APPEND "${output_file}" "Description: ${GEN_PKG_DESCRIPTION}\n") |
| 375 | endif() |
| 376 | |
Eugene Kliuchnikov | fe9f9a9 | 2016-12-22 08:57:44 +0100 | [diff] [blame] | 377 | if(GEN_PKG_URL) |
| 378 | file(APPEND "${output_file}" "URL: ${GEN_PKG_URL}\n") |
| 379 | endif() |
| 380 | |
Evan Nemerson | 6c47009 | 2016-11-01 02:03:29 -0700 | [diff] [blame] | 381 | if(GEN_PKG_VERSION) |
| 382 | file(APPEND "${output_file}" "Version: ${GEN_PKG_VERSION}\n") |
| 383 | endif() |
| 384 | |
Eugene Kliuchnikov | fe9f9a9 | 2016-12-22 08:57:44 +0100 | [diff] [blame] | 385 | if(GEN_PKG_DEPENDS_PRIVATE) |
| 386 | file(APPEND "${output_file}" "Requires.private:") |
| 387 | foreach(lib ${GEN_PKG_DEPENDS_PRIVATE}) |
| 388 | file(APPEND "${output_file}" " ${lib}") |
| 389 | endforeach() |
| 390 | file(APPEND "${output_file}" "\n") |
| 391 | endif() |
| 392 | |
Evan Nemerson | 6c47009 | 2016-11-01 02:03:29 -0700 | [diff] [blame] | 393 | if(GEN_PKG_LIBRARIES) |
| 394 | set(libs) |
| 395 | |
| 396 | file(APPEND "${output_file}" "Libs: -L\${libdir}") |
| 397 | foreach(lib ${GEN_PKG_LIBRARIES}) |
| 398 | file(APPEND "${output_file}" " -l${lib}") |
| 399 | endforeach() |
| 400 | file(APPEND "${output_file}" "\n") |
| 401 | endif() |
| 402 | |
| 403 | file(APPEND "${output_file}" "Cflags: -I\${includedir}") |
| 404 | if(GEN_PKG_CFLAGS) |
| 405 | foreach(cflag ${GEN_PKG_CFLAGS}) |
| 406 | file(APPEND "${output_file}" " ${cflag}") |
| 407 | endforeach() |
| 408 | endif() |
| 409 | file(APPEND "${output_file}" "\n") |
| 410 | endfunction(generate_pkg_config) |
| 411 | |
Eugene Kliuchnikov | fe9f9a9 | 2016-12-22 08:57:44 +0100 | [diff] [blame] | 412 | generate_pkg_config ("${CMAKE_CURRENT_BINARY_DIR}/libbrotlicommon.pc" |
| 413 | NAME libbrotlicommon |
| 414 | DESCRIPTION "Shared data used by libbrotlienc and libbrotlidec libraries" |
| 415 | URL "https://github.com/google/brotli" |
Evan Nemerson | 6c47009 | 2016-11-01 02:03:29 -0700 | [diff] [blame] | 416 | VERSION "${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_REVISION}" |
Eugene Kliuchnikov | fe9f9a9 | 2016-12-22 08:57:44 +0100 | [diff] [blame] | 417 | LIBRARIES brotlicommon) |
| 418 | |
| 419 | generate_pkg_config ("${CMAKE_CURRENT_BINARY_DIR}/libbrotlidec.pc" |
| 420 | NAME libbrotlidec |
| 421 | DESCRIPTION "Brotli decoder library" |
| 422 | VERSION "${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_REVISION}" |
| 423 | URL "https://github.com/google/brotli" |
| 424 | DEPENDS_PRIVATE libbrotlicommon |
| 425 | LIBRARIES brotlidec) |
| 426 | |
| 427 | generate_pkg_config ("${CMAKE_CURRENT_BINARY_DIR}/libbrotlienc.pc" |
| 428 | NAME libbrotlienc |
| 429 | DESCRIPTION "Brotli encoder library" |
| 430 | VERSION "${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_REVISION}" |
| 431 | URL "https://github.com/google/brotli" |
Ian Duncan | aaa4424 | 2017-03-02 00:19:57 +0900 | [diff] [blame] | 432 | DEPENDS_PRIVATE libbrotlicommon |
Eugene Kliuchnikov | fe9f9a9 | 2016-12-22 08:57:44 +0100 | [diff] [blame] | 433 | LIBRARIES brotlienc) |
Evan Nemerson | 6c47009 | 2016-11-01 02:03:29 -0700 | [diff] [blame] | 434 | |
| 435 | if(NOT BROTLI_BUNDLED_MODE) |
Eugene Kliuchnikov | fe9f9a9 | 2016-12-22 08:57:44 +0100 | [diff] [blame] | 436 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libbrotlicommon.pc" |
| 437 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 438 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libbrotlidec.pc" |
| 439 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 440 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libbrotlienc.pc" |
Evan Nemerson | 6c47009 | 2016-11-01 02:03:29 -0700 | [diff] [blame] | 441 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 442 | endif() |
| 443 | |
| 444 | if (ENABLE_COVERAGE STREQUAL "yes") |
| 445 | SETUP_TARGET_FOR_COVERAGE(coverage test coverage) |
| 446 | endif () |