CMakeLists.txt 2.41 KB
Newer Older
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
1
2
3
cmake_minimum_required(VERSION 3.13...3.19)
project(libaec LANGUAGES C VERSION 1.0.4)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
4

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
5
6
7
8
9
10
# Automatically export symbls for Windows DLLs
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
11
enable_testing()
12

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

# 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
22
if(NOT HAVE_DECL___BUILTIN_CLZLL)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
23
24
25
26
27
28
  # 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()
29

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
30
include(CheckSymbolExists)
31
32
33
34
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
35
endif()
36

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

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
43
44
add_subdirectory(src)
add_subdirectory(tests)
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()

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
64
# Cpack configuration mainly for Windows installer
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
65
66
67
set(CPACK_PACKAGE_NAME "libaec")
set(CPACK_PACKAGE_VENDOR "Deutsches Klimarechenzentrum GmbH")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
68
  "libaec - Adaptive Entropy Coding library")
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
69
set(CPACK_PACKAGE_INSTALL_DIRECTORY "libaec")
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
70
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
71

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
72
73
74
if(WIN32)
  set(CPACK_GENERATOR "WIX")
  set(CPACK_WIX_UPGRADE_GUID "E58A21F6-BB99-46B5-8AD8-6114E4CCA0A6")
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
75
76
77
78
79
80
81
82
endif()

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

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