forked from fast-pack/streamvbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
190 lines (164 loc) · 6 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
cmake_minimum_required(VERSION 3.3)
project(STREAMVBYTE VERSION "1.0.0")
set(STREAMVBYTE_LIB_VERSION "1.0.0" CACHE STRING "streamvbyte library version")
set(STREAMVBYTE_LIB_SOVERSION "1" CACHE STRING "streamvbyte library soversion")
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
include(CheckCCompilerFlag)
include(GNUInstallDirs)
option(STREAMVBYTE_WERROR "Treat warnings as errors." OFF)
option(STREAMVBYTE_WALL "Emit all warnings during compilation." ON)
if(STREAMVBYTE_WERROR)
if(MSVC)
check_c_compiler_flag("/WX" WERROR_MSVC_SUPPORTED)
if(WERROR_MSVC_SUPPORTED)
add_compile_options(/WX)
endif()
# Wall + WX may throw errors from the corecrt headers. Workaround:
if(STREAMVBYTE_WALL)
check_c_compiler_flag("/W3" W3_MSVC_SUPPORTED)
if(W3_MSVC_SUPPORTED)
add_compile_options(/W3)
endif()
check_c_compiler_flag("/w34714" SUPPRESS_C34714_MSVC_SUPPORTED)
if(SUPPRESS_C34714_MSVC_SUPPORTED)
add_compile_options(/w34714)
endif()
check_c_compiler_flag("/wd5045" SUPPRESS_SPECTRE_MSVC_SUPPORTED)
if(SUPPRESS_SPECTRE_MSVC_SUPPORTED)
add_compile_options(/wd5045)
endif()
check_c_compiler_flag("/sdl" SDL_MSVC_SUPPORTED)
if(SDL_MSVC_SUPPORTED)
add_compile_options(/sdl)
endif()
endif()
else()
check_c_compiler_flag(-Werror WERROR_GNU_SUPPORTED)
if(WERROR_GNU_SUPPORTED)
add_compile_options(-Werror)
endif()
endif()
endif()
if(STREAMVBYTE_WALL AND NOT(STREAMVBYTE_WERROR))
if(MSVC)
check_c_compiler_flag("/Wall" WALL_MSVC_SUPPORTED)
if(WALL_MSVC_SUPPORTED)
add_compile_options(/Wall)
endif()
else()
check_c_compiler_flag(-Wall WALL_GNU_SUPPORTED)
if(WALL_GNU_SUPPORTED)
add_compile_options(-Wall)
endif()
endif()
endif()
option(STREAMVBYTE_SANITIZE "Sanitize addresses" OFF)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected")
if(STREAMVBYTE_SANITIZE)
message(STATUS "Default to Debug")
set(CMAKE_BUILD_TYPE Debug
CACHE STRING "Choose the type of build."
FORCE
)
else()
message(STATUS "Default to Release")
set(CMAKE_BUILD_TYPE Release
CACHE STRING "Choose the type of build."
FORCE
)
endif()
endif()
if(STREAMVBYTE_SANITIZE)
message(STATUS "Enabling memory sanitizer.")
add_compile_options(
-fsanitize=address
-fno-omit-frame-pointer
-fno-sanitize-recover=all
)
add_compile_definitions(ASAN_OPTIONS=detect_leaks=1)
endif()
if(MSVC)
add_definitions("-D__restrict__=__restrict")
endif()
# test for arm
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
set(BASE_FLAGS ${BASE_FLAGS} "-D__ARM_NEON__")
endif()
set(STREAMVBYTE_SRCS
${PROJECT_SOURCE_DIR}/src/streamvbyte_encode.c
${PROJECT_SOURCE_DIR}/src/streamvbyte_decode.c
${PROJECT_SOURCE_DIR}/src/streamvbyte_zigzag.c
${PROJECT_SOURCE_DIR}/src/streamvbytedelta_encode.c
${PROJECT_SOURCE_DIR}/src/streamvbytedelta_decode.c
${PROJECT_SOURCE_DIR}/src/streamvbyte_0124_encode.c
${PROJECT_SOURCE_DIR}/src/streamvbyte_0124_decode.c
)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_library(streamvbyte "${STREAMVBYTE_SRCS}")
target_link_libraries(streamvbyte ${BASE_FLAGS})
set_target_properties(
streamvbyte
PROPERTIES
VERSION "${STREAMVBYTE_LIB_VERSION}"
SOVERSION "${STREAMVBYTE_LIB_SOVERSION}"
WINDOWS_EXPORT_ALL_SYMBOLS YES
)
target_include_directories(
streamvbyte
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>
)
install(
FILES
${PROJECT_SOURCE_DIR}/include/streamvbyte.h
${PROJECT_SOURCE_DIR}/include/streamvbytedelta.h
${PROJECT_SOURCE_DIR}/include/streamvbyte_zigzag.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
TARGETS streamvbyte
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
option(STREAMVBYTE_SANITIZE_UNDEFINED "Sanitize undefined behavior" OFF)
if(STREAMVBYTE_SANITIZE_UNDEFINED)
add_compile_options(-fsanitize=undefined -fno-sanitize-recover=all)
add_link_options(-fsanitize=undefined -fno-sanitize-recover=all)
endif()
message(STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR})
message(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE}) # this tends to be "sticky" so you can remain unknowingly in debug mode
message(STATUS "CMAKE_C_COMPILER: " ${CMAKE_C_COMPILER}) # important to know which compiler is used
message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS}) # important to know the flags
message(STATUS "CMAKE_C_FLAGS_DEBUG: " ${CMAKE_C_FLAGS_DEBUG})
message(STATUS "CMAKE_C_FLAGS_RELEASE: " ${CMAKE_C_FLAGS_RELEASE})
# build programs
# example
option(STREAMVBYTE_ENABLE_EXAMPLES "Enable examples for streamvbyte" OFF)
if(STREAMVBYTE_ENABLE_EXAMPLES)
add_executable(example ${PROJECT_SOURCE_DIR}/examples/example.c)
target_link_libraries(example streamvbyte)
endif()
option(STREAMVBYTE_ENABLE_TESTS "Enable unit tests for streamvbyte" OFF)
if(STREAMVBYTE_ENABLE_TESTS)
if(NOT MSVC)
# perf
add_executable(perf ${PROJECT_SOURCE_DIR}/tests/perf.c)
target_link_libraries(perf streamvbyte)
target_link_libraries(perf m)
endif()
# writeseq
add_executable(writeseq ${PROJECT_SOURCE_DIR}/tests/writeseq.c)
target_link_libraries(writeseq streamvbyte)
# unit
add_executable(unit ${PROJECT_SOURCE_DIR}/tests/unit.c)
target_link_libraries(unit streamvbyte)
target_include_directories(unit PRIVATE ${PROJECT_SOURCE_DIR}/src)
enable_testing()
# add unit tests
add_test(NAME unit COMMAND unit)
add_custom_target(check COMMAND ctest --output-on-failure DEPENDS unit)
endif()