-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
249 lines (216 loc) · 8.82 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
message("====================================================================")
message("FrankyCPP Main")
message("CMAKE " ${CMAKE_VERSION} " " ${CMAKE_COMMAND})
message("====================================================================")
cmake_minimum_required(VERSION 3.16)
# Project name and version
project(FrankyCPP VERSION 0.4)
message("FrankyCPP v" ${PROJECT_VERSION_MAJOR} "." ${PROJECT_VERSION_MINOR})
# updates template file and replaces placeholder variables
configure_file(src/version.h.in version.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# C++ settings
set(CMAKE_CXX_STANDARD 17)
# Unit testing enabled
enable_testing()
# Platform
message("Recognized platform is " ${CMAKE_SYSTEM_NAME} " " ${CMAKE_SYSTEM_VERSION})
# Compiler Settings
message("Compiler is " ${CMAKE_CXX_COMPILER_ID} " " ${CMAKE_CXX_COMPILER_VERSION} " " ${CMAKE_CXX_COMPILER})
# Apple OS X compiler
if (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
message("Compiler Settings: AppleClang")
set(CMAKE_CXX_FLAGS "-std=c++17 -Wall -Wextra -mpopcnt -mbmi2")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -fprofile-instr-generate -fcoverage-mapping -Wpedantic -Wshadow -Wno-conversion -Wunreachable-code -Wuninitialized -Wold-style-cast -Wunused-variable -Wfloat-equal -Wno-gnu-zero-variadic-macro-arguments")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
# std::execution lib for parallel std operations. Not available on all platforms
# message("Using HAS_EXECUTION_LIB")
# add_compile_definitions(HAS_EXECUTION_LIB)
# Availability of PEXT compiler intrinsic. Not available on all platforms
message("Using HAS_PEXT")
add_compile_definitions(HAS_PEXT)
# GNU compiler for WIndows WSL and Travis
elseif (CMAKE_COMPILER_IS_GNUCXX)
message("Compiler Settings: GNU")
set(CMAKE_CXX_FLAGS "-std=c++17 -m64 -msse -msse3 -msse4 -mpopcnt -mbmi2 -Wall -Wextra -Wpedantic -Wno-error=pedantic -Wno-unknown-pragmas -Wno-variadic-macros -Wno-sign-compare -Wno-subobject-linkage")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 --coverage -Wno-unused-parameter -Wno-unused-variable")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
# additional: -Wshadow -Wno-unknown-pragmas -Weffc++ -Wimplicit-fallthrough -Wswitch -Wpointer-arith -Wcast-qual -Wconversion -Wno-sign-conversion -Wno-error=padded -Wno-error=inline")
# link time optimization on Travis does not work (yet)
# # Test for -flto support
# include(CheckCXXCompilerFlag)
# include(CheckCCompilerFlag)
# CHECK_CXX_COMPILER_FLAG(-flto CXX_SUPPORTS_FLTO)
# CHECK_C_COMPILER_FLAG(-flto C_SUPPORTS_FLTO)
# if(CXX_SUPPORTS_FLTO AND C_SUPPORTS_FLTO)
# message(STATUS "Compiling with FLTO support")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
# set(CMAKE_AR "gcc-ar")
# set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <LINK_FLAGS> ")
# set(CMAKE_C_ARCHIVE_FINISH true)
# set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <LINK_FLAGS> ")
# set(CMAKE_CXX_ARCHIVE_FINISH true)
# endif()
# Test if we are on a Travis environment
if(DEFINED ENV{TRAVIS})
message("TRAVIS BUILD")
else()
message("NONE TRAVIS BUILD")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
endif()
# Availability of PEXT compiler intrinsic. Not available on all platforms
message("Using HAS_PEXT")
add_compile_definitions(HAS_PEXT)
# std::execution lib for parallel std operations. Only on gcc-10 and above
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "10")
message("GCC >= 10.x")
message("Using HAS_EXECUTION_LIB")
add_compile_definitions(HAS_EXECUTION_LIB)
else ()
message("GCC < 10.x")
endif ()
# Microsoft Visual Compiler
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# this needs to be added to CLION cmake options
# -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -G Ninja
message("Compiler Settings: MSVC")
set(CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /favor:INTEL64 /Gr /Qpar /W4 /GR /EHsc /std:c++17 /arch:AVX2 /MP")
set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MD /DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "/Od /Ob0 /MDd /Zi /RTC1")
# std::execution lib for parallel std operations. Not available on all platforms
message("Using HAS_EXECUTION_LIB")
add_compile_definitions(HAS_EXECUTION_LIB)
# Availability of PEXT compiler intrinsic. Not available on all platforms
message("Using HAS_PEXT")
add_compile_definitions(HAS_PEXT)
# Clang compiler - needs more testing
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message("Compiler Settings: Clang")
set(CMAKE_CXX_FLAGS "-std=c++17 -Wall -Wextra -mpopcnt -mbmi2")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -fprofile-instr-generate -fcoverage-mapping -Wpedantic -Wshadow -Wno-conversion -Wunreachable-code -Wuninitialized -Wold-style-cast -Wunused-variable -Wfloat-equal -Wno-gnu-zero-variadic-macro-arguments")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
# std::execution lib for parallel std operations. Not available on all platforms
message("Using HAS_EXECUTION_LIB")
add_compile_definitions(HAS_EXECUTION_LIB)
# Availability of PEXT compiler intrinsic. Not available on all platforms
message("Using HAS_PEXT")
add_compile_definitions(HAS_PEXT)
endif ()
# Print some info to be able to check which compiler has been picked
message("Generator: " ${CMAKE_GENERATOR} " " ${CMAKE_MAKE_PROGRAM})
message("Compiler flags: " ${CMAKE_CXX_FLAGS})
message("Compiler DEBUG flags: " ${CMAKE_CXX_FLAGS_DEBUG})
message("Compiler RELEASE flags: " ${CMAKE_CXX_FLAGS_RELEASE})
message("EXEC: " ${CMAKE_CXX_LINK_EXECUTABLE})
# For downloading with GIT
message("Finding GIT...")
set(GIT_EXECUTABLE)
find_package(Git)
if (GIT_FOUND)
message("GIT found: ${GIT_EXECUTABLE}")
elseif ()
message("GIT NOT found:")
endif ()
set(FETCHCONTENT_QUIET OFF)
set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
include(FetchContent)
# GOOGLE TEST
message("Downloading/Update Google Test")
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
)
FetchContent_Declare(googletest)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
option(INSTALL_GMOCK OFF)
option(INSTALL_GTEST OFF)
FetchContent_MakeAvailable(googletest)
include_directories(
${googletest_SOURCE_DIR}/googletest/include
)
# GOOGLE BENCHMARK
FetchContent_Declare(
googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.5.5) # need master for benchmark::benchmark
option(BENCHMARK_ENABLE_LTO ON)
option(BENCHMARK_ENABLE_GTEST_TESTS OFF)
option(BENCHMARK_ENABLE_TESTING OFF)
option(BENCHMARK_ENABLE_INSTALL OFF)
FetchContent_MakeAvailable(googlebenchmark)
include_directories(
${googlebenchmark_SOURCE_DIR}/include
)
# FMT
message("Downloading/Update FMT")
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 7.1.3
)
FetchContent_MakeAvailable(fmt)
include_directories(
${fmt_SOURCE_DIR}/include
)
# SPDLOG
message("Downloading/Update SPDLOG")
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.8.5
)
option(SPDLOG_FMT_EXTERNAL ON)
set(SPDLOG_FMT_EXTERNAL ON)
FetchContent_MakeAvailable(spdlog)
include_directories(
${spdlog_SOURCE_DIR}/include
)
# BOOST
if (APPLE)
message("Find Boost on Apple")
if (NOT BOOST_ROOT)
set(BOOST_ROOT "/usr/local/boost_1_73_0")
set(Boost_INCLUDE_DIR "/usr/local/boost_1_73_0")
endif()
elseif (CYGWIN)
message("Find Boost on Cygwin")
set(BOOST_ROOT "/usr/local/boost_1_72_0")
set(Boost_INCLUDE_DIR "/usr/local/boost_1_72_0")
elseif (WIN32)
message("Find Boost on Win32")
if (NOT BOOST_ROOT)
set(BOOST_ROOT "D:/Boost")
set(BOOST_INCLUDEDIR "D:/Boost/include/boost-1_76")
set(BOOST_LIBRARYDIR "D:/Boost/lib")
endif()
else ()
message("Find Boost on Unix")
set(BOOST_ROOT "/usr/local")
set(Boost_INCLUDE_DIR "/usr/local/include/boost")
endif ()
set(Boost_DEBUG FALSE)
set(Boost_USE_MULTITHREADED TRUE)
set(Boost_USE_STATIC_LIBS TRUE)
set(Boost_USE_STATIC_RUNTIME FALSE)
find_package(Boost 1.72.0 COMPONENTS serialization program_options REQUIRED)
# log log_setup
if (Boost_FOUND)
message("BOOST found: " ${BOOST_ROOT} " " ${Boost_INCLUDE_DIR})
include_directories(${Boost_INCLUDE_DIRS})
endif ()
set(BOOST_ALL_NO_LIB 0)
set(BOOST_LIB_DIAGNOSTIC 1)
# include sub directories
include_directories(
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/test
${PROJECT_SOURCE_DIR}/testbench
)
# project sub directories - need to have their own CMakeList.txt
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(testbench)