This repository has been archived by the owner on Sep 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
176 lines (144 loc) · 5.74 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
cmake_minimum_required(VERSION 3.12)
project(coolc)
option(ASAN "Build with AddressSanitizer" OFF)
option(UBSAN "Build with UndefinedBehaviorSanitizer" OFF)
set(ARCH "LLVM" CACHE STRING "Target architecture")
set(GCTYPE "LLVM_STATEPOINT_EXAMPLE" CACHE STRING "GC")
execute_process(
COMMAND sh -c "rm -rf ${PROJECT_SOURCE_DIR}/bin"
)
execute_process(
COMMAND sh -c "rm -rf ${PROJECT_SOURCE_DIR}/lib"
)
if(ARCH STREQUAL "LLVM")
execute_process(COMMAND sh -c "llvm-config --includedir" OUTPUT_VARIABLE LLVM_INCLUDE_DIR)
string(STRIP ${LLVM_INCLUDE_DIR} LLVM_INCLUDE_DIR)
message(STATUS "LLVM_INCLUDE_DIR = ${LLVM_INCLUDE_DIR}")
include_directories(${LLVM_INCLUDE_DIR})
execute_process(COMMAND sh -c "llvm-config --libs all" OUTPUT_VARIABLE LIBS)
string(STRIP ${LIBS} LIBS)
message(STATUS "LIBS = ${LIBS}")
execute_process(COMMAND sh -c "llvm-config --libdir" OUTPUT_VARIABLE LIB_DIR)
string(STRIP ${LIB_DIR} LIB_DIR)
message(STATUS "LIB_DIR = ${LIB_DIR}")
link_directories(${LIB_DIR})
if(GCTYPE STREQUAL "LLVM_SHADOW_STACK")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DLLVM_SHADOW_STACK")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_SHADOW_STACK")
elseif(GCTYPE STREQUAL "LLVM_STATEPOINT_EXAMPLE")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DLLVM_STATEPOINT_EXAMPLE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_STATEPOINT_EXAMPLE")
endif()
else()
set(GCTYPE "NO_GC")
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--extra-arg=-std=gnu++2a")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type -Wno-switch -D${ARCH}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -D${ARCH}")
if(ASAN)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DASAN -fsanitize=address -fno-omit-frame-pointer")
endif()
if(UBSAN)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DUBSAN -fsanitize=undefined -fno-omit-frame-pointer")
endif()
message(STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}")
unset(ASAN CACHE)
unset(UBSAN CACHE)
include_directories(src)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
if(ARCH STREQUAL "LLVM")
find_package(Boost 1.61 COMPONENTS filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
set(ADDITIONAL_LIBS "${Boost_LIBRARIES}")
message(STATUS "ADDITIONAL_LIBS = ${ADDITIONAL_LIBS}")
endif()
add_subdirectory(src/lexer)
add_subdirectory(src/parser)
add_subdirectory(src/semant)
add_subdirectory(src/utils)
add_subdirectory(src/ast)
add_subdirectory(src/decls)
add_subdirectory(src/codegen)
add_executable(coolc src/coolc.cpp)
target_link_libraries(coolc lexer parser semant utils ast codegen decls ${LIBS} ${ADDITIONAL_LIBS} -ldl)
if(ARCH STREQUAL "LLVM")
if(APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
set(CMAKE_SHARED_LIBRARY_SUFFIX .so)
endif()
add_subdirectory(src/runtime)
endif()
enable_testing()
include_directories(tests/src)
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_test(PrepareLexerTestsResults
${PROJECT_SOURCE_DIR}/tests/lexer/make_results.sh
${EXECUTABLE_OUTPUT_PATH}
)
add_executable(lexer_tests tests/src/test.cpp tests/src/lexer/test.cpp)
target_link_libraries(lexer_tests ${GTEST_LIBRARIES} pthread ${GTEST_MAIN_LIBRARIES})
add_test(LexerTests ${EXECUTABLE_OUTPUT_PATH}/lexer_tests)
add_test(PrepareParserSemantTestsResults
${PROJECT_SOURCE_DIR}/tests/parser-semant/make_results.sh
${EXECUTABLE_OUTPUT_PATH}
)
add_executable(parser_semant_tests tests/src/test.cpp tests/src/parser-semant/test.cpp)
target_link_libraries(parser_semant_tests ${GTEST_LIBRARIES} pthread ${GTEST_MAIN_LIBRARIES})
add_test(ParserSemantTests ${EXECUTABLE_OUTPUT_PATH}/parser_semant_tests)
endif()
if(ARCH STREQUAL "MIPS")
set(RUN_DIR mips)
else()
set(RUN_DIR llvm)
endif()
add_executable(codegen_tests tests/src/test.cpp tests/src/codegen/test.cpp)
target_link_libraries(codegen_tests ${GTEST_LIBRARIES} pthread ${GTEST_MAIN_LIBRARIES})
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)" AND ARCH STREQUAL "MIPS")
add_test(PrepareCodegenTestsResults
${PROJECT_SOURCE_DIR}/tests/codegen/make_results.sh
${EXECUTABLE_OUTPUT_PATH}
${PROJECT_SOURCE_DIR}/tests/codegen/arch/${RUN_DIR}/run.sh
)
add_test(CodegenTests ${EXECUTABLE_OUTPUT_PATH}/codegen_tests)
elseif(ARCH STREQUAL "LLVM")
add_test(PrepareCodegenMarkAndSweepTestsResults
${PROJECT_SOURCE_DIR}/tests/codegen/make_results.sh
${EXECUTABLE_OUTPUT_PATH}
${PROJECT_SOURCE_DIR}/tests/codegen/arch/${RUN_DIR}/run.sh
1
"6Kb"
)
add_test(CodegenTestsMarkAndSweep ${EXECUTABLE_OUTPUT_PATH}/codegen_tests)
add_test(PrepareCodegenThreadedTestsResults
${PROJECT_SOURCE_DIR}/tests/codegen/make_results.sh
${EXECUTABLE_OUTPUT_PATH}
${PROJECT_SOURCE_DIR}/tests/codegen/arch/${RUN_DIR}/run.sh
2
"5Kb"
)
add_test(CodegenTestsThreaded ${EXECUTABLE_OUTPUT_PATH}/codegen_tests)
add_test(PrepareCodegenCompressorTestsResults
${PROJECT_SOURCE_DIR}/tests/codegen/make_results.sh
${EXECUTABLE_OUTPUT_PATH}
${PROJECT_SOURCE_DIR}/tests/codegen/arch/${RUN_DIR}/run.sh
3
"5Kb"
)
add_test(CodegenTestsCompressor ${EXECUTABLE_OUTPUT_PATH}/codegen_tests)
add_test(PrepareCodegenSemispaceTestsResults
${PROJECT_SOURCE_DIR}/tests/codegen/make_results.sh
${EXECUTABLE_OUTPUT_PATH}
${PROJECT_SOURCE_DIR}/tests/codegen/arch/${RUN_DIR}/run.sh
4
"10Kb"
)
add_test(CodegenTestsSemispace ${EXECUTABLE_OUTPUT_PATH}/codegen_tests)
endif()
unset(ARCH CACHE)
unset(GCTYPE CACHE)