CMakeLists.txt 2.98 KB
Newer Older
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
1
cmake_minimum_required(VERSION 3.13...3.19)
Jan-Willem Blokland's avatar
Jan-Willem Blokland committed
2
project(libaec LANGUAGES C VERSION 1.0.5)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
3

Jan-Willem Blokland's avatar
Jan-Willem Blokland committed
4
# Automatically export symbols for Windows DLLs
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
5
6
7
8
9
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
10
include(CTest)
11

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
12
include(TestBigEndian)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
13
test_big_endian(WORDS_BIGENDIAN)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
14
15
16
17
18
19
20

# Check for __builtin_clzll for faster decoding
include(CheckCSourceCompiles)
check_c_source_compiles(
  "int main(void)\n{return __builtin_clzll(1LL);}"
  HAVE_DECL___BUILTIN_CLZLL)

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
21
if(NOT HAVE_DECL___BUILTIN_CLZLL)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
22
23
24
25
26
27
  # With MSVC we can use _BitScanReverse64
  check_c_source_compiles(
    "int main(void){unsigned long foo; unsigned __int64 bar=1LL;
return _BitScanReverse64(&foo, bar);}"
    HAVE_BSR64)
endif()
28

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
29
include(CheckSymbolExists)
30
31
32
33
check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF)
if(NOT HAVE_SNPRINTF)
  check_symbol_exists(_snprintf "stdio.h" HAVE__SNPRINTF)
  check_symbol_exists(_snprintf_s "stdio.h" HAVE__SNPRINTF_S)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
34
endif()
35

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
36
# Communicate findings to code. Has to be compatible with autoconf's config.h.
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
37
configure_file(
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
38
39
  "cmake/config.h.in"
  "${CMAKE_CURRENT_BINARY_DIR}/config.h")
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
40

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
41
add_subdirectory(src)
42
43
44
if(BUILD_TESTING)
  add_subdirectory(tests)
endif()
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
45
46

option(AEC_FUZZING "Enable build of fuzzing target" OFF)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
47
if(AEC_FUZZING)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
48
49
50
51
52
53
54
55
56
57
  enable_language(CXX)

  if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
  endif()

  if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0")
    message(FATAL_ERROR "You need Clang ≥ 6.0.0")
  endif()

58
  add_subdirectory(fuzzing)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
59
60
61
  set(FUZZ_TARGET_SAN_FLAGS -fsanitize=fuzzer-no-link,address,undefined)
  target_compile_options(aec PUBLIC -g -O1 ${FUZZ_TARGET_SAN_FLAGS})
  target_link_options(aec PUBLIC ${FUZZ_TARGET_SAN_FLAGS})
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
62
63
endif()

Jan-Willem Blokland's avatar
Jan-Willem Blokland committed
64
65
66
67
68
69
70
71
72
73
74
75
# Install the cmake files.
set(libaec_CONFIG_IN  ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libaec-config.cmake.in)
set(libaec_CONFIG_OUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/libaec-config.cmake)
configure_file(${libaec_CONFIG_IN} ${libaec_CONFIG_OUT} @ONLY)
set(libaec_CONFIG_VERSION_IN  ${CMAKE_CURRENT_SOURCE_DIR}/cmake/libaec-config-version.cmake.in)
set(libaec_CONFIG_VERSION_OUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/libaec-config-version.cmake)
configure_file(${libaec_CONFIG_VERSION_IN} ${libaec_CONFIG_VERSION_OUT} @ONLY)
install(FILES ${libaec_CONFIG_OUT}
        DESTINATION cmake)
install(FILES ${libaec_CONFIG_VERSION_OUT}
        DESTINATION cmake)

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
76
# Cpack configuration mainly for Windows installer
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
77
78
79
set(CPACK_PACKAGE_NAME "libaec")
set(CPACK_PACKAGE_VENDOR "Deutsches Klimarechenzentrum GmbH")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
80
  "libaec - Adaptive Entropy Coding library")
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
81
set(CPACK_PACKAGE_INSTALL_DIRECTORY "libaec")
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
82
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
83

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
84
85
86
if(WIN32)
  set(CPACK_GENERATOR "WIX")
  set(CPACK_WIX_UPGRADE_GUID "E58A21F6-BB99-46B5-8AD8-6114E4CCA0A6")
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
87
88
89
90
91
92
93
94
endif()

set(CPACK_SOURCE_IGNORE_FILES
    /.git
    /.*build.*
    .*~
    .*\#.*\#
    \..*\#.*)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
95

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
96
include(CPack)