forked from quiet/libcorrect
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
227 lines (196 loc) · 6.65 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
cmake_minimum_required(VERSION 3.25)
project(Correct
VERSION 2.0.0
LANGUAGES C
DESCRIPTION "Forward Error Correction Library")
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
include(CheckLibraryExists)
include(CheckIncludeFiles)
include(CheckCSourceCompiles)
include(CMakePushCheckState)
include(CheckCCompilerFlag)
option(ENABLE_LIBCORRECT_TEST "Build tests" OFF)
# Compiler and build settings
if(MSVC)
set(LIBM "")
add_compile_options(/W4 /WX)
else()
set(LIBM "m")
add_compile_options(-fPIC -Wall -Werror)
check_c_compiler_flag(-Wpedantic COMPILER_SUPPORTS_WPEDANTIC)
if(COMPILER_SUPPORTS_WPEDANTIC)
add_compile_options(-Wpedantic)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-g3 -O0)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
# Sanitizer options
option(USE_ASAN_UBSAN "Use AddressSanitizer and UndefinedBehaviorSanitizer" OFF)
option(USE_MSAN "Use MemorySanitizer" ON)
if(USE_MSAN AND HAVE_MSAN)
if(USE_ASAN_UBSAN)
message(FATAL_ERROR "MemorySanitizer cannot be used with AddressSanitizer")
endif()
add_compile_options(-fsanitize=memory -fno-optimize-sibling-calls -fno-omit-frame-pointer)
add_link_options(-fsanitize=memory)
elseif(USE_ASAN_UBSAN AND HAVE_ASAN_UBSAN)
add_compile_options(-fsanitize=address -fno-optimize-sibling-calls -fno-omit-frame-pointer)
add_link_options(-fsanitize=address)
endif()
endif()
else()
add_compile_options(-O2)
if(CMAKE_BUILD_TYPE STREQUAL "Profiling")
add_compile_options(-g3)
endif()
endif()
endif()
# Library detection
find_library(FEC fec)
check_library_exists(FEC dotprod "" HAVE_LIBFEC)
# SSE detection
if(NOT CMAKE_CROSSCOMPILING)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_DEFINITIONS -march=native)
check_c_source_compiles("
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <x86intrin.h>
#endif
int main(void) {
#if defined(_MSC_VER)
__m128i a = _mm_setzero_si128();
__m128i b = _mm_setzero_si128();
__m128i c = _mm_min_epu16(a, b);
#else
__m128i a;
__m128i b;
__m128i c = _mm_min_epu16(a, b);
#endif
return 0;
}" HAVE_SSE)
cmake_pop_check_state()
endif()
if(HAVE_SSE)
if(MSVC)
add_compile_definitions(__SSE4_1__)
else()
add_compile_options(-msse4.1)
endif()
endif()
# SSE2NEON Detection
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*|aarch64.*)")
set(HAVE_NEON TRUE)
set(HAVE_SSE TRUE)
message(NOTICE "Using ASIMD/NEON instructions with sse2neon translation")
endif()
if(HAVE_NEON)
add_compile_definitions(HAVE_NEON=1)
add_compile_definitions(SSE2NEON_SUPPRESS_WARNINGS=1)
include_directories(${PROJECT_SOURCE_DIR}/third_party/sse2neon)
if(MSVC)
add_compile_definitions(__ARM_NEON__)
elseif(NOT APPLE)
check_c_compiler_flag(-mfpu=neon COMPILER_SUPPORTS_MFPU_NEON)
if(COMPILER_SUPPORTS_MFPU_NEON)
add_compile_options(-mfpu=neon)
endif()
endif()
endif()
# Build settings
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
# Output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
# Include directories
include_directories(${PROJECT_SOURCE_DIR}/include)
# Add subdirectories for source files
add_subdirectory(src)
# Header file installation preparation
set(INSTALL_HEADERS "${PROJECT_BINARY_DIR}/include/correct.h")
add_custom_target(correct-h ALL
COMMAND ${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/include/correct.h
${PROJECT_BINARY_DIR}/include/correct.h
COMMENT "Copying correct.h"
VERBATIM)
# Object files configuration
if(HAVE_SSE)
set(correct_obj_files
$<TARGET_OBJECTS:correct-reed-solomon>
$<TARGET_OBJECTS:correct-convolutional>
$<TARGET_OBJECTS:correct-convolutional-sse>)
list(APPEND INSTALL_HEADERS "${PROJECT_BINARY_DIR}/include/correct-sse.h")
add_custom_target(correct-sse-h ALL
COMMAND ${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/include/correct-sse.h
${PROJECT_BINARY_DIR}/include/correct-sse.h
COMMENT "Copying correct-sse.h"
VERBATIM)
else()
set(correct_obj_files
$<TARGET_OBJECTS:correct-reed-solomon>
$<TARGET_OBJECTS:correct-convolutional>)
endif()
# Main library targets
add_library(correct SHARED ${correct_obj_files})
add_library(correct_static STATIC ${correct_obj_files})
set_target_properties(correct_static PROPERTIES
OUTPUT_NAME "correct"
POSITION_INDEPENDENT_CODE ON)
if(HAVE_SSE)
target_compile_definitions(correct PUBLIC HAVE_SSE=1)
target_compile_definitions(correct_static PUBLIC HAVE_SSE=1)
endif()
# Additional components
if(ENABLE_LIBCORRECT_TEST)
add_subdirectory(util)
add_subdirectory(tests)
add_subdirectory(tools)
# add_subdirectory(benchmarks)
endif()
# Installation rules
include(GNUInstallDirs)
install(TARGETS correct correct_static
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(FILES ${INSTALL_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# FEC shim library
add_library(fec_shim_static STATIC EXCLUDE_FROM_ALL
src/fec_shim.c
${correct_obj_files})
add_library(fec_shim_shared SHARED EXCLUDE_FROM_ALL
src/fec_shim.c
${correct_obj_files})
set_target_properties(fec_shim_static PROPERTIES
OUTPUT_NAME "fec"
POSITION_INDEPENDENT_CODE ON)
set_target_properties(fec_shim_shared PROPERTIES
OUTPUT_NAME "fec")
add_custom_target(fec-shim-h
COMMAND ${CMAKE_COMMAND} -E copy
${PROJECT_SOURCE_DIR}/include/fec_shim.h
${PROJECT_BINARY_DIR}/include/fec.h
COMMENT "Copying fec_shim.h"
VERBATIM)
add_custom_target(shim DEPENDS fec_shim_static fec_shim_shared fec-shim-h)
# Optional FEC shim installation
install(TARGETS fec_shim_static fec_shim_shared
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
OPTIONAL
)
install(FILES ${PROJECT_BINARY_DIR}/include/fec.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
OPTIONAL
)