126fa459cSmrg# Ubuntu 12.04 LTS has CMake 2.8.7, and is an important target since 226fa459cSmrg# several CI services, such as Travis and Drone, use it. Solaris 11 326fa459cSmrg# has 2.8.6, and it's not difficult to support if you already have to 426fa459cSmrg# support 2.8.7. 526fa459cSmrgcmake_minimum_required(VERSION 2.8.6) 626fa459cSmrg 726fa459cSmrgproject(brotli C) 826fa459cSmrg 926fa459cSmrgif(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 1026fa459cSmrg message(STATUS "Setting build type to Release as none was specified.") 1126fa459cSmrg set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE) 1226fa459cSmrgelse() 1326fa459cSmrg message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'") 1426fa459cSmrgendif() 1526fa459cSmrg 1626fa459cSmrginclude(CheckCSourceCompiles) 1726fa459cSmrgcheck_c_source_compiles( 1826fa459cSmrg "#if defined(__EMSCRIPTEN__) 1926fa459cSmrg int main() {return 0;} 2026fa459cSmrg #endif" 2126fa459cSmrg BROTLI_EMSCRIPTEN 2226fa459cSmrg) 2326fa459cSmrgif (BROTLI_EMSCRIPTEN) 2426fa459cSmrg message("-- Compiler is EMSCRIPTEN") 2526fa459cSmrgelse() 2626fa459cSmrg message("-- Compiler is not EMSCRIPTEN") 2726fa459cSmrgendif() 2826fa459cSmrg 2926fa459cSmrg# If Brotli is being bundled in another project, we don't want to 3026fa459cSmrg# install anything. However, we want to let people override this, so 3126fa459cSmrg# we'll use the BROTLI_BUNDLED_MODE variable to let them do that; just 3226fa459cSmrg# set it to OFF in your project before you add_subdirectory(brotli). 3326fa459cSmrgget_directory_property(BROTLI_PARENT_DIRECTORY PARENT_DIRECTORY) 3426fa459cSmrgif(NOT DEFINED BROTLI_BUNDLED_MODE) 3526fa459cSmrg # Bundled mode hasn't been set one way or the other, set the default 3626fa459cSmrg # depending on whether or not we are the top-level project. 3726fa459cSmrg if(BROTLI_PARENT_DIRECTORY) 3826fa459cSmrg set(BROTLI_BUNDLED_MODE ON) 3926fa459cSmrg else() 4026fa459cSmrg set(BROTLI_BUNDLED_MODE OFF) 4126fa459cSmrg endif() 4226fa459cSmrgendif() 4326fa459cSmrgmark_as_advanced(BROTLI_BUNDLED_MODE) 4426fa459cSmrg 4526fa459cSmrginclude(GNUInstallDirs) 4626fa459cSmrg 4726fa459cSmrg# Parse version information from common/version.h. Normally we would 4826fa459cSmrg# define these values here and write them out to configuration file(s) 4926fa459cSmrg# (i.e., config.h), but in this case we parse them from 5026fa459cSmrg# common/version.h to be less intrusive. 5126fa459cSmrgfunction(hex_to_dec HEXADECIMAL DECIMAL) 5226fa459cSmrg string(TOUPPER "${HEXADECIMAL}" _tail) 5326fa459cSmrg set(_decimal 0) 5426fa459cSmrg string(LENGTH "${_tail}" _tail_length) 5526fa459cSmrg while (_tail_length GREATER 0) 5626fa459cSmrg math(EXPR _decimal "${_decimal} * 16") 5726fa459cSmrg string(SUBSTRING "${_tail}" 0 1 _digit) 5826fa459cSmrg string(SUBSTRING "${_tail}" 1 -1 _tail) 5926fa459cSmrg if (_digit STREQUAL "A") 6026fa459cSmrg math(EXPR _decimal "${_decimal} + 10") 6126fa459cSmrg elseif (_digit STREQUAL "B") 6226fa459cSmrg math(EXPR _decimal "${_decimal} + 11") 6326fa459cSmrg elseif (_digit STREQUAL "C") 6426fa459cSmrg math(EXPR _decimal "${_decimal} + 12") 6526fa459cSmrg elseif (_digit STREQUAL "D") 6626fa459cSmrg math(EXPR _decimal "${_decimal} + 13") 6726fa459cSmrg elseif (_digit STREQUAL "E") 6826fa459cSmrg math(EXPR _decimal "${_decimal} + 14") 6926fa459cSmrg elseif (_digit STREQUAL "F") 7026fa459cSmrg math(EXPR _decimal "${_decimal} + 15") 7126fa459cSmrg else() 7226fa459cSmrg math(EXPR _decimal "${_decimal} + ${_digit}") 7326fa459cSmrg endif() 7426fa459cSmrg string(LENGTH "${_tail}" _tail_length) 7526fa459cSmrg endwhile() 7626fa459cSmrg set(${DECIMAL} ${_decimal} PARENT_SCOPE) 7726fa459cSmrgendfunction(hex_to_dec) 7826fa459cSmrg 7926fa459cSmrg# Version information 8026fa459cSmrgfile(STRINGS "c/common/version.h" _brotli_version_line REGEX "^#define BROTLI_VERSION (0x[0-9a-fA-F]+)$") 8126fa459cSmrgstring(REGEX REPLACE "^#define BROTLI_VERSION 0x([0-9a-fA-F]+)$" "\\1" _brotli_version_hex "${_brotli_version_line}") 8226fa459cSmrghex_to_dec("${_brotli_version_hex}" _brotli_version) 8326fa459cSmrgmath(EXPR BROTLI_VERSION_MAJOR "${_brotli_version} >> 24") 8426fa459cSmrgmath(EXPR BROTLI_VERSION_MINOR "(${_brotli_version} >> 12) & 4095") 8526fa459cSmrgmath(EXPR BROTLI_VERSION_PATCH "${_brotli_version} & 4095") 8626fa459cSmrgset(BROTLI_VERSION "${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_PATCH}") 8726fa459cSmrgmark_as_advanced(BROTLI_VERSION BROTLI_VERSION_MAJOR BROTLI_VERSION_MINOR BROTLI_VERSION_PATCH) 8826fa459cSmrg 8926fa459cSmrg# ABI Version information 9026fa459cSmrgfile(STRINGS "c/common/version.h" _brotli_abi_info_line REGEX "^#define BROTLI_ABI_VERSION (0x[0-9a-fA-F]+)$") 9126fa459cSmrgstring(REGEX REPLACE "^#define BROTLI_ABI_VERSION 0x([0-9a-fA-F]+)$" "\\1" _brotli_abi_info_hex "${_brotli_abi_info_line}") 9226fa459cSmrghex_to_dec("${_brotli_abi_info_hex}" _brotli_abi_info) 9326fa459cSmrgmath(EXPR BROTLI_ABI_CURRENT "${_brotli_abi_info} >> 24") 9426fa459cSmrgmath(EXPR BROTLI_ABI_REVISION "(${_brotli_abi_info} >> 12) & 4095") 9526fa459cSmrgmath(EXPR BROTLI_ABI_AGE "${_brotli_abi_info} & 4095") 9626fa459cSmrgmath(EXPR BROTLI_ABI_COMPATIBILITY "${BROTLI_ABI_CURRENT} - ${BROTLI_ABI_AGE}") 9726fa459cSmrgmark_as_advanced(BROTLI_ABI_CURRENT BROTLI_ABI_REVISION BROTLI_ABI_AGE BROTLI_ABI_COMPATIBILITY) 9826fa459cSmrg 9926fa459cSmrgif (ENABLE_SANITIZER) 10026fa459cSmrg set(CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} -fsanitize=${ENABLE_SANITIZER}") 10126fa459cSmrg set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fsanitize=${ENABLE_SANITIZER}") 10226fa459cSmrg set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${ENABLE_SANITIZER}") 10326fa459cSmrg 10426fa459cSmrg # By default, brotli depends on undefined behavior, but setting 10526fa459cSmrg # BROTLI_BUILD_PORTABLE should result in a build which does not. 10626fa459cSmrg if(ENABLE_SANITIZER STREQUAL "undefined") 10726fa459cSmrg add_definitions(-DBROTLI_BUILD_PORTABLE) 10826fa459cSmrg endif() 10926fa459cSmrgendif () 11026fa459cSmrg 11126fa459cSmrginclude(CheckFunctionExists) 11226fa459cSmrgset(LIBM_LIBRARY) 11326fa459cSmrgCHECK_FUNCTION_EXISTS(log2 LOG2_RES) 11426fa459cSmrgif(NOT LOG2_RES) 11526fa459cSmrg set(orig_req_libs "${CMAKE_REQUIRED_LIBRARIES}") 11626fa459cSmrg set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};m") 11726fa459cSmrg CHECK_FUNCTION_EXISTS(log2 LOG2_LIBM_RES) 11826fa459cSmrg if(LOG2_LIBM_RES) 11926fa459cSmrg set(LIBM_LIBRARY "m") 12026fa459cSmrg add_definitions(-DBROTLI_HAVE_LOG2=1) 12126fa459cSmrg else() 12226fa459cSmrg add_definitions(-DBROTLI_HAVE_LOG2=0) 12326fa459cSmrg endif() 12426fa459cSmrg 12526fa459cSmrg set(CMAKE_REQUIRED_LIBRARIES "${orig_req_libs}") 12626fa459cSmrg unset(LOG2_LIBM_RES) 12726fa459cSmrg unset(orig_req_libs) 12826fa459cSmrgelse() 12926fa459cSmrg add_definitions(-DBROTLI_HAVE_LOG2=1) 13026fa459cSmrgendif() 13126fa459cSmrgunset(LOG2_RES) 13226fa459cSmrg 13326fa459cSmrgset(BROTLI_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/c/include") 13426fa459cSmrgmark_as_advanced(BROTLI_INCLUDE_DIRS) 13526fa459cSmrg 13626fa459cSmrgset(BROTLI_LIBRARIES_CORE brotlienc brotlidec brotlicommon) 13726fa459cSmrgset(BROTLI_LIBRARIES ${BROTLI_LIBRARIES_CORE} ${LIBM_LIBRARY}) 13826fa459cSmrgmark_as_advanced(BROTLI_LIBRARIES) 13926fa459cSmrg 14026fa459cSmrgset(BROTLI_LIBRARIES_CORE_STATIC brotlienc-static brotlidec-static brotlicommon-static) 14126fa459cSmrgset(BROTLI_LIBRARIES_STATIC ${BROTLI_LIBRARIES_CORE_STATIC} ${LIBM_LIBRARY}) 14226fa459cSmrgmark_as_advanced(BROTLI_LIBRARIES_STATIC) 14326fa459cSmrg 14426fa459cSmrgif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") 14526fa459cSmrg add_definitions(-DOS_LINUX) 14626fa459cSmrgelseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 14726fa459cSmrg add_definitions(-DOS_FREEBSD) 14826fa459cSmrgelseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 14926fa459cSmrg add_definitions(-DOS_MACOSX) 15026fa459cSmrgendif() 15126fa459cSmrg 15226fa459cSmrgfunction(transform_sources_list INPUT_FILE OUTPUT_FILE) 15326fa459cSmrg file(READ ${INPUT_FILE} TEXT) 15426fa459cSmrg string(REGEX REPLACE "\\\\\n" "~continuation~" TEXT ${TEXT}) 15526fa459cSmrg string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" TEXT ${TEXT}) 15626fa459cSmrg string(REPLACE "~continuation~" "\n" TEXT ${TEXT}) 15726fa459cSmrg file(WRITE ${OUTPUT_FILE} ${TEXT}) 15826fa459cSmrgendfunction() 15926fa459cSmrg 16026fa459cSmrgtransform_sources_list("scripts/sources.lst" "${CMAKE_CURRENT_BINARY_DIR}/sources.lst.cmake") 16126fa459cSmrginclude("${CMAKE_CURRENT_BINARY_DIR}/sources.lst.cmake") 16226fa459cSmrg 16326fa459cSmrgif(BROTLI_EMSCRIPTEN) 16426fa459cSmrg set(BROTLI_SHARED_LIBS "") 16526fa459cSmrgelse() 16626fa459cSmrg set(BROTLI_SHARED_LIBS brotlicommon brotlidec brotlienc) 16726fa459cSmrg add_library(brotlicommon SHARED ${BROTLI_COMMON_C}) 16826fa459cSmrg add_library(brotlidec SHARED ${BROTLI_DEC_C}) 16926fa459cSmrg add_library(brotlienc SHARED ${BROTLI_ENC_C}) 17026fa459cSmrgendif() 17126fa459cSmrg 17226fa459cSmrgset(BROTLI_STATIC_LIBS brotlicommon-static brotlidec-static brotlienc-static) 17326fa459cSmrgadd_library(brotlicommon-static STATIC ${BROTLI_COMMON_C}) 17426fa459cSmrgadd_library(brotlidec-static STATIC ${BROTLI_DEC_C}) 17526fa459cSmrgadd_library(brotlienc-static STATIC ${BROTLI_ENC_C}) 17626fa459cSmrg 17726fa459cSmrg# Older CMake versions does not understand INCLUDE_DIRECTORIES property. 17826fa459cSmrginclude_directories(${BROTLI_INCLUDE_DIRS}) 17926fa459cSmrg 18026fa459cSmrgforeach(lib IN LISTS BROTLI_SHARED_LIBS) 18126fa459cSmrg target_compile_definitions(${lib} PUBLIC "BROTLI_SHARED_COMPILATION" ) 18226fa459cSmrg string(TOUPPER "${lib}" LIB) 18326fa459cSmrg set_target_properties (${lib} PROPERTIES DEFINE_SYMBOL "${LIB}_SHARED_COMPILATION") 18426fa459cSmrgendforeach() 18526fa459cSmrg 18626fa459cSmrgforeach(lib IN LISTS BROTLI_SHARED_LIBS BROTLI_STATIC_LIBS) 18726fa459cSmrg target_link_libraries(${lib} ${LIBM_LIBRARY}) 18826fa459cSmrg set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIRS}) 18926fa459cSmrg set_target_properties(${lib} PROPERTIES 19026fa459cSmrg VERSION "${BROTLI_ABI_COMPATIBILITY}.${BROTLI_ABI_AGE}.${BROTLI_ABI_REVISION}" 19126fa459cSmrg SOVERSION "${BROTLI_ABI_COMPATIBILITY}") 19226fa459cSmrg if(NOT BROTLI_EMSCRIPTEN) 19326fa459cSmrg set_target_properties(${lib} PROPERTIES POSITION_INDEPENDENT_CODE TRUE) 19426fa459cSmrg endif() 19526fa459cSmrg set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIRS}") 19626fa459cSmrgendforeach() 19726fa459cSmrg 19826fa459cSmrgif(NOT BROTLI_EMSCRIPTEN) 19926fa459cSmrgtarget_link_libraries(brotlidec brotlicommon) 20026fa459cSmrgtarget_link_libraries(brotlienc brotlicommon) 20126fa459cSmrgendif() 20226fa459cSmrg 20326fa459cSmrgtarget_link_libraries(brotlidec-static brotlicommon-static) 20426fa459cSmrgtarget_link_libraries(brotlienc-static brotlicommon-static) 20526fa459cSmrg 20626fa459cSmrg# For projects stuck on older versions of CMake, this will set the 20726fa459cSmrg# BROTLI_INCLUDE_DIRS and BROTLI_LIBRARIES variables so they still 20826fa459cSmrg# have a relatively easy way to use Brotli: 20926fa459cSmrg# 21026fa459cSmrg# include_directories(${BROTLI_INCLUDE_DIRS}) 21126fa459cSmrg# target_link_libraries(foo ${BROTLI_LIBRARIES}) 21226fa459cSmrgif(BROTLI_PARENT_DIRECTORY) 21326fa459cSmrg set(BROTLI_INCLUDE_DIRS "${BROTLI_INCLUDE_DIRS}" PARENT_SCOPE) 21426fa459cSmrg set(BROTLI_LIBRARIES "${BROTLI_LIBRARIES}" PARENT_SCOPE) 21526fa459cSmrgendif() 21626fa459cSmrg 21726fa459cSmrg# Build the brotli executable 21826fa459cSmrgadd_executable(brotli ${BROTLI_CLI_C}) 21926fa459cSmrgtarget_link_libraries(brotli ${BROTLI_LIBRARIES_STATIC}) 22026fa459cSmrg 22126fa459cSmrg# Installation 22226fa459cSmrgif(NOT BROTLI_EMSCRIPTEN) 22326fa459cSmrgif(NOT BROTLI_BUNDLED_MODE) 22426fa459cSmrg install( 22526fa459cSmrg TARGETS brotli 22626fa459cSmrg RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 22726fa459cSmrg ) 22826fa459cSmrg 22926fa459cSmrg install( 23026fa459cSmrg TARGETS ${BROTLI_LIBRARIES_CORE} 23126fa459cSmrg ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 23226fa459cSmrg LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 23326fa459cSmrg RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 23426fa459cSmrg ) 23526fa459cSmrg 23626fa459cSmrg install( 23726fa459cSmrg TARGETS ${BROTLI_LIBRARIES_CORE_STATIC} 23826fa459cSmrg ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 23926fa459cSmrg LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 24026fa459cSmrg RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 24126fa459cSmrg ) 24226fa459cSmrg 24326fa459cSmrg install( 24426fa459cSmrg DIRECTORY ${BROTLI_INCLUDE_DIRS}/brotli 24526fa459cSmrg DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" 24626fa459cSmrg ) 24726fa459cSmrgendif() # BROTLI_BUNDLED_MODE 24826fa459cSmrgendif() # BROTLI_EMSCRIPTEN 24926fa459cSmrg 25026fa459cSmrg# Tests 25126fa459cSmrg 25226fa459cSmrg# If we're targeting Windows but not running on Windows, we need Wine 25326fa459cSmrg# to run the tests... 25426fa459cSmrgif(NOT BROTLI_DISABLE_TESTS) 25526fa459cSmrg if(WIN32 AND NOT CMAKE_HOST_WIN32) 25626fa459cSmrg find_program(BROTLI_WRAPPER NAMES wine) 25726fa459cSmrg 25826fa459cSmrg if(NOT BROTLI_WRAPPER) 25926fa459cSmrg message(STATUS "wine not found, disabling tests") 26026fa459cSmrg set(BROTLI_DISABLE_TESTS TRUE) 26126fa459cSmrg endif() 26226fa459cSmrg endif() 26326fa459cSmrgendif() 26426fa459cSmrg 26526fa459cSmrg# If our compiler is a cross-compiler that we know about (arm/aarch64), 26626fa459cSmrg# then we need to use qemu to execute the tests. 26726fa459cSmrgif(NOT BROTLI_DISABLE_TESTS) 26826fa459cSmrg if ("${CMAKE_C_COMPILER}" MATCHES "^.*/arm-linux-gnueabihf-.*$") 26926fa459cSmrg message(STATUS "Detected arm-linux-gnueabihf cross-compilation") 27026fa459cSmrg set(BROTLI_WRAPPER "qemu-arm") 27126fa459cSmrg set(BROTLI_WRAPPER_LD_PREFIX "/usr/arm-linux-gnueabihf") 27226fa459cSmrg endif() 27326fa459cSmrg 27426fa459cSmrg if ("${CMAKE_C_COMPILER}" MATCHES "^.*/arm-linux-gnueabi-.*$") 27526fa459cSmrg message(STATUS "Detected arm-linux-gnueabi cross-compilation") 27626fa459cSmrg set(BROTLI_WRAPPER "qemu-arm") 27726fa459cSmrg set(BROTLI_WRAPPER_LD_PREFIX "/usr/arm-linux-gnueabi") 27826fa459cSmrg endif() 27926fa459cSmrg 28026fa459cSmrg if ("${CMAKE_C_COMPILER}" MATCHES "^.*/aarch64-linux-gnu-.*$") 28126fa459cSmrg message(STATUS "Detected aarch64-linux-gnu cross-compilation") 28226fa459cSmrg set(BROTLI_WRAPPER "qemu-aarch64") 28326fa459cSmrg set(BROTLI_WRAPPER_LD_PREFIX "/usr/aarch64-linux-gnu") 28426fa459cSmrg endif() 28526fa459cSmrgendif() 28626fa459cSmrg 28726fa459cSmrgif(NOT BROTLI_DISABLE_TESTS) 28826fa459cSmrg include(CTest) 28926fa459cSmrg enable_testing() 29026fa459cSmrg 29126fa459cSmrg set(ROUNDTRIP_INPUTS 29226fa459cSmrg tests/testdata/alice29.txt 29326fa459cSmrg tests/testdata/asyoulik.txt 29426fa459cSmrg tests/testdata/lcet10.txt 29526fa459cSmrg tests/testdata/plrabn12.txt 29626fa459cSmrg c/enc/encode.c 29726fa459cSmrg c/common/dictionary.h 29826fa459cSmrg c/dec/decode.c) 29926fa459cSmrg 30026fa459cSmrg foreach(INPUT ${ROUNDTRIP_INPUTS}) 30126fa459cSmrg get_filename_component(OUTPUT_NAME "${INPUT}" NAME) 30226fa459cSmrg 30326fa459cSmrg set(OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}") 30426fa459cSmrg set(INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${INPUT}") 30526fa459cSmrg 30626fa459cSmrg if (EXISTS "${INPUT_FILE}") 30726fa459cSmrg foreach(quality 1 6 9 11) 30826fa459cSmrg add_test(NAME "${BROTLI_TEST_PREFIX}roundtrip/${INPUT}/${quality}" 30926fa459cSmrg COMMAND "${CMAKE_COMMAND}" 31026fa459cSmrg -DBROTLI_WRAPPER=${BROTLI_WRAPPER} 31126fa459cSmrg -DBROTLI_WRAPPER_LD_PREFIX=${BROTLI_WRAPPER_LD_PREFIX} 31226fa459cSmrg -DBROTLI_CLI=$<TARGET_FILE:brotli> 31326fa459cSmrg -DQUALITY=${quality} 31426fa459cSmrg -DINPUT=${INPUT_FILE} 31526fa459cSmrg -DOUTPUT=${OUTPUT_FILE}.${quality} 31626fa459cSmrg -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run-roundtrip-test.cmake) 31726fa459cSmrg endforeach() 31826fa459cSmrg else() 31926fa459cSmrg message(WARNING "Test file ${INPUT} does not exist.") 32026fa459cSmrg endif() 32126fa459cSmrg endforeach() 32226fa459cSmrg 32326fa459cSmrg file(GLOB_RECURSE 32426fa459cSmrg COMPATIBILITY_INPUTS 32526fa459cSmrg RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 32626fa459cSmrg tests/testdata/*.compressed*) 32726fa459cSmrg 32826fa459cSmrg foreach(INPUT ${COMPATIBILITY_INPUTS}) 32926fa459cSmrg add_test(NAME "${BROTLI_TEST_PREFIX}compatibility/${INPUT}" 33026fa459cSmrg COMMAND "${CMAKE_COMMAND}" 33126fa459cSmrg -DBROTLI_WRAPPER=${BROTLI_WRAPPER} 33226fa459cSmrg -DBROTLI_WRAPPER_LD_PREFIX=${BROTLI_WRAPPER_LD_PREFIX} 33326fa459cSmrg -DBROTLI_CLI=$<TARGET_FILE:brotli> 33426fa459cSmrg -DINPUT=${CMAKE_CURRENT_SOURCE_DIR}/${INPUT} 33526fa459cSmrg -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run-compatibility-test.cmake) 33626fa459cSmrg endforeach() 33726fa459cSmrgendif() 33826fa459cSmrg 33926fa459cSmrg# Generate a pkg-config files 34026fa459cSmrg 34126fa459cSmrgfunction(generate_pkg_config_path outvar path) 34226fa459cSmrg string(LENGTH "${path}" path_length) 34326fa459cSmrg 34426fa459cSmrg set(path_args ${ARGV}) 34526fa459cSmrg list(REMOVE_AT path_args 0 1) 34626fa459cSmrg list(LENGTH path_args path_args_remaining) 34726fa459cSmrg 34826fa459cSmrg set("${outvar}" "${path}") 34926fa459cSmrg 35026fa459cSmrg while(path_args_remaining GREATER 1) 35126fa459cSmrg list(GET path_args 0 name) 35226fa459cSmrg list(GET path_args 1 value) 35326fa459cSmrg 35426fa459cSmrg get_filename_component(value_full "${value}" ABSOLUTE) 35526fa459cSmrg string(LENGTH "${value}" value_length) 35626fa459cSmrg 35726fa459cSmrg if(path_length EQUAL value_length AND path STREQUAL value) 35826fa459cSmrg set("${outvar}" "\${${name}}") 35926fa459cSmrg break() 36026fa459cSmrg elseif(path_length GREATER value_length) 36126fa459cSmrg # We might be in a subdirectory of the value, but we have to be 36226fa459cSmrg # careful about a prefix matching but not being a subdirectory 36326fa459cSmrg # (for example, /usr/lib64 is not a subdirectory of /usr/lib). 36426fa459cSmrg # We'll do this by making sure the next character is a directory 36526fa459cSmrg # separator. 36626fa459cSmrg string(SUBSTRING "${path}" ${value_length} 1 sep) 36726fa459cSmrg if(sep STREQUAL "/") 36826fa459cSmrg string(SUBSTRING "${path}" 0 ${value_length} s) 36926fa459cSmrg if(s STREQUAL value) 37026fa459cSmrg string(SUBSTRING "${path}" "${value_length}" -1 suffix) 37126fa459cSmrg set("${outvar}" "\${${name}}${suffix}") 37226fa459cSmrg break() 37326fa459cSmrg endif() 37426fa459cSmrg endif() 37526fa459cSmrg endif() 37626fa459cSmrg 37726fa459cSmrg list(REMOVE_AT path_args 0 1) 37826fa459cSmrg list(LENGTH path_args path_args_remaining) 37926fa459cSmrg endwhile() 38026fa459cSmrg 38126fa459cSmrg set("${outvar}" "${${outvar}}" PARENT_SCOPE) 38226fa459cSmrgendfunction(generate_pkg_config_path) 38326fa459cSmrg 38426fa459cSmrgfunction(transform_pc_file INPUT_FILE OUTPUT_FILE VERSION) 38526fa459cSmrg file(READ ${INPUT_FILE} TEXT) 38626fa459cSmrg 38726fa459cSmrg set(PREFIX "${CMAKE_INSTALL_PREFIX}") 38826fa459cSmrg string(REGEX REPLACE "@prefix@" "${PREFIX}" TEXT ${TEXT}) 38926fa459cSmrg string(REGEX REPLACE "@exec_prefix@" "${PREFIX}" TEXT ${TEXT}) 39026fa459cSmrg 39126fa459cSmrg generate_pkg_config_path(LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}" prefix "${PREFIX}") 39226fa459cSmrg string(REGEX REPLACE "@libdir@" "${LIBDIR}" TEXT ${TEXT}) 39326fa459cSmrg 39426fa459cSmrg generate_pkg_config_path(INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}" prefix "${PREFIX}") 39526fa459cSmrg string(REGEX REPLACE "@includedir@" "${INCLUDEDIR}" TEXT ${TEXT}) 39626fa459cSmrg 39726fa459cSmrg string(REGEX REPLACE "@PACKAGE_VERSION@" "${VERSION}" TEXT ${TEXT}) 39826fa459cSmrg 39926fa459cSmrg file(WRITE ${OUTPUT_FILE} ${TEXT}) 40026fa459cSmrgendfunction() 40126fa459cSmrg 40226fa459cSmrgtransform_pc_file("scripts/libbrotlicommon.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libbrotlicommon.pc" "${BROTLI_VERSION}") 40326fa459cSmrg 40426fa459cSmrgtransform_pc_file("scripts/libbrotlidec.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libbrotlidec.pc" "${BROTLI_VERSION}") 40526fa459cSmrg 40626fa459cSmrgtransform_pc_file("scripts/libbrotlienc.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libbrotlienc.pc" "${BROTLI_VERSION}") 40726fa459cSmrg 40826fa459cSmrgif(NOT BROTLI_EMSCRIPTEN) 40926fa459cSmrgif(NOT BROTLI_BUNDLED_MODE) 41026fa459cSmrg install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libbrotlicommon.pc" 41126fa459cSmrg DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 41226fa459cSmrg install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libbrotlidec.pc" 41326fa459cSmrg DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 41426fa459cSmrg install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libbrotlienc.pc" 41526fa459cSmrg DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 41626fa459cSmrgendif() # BROTLI_BUNDLED_MODE 41726fa459cSmrgendif() # BROTLI_EMSCRIPTEN 41826fa459cSmrg 41926fa459cSmrgif (ENABLE_COVERAGE STREQUAL "yes") 42026fa459cSmrg SETUP_TARGET_FOR_COVERAGE(coverage test coverage) 42126fa459cSmrgendif () 422