This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
forked from zcnet4/warpcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
194 lines (168 loc) · 5.9 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
cmake_minimum_required(VERSION 3.9)
project(warpcore VERSION 0.20.0 LANGUAGES C CXX)
# Check for dependencies before mucking with the compiler flags
include(CheckFunctionExists)
check_function_exists(recvmmsg HAVE_RECVMMSG)
check_function_exists(sendmmsg HAVE_SENDMMSG)
check_function_exists(kqueue HAVE_KQUEUE)
check_function_exists(epoll_create HAVE_EPOLL)
check_function_exists(arc4random HAVE_ARC4RANDOM)
check_function_exists(ether_ntoa_r HAVE_ETHER_NTOA_R)
# Look for netmap
include(CheckIncludeFile)
set(CMAKE_REQUIRED_INCLUDES
/usr/include /usr/local/include ${CMAKE_SOURCE_DIR}/lib/include
)
check_include_file(net/netmap_user.h HAVE_NETMAP_H)
include(CMakePushCheckState)
cmake_reset_check_state()
# Check if _GNU_SOURCE is available.
include(CheckSymbolExists)
check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
if (NOT _GNU_SOURCE)
unset(_GNU_SOURCE CACHE)
check_symbol_exists(_GNU_SOURCE "features.h" _GNU_SOURCE)
endif()
if(_GNU_SOURCE)
add_definitions(-D_GNU_SOURCE)
endif()
# Build "Debug" type by default
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug
CACHE STRING "Set build type (default Debug)" FORCE)
endif()
# Generate compile_commands.json for clang-tidy
set(CMAKE_EXPORT_COMPILE_COMMANDS True)
# Use modern C and C++
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 11)
# Set general compile flags, if they are supported
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
foreach(FLAG -march=native -Wextra -Wpedantic -Weverything -Werror
-fcolor-diagnostics -fdiagnostics-color=always
# for older gcc:
-Wno-missing-field-initializers -Wno-disabled-macro-expansion
)
string(REGEX REPLACE "[-=+]" "_" F ${FLAG})
check_c_compiler_flag(${FLAG} ${F})
if(${F})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
endif()
check_cxx_compiler_flag(${FLAG} ${F})
if(${F})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
endif()
endforeach()
# Set CXX flags
foreach(FLAG -Wno-c++98-compat -Wno-global-constructors)
string(REGEX REPLACE "[-=+]" "_" F ${FLAG})
check_cxx_compiler_flag(${FLAG} ${F})
if(${F})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
endif()
endforeach()
# flags for "Debug" and "None" builds
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
# disable IPO by default
set(IPO NO)
if(CMAKE_BUILD_TYPE MATCHES Debug)
# Default debug logging level
if(NOT DEFINED DLEVEL)
set(DLEVEL "DBG")
endif()
# Enable debug support in the queue.h macros
add_definitions(-DQUEUE_MACRO_DEBUG_TRASH)
# See if we can use the address sanitizer
check_include_file(sanitizer/asan_interface.h HAVE_ASAN)
if(HAVE_ASAN)
set(CMAKE_REQUIRED_FLAGS -fsanitize=address)
check_c_compiler_flag("" _fsanitize_address)
if(_fsanitize_address)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif()
unset(CMAKE_REQUIRED_FLAGS)
endif()
# Set some additional flags for Debug builds
set(FLAGS -fno-omit-frame-pointer -fsanitize-address-use-after-scope
-fsanitize=undefined -fsanitize=unsigned-integer-overflow
-fno-sanitize=alignment -fno-common
)
foreach(FLAG ${FLAGS})
string(REGEX REPLACE "[-=+]" "_" F ${FLAG})
check_c_compiler_flag(${FLAG} ${F})
if(${F})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
endif()
check_cxx_compiler_flag(${FLAG} ${F})
if(${F})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
endif()
endforeach()
if (APPLE)
find_program (DSYMUTIL dsymutil)
endif()
find_program(CPPCHECK NAMES cppcheck)
if(CPPCHECK)
message(STATUS "Found cppcheck: ${CPPCHECK}")
set(CMAKE_C_CPPCHECK ${CPPCHECK} -q --inline-suppr
--enable=warning,style,performance,portability
-I external/include -I lib/include -I ${PROJECT_SOURCE_DIR}/lib/include
)
set(CMAKE_CXX_CPPCHECK ${CMAKE_C_CPPCHECK})
endif()
# Use include-what-you-use to check #includes, if it's installed
find_program(IWYU NAMES include-what-you-use iwyu)
if(IWYU)
message(STATUS "Found include-what-you-use: ${IWYU}")
string(TOLOWER ${CMAKE_SYSTEM_NAME} CMAKE_SYSTEM_NAME_LC)
set(CMAKE_C_INCLUDE_WHAT_YOU_USE
${IWYU} -Xiwyu
--mapping_file=${PROJECT_SOURCE_DIR}/misc/${CMAKE_SYSTEM_NAME_LC}.imp)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMAKE_C_INCLUDE_WHAT_YOU_USE})
endif()
if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Use clang-tidy for extra warnings, if it's installed
find_program(CLANGTIDY NAMES clang-tidy clang-tidy40 clang-tidy39
clang-tidy38 clang-tidy37)
if(CLANGTIDY)
message(STATUS "Found clang-tidy: ${CLANGTIDY}")
set(CLANG_TIDY_CHECKS *
-google-readability-braces-around-statements
-readability-braces-around-statements
-google-readability-todo
-cppcoreguidelines-pro-type-vararg
-clang-diagnostic-unused-command-line-argument
)
string(REPLACE ";" "," CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS}")
set(CMAKE_C_CLANG_TIDY ${CLANGTIDY}
-analyze-temporary-dtors -system-headers
-checks=${CLANG_TIDY_CHECKS}
)
set(CMAKE_CXX_CLANG_TIDY ${CMAKE_C_CLANG_TIDY})
endif()
endif()
else()
# Default logging level
if(NOT DEFINED DLEVEL)
set(DLEVEL "NTE")
endif()
# check for INTERPROCEDURAL_OPTIMIZATION support
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO)
endif()
# flags for "Release" builds
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -Ofast")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
# flags for "RelWithDebInfo" builds
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
add_definitions(-DDLEVEL=${DLEVEL})
add_subdirectory(doc)
add_subdirectory(bin)
add_subdirectory(lib)
add_subdirectory(test)
enable_testing()