-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
executable file
·289 lines (255 loc) · 8.75 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
cmake_minimum_required(VERSION 3.10)
project(Pryst VERSION 1.0)
# Set up system paths
set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR} ${CMAKE_PREFIX_PATH})
# Set C++17 as required and enable debug symbols
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -frtti")
# Enable testing
enable_testing()
# Find GTest package
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
# Find LLVM 14
find_package(LLVM 14 REQUIRED CONFIG)
if(NOT LLVM_FOUND OR NOT LLVM_PACKAGE_VERSION VERSION_EQUAL "14.0.6")
message(FATAL_ERROR "LLVM 14.0.x is required. Found version: ${LLVM_PACKAGE_VERSION}")
endif()
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
# Add LLVM flags and definitions
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
# Get LLVM library directory and add to link path
link_directories(/usr/lib/llvm-14/lib)
# Get LLVM library list from llvm-config
execute_process(
COMMAND llvm-config-14 --libs
OUTPUT_VARIABLE LLVM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "LLVM Libs from llvm-config: ${LLVM_LIBS}")
# Find Boehm GC and verify version
find_package(PkgConfig REQUIRED)
pkg_check_modules(GC REQUIRED bdw-gc>=8.0.0)
if(NOT GC_FOUND)
message(FATAL_ERROR "Boehm GC >= 8.0.0 is required")
endif()
message(STATUS "Found Boehm GC ${GC_VERSION}")
include_directories(${GC_INCLUDE_DIRS})
link_directories(${GC_LIBRARY_DIRS})
# Handle cpp-httplib and verify version
if(NOT EXISTS "/usr/local/include/httplib/httplib.h")
message(FATAL_ERROR "cpp-httplib header not found. Please install it manually:
git clone https://github.com/yhirose/cpp-httplib.git
cd cpp-httplib
sudo mkdir -p /usr/local/include/httplib
sudo cp httplib.h /usr/local/include/httplib/")
endif()
include_directories("/usr/local/include")
# Find Java for ANTLR
find_package(Java REQUIRED COMPONENTS Runtime)
# Find system ANTLR4 Runtime
find_package(PkgConfig REQUIRED)
pkg_check_modules(ANTLR4 REQUIRED antlr4-runtime>=4.13.1)
message(STATUS "Found ANTLR4 Runtime: ${ANTLR4_VERSION}")
# Set up ANTLR JAR and verify version
set(ANTLR4_JAR_LOCATION /usr/local/lib/antlr-4.13.1-complete.jar)
execute_process(
COMMAND java -jar ${ANTLR4_JAR_LOCATION} -version
OUTPUT_VARIABLE ANTLR4_TOOL_VERSION
ERROR_VARIABLE ANTLR4_TOOL_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Set up generated files directory
set(GENERATED_DIR "${CMAKE_SOURCE_DIR}/src/generated")
set(GENERATED_SRC
${GENERATED_DIR}/PrystLexer.cpp
${GENERATED_DIR}/PrystParser.cpp
${GENERATED_DIR}/PrystParserBaseVisitor.cpp
${GENERATED_DIR}/PrystParserVisitor.cpp
)
set(GENERATED_HEADERS
${GENERATED_DIR}/PrystLexer.h
${GENERATED_DIR}/PrystParser.h
${GENERATED_DIR}/PrystParserBaseVisitor.h
${GENERATED_DIR}/PrystParserVisitor.h
)
# Create custom target for generated files
add_custom_target(antlr4_generation
COMMAND
java -jar ${ANTLR4_JAR_LOCATION} -Dlanguage=Cpp -no-listener -visitor
-package pryst
-o ${GENERATED_DIR}
${CMAKE_SOURCE_DIR}/src/PrystLexer.g4
${CMAKE_SOURCE_DIR}/src/PrystParser.g4
DEPENDS
${CMAKE_SOURCE_DIR}/src/PrystLexer.g4
${CMAKE_SOURCE_DIR}/src/PrystParser.g4
)
# Include directories
include_directories(
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/generated
${ANTLR4_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/src/include
${CMAKE_SOURCE_DIR}/src/type_system/core
${CMAKE_SOURCE_DIR}/src/type_system/advanced
${CMAKE_SOURCE_DIR}/src/error_handling/core
${CMAKE_SOURCE_DIR}/src/error_handling/advanced
${CMAKE_SOURCE_DIR}/src/runtime/core
)
# Add source files (excluding main.cpp for library use)
set(LIB_SOURCE_FILES
src/compiler.cpp
src/type_checker.cpp
src/type_system/core/llvm_codegen.cpp
src/type_system/core/types.cpp
src/type_system/core/type_registry.cpp
src/error_handling/core/diagnostic_error_listener.cpp
src/error_handling/core/error_handler.cpp
src/error_handling/core/error_chain.cpp
src/type_system/core/type_inference.cpp
src/runtime/core/runtime.cpp
src/runtime/core/runtime_registry.cpp
src/runtime/core/web.cpp
src/runtime/core/web_types.cpp
src/runtime/core/web_impl.cpp
src/runtime/core/map_impl.cpp
src/runtime/core/array_impl.cpp
src/runtime/core/string_impl.cpp
src/runtime/core/error_impl.cpp
src/runtime/core/error_bindings.cpp
src/runtime/core/string_bindings.cpp
src/runtime/core/array_bindings.cpp
src/runtime/core/map_bindings.cpp
src/runtime/core/io_impl.cpp
src/runtime/core/io_bindings.cpp
src/runtime/core/runtime_type_ops.cpp
src/runtime/core/type_ops.cpp
src/type_system/advanced/type_checker_advanced.cpp
src/error_handling/advanced/chain/error_chain_advanced.cpp
src/error_handling/advanced/propagation/error_propagation.cpp
src/error_handling/advanced/transformation/error_transform.cpp
src/type_system/advanced/inference/type_inference_advanced.cpp
src/type_system/advanced/validation/type_validation.cpp
)
# Create library target
add_library(libpryst STATIC ${LIB_SOURCE_FILES} ${GENERATED_SRC} ${HEADER_FILES})
add_dependencies(libpryst antlr4_generation)
set_target_properties(libpryst PROPERTIES OUTPUT_NAME "pryst")
# Link libraries to libpryst
target_link_libraries(libpryst
${ANTLR4_LIBRARIES}
LLVM-14
${GC_LIBRARIES}
pthread
dl
${HTTPLIB_LIBRARIES}
)
# Add header files
set(HEADER_FILES
src/error_handling/core/diagnostic_error_listener.hpp
src/error_handling/core/error.hpp
src/error_handling/core/error_chain.hpp
src/error_handling/core/error_handler.hpp
src/type_system/core/llvm_codegen.hpp
src/type_system/core/types.hpp
src/type_system/core/type_registry.hpp
src/type_system/core/type_inference.hpp
src/runtime/core/runtime.hpp
src/runtime/core/runtime_registry.hpp
src/runtime/core/web.hpp
src/runtime/core/web_types.hpp
src/runtime/core/web_impl.hpp
src/runtime/core/map_impl.hpp
src/runtime/core/array_impl.hpp
src/runtime/core/string_impl.hpp
src/runtime/core/error_impl.hpp
src/runtime/core/io_impl.hpp
src/runtime/core/runtime_type_ops.hpp
src/runtime/core/type_ops.hpp
)
# Add main executable
add_executable(pryst
src/main.cpp
${LIB_SOURCE_FILES}
${GENERATED_SRC}
${HEADER_FILES}
)
add_dependencies(pryst antlr4_generation)
# Add unified test executable
add_executable(run_tests
tests/test_runner.cpp
tests/error_handling_test.cpp
tests/nullable_test.cpp
tests/nullable_type_test.cpp
tests/type_checker_tests.cpp
tests/core/cpp/parser_test.cpp
tests/core/cpp/map_type_test.cpp
tests/core/cpp/type_ops_test.cpp
tests/core/cpp/type_operators_test.cpp
tests/core/cpp/io_test.cpp
tests/core/cpp/nullable_pst_test.cpp
tests/core/cpp/function_type_test.cpp
tests/core/cpp/array_type_test.cpp
tests/core/cpp/runtime/io_test.cpp
tests/web/webserver_test.cpp
tests/advanced/type_system_test.cpp
tests/advanced/error_handling_test.cpp
tests/advanced/type_system_integration_test.cpp
tests/advanced/type_checker_integration_test.cpp
tests/advanced/error_chain_integration_test.cpp
tests/advanced/llvm_type_integration_test.cpp
tests/advanced/scope_integration_test.cpp
tests/advanced/web_type_integration_test.cpp
${LIB_SOURCE_FILES}
${GENERATED_SRC}
)
add_dependencies(run_tests antlr4_generation)
# Link libraries for main executable and unified test target
foreach(target pryst run_tests)
target_link_libraries(${target}
${ANTLR4_LIBRARIES}
LLVM-14
${GC_LIBRARIES}
pthread
dl
${HTTPLIB_LIBRARIES}
)
target_include_directories(${target} PRIVATE
${GENERATED_DIR}
${CMAKE_SOURCE_DIR}/src
${ANTLR4_INCLUDE_DIRS}
)
endforeach()
# Add GTest only to run_tests target
target_link_libraries(run_tests
${GTEST_LIBRARIES}
gtest
gtest_main
)
target_include_directories(run_tests PRIVATE
${GTEST_INCLUDE_DIRS}
)
# Create unified test directory structure
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
# Add unified tests directory
add_subdirectory(tests)
# Copy test files during configure phase
file(GLOB_RECURSE ALL_PST_FILES
"${CMAKE_SOURCE_DIR}/tests/**/*.pst"
)
# Copy each test file to the build directory
foreach(TEST_FILE ${ALL_PST_FILES})
get_filename_component(FILENAME ${TEST_FILE} NAME)
configure_file(${TEST_FILE} ${CMAKE_BINARY_DIR}/tests/${FILENAME} COPYONLY)
endforeach()
# Add unified test suite
add_test(NAME PrystTests COMMAND run_tests)
# Set test environment
set_tests_properties(PrystTests PROPERTIES
ENVIRONMENT "TEST_FILES_DIR=${CMAKE_BINARY_DIR}/tests"
)