forked from runtimeverification/llvm-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
269 lines (228 loc) · 7.78 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
cmake_minimum_required (VERSION 3.4)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(LLVMKompilePrelude)
project (KLLVM CXX C)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_definitions(-Wall -Werror -Wno-return-type-c-linkage)
if (CMAKE_BUILD_TYPE STREQUAL "GcStats")
add_definitions(-DGC_DBG)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector")
set(CMAKE_C_FLAGS_FASTBUILD "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_GCSTATS "${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -flto -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_FASTBUILD "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_GCSTATS "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -flto -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
set(CMAKE_EXE_LINKER_FLAGS_GCSTATS "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto")
if(APPLE)
set(BACKEND_TARGET_TRIPLE "x86_64-apple-darwin")
if(NOT USE_NIX)
include_directories(AFTER SYSTEM /usr/local/include)
link_directories(AFTER /usr/local/lib)
set(ENV{PKG_CONFIG_PATH} "/usr/local/opt/libffi/lib/pkgconfig")
endif() # USE_NIX
else()
set(BACKEND_TARGET_TRIPLE "x86_64-unknown-linux-gnu")
endif()
find_package(PkgConfig REQUIRED)
pkg_check_modules(FFI REQUIRED libffi)
if(USE_NIX)
include_directories(AFTER ${FFI_INCLUDE_DIRS})
link_directories(AFTER ${FFI_LIBRARY_DIRS})
else() # USE_NIX
include_directories(AFTER SYSTEM ${FFI_INCLUDE_DIRS})
link_directories(AFTER SYSTEM ${FFI_LIBRARY_DIRS})
endif() # USE_NIX
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(LLVM_KOMPILE_LTO "lto")
else()
set(LLVM_KOMPILE_LTO "nolto")
endif()
set(CMAKE_AR "${CMAKE_C_COMPILER_AR}")
set(CMAKE_RANLIB "${CMAKE_C_COMPILER_RANLIB}")
find_package(LLVM 12 QUIET CONFIG)
if (NOT LLVM_FOUND)
find_package(LLVM 11.1 QUIET CONFIG)
endif()
if (NOT LLVM_FOUND)
find_package(LLVM 11 QUIET CONFIG)
endif()
if (NOT LLVM_FOUND)
find_package(LLVM 10 QUIET CONFIG)
endif()
if (NOT LLVM_FOUND)
find_package(LLVM 9 QUIET CONFIG)
endif()
if (NOT LLVM_FOUND)
find_package(LLVM 8 QUIET CONFIG)
endif()
if (NOT LLVM_FOUND)
find_package(LLVM 7.1 QUIET CONFIG)
endif()
if (NOT LLVM_FOUND)
find_package(LLVM 7 REQUIRED CONFIG)
endif()
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
if (${LLVM_PACKAGE_VERSION} VERSION_LESS 7.0.1)
message(FATAL_ERROR "LLVM 7.0.1 or newer is required")
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(LLVM_BUILD_TOOLS ON)
find_package(ZLIB REQUIRED)
find_package(FLEX REQUIRED)
find_package(GMP REQUIRED)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
link_directories(${LLVM_LIBRARY_DIR})
include_directories(${LLVM_INCLUDE_DIR})
include_directories (${PROJECT_SOURCE_DIR}/include)
# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs support core irreader)
macro(kllvm_add_tool name)
add_executable(${name} ${ARGN})
# Link against LLVM libraries
llvm_config(${name})
if(APPLE)
if(NOT USE_NIX)
target_link_libraries(${name} PUBLIC "-ljemalloc" "-Wl,-rpath /usr/local/lib" "-ldl")
else()
target_link_libraries(${name} PUBLIC "-ljemalloc" "-ldl")
endif() # NOT USE_NIX
else()
if(NOT USE_NIX)
target_link_libraries(${name} PUBLIC "-ljemalloc" "-Wl,-rpath /usr/local/lib" "-ldl")
else()
target_link_libraries(${name} PUBLIC "-ljemalloc" "-ldl")
endif() # NOT USE_NIX
endif() # APPLE
endmacro(kllvm_add_tool)
install(
FILES runtime/main/main.ll runtime/main/search.cpp
DESTINATION lib/kllvm/llvm/main
)
find_program(OPT opt-12)
find_program(OPT opt-11)
find_program(OPT opt-10)
find_program(OPT opt-9)
find_program(OPT opt-8)
find_program(OPT opt-7)
find_program(OPT opt)
find_program(LLC llc-12)
find_program(LLC llc-11)
find_program(LLC llc-10)
find_program(LLC llc-9)
find_program(LLC llc-8)
find_program(LLC llc-7)
find_program(LLC llc)
if(${OPT} STREQUAL "OPT-NOTFOUND")
message(FATAL_ERROR "Could not find an opt binary. Is llvm installed on your PATH?")
endif()
if(${LLC} STREQUAL "OPT-NOTFOUND")
message(FATAL_ERROR "Could not find an llvm binary. Is llvm installed on your PATH?")
endif()
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
configure_file(bin/llvm-kompile bin @ONLY)
configure_file(bin/llvm-krun bin @ONLY)
configure_file(bin/llvm-kompile-testing bin @ONLY)
configure_file(bin/llvm-kompile-clang bin @ONLY)
install(
PROGRAMS
${CMAKE_CURRENT_BINARY_DIR}/bin/llvm-kompile
${CMAKE_CURRENT_BINARY_DIR}/bin/llvm-kompile-clang
${CMAKE_CURRENT_BINARY_DIR}/bin/llvm-krun
DESTINATION bin
)
install(
DIRECTORY include/runtime
DESTINATION include/kllvm
)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/immer
DESTINATION include/kllvm
)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/rapidjson
DESTINATION include/kllvm
)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/config
DESTINATION include/kllvm
)
file(COPY ${PROJECT_SOURCE_DIR}/deps/immer/immer DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include)
file(COPY ${PROJECT_SOURCE_DIR}/deps/rapidjson/include/rapidjson DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include)
set(GC_THRESHOLD 2097152 CACHE STRING "Initial Young Generation Size")
set(NOT_YOUNG_OBJECT_BIT 0x10000000000000)
if(CMAKE_BUILD_TYPE STREQUAL "GcStats")
set(AGE_MASK 0x7ff0000000000)
set(AGE_OFFSET 40)
set(AGE_WIDTH 11)
else()
set(AGE_MASK 0x4000000000000)
set(AGE_OFFSET 50)
set(AGE_WIDTH 1)
endif()
set(FWD_PTR_BIT 0x20000000000000)
set(VARIABLE_BIT 0x8000000000000)
set(LAYOUT_OFFSET 54)
set(TAG_MASK 0xffffffff)
set(LENGTH_MASK 0xffffffffff)
if(CMAKE_BUILD_TYPE STREQUAL "GcStats")
set(HDR_MASK -18013298997854209) # 0xffc000ffffffffff
else()
set(HDR_MASK -16888498602639361) # 0xffc3ffffffffffff
endif()
set(MAP_LAYOUT 1)
set(LIST_LAYOUT 2)
set(SET_LAYOUT 3)
set(INT_LAYOUT 4)
set(FLOAT_LAYOUT 5)
set(STRINGBUFFER_LAYOUT 6)
set(BOOL_LAYOUT 7)
set(SYMBOL_LAYOUT 8)
set(VARIABLE_LAYOUT 9)
get_filename_component(INSTALL_DIR_ABS_PATH "${CMAKE_INSTALL_PREFIX}"
REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
configure_file(config/macros.h include/config/macros.h @ONLY)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/runtime)
configure_file(runtime/equality.ll runtime @ONLY)
configure_file(runtime/finish_rewriting.ll runtime @ONLY)
configure_file(runtime/fresh.ll runtime @ONLY)
configure_file(runtime/getTag.ll runtime @ONLY)
configure_file(runtime/move_float.ll runtime @ONLY)
configure_file(runtime/move_int.ll runtime @ONLY)
configure_file(runtime/string_equal.ll runtime @ONLY)
configure_file(runtime/take_steps.ll runtime @ONLY)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gdb)
configure_file(gdb/interpreter-gdb.py gdb @ONLY)
configure_file(gdb/kllvm.py gdb @ONLY)
configure_file(gdb/__init__.py gdb @ONLY)
FILE(GLOB LLVMFiles ${CMAKE_CURRENT_BINARY_DIR}/runtime/*.ll)
FILE(GLOB GDBFiles ${CMAKE_CURRENT_BINARY_DIR}/gdb/*.py)
install(
FILES ${LLVMFiles}
DESTINATION lib/kllvm/llvm
)
install(
FILES ${GDBFiles}
DESTINATION lib/kllvm/gdb
)
FILE(GLOB_RECURSE HaskellSources matching/src/*.hs matching/app/Main.hs)
# Auto-generated header path
set(KLLVM_AUTOGEN_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
include_directories(${KLLVM_AUTOGEN_INCLUDE_DIR})
add_subdirectory(lib)
add_subdirectory(tools)
add_subdirectory(runtime)
add_subdirectory(unittests)
#add_subdirectory(test)