-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
188 lines (180 loc) · 8.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
cmake_minimum_required(VERSION 3.28)
project(DT C CXX ASM)
set(CMAKE_PROJECT_VERSION_MAJOR 0)
set(CMAKE_PROJECT_VERSION_MINOR 8)
set(CMAKE_PROJECT_VERSION_PATCH 0)
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed")
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release
CACHE STRING "Choose the type of build: Release Debug Coverage Profile Valgrind."
FORCE)
endif()
set(COVERAGE_ARGS "" CACHE STRING "select specific unit tests to run for test coverage evaluations")
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_EXTENSIONS NO)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wall)
add_compile_options(-Wextra)
add_compile_options(-Wthread-safety)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wall)
add_compile_options(-Wextra)
add_compile_options(-Wpedantic)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-changes-meaning>)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
if (MSVC)
add_compile_options(/bigobj)
add_compile_options(/utf-8)
add_link_options(/Stack:16777216)
enable_language(ASM_MASM)
endif()
if (MINGW)
add_compile_options(-Wa)
add_compile_options(-mbig-obj)
list(APPEND CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES /mingw64/include)
endif()
if(UNIX)
add_compile_options(-g)
add_link_options(-g)
if(NOT APPLE)
link_libraries("atomic")
endif()
endif()
add_subdirectory(3rdparty)
add_subdirectory(lib)
target_link_libraries(lib PUBLIC 3rdparty 3rdparty-cpp)
add_executable(dt src/dt.cpp)
target_link_libraries(dt PRIVATE lib 3rdparty 3rdparty-cpp)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
include(InstallRequiredSystemLibraries)
install(PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION bin)
install(TARGETS dt RUNTIME DESTINATION bin)
install(DIRECTORY etc/ DESTINATION etc)
if (WIN32)
if (MINGW)
add_custom_command(TARGET dt POST_BUILD COMMAND ldd ${CMAKE_BINARY_DIR}/dt.exe | awk '{ print $$3 }' | grep -vi system > ${CMAKE_BINARY_DIR}/dlls.txt)
add_custom_command(TARGET dt POST_BUILD COMMAND cygpath -w -f ${CMAKE_BINARY_DIR}/dlls.txt > ${CMAKE_BINARY_DIR}/dlls-win-path.txt)
install(CODE [[
file(READ $<TARGET_FILE_DIR:dt>/dlls-win-path.txt DLLS)
string(REPLACE "\n" ";" DLLS_LIST ${DLLS})
file(COPY ${DLLS_LIST} DESTINATION $<INSTALL_PREFIX>/bin)
]])
else()
file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR} BIN_DIR_WIN)
add_custom_command(TARGET dt POST_BUILD COMMAND dir /b ${BIN_DIR_WIN}\\*.dll > ${BIN_DIR_WIN}\\dlls.txt COMMAND_EXPAND_LISTS)
install(CODE [[
file(READ $<TARGET_FILE_DIR:dt>/dlls.txt DLLS)
string(REPLACE "\n" ";" DLLS_LIST ${DLLS})
foreach(lib ${DLLS_LIST})
LIST(APPEND DLLS_WITH_PATH "$<TARGET_FILE_DIR:dt>/${lib}")
endforeach()
file(COPY ${DLLS_WITH_PATH} DESTINATION $<INSTALL_PREFIX>/bin)
]])
endif()
endif()
file(GLOB ITEST_SRCS test/*.cpp)
foreach(ITEST_SRC IN LISTS ITEST_SRCS)
cmake_path(GET ITEST_SRC STEM ITEST)
add_executable(${ITEST} ${ITEST_SRC})
target_link_libraries(${ITEST} PRIVATE lib 3rdparty 3rdparty-cpp)
endforeach()
file(GLOB_RECURSE TEST_SRCS lib/dt/*.test.cpp)
add_executable(run-test src/run-test.cpp ${TEST_SRCS})
target_link_libraries(run-test PRIVATE lib 3rdparty 3rdparty-cpp)
file(GLOB_RECURSE BENCH_SRCS lib/dt/*.bench.cpp)
add_executable(run-bench src/run-test.cpp ${BENCH_SRCS})
target_link_libraries(run-bench PRIVATE lib 3rdparty 3rdparty-cpp)
if(UNIX)
add_executable(dt-prof src/dt.cpp)
target_link_libraries(dt-prof PRIVATE lib 3rdparty 3rdparty-cpp)
target_link_options(dt-prof PRIVATE -g -lprofiler)
endif()
message("copying configs")
file(COPY etc DESTINATION .)
if (EXISTS ${CMAKE_SOURCE_DIR}/publisher)
file(COPY publisher DESTINATION .)
endif()
message("copying test data")
file(COPY data DESTINATION .)
if(CMAKE_BUILD_TYPE STREQUAL Sanitize)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(SANITIZER "address")
add_compile_options(-g)
add_compile_options(-O3)
add_compile_options("-fsanitize=${SANITIZER}")
add_link_options("-fsanitize=${SANITIZER}")
else()
message(FATAL_ERROR "Sinitize builds are only supported with Clang")
endif()
file(GLOB_RECURSE FUZZ_SRCS lib/dt/*.fuzz.cpp)
foreach(FUZZ_SRC IN LISTS FUZZ_SRCS)
cmake_path(GET FUZZ_SRC STEM FUZZ_NAME)
add_executable(fuzz-${FUZZ_NAME} ${FUZZ_SRC})
target_link_libraries(fuzz-${FUZZ_NAME} PRIVATE lib 3rdparty 3rdparty-cpp)
endforeach()
elseif(CMAKE_BUILD_TYPE STREQUAL Coverage)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(lib PRIVATE -fprofile-instr-generate -fcoverage-mapping -g -O3)
target_compile_options(run-test PRIVATE -fprofile-instr-generate -fcoverage-mapping -g -O3)
target_link_options(run-test PRIVATE -fprofile-instr-generate -fcoverage-mapping -g)
add_custom_target(coverage
COMMENT "Running test coverage ..."
COMMAND $<TARGET_FILE:run-test> ${COVERAGE_ARGS}
COMMAND echo "Indexing raw profdata"
COMMAND llvm-profdata merge -sparse default.profraw -o run-test.profdata
COMMAND echo "Generating coverage report"
COMMAND llvm-cov report $<TARGET_FILE:run-test> -instr-profile=run-test.profdata
DEPENDS run-test
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
else()
target_compile_options(lib PRIVATE -g --coverage)
target_compile_options(run-test PRIVATE -g --coverage)
target_link_options(run-test PRIVATE -g --coverage -lgcov)
add_custom_command(TARGET run-test PRE_BUILD COMMAND
find ${CMAKE_BINARY_DIR} -type f -name '*.gcda' -exec rm {} +)
find_program(GCOVR_PATH gcovr)
if (GCOVR_PATH)
message("adding target coverage using ${GCOVR_PATH}")
add_custom_target(coverage
COMMENT "Running test coverage ..."
COMMAND $<TARGET_FILE:run-test> ${COVERAGE_ARGS}
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/coverage
COMMAND ${GCOVR_PATH} -j 8 -r ${CMAKE_SOURCE_DIR} --gcov-ignore-parse-errors=negative_hits.warn --merge-mode-functions=separate --html-details ${CMAKE_BINARY_DIR}/coverage/coverage.html .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
endif()
endif()
if (EXISTS ${CMAKE_SOURCE_DIR}/ui)
add_subdirectory(ui)
set(CPACK_THREADS 0)
set(CPACK_PACKAGE_NAME "DT Explorer")
set(CPACK_PACKAGE_VENDOR "R2 Rationality")
set(CPACK_PACKAGE_FILE_NAME "dt-explorer-${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
if (WIN32)
set(APP_NAME "DT Explorer")
set(CPACK_GENERATOR "NSIS")
set(CPACK_NSIS_COMPRESSOR "/SOLID zlib")
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
set(CPACK_NSIS_MUI_HEADERIMAGE "${CMAKE_SOURCE_DIR}\\\\ui\\\\etc\\\\nsis-header.bmp")
set(CPACK_NSIS_MUI_UNHEADERIMAGE "${CMAKE_SOURCE_DIR}\\\\ui\\\\etc\\\\nsis-header.bmp")
set(CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP "${CMAKE_SOURCE_DIR}\\\\ui\\\\etc\\\\nsis-welcome.bmp")
set(CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP "${CMAKE_SOURCE_DIR}\\\\ui\\\\etc\\\\nsis-welcome.bmp")
set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}\\\\ui\\\\etc\\\\logo.ico")
set(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}\\\\ui\\\\etc\\\\logo.ico")
set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\dt-explorer.exe")
set(CPACK_NSIS_MUI_FINISHPAGE_RUN "dt-explorer")
set(CPACK_NSIS_URL_INFO_ABOUT "https://github.com/sierkov/daedalus-turbo")
set(CPACK_NSIS_BRANDING_TEXT " ")
set(CPACK_PACKAGE_EXECUTABLES "dt-explorer" ${APP_NAME})
set(CPACK_CREATE_DESKTOP_LINKS "dt-explorer")
endif()
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
include(CPack)
endif()