-
Notifications
You must be signed in to change notification settings - Fork 102
/
CMakeLists.txt
296 lines (247 loc) · 8.48 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
cmake_minimum_required(VERSION 3.8)
include(ProcessorCount)
project(Alive2)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
if (MSVC)
set(CMAKE_CXX_FLAGS "/GL /EHsc /W2 /Zc:__cplusplus ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "/Od /Zi ${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Oi /Oy /Zc:inline ${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Oi /Zi ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(CMAKE_EXE_LINKER_FLAGS "/LTCG:INCREMENTAL ${CMAKE_EXE_LINKER_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "-Wall -Werror -fPIC -fstrict-enums ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "-g -Og ${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 ${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -g ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
macro(remove_flags)
foreach(var ${ARGN})
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
remove_definitions(${var})
endforeach()
endmacro(remove_flags)
remove_flags(-DNDEBUG)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
if (CYGWIN)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll")
endif()
find_package(Git REQUIRED)
add_custom_command(
OUTPUT "${PROJECT_BINARY_DIR}/version_gen.h.tmp"
COMMAND "${CMAKE_COMMAND}" -E echo_append "#define ALIVE_VERSION_MACRO " > "${PROJECT_BINARY_DIR}/version_gen.h.tmp"
COMMAND "${GIT_EXECUTABLE}" describe --tags --dirty --always >> "${PROJECT_BINARY_DIR}/version_gen.h.tmp"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
VERBATIM
)
add_custom_command(
DEPENDS "${PROJECT_BINARY_DIR}/version_gen.h.tmp"
OUTPUT "${PROJECT_BINARY_DIR}/version_gen.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${PROJECT_BINARY_DIR}/version_gen.h.tmp" "${PROJECT_BINARY_DIR}/version_gen.h"
COMMAND "${CMAKE_COMMAND}" -E remove -f "${PROJECT_BINARY_DIR}/version_gen.h.tmp"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
VERBATIM
)
add_custom_target(
generate_version ALL
DEPENDS "${PROJECT_BINARY_DIR}/version_gen.h"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
find_package(ZLIB)
find_package(Z3 4.8.5 REQUIRED)
include_directories(${Z3_INCLUDE_DIR})
find_program(RE2C re2c)
if (RE2C)
message(STATUS "RE2C: ${RE2C}")
else()
message(SEND_ERROR "re2c executable not found")
endif()
add_custom_command(OUTPUT "${PROJECT_BINARY_DIR}/tools/alive_lexer.cpp"
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/tools"
COMMAND ${RE2C} ARGS "-d" "-b" "-T" "--no-generation-date"
"-o" "${PROJECT_BINARY_DIR}/tools/alive_lexer.cpp"
"${PROJECT_SOURCE_DIR}/tools/alive_lexer.re"
DEPENDS "tools/alive_lexer.re")
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_BINARY_DIR})
set(IR_SRCS
ir/attrs.cpp
ir/constant.cpp
ir/fast_math.cpp
ir/function.cpp
ir/functions.cpp
ir/globals.cpp
ir/instr.cpp
ir/memory.cpp
ir/pointer.cpp
ir/precondition.cpp
ir/state.cpp
ir/state_value.cpp
ir/type.cpp
ir/value.cpp
)
add_library(ir STATIC ${IR_SRCS})
set(SMT_SRCS
smt/ctx.cpp
smt/expr.cpp
smt/exprs.cpp
smt/smt.cpp
smt/solver.cpp
)
add_library(smt STATIC ${SMT_SRCS})
set(TOOLS_SRCS
tools/transform.cpp
)
add_library(tools STATIC ${TOOLS_SRCS})
set(UTIL_SRCS
"${PROJECT_BINARY_DIR}/version_gen.h"
util/compiler.cpp
util/config.cpp
util/crc.cpp
util/errors.cpp
util/file.cpp
util/random.cpp
util/sort.cpp
util/stopwatch.cpp
util/symexec.cpp
util/unionfind.cpp
util/version.cpp
)
if (BUILD_TV)
set(UTIL_SRCS
${UTIL_SRCS}
util/parallel.cpp
util/parallel_fifo.cpp
util/parallel_null.cpp
util/parallel_unrestricted.cpp
)
endif()
add_library(util STATIC ${UTIL_SRCS})
add_dependencies(util generate_version)
set(ALIVE_LIBS ir smt tools util)
find_package(hiredis)
if (HIREDIS_LIBRARIES)
include_directories(${HIREDIS_INCLUDE_DIR})
set(CACHE_SRCS
cache/cache.cpp
)
add_library(cache STATIC ${CACHE_SRCS})
set(ALIVE_LIBS cache ${ALIVE_LIBS})
else()
set(HIREDIS_LIBRARIES $<0:''>)
add_compile_definitions(NO_REDIS_SUPPORT)
endif()
if (BUILD_LLVM_UTILS OR BUILD_TV)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
if (NOT LLVM_ENABLE_RTTI)
message(FATAL_ERROR "LLVM must be built with '-DLLVM_ENABLE_RTTI=ON'")
endif()
if (NOT LLVM_ENABLE_EH)
message(FATAL_ERROR "LLVM must be built with '-DLLVM_ENABLE_EH=ON'")
endif()
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(AddLLVM)
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
set(LLVM_UTIL_SRCS
"llvm_util/compare.cpp"
"llvm_util/known_fns.cpp"
"llvm_util/llvm_optimizer.cpp"
"llvm_util/llvm2alive.cpp"
"llvm_util/utils.cpp"
)
add_library(llvm_util STATIC ${LLVM_UTIL_SRCS})
set(ALIVE_LIBS_LLVM llvm_util ${ALIVE_LIBS})
set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TargetParser)
add_llvm_executable(alive-tv
"tools/alive-tv.cpp"
)
add_llvm_executable(quick-fuzz
"tools/quick-fuzz.cpp"
)
add_llvm_executable(alive-exec
"tools/alive-exec.cpp"
)
else()
set(LLVM_UTIL_SRCS "")
endif()
if (BUILD_TV)
if (CYGWIN)
message(FATAL_ERROR "LLVM plugins not supported on cygwin")
endif()
message(STATUS "Compiling translation validation plugin")
add_subdirectory(tv)
set(FOR_ALIVE2_TEST 0)
configure_file(
${CMAKE_SOURCE_DIR}/scripts/opt-alive.sh.in
${CMAKE_BINARY_DIR}/opt-alive.sh
@ONLY
)
set(FOR_ALIVE2_TEST 1)
configure_file(
${CMAKE_SOURCE_DIR}/scripts/opt-alive.sh.in
${CMAKE_BINARY_DIR}/opt-alive-test.sh
@ONLY
)
unset(FOR_ALIVE2_TEST)
else()
message(STATUS "Skipping translation validation plugin")
endif()
add_executable(alive
"tools/alive.cpp"
"${PROJECT_BINARY_DIR}/tools/alive_lexer.cpp"
"tools/alive_parser.cpp"
)
target_link_libraries(alive PRIVATE ${ALIVE_LIBS})
add_executable(alive-jobserver
"tools/alive-jobserver.cpp"
)
install(TARGETS alive alive-jobserver)
#add_library(alive2 SHARED ${IR_SRCS} ${SMT_SRCS} ${TOOLS_SRCS} ${UTIL_SRCS} ${LLVM_UTIL_SRCS})
if (BUILD_LLVM_UTILS OR BUILD_TV)
llvm_map_components_to_libnames(llvm_libs support core irreader bitwriter analysis passes transformutils)
# target_link_libraries(alive2 PRIVATE ${llvm_libs})
target_link_libraries(alive-tv PRIVATE ${ALIVE_LIBS_LLVM} ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES} ${llvm_libs})
target_link_libraries(quick-fuzz PRIVATE ${ALIVE_LIBS_LLVM} ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES} ${llvm_libs})
target_link_libraries(alive-exec PRIVATE ${ALIVE_LIBS_LLVM} ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES} ${llvm_libs})
install(TARGETS alive-tv quick-fuzz alive-exec)
endif()
target_link_libraries(alive PRIVATE ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES})
#target_link_libraries(alive2 PRIVATE ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES})
if (NOT DEFINED TEST_NTHREADS)
ProcessorCount(TEST_NTHREADS)
if (TEST_NTHREADS EQUAL 0)
set(TEST_NTHREADS 1)
endif()
endif()
add_custom_target("check"
COMMAND "python3"
"${PROJECT_SOURCE_DIR}/tests/lit/lit.py"
"-s"
"${PROJECT_SOURCE_DIR}/tests"
"-j${TEST_NTHREADS}"
DEPENDS "alive"
USES_TERMINAL
)
if (BUILD_TV)
add_dependencies("check" "alive-tv" "quick-fuzz" "tv")
endif()
# EXTERNAL_PROJECTS option that works analogous to LLVM's LLVM_EXTERNAL_PROJECTS option
foreach(EXTERNAL_PROJECT IN LISTS EXTERNAL_PROJECTS)
canonicalize_tool_name(${EXTERNAL_PROJECT} PROJECT_CANON)
message(STATUS "Adding external project ${EXTERNAL_PROJECT} at ${EXTERNAL_${PROJECT_CANON}_SOURCE_DIR}")
add_subdirectory(${EXTERNAL_${PROJECT_CANON}_SOURCE_DIR} ${EXTERNAL_PROJECT})
endforeach()