blob: fcd0e96868bddfd4e1af94fe443eaa9b026281c7 [file] [log] [blame]
Evan Nemerson93ef13f2016-06-20 13:07:35 -07001# 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.
5cmake_minimum_required(VERSION 2.8.6)
6
7project(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).
13get_directory_property(BROTLI_PARENT_DIRECTORY PARENT_DIRECTORY)
14if(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()
22endif()
23mark_as_advanced(BROTLI_BUNDLED_MODE)
24
Evan Nemerson6c470092016-11-01 02:03:29 -070025include(GNUInstallDirs)
26
Frédéric Wang074e4ac2016-08-27 12:04:48 +020027# 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 Kliuchnikov52f04832017-09-19 09:40:48 +020029set(CMAKE_SKIP_BUILD_RPATH FALSE)
30set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
31set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
32list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_LIBDIR}" isSystemDir)
33if ("${isSystemDir}" STREQUAL "-1")
34 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")
Frédéric Wang074e4ac2016-08-27 12:04:48 +020035endif()
36
Eugene Kliuchnikovb93cb692016-10-18 17:14:49 +020037# Parse version information from common/version.h. Normally we would
Evan Nemerson93ef13f2016-06-20 13:07:35 -070038# 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 Kliuchnikov2c2d5572016-08-22 15:44:12 +020040# common/version.h to be less intrusive.
41function(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)
67endfunction(hex_to_dec)
68
Evan Nemerson6c470092016-11-01 02:03:29 -070069# Version information
Eugene Kliuchnikov6ece1d82017-04-23 14:07:08 +020070file(STRINGS "c/common/version.h" _brotli_version_line REGEX "^#define BROTLI_VERSION (0x[0-9a-fA-F]+)$")
Eugene Kliuchnikov2c2d5572016-08-22 15:44:12 +020071string(REGEX REPLACE "^#define BROTLI_VERSION 0x([0-9a-fA-F]+)$" "\\1" _brotli_version_hex "${_brotli_version_line}")
72hex_to_dec("${_brotli_version_hex}" _brotli_version)
73math(EXPR BROTLI_VERSION_MAJOR "${_brotli_version} >> 24")
74math(EXPR BROTLI_VERSION_MINOR "(${_brotli_version} >> 12) & 4095")
75math(EXPR BROTLI_VERSION_REVISION "${_brotli_version} & 4095")
Evan Nemerson93ef13f2016-06-20 13:07:35 -070076mark_as_advanced(BROTLI_VERSION_MAJOR BROTLI_VERSION_MINOR BROTLI_VERSION_REVISION)
77
Evan Nemerson37be4e32016-06-28 20:35:16 -070078if (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 Nemerson26a59352016-07-26 08:22:58 -070082
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 Nemerson37be4e32016-06-28 20:35:16 -070088endif ()
89
Evan Nemersonc1ec7ba2016-07-29 11:52:15 -070090include(CheckFunctionExists)
91set(LIBM_LIBRARY)
92CHECK_FUNCTION_EXISTS(log2 LOG2_RES)
93if(NOT LOG2_RES)
Evan Nemersonc1ec7ba2016-07-29 11:52:15 -070094 set(orig_req_libs "${CMAKE_REQUIRED_LIBRARIES}")
95 set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};m")
Evan Nemersonfe0e1532016-08-04 18:51:20 -070096 CHECK_FUNCTION_EXISTS(log2 LOG2_LIBM_RES)
97 if(LOG2_LIBM_RES)
Evan Nemersonc1ec7ba2016-07-29 11:52:15 -070098 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 Nemersonfe0e1532016-08-04 18:51:20 -0700104 unset(LOG2_LIBM_RES)
Evan Nemersonc1ec7ba2016-07-29 11:52:15 -0700105 unset(orig_req_libs)
106endif()
107unset(LOG2_RES)
108
Eugene Kliuchnikov6ece1d82017-04-23 14:07:08 +0200109set(BROTLI_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/c/include")
Eugene Kliuchnikov52f04832017-09-19 09:40:48 +0200110mark_as_advanced(BROTLI_INCLUDE_DIRS)
111
Frédéric Wanged2748a2016-10-12 18:23:34 +0200112set(BROTLI_LIBRARIES_CORE brotlienc brotlidec brotlicommon)
Frédéric Wang074e4ac2016-08-27 12:04:48 +0200113set(BROTLI_LIBRARIES ${BROTLI_LIBRARIES_CORE} ${LIBM_LIBRARY})
Eugene Kliuchnikov52f04832017-09-19 09:40:48 +0200114mark_as_advanced(BROTLI_LIBRARIES)
115
116set(BROTLI_LIBRARIES_CORE_STATIC brotlienc-static brotlidec-static brotlicommon-static)
117set(BROTLI_LIBRARIES_STATIC ${BROTLI_LIBRARIES_CORE_STATIC} ${LIBM_LIBRARY})
118mark_as_advanced(BROTLI_LIBRARIES_STATIC)
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700119
120if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
121 add_definitions(-DOS_LINUX)
122elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
123 add_definitions(-DOS_FREEBSD)
124elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
125 add_definitions(-DOS_MACOSX)
126endif()
127
Eugene Kliuchnikov52f04832017-09-19 09:40:48 +0200128set(BROTLICOMMON_SOURCES
Eugene Kliuchnikov6ece1d82017-04-23 14:07:08 +0200129 c/common/dictionary.c)
Eugene Kliuchnikov52f04832017-09-19 09:40:48 +0200130set(BROTLIDEC_SOURCES
Eugene Kliuchnikov6ece1d82017-04-23 14:07:08 +0200131 c/dec/bit_reader.c
132 c/dec/decode.c
133 c/dec/huffman.c
134 c/dec/state.c)
Eugene Kliuchnikov52f04832017-09-19 09:40:48 +0200135set(BROTLIENC_SOURCES
Eugene Kliuchnikov6ece1d82017-04-23 14:07:08 +0200136 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 Nemerson93ef13f2016-06-20 13:07:35 -0700153
Eugene Kliuchnikov52f04832017-09-19 09:40:48 +0200154add_library(brotlicommon SHARED ${BROTLICOMMON_SOURCES})
155add_library(brotlidec SHARED ${BROTLIDEC_SOURCES})
156add_library(brotlienc SHARED ${BROTLIENC_SOURCES})
157
158add_library(brotlicommon-static STATIC ${BROTLICOMMON_SOURCES})
159add_library(brotlidec-static STATIC ${BROTLIDEC_SOURCES})
160add_library(brotlienc-static STATIC ${BROTLIENC_SOURCES})
161
Eugene Kliuchnikov532921b2016-08-23 15:35:54 +0200162# Older CMake versions does not understand INCLUDE_DIRECTORIES property.
163include_directories(${BROTLI_INCLUDE_DIRS})
164
Frédéric Wanged2748a2016-10-12 18:23:34 +0200165foreach(lib brotlicommon brotlidec brotlienc)
Eugene Kliuchnikov52f04832017-09-19 09:40:48 +0200166 target_compile_definitions(${lib} PUBLIC "BROTLI_SHARED_COMPILATION" )
167 string(TOUPPER "${lib}" LIB)
168 set_target_properties (${lib} PROPERTIES DEFINE_SYMBOL "${LIB}_SHARED_COMPILATION" )
169endforeach()
170
171foreach(lib brotlicommon brotlidec brotlienc brotlicommon-static brotlidec-static brotlienc-static)
Evan Nemersonc1ec7ba2016-07-29 11:52:15 -0700172 target_link_libraries(${lib} ${LIBM_LIBRARY})
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700173 set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIRS})
174 set_target_properties(${lib} PROPERTIES
Evan Nemerson6c470092016-11-01 02:03:29 -0700175 SOVERSION "${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_REVISION}"
176 VERSION "${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_REVISION}"
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700177 POSITION_INDEPENDENT_CODE TRUE)
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700178 set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIRS}")
179endforeach()
Eugene Kliuchnikov69982c22016-10-18 16:45:32 +0200180
Evan Nemerson6c470092016-11-01 02:03:29 -0700181target_link_libraries(brotlidec brotlicommon)
182target_link_libraries(brotlienc brotlicommon)
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700183
Eugene Kliuchnikov52f04832017-09-19 09:40:48 +0200184target_link_libraries(brotlidec-static brotlicommon-static)
185target_link_libraries(brotlienc-static brotlicommon-static)
186
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700187# 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})
193if(BROTLI_PARENT_DIRECTORY)
194 set(BROTLI_INCLUDE_DIRS "${BROTLI_INCLUDE_DIRS}" PARENT_SCOPE)
195 set(BROTLI_LIBRARIES "${BROTLI_LIBRARIES}" PARENT_SCOPE)
196endif()
197
Eugene Kliuchnikov03739d22017-05-29 17:55:14 +0200198# Build the brotli executable
199add_executable(brotli c/tools/brotli.c)
Eugene Kliuchnikov52f04832017-09-19 09:40:48 +0200200target_link_libraries(brotli ${BROTLI_LIBRARIES_STATIC})
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700201
202# Installation
Frédéric Wang5e1219a2016-08-27 12:14:13 +0200203if(NOT BROTLI_BUNDLED_MODE)
Eugene Kliuchnikov2c001012017-05-24 17:19:34 +0200204 install(
Eugene Kliuchnikov03739d22017-05-29 17:55:14 +0200205 TARGETS brotli
Eugene Kliuchnikov2c001012017-05-24 17:19:34 +0200206 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
207 )
Frédéric Wang074e4ac2016-08-27 12:04:48 +0200208
Eugene Kliuchnikov2c001012017-05-24 17:19:34 +0200209 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 Wang074e4ac2016-08-27 12:04:48 +0200215
Eugene Kliuchnikov2c001012017-05-24 17:19:34 +0200216 install(
Eugene Kliuchnikovb6a01742017-09-20 10:04:06 +0200217 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 Kliuchnikov2c001012017-05-24 17:19:34 +0200224 DIRECTORY ${BROTLI_INCLUDE_DIRS}/brotli
225 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
226 )
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700227endif()
228
229# Tests
Evan Nemerson03657e82016-07-28 13:31:09 -0700230
231# If we're targeting Windows but not running on Windows, we need Wine
232# to run the tests...
233if(NOT BROTLI_DISABLE_TESTS)
234 if(WIN32 AND NOT CMAKE_HOST_WIN32)
235 find_program(BROTLI_WINE NAMES wine)
Evan Nemerson03657e82016-07-28 13:31:09 -0700236
Evan Nemersonc1ec7ba2016-07-29 11:52:15 -0700237 if(NOT BROTLI_WINE)
238 message(STATUS "wine not found, disabling tests")
239 set(BROTLI_DISABLE_TESTS TRUE)
240 endif()
Evan Nemerson03657e82016-07-28 13:31:09 -0700241 endif()
242endif()
243
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700244if(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 Kliuchnikov6ece1d82017-04-23 14:07:08 +0200253 c/enc/encode.c
254 c/common/dictionary.h
255 c/dec/decode.c)
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700256
257 foreach(INPUT ${ROUNDTRIP_INPUTS})
Evan Nemerson03657e82016-07-28 13:31:09 -0700258 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 Nemerson93ef13f2016-06-20 13:07:35 -0700263 foreach(quality 1 6 9 11)
264 add_test(NAME "${BROTLI_TEST_PREFIX}roundtrip/${INPUT}/${quality}"
265 COMMAND "${CMAKE_COMMAND}"
Evan Nemerson03657e82016-07-28 13:31:09 -0700266 -DBROTLI_WRAPPER=${BROTLI_WINE}
Eugene Kliuchnikov03739d22017-05-29 17:55:14 +0200267 -DBROTLI_CLI=$<TARGET_FILE:brotli>
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700268 -DQUALITY=${quality}
Evan Nemerson03657e82016-07-28 13:31:09 -0700269 -DINPUT=${INPUT_FILE}
Eugene Kliuchnikovb6a01742017-09-20 10:04:06 +0200270 -DOUTPUT=${OUTPUT_FILE}.${quality}
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700271 -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 Nemerson03657e82016-07-28 13:31:09 -0700283 -DBROTLI_WRAPPER=${BROTLI_WINE}
Eugene Kliuchnikov03739d22017-05-29 17:55:14 +0200284 -DBROTLI_CLI=$<TARGET_FILE:brotli>
Evan Nemerson93ef13f2016-06-20 13:07:35 -0700285 -DINPUT=${CMAKE_CURRENT_SOURCE_DIR}/${INPUT}
286 -P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run-compatibility-test.cmake)
287 endforeach()
288endif()
Evan Nemerson6c470092016-11-01 02:03:29 -0700289
290# Generate a pkg-config file
291
292include(CMakeParseArguments)
293
294function(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)
335endfunction(generate_pkg_config_path)
336
337function(generate_pkg_config output_file)
338 set (options)
Eugene Kliuchnikovfe9f9a92016-12-22 08:57:44 +0100339 set (oneValueArgs NAME DESCRIPTION URL VERSION PREFIX LIBDIR INCLUDEDIR)
340 set (multiValueArgs DEPENDS_PRIVATE CFLAGS LIBRARIES)
Evan Nemerson6c470092016-11-01 02:03:29 -0700341 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 Kliuchnikovfe9f9a92016-12-22 08:57:44 +0100377 if(GEN_PKG_URL)
378 file(APPEND "${output_file}" "URL: ${GEN_PKG_URL}\n")
379 endif()
380
Evan Nemerson6c470092016-11-01 02:03:29 -0700381 if(GEN_PKG_VERSION)
382 file(APPEND "${output_file}" "Version: ${GEN_PKG_VERSION}\n")
383 endif()
384
Eugene Kliuchnikovfe9f9a92016-12-22 08:57:44 +0100385 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 Nemerson6c470092016-11-01 02:03:29 -0700393 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")
410endfunction(generate_pkg_config)
411
Eugene Kliuchnikovfe9f9a92016-12-22 08:57:44 +0100412generate_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 Nemerson6c470092016-11-01 02:03:29 -0700416 VERSION "${BROTLI_VERSION_MAJOR}.${BROTLI_VERSION_MINOR}.${BROTLI_VERSION_REVISION}"
Eugene Kliuchnikovfe9f9a92016-12-22 08:57:44 +0100417 LIBRARIES brotlicommon)
418
419generate_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
427generate_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 Duncanaaa44242017-03-02 00:19:57 +0900432 DEPENDS_PRIVATE libbrotlicommon
Eugene Kliuchnikovfe9f9a92016-12-22 08:57:44 +0100433 LIBRARIES brotlienc)
Evan Nemerson6c470092016-11-01 02:03:29 -0700434
435if(NOT BROTLI_BUNDLED_MODE)
Eugene Kliuchnikovfe9f9a92016-12-22 08:57:44 +0100436 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 Nemerson6c470092016-11-01 02:03:29 -0700441 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
442endif()
443
444if (ENABLE_COVERAGE STREQUAL "yes")
445 SETUP_TARGET_FOR_COVERAGE(coverage test coverage)
446endif ()