-
Notifications
You must be signed in to change notification settings - Fork 25
/
CMakeLists.txt
258 lines (212 loc) · 7.11 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
247
248
249
250
251
252
253
254
255
256
257
258
cmake_minimum_required(VERSION 3.11)
project(e VERSION 3.3.6)
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
if(WIN32)
message(
FATAL_ERROR
"WIN32 target is obsolete. Please use Windows Subsystems for Linux")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
option(SANITIZER "enable clang sanitzer (default: OFF)")
option(SOLUTION_PATH "custom solution path (default: OFF)")
if("${SANITIZER}" STREQUAL "address")
message(STATUS "Sanitizer Selected: address")
set(SANITIZER_FLAGS "-g -fsanitize=address -fno-omit-frame-pointer")
elseif("${SANITIZER}" STREQUAL "thread")
message(STATUS "Sanitizer Selected: thread")
set(SANITIZER_FLAGS "-g -fsanitize=thread")
elseif("${SANITIZER}" STREQUAL "memory")
message(STATUS "Sanitizer Selected: memory")
set(SANITIZER_FLAGS "-g -fsanitize=memory -fno-omit-frame-pointer")
elseif("${SANITIZER}" STREQUAL "undefined")
message(STATUS "Sanitizer Selected: undefined")
set(SANITIZER_FLAGS "-g -fsanitize=undefined")
endif()
if(SANITIZER_FLAGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${SANITIZER_FLAGS}")
endif()
# Compiler Test
include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"
class a{
int f(int leverl, const char *format, ...)
__attribute__((format(printf, 3, 4)));
};
int main(void) {return 0;}
"
HAVE_ATTR_FORMAT)
if(HAVE_ATTR_FORMAT)
add_compile_definitions(HAVE_ATTR_FORMAT)
endif()
check_cxx_source_compiles(
"
struct a{
char b;
long c;
} __attribute__((packed));
int main(void) {
struct a a1;
return 0;
}
"
HAVE_ATTR_PACK)
check_cxx_source_compiles(
"
#pragma pack(push, 1)
struct a{
char b;
long c;
};
#pragma pack(pop)
int main(void) {
struct a a1;
return 0;
}
"
HAVE_PRAGMA_PACK)
check_cxx_source_compiles(
"
#include <cassert>
#include <cstring>
#include <cxxabi.h>
#include <typeinfo>
struct aAa {};
int main(void) {
struct aAa a1;
int status = -4;
char *ret = abi::__cxa_demangle(typeid(a1).name(), NULL, NULL, &status);
assert(std::strcmp(ret, \"aAa\") == 0);
return 0;
}
"
HAVE_DEMANGLE)
if(HAVE_ATTR_PACK)
add_compile_definitions(HAVE_ATTR_PACK)
elseif(HAVE_PRAGMA_PACK)
add_compile_definitions(HAVE_PRAGMA_PACK)
else()
message(FATAL_ERROR "Compiler must support packing")
endif()
if(HAVE_DEMANGLE)
add_compile_definitions(HAVE_DEMANGLE)
endif()
# Build E
file(GLOB_RECURSE e_SOURCES "src/*.cpp")
file(GLOB_RECURSE e_HEADERS "include/*.hpp")
add_library(e SHARED ${e_SOURCES} ${e_HEADERS})
target_include_directories(e PUBLIC ${PROJECT_SOURCE_DIR}/include)
find_package(Threads REQUIRED)
target_link_libraries(e PUBLIC Threads::Threads)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_target_properties(e PROPERTIES OSX_ARCHITECTURES "arm64;x86_64")
endif()
target_compile_options(e PRIVATE -g -O0 -Wall)
# Get Library: GTest
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/dddb219c3eb96d7f9200f09b0a381f016e6b4562.zip
URL_HASH
SHA256=4599154210502714ad841821b9d086431816e5c8bfae90872e43305cc0f12eb2)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()
# Find Solution
function(get_solution_name TARGET)
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_SYSTEM_NAME STREQUAL
"Darwin")
set(${TARGET}_SOLUTION_NAME
"${TARGET}-universal-${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}.zip"
PARENT_SCOPE)
elseif((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_ID
STREQUAL "Clang")
AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(${TARGET}_SOLUTION_NAME
"${TARGET}-${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}-Clang.zip"
PARENT_SCOPE)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL
"Clang")
string(REPLACE "." ";" CMAKE_CXX_COMPILER_VERSION_LIST
"${CMAKE_CXX_COMPILER_VERSION}")
list(GET CMAKE_CXX_COMPILER_VERSION_LIST 0 CMAKE_CXX_COMPILER_VERSION_MAJOR)
set(${TARGET}_SOLUTION_NAME
"${TARGET}-${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION_MAJOR}.zip"
PARENT_SCOPE)
else()
set(${TARGET}_SOLUTION_NAME
"${TARGET}-${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}.zip"
PARENT_SCOPE)
endif()
endfunction()
# Build Solutions (If exists)
file(GLOB_RECURSE e_solution_CMAKELISTS
"${PROJECT_SOURCE_DIR}/solution/*/CMakeLists.txt")
foreach(cmakelists ${e_solution_CMAKELISTS})
get_filename_component(e_solution_DIR ${cmakelists} DIRECTORY)
add_subdirectory(${e_solution_DIR})
endforeach()
# Solution Downloader
include(FetchContent)
function(get_solution)
set(SOLUTION_REPO
"https://anlab-kaist.github.io/KENSv3/solution/${CMAKE_PROJECT_VERSION}")
foreach(arg IN LISTS ARGN)
# Find Solution
if(NOT TARGET ${arg}_solution)
find_library(${arg}_solution_path ${arg}_solution PATH ${SOLUTION_PATH}
EXACT)
if(NOT ${arg}_solution_path)
# Download Solution
message(STATUS "Donwloading ${arg}_solution")
get_solution_name(${arg}_solution)
include(FetchContent)
FetchContent_Declare(
${arg}_solution
URL "${SOLUTION_REPO}/${${arg}_solution_SOLUTION_NAME}")
FetchContent_GetProperties(${arg}_solution)
if(NOT (${arg}_solution_POPULATED))
FetchContent_Populate(${arg}_solution)
endif()
find_library(${arg}_solution_path ${arg}_solution PATH
${${arg}_solution_SOURCE_DIR} EXACT)
endif()
add_library(${arg}_solution SHARED IMPORTED GLOBAL)
set_property(TARGET ${arg}_solution PROPERTY IMPORTED_LOCATION
${${arg}_solution_path})
target_link_libraries(${arg}_solution INTERFACE e)
endif()
endforeach()
endfunction()
# Build Apps
include(cmake/app-ref.cmake OPTIONAL)
if(e_apps_CMAKELISTS)
else()
file(GLOB e_apps_CMAKELISTS "${PROJECT_SOURCE_DIR}/app/*/CMakeLists.txt")
endif()
list(FILTER e_apps_CMAKELISTS EXCLUDE REGEX ".*/scheduling/.*")
foreach(cmakelists ${e_apps_CMAKELISTS})
get_filename_component(e_apps_DIR ${cmakelists} DIRECTORY)
add_subdirectory(${e_apps_DIR})
endforeach()
find_package(Doxygen)
if(DOXYGEN_FOUND)
add_custom_target(
doxygen
COMMAND
${CMAKE_COMMAND} -E env
"DOXYGEN_OUTPUT_DIRECTORY=${PROJECT_BINARY_DIR}/doc" doxygen
${PROJECT_SOURCE_DIR}/doxygen/Doxyfile
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
endif()
include(cmake/kens-dist.cmake OPTIONAL)