forked from google/souper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
402 lines (327 loc) · 12.2 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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
cmake_minimum_required(VERSION 2.8)
project(Souper)
set(CMAKE_MACOSX_RPATH NEW)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
set(LLVM_CONFIG_EXECUTABLE ${CMAKE_SOURCE_DIR}/third_party/llvm/${CMAKE_BUILD_TYPE}/bin/llvm-config)
if(NOT EXISTS ${LLVM_CONFIG_EXECUTABLE})
message(FATAL_ERROR "llvm-config could not be found!")
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --includedir
OUTPUT_VARIABLE LLVM_INCLUDEDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --cppflags
OUTPUT_VARIABLE LLVM_CXXFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -fno-exceptions -fno-rtti")
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs
OUTPUT_VARIABLE LLVM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --system-libs
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(LLVM_LIBS "${LLVM_LIBS} ${LLVM_SYSTEM_LIBS}")
string(STRIP ${LLVM_LIBS} LLVM_LIBS)
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --ldflags
OUTPUT_VARIABLE LLVM_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(PASS_LDFLAGS "${LLVM_LDFLAGS}")
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --bindir
OUTPUT_VARIABLE LLVM_BINDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --src-root
OUTPUT_VARIABLE LLVM_SRC
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --obj-root
OUTPUT_VARIABLE LLVM_BUILD
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(CLANG_CXXFLAGS "")
set(CLANG_INCLUDEDIR "${LLVM_SRC}/tools/clang/include" "${LLVM_BUILD}/tools/clang/include")
set(ALIVE_DIR "${CMAKE_SOURCE_DIR}/third_party/alive2")
set(ALIVE_LDFLAGS "-L ${ALIVE_DIR}/build -lalive2")
set(CLANG_LIBS "-lclangCodeGen -lclangTooling -lclangRewrite -lclangFrontend -lclangAnalysis -lclangParse -lclangSerialization -lclangSema -lclangEdit -lclangAnalysis -lclangAST -lclangDriver -lclangLex -lclangBasic")
set(GTEST_CXXFLAGS "-DGTEST_HAS_RTTI=0")
set(GTEST_INCLUDEDIR "${LLVM_SRC}/utils/unittest/googletest/include")
set(GTEST_LIBS "-lgtest_main -lgtest")
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -std=c++17")
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++17")
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -fvisibility-inlines-hidden")
set(PASS_LDFLAGS "-Wl,-undefined,dynamic_lookup")
endif()
include_directories(include third_party/klee/include)
include_directories(include "${ALIVE_DIR}")
include_directories(include "${ALIVE_DIR}/alive2")
set(KLEE_EXPR_FILES
third_party/klee/lib/Expr/Constraints.cpp
third_party/klee/lib/Expr/ExprBuilder.cpp
third_party/klee/lib/Expr/Expr.cpp
third_party/klee/lib/Expr/ExprEvaluator.cpp
third_party/klee/lib/Expr/ExprPPrinter.cpp
third_party/klee/lib/Expr/ExprSMTLIBPrinter.cpp
third_party/klee/lib/Expr/ExprUtil.cpp
third_party/klee/lib/Expr/ExprVisitor.cpp
third_party/klee/lib/Expr/Lexer.cpp
third_party/klee/lib/Expr/Parser.cpp
third_party/klee/lib/Expr/Updates.cpp
)
add_library(kleeExpr STATIC
${KLEE_EXPR_FILES}
)
find_path(HIREDIS_INCLUDE_DIR
NAMES
hiredis/hiredis.h
PATHS
third_party/hiredis/install/include
NO_DEFAULT_PATH)
include_directories(${HIREDIS_INCLUDE_DIR}/hiredis)
find_library(HIREDIS_LIBRARY
NAMES
hiredis
PATHS
third_party/hiredis/install/lib
NO_DEFAULT_PATH)
find_library(ALIVE_LIBRARY alive2 PATHS "${ALIVE_DIR}/build" NO_DEFAULT_PATH)
find_path(Z3_INCLUDE_DIRECTORY
NAMES
z3.h
z3++.h
PATHS
third_party/z3-install/include
NO_DEFAULT_PATH)
include_directories(${Z3_INCLUDE_DIRECTORY})
find_library(Z3_LIBRARY
NAMES
libz3.a
PATHS
third_party/z3-install/lib
NO_DEFAULT_PATH)
find_program(Z3
NAMES
z3
PATHS
third_party/z3-install/bin
NO_DEFAULT_PATH)
set(TEST_SOLVER "-z3-path=${Z3}")
set(SOUPER_CLANG_TOOL_FILES
lib/ClangTool/Actions.cpp
include/souper/ClangTool/Actions.h
)
add_library(souperClangTool STATIC
${SOUPER_CLANG_TOOL_FILES}
)
set(SOUPER_EXTRACTOR_FILES
lib/Extractor/Candidates.cpp
lib/Extractor/ExprBuilder.cpp
lib/Extractor/KLEEBuilder.cpp
lib/Extractor/Solver.cpp
include/souper/Extractor/Candidates.h
include/souper/Extractor/ExprBuilder.h
include/souper/Extractor/Solver.h
)
add_library(souperExtractor STATIC
${SOUPER_EXTRACTOR_FILES}
)
set(SOUPER_KVSTORE_FILES
lib/KVStore/KVStore.cpp
include/souper/KVStore/KVStore.h
)
add_library(souperKVStore STATIC
${SOUPER_KVSTORE_FILES}
)
set(SOUPER_INFER_FILES
lib/Infer/InstSynthesis.cpp
include/souper/Infer/InstSynthesis.h
lib/Infer/ExhaustiveSynthesis.cpp
include/souper/Infer/ExhaustiveSynthesis.h
lib/Infer/AliveDriver.cpp
include/souper/Infer/AliveDriver.h
lib/Infer/DataflowPruning.cpp
include/souper/Infer/DataflowPruning.h
lib/Infer/Interpreter.cpp
include/souper/Infer/Interpreter.h
)
add_library(souperInfer STATIC
${SOUPER_INFER_FILES}
)
set(SOUPER_INST_FILES
lib/Inst/Inst.cpp
include/souper/Inst/Inst.h
)
add_library(souperInst STATIC
${SOUPER_INST_FILES}
)
set(SOUPER_PARSER_FILES
lib/Parser/Parser.cpp
include/souper/Parser/Parser.h
)
add_library(souperParser STATIC
${SOUPER_PARSER_FILES}
)
set(SOUPER_SMTLIB2_FILES
lib/SMTLIB2/Solver.cpp
include/souper/SMTLIB2/Solver.h
)
add_library(souperSMTLIB2 STATIC
${SOUPER_SMTLIB2_FILES}
)
set(SOUPER_TOOL_FILES
lib/Tool/CandidateMapUtils.cpp
include/souper/Tool/CandidateMapUtils.h
include/souper/Tool/GetSolverFromArgs.h
)
add_library(souperTool STATIC
${SOUPER_TOOL_FILES}
)
set(SOUPER_SOURCES
${SOUPER_EXTRACTOR_FILES}
${SOUPER_INST_FILES}
${SOUPER_KVSTORE_FILES}
${SOUPER_PARSER_FILES}
${SOUPER_SMTLIB2_FILES}
${SOUPER_TOOL_FILES}
${SOUPER_INFER_FILES})
add_library(souperPass SHARED
${KLEE_EXPR_FILES}
${SOUPER_SOURCES}
lib/Pass/Pass.cpp
)
add_library(souperPassProfileAll SHARED
${KLEE_EXPR_FILES}
${SOUPER_SOURCES}
lib/Pass/Pass.cpp
)
target_compile_definitions(souperPassProfileAll PRIVATE DYNAMIC_PROFILE_ALL=1)
add_executable(clang-souper
tools/clang-souper.cpp
)
add_executable(souper
tools/souper.cpp
)
add_executable(internal-solver-test
tools/internal-solver-test.cpp
)
add_executable(lexer-test
tools/lexer-test.cpp
)
add_executable(parser-test
tools/parser-test.cpp
)
add_executable(souper-check
tools/souper-check.cpp
)
add_executable(count-insts
tools/count-insts.cpp
)
add_executable(extractor_tests
unittests/Extractor/ExtractorTests.cpp
)
add_executable(inst_tests
unittests/Inst/InstTests.cpp
)
add_executable(parser_tests
unittests/Parser/ParserTests.cpp
)
set(LLVM_LDFLAGS "${LLVM_LDFLAGS} ${ALIVE_LDFLAGS}")
foreach(target souper internal-solver-test lexer-test parser-test souper-check count-insts
souperExtractor souperInfer souperInst souperKVStore souperParser
souperSMTLIB2 souperTool souperPass souperPassProfileAll kleeExpr)
set_target_properties(${target} PROPERTIES COMPILE_FLAGS "${LLVM_CXXFLAGS}")
target_include_directories(${target} PRIVATE "${LLVM_INCLUDEDIR}")
endforeach()
foreach(target souperClangTool clang-souper)
set_target_properties(${target} PROPERTIES COMPILE_FLAGS "${CLANG_CXXFLAGS} ${LLVM_CXXFLAGS}")
target_include_directories(${target} PRIVATE "${LLVM_INCLUDEDIR}" ${CLANG_INCLUDEDIR})
endforeach()
foreach(target extractor_tests inst_tests parser_tests)
set_target_properties(${target} PROPERTIES COMPILE_FLAGS "${GTEST_CXXFLAGS} ${LLVM_CXXFLAGS}")
target_include_directories(${target} PRIVATE "${LLVM_INCLUDEDIR}" "${GTEST_INCLUDEDIR}")
endforeach()
add_library(z3 STATIC IMPORTED)
set_target_properties(z3 PROPERTIES IMPORTED_LOCATION ${Z3_LIBRARY})
set_target_properties(z3 PROPERTIES IMPORTED_IMPLIB ${Z3_LIBRARY})
target_link_libraries(kleeExpr ${LLVM_LIBS} ${LLVM_LDFLAGS})
target_link_libraries(souperClangTool souperExtractor souperTool ${CLANG_LIBS} ${LLVM_LIBS} ${LLVM_LDFLAGS})
target_link_libraries(souperExtractor souperInfer souperInst kleeExpr)
target_link_libraries(souperInfer ${LLVM_LIBS} ${LLVM_LDFLAGS} z3)
target_link_libraries(souperInst ${LLVM_LIBS} ${LLVM_LDFLAGS})
target_link_libraries(souperKVStore ${LLVM_LIBS} ${LLVM_LDFLAGS})
target_link_libraries(souperParser souperInst ${LLVM_LIBS} ${LLVM_LDFLAGS} ${ALIVE_LIBRARY})
target_link_libraries(souperSMTLIB2 ${LLVM_LIBS} ${LLVM_LDFLAGS})
target_link_libraries(souperTool souperExtractor souperSMTLIB2)
target_link_libraries(souperPass ${PASS_LDFLAGS} ${HIREDIS_LIBRARY} ${ALIVE_LIBRARY} z3)
target_link_libraries(souperPassProfileAll ${PASS_LDFLAGS} ${HIREDIS_LIBRARY} ${ALIVE_LIBRARY} z3)
target_link_libraries(souper souperExtractor souperKVStore souperParser souperSMTLIB2 souperTool kleeExpr ${HIREDIS_LIBRARY} ${ALIVE_LIBRARY} z3)
target_link_libraries(internal-solver-test souperSMTLIB2)
target_link_libraries(lexer-test souperParser)
target_link_libraries(parser-test souperParser)
target_link_libraries(souper-check souperTool souperExtractor souperKVStore souperSMTLIB2 souperParser ${HIREDIS_LIBRARY} ${ALIVE_LIBRARY} z3)
target_link_libraries(clang-souper souperClangTool souperExtractor souperKVStore souperParser souperSMTLIB2 souperTool kleeExpr ${CLANG_LIBS} ${LLVM_LIBS} ${LLVM_LDFLAGS} ${HIREDIS_LIBRARY} ${ALIVE_LIBRARY} z3)
target_link_libraries(count-insts souperParser)
target_link_libraries(extractor_tests souperExtractor ${GTEST_LIBS} ${ALIVE_LIBRARY})
target_link_libraries(inst_tests souperInfer souperInst ${GTEST_LIBS} ${ALIVE_LIBRARY})
target_link_libraries(parser_tests souperParser ${GTEST_LIBS} ${ALIVE_LIBRARY})
SET(BUILD_CLANG_TOOL 1 CACHE BOOL "Build the Souper Clang tool")
if (NOT BUILD_CLANG_TOOL)
message(STATUS "Excluding Clang tool from build")
set_target_properties(souperClangTool clang-souper PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
endif()
set(TEST_SYNTHESIS "ON" CACHE STRING "Enable additional, computationally intensive synthesis tests")
set(TEST_LONG_DURATION_SYNTHESIS "" CACHE STRING "Enable long duration (> 10 min) synthesis tests")
configure_file(
${CMAKE_SOURCE_DIR}/test/lit.site.cfg.in
${CMAKE_BINARY_DIR}/test/lit.site.cfg
)
configure_file(
${CMAKE_SOURCE_DIR}/utils/run_lit.in
${CMAKE_BINARY_DIR}/run_lit
)
add_custom_target(check
COMMAND ${CMAKE_BINARY_DIR}/run_lit
DEPENDS extractor_tests inst_tests parser-test parser_tests profileRuntime souper souper-check souperPass souperPassProfileAll count-insts
USES_TERMINAL)
find_program(GO_EXECUTABLE NAMES go DOC "go executable")
if(NOT GO_EXECUTABLE STREQUAL "GO_EXECUTABLE-NOTFOUND")
add_executable(souperweb-backend
tools/souperweb-backend.cpp
)
set_target_properties(souperweb-backend
PROPERTIES COMPILE_FLAGS "${LLVM_CXXFLAGS}")
target_include_directories(souperweb-backend PRIVATE "${LLVM_INCLUDEDIR}")
target_link_libraries(souperweb-backend souperTool souperExtractor souperKVStore souperSMTLIB2 souperParser souperInst ${HIREDIS_LIBRARY})
add_custom_target(souperweb ALL COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_BINARY_DIR}/souperweb ${CMAKE_SOURCE_DIR}/tools/souperweb.go
COMMENT "Building souperweb")
endif()
add_library(profileRuntime STATIC
runtime/souperPassProfile.c)
set(SOUPER_PASS ${CMAKE_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}souperPass${CMAKE_SHARED_LIBRARY_SUFFIX})
set(SOUPER_PASS_PROFILE_ALL ${CMAKE_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}souperPassProfileAll${CMAKE_SHARED_LIBRARY_SUFFIX})
set(PROFILE_LIBRARY ${CMAKE_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}profileRuntime${CMAKE_STATIC_LIBRARY_SUFFIX})
configure_file(${CMAKE_SOURCE_DIR}/utils/reduce.in ${CMAKE_BINARY_DIR}/reduce @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/cache_dump.in ${CMAKE_BINARY_DIR}/cache_dump @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/cache_import.in ${CMAKE_BINARY_DIR}/cache_import @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/cache_infer.in ${CMAKE_BINARY_DIR}/cache_infer @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/souper2llvm.in ${CMAKE_BINARY_DIR}/souper2llvm @ONLY)
if (BUILD_CLANG_TOOL)
configure_file(${CMAKE_SOURCE_DIR}/utils/sclang.in ${CMAKE_BINARY_DIR}/sclang @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/utils/sclang.in ${CMAKE_BINARY_DIR}/sclang++ @ONLY)
endif()
add_subdirectory(docs)