-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCMakeLists.txt
193 lines (164 loc) · 6.06 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
cmake_minimum_required(VERSION 3.10)
# set the project name
#
project(PochiVM)
# specify the C++ compiler
#
SET(CMAKE_C_COMPILER clang)
SET(CMAKE_CXX_COMPILER clang++)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
else()
message( FATAL_ERROR "ccache not found!" )
endif()
# specify the C++ standard
#
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# build flavor
# DEBUG: test-debug build, no optimization, all assertions
# RELEASE: test-release build, optimized but with debug symbols, 'assert' disabled but 'TestAssert' enabled
# PRODUCTION: production build, optimized, no debug symbols, no assertions
#
set(BUILD_FLAVOR "" CACHE STRING "Build flavor, supports DEBUG/RELEASE/PRODUCTION")
if(BUILD_FLAVOR STREQUAL "DEBUG")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBUILD_FLAVOR=DEBUG -DTESTBUILD -O0 -g ")
SET(GENERATED_FILES_DIR "${PROJECT_SOURCE_DIR}/__generated__/debug/generated")
include_directories("${PROJECT_SOURCE_DIR}/__generated__/debug")
elseif(BUILD_FLAVOR STREQUAL "RELEASE")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBUILD_FLAVOR=RELEASE -DTESTBUILD -DNDEBUG -O3 -g ")
SET(GENERATED_FILES_DIR "${PROJECT_SOURCE_DIR}/__generated__/release/generated")
include_directories("${PROJECT_SOURCE_DIR}/__generated__/release")
elseif(BUILD_FLAVOR STREQUAL "PRODUCTION")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBUILD_FLAVOR=PRODUCTION -DNDEBUG -O3 ")
SET(GENERATED_FILES_DIR "${PROJECT_SOURCE_DIR}/__generated__/production/generated")
include_directories("${PROJECT_SOURCE_DIR}/__generated__/production")
else()
message( FATAL_ERROR "Unknown build flavor!" )
endif()
# add -pthread
#
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread ")
# -rdynamic so symbols are exposed to generated code
#
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic ")
# If debug symbols are emitted, redirect them to point at the right location
# The reference to source code files always have prefix ../../ (since we are building
# in directory build/flavor/), remove this prefix
#
if((BUILD_FLAVOR STREQUAL "DEBUG") OR (BUILD_FLAVOR STREQUAL "RELEASE"))
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffile-prefix-map=../../= ")
endif()
# gtest header
#
include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/gtest/include")
# build gtest, we don't need the additional cxxflags to build gtest.
#
add_subdirectory(gtest)
# Append extra cxx warning flags
#
SET(EXTRA_WARNING_FLAGS "-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-unused-macros -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables -Wno-padded -Wno-alloca -Wno-missing-prototypes -Wno-zero-length-array -Werror ")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_WARNING_FLAGS} ")
# llvm-specific flags
#
SET(LLVM_EXTRA_COMPILE_FLAGS "-I/usr/local/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS ")
execute_process(
COMMAND bash "-c" "llvm-config --ldflags"
OUTPUT_VARIABLE LLVM_EXTRA_LINK_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# TODO: only append llvm-specific flags when needed
#
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_EXTRA_COMPILE_FLAGS} ")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LLVM_EXTRA_LINK_FLAGS} ")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN/shared_libs' ")
# Get the llvm-specific link libraries
# There are two parts:
# (1) the LLVM libraries (which are outputted in absolute paths)
#
execute_process(
COMMAND bash "-c" "llvm-config --libfiles"
OUTPUT_VARIABLE _tmp
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REPLACE " " ";" LLVM_EXTRA_LINK_LIBRARIES ${_tmp})
# (2) the system libraries. They are outputted in forms like "-lfoo -lbar".
# We transform the output to format "foo bar", and append to LLVM_EXTRA_LINK_LIBRARIES
#
execute_process(
COMMAND bash "-c" "llvm-config --system-libs"
OUTPUT_VARIABLE _tmp
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REPLACE " " ";" _tmp ${_tmp})
foreach(_loop_var ${_tmp})
STRING(REGEX REPLACE "^-l" "" _libname ${_loop_var})
LIST(APPEND LLVM_EXTRA_LINK_LIBRARIES ${_libname})
endforeach()
include_directories(${PROJECT_SOURCE_DIR})
include_directories("${PROJECT_SOURCE_DIR}/pochivm")
# Build tools that generates the runtime library
#
add_subdirectory(runtime_lib_builder)
# Build runtime library
#
add_subdirectory(runtime)
# Build fastinterp library
#
add_subdirectory(fastinterp)
# Build PochiVM library
#
add_subdirectory(pochivm)
# Build application: mini_db_backend
#
add_subdirectory(mini_db_backend)
# add the executable
#
add_executable(main
main.cpp
test_sanity_arith_expr.cpp
test_sanity_llvm_optimization.cpp
test_error_cases.cpp
test_sanity_break_continue.cpp
test_sanity_logical_op.cpp
test_fibonacci.cpp
test_sanity_deref.cpp
test_sanity_typecasts.cpp
test_find_nth_prime.cpp
test_sanity_irdump.cpp
test_sanity_bitcode.cpp
test_call_cpp_func.cpp
test_catch_throw.cpp
test_metavar_framework.cpp
test_fast_interp_internals.cpp
test_fast_interp.cpp
test_paper_microbenchmarks.cpp
test_sanity_pointer_arithmetic.cpp
test_mini_db_backend_unit_test.cpp
test_generated_function_pointer.cpp
)
# Important to link runtime using '--whole-archive'
# Symbols in runtime library, even if unused by main program,
# may be used at runtime and must not be dropped.
#
target_link_libraries(main PUBLIC
"-Wl,--whole-archive" runtime "-Wl,--no-whole-archive" runtime_bc
)
target_link_libraries(main PUBLIC
gtest
pochivm
mini_db_backend
${LLVM_EXTRA_LINK_LIBRARIES}
)
add_subdirectory(post_build_verifier)
set(POST_BUILD_DUMMY_TIMESTAMP_FILE "${PROJECT_BINARY_DIR}/post_build_validate_symbols_fake_target")
add_custom_command(
OUTPUT ${POST_BUILD_DUMMY_TIMESTAMP_FILE}
COMMAND ${PROJECT_BINARY_DIR}/post_build_verifier/post_build_verifier ARGS "${PROJECT_BINARY_DIR}/main"
COMMAND ${CMAKE_COMMAND} -E touch "${POST_BUILD_DUMMY_TIMESTAMP_FILE}"
DEPENDS main post_build_verifier
)
add_custom_target(post_build_verifer_event ALL
DEPENDS ${POST_BUILD_DUMMY_TIMESTAMP_FILE}
)