-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
105 lines (93 loc) · 3.5 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
cmake_minimum_required(VERSION 3.26)
project(cpplox)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_COMPILER "g++-13")
find_package(LLVM 19 REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(${LLVM_INCLUDE_DIRS} SYSTEM)
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})
get_filename_component(binFile "../bin" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${binFile})
add_executable(cpplox src/main.cpp
src/frontend/Token.h
src/frontend/Scanner.h
src/frontend/Error.h
src/frontend/AST.h
src/Util.h
src/frontend/Resolver.h
src/compiler/Expr.cpp
src/compiler/ModuleCompiler.cpp
src/compiler/Value.h
src/compiler/Value.cpp
src/compiler/String.cpp
src/compiler/Memory.cpp
src/compiler/Stmt.cpp
src/compiler/ModuleCompiler.h
src/compiler/LoxBuilder.h
src/compiler/FunctionCompiler.cpp
src/compiler/FunctionCompiler.h
src/compiler/Function.cpp
src/compiler/LoxModule.h
src/compiler/Upvalue.cpp
src/compiler/Upvalue.h
src/compiler/Class.cpp
src/compiler/Table.cpp
src/compiler/Callstack.h
src/frontend/Parser.h
src/compiler/Callstack.cpp
src/Debug.h
src/compiler/GC.cpp
src/compiler/GC.h
src/compiler/Table.h
src/compiler/Memory.h
src/compiler/Stack.h
src/compiler/Stack.cpp
src/compiler/LoxModule.cpp
src/compiler/MDUtil.h
src/interpreter/LoxObject.cpp
src/interpreter/LoxObject.h
src/interpreter/LoxCallable.h
src/interpreter/Interpreter.h
src/interpreter/Environment.cpp
src/interpreter/Environment.h
src/interpreter/Interpreter.cpp
src/interpreter/LoxInstance.cpp
src/interpreter/LoxInstance.h
src/interpreter/NativeFunction.h
src/interpreter/LoxClass.h
src/interpreter/LoxFunction.cpp
src/interpreter/LoxFunction.h
src/interpreter/LoxClass.cpp
)
target_compile_options(cpplox PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
-O2
# -std=c++20 -stdlib=libc++
)
llvm_map_components_to_libnames(llvm_libs
${LLVM_TARGETS_TO_BUILD}
orcjit
support
core
irreader
codegen
mc
mcparser
option)
target_link_libraries(cpplox ${llvm_libs})
#set(DART_PATH "/opt/dart-sdk-v2/bin/dart")
#set(CRAFTING_INTERPRETERS_PATH "~/Projects/craftinginterpreters")
set(CRAFTING_INTERPRETERS_PATH $ENV{CRAFTING_INTERPRETERS_PATH})
file(WRITE ${CMAKE_BINARY_DIR}/cpplox-compiler.sh "\
#!/bin/bash\n \
TMPFILE=$(mktemp --suffix .ll)\n \
script_dir=$(dirname \"$0\")\n \
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cpplox $1 -o $TMPFILE && clang $TMPFILE -o out && ./out \n"
)
file(CHMOD ${CMAKE_BINARY_DIR}/cpplox-compiler.sh PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
enable_testing()
add_test(NAME interpreter COMMAND dart tool/bin/test.dart jlox -i ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cpplox WORKING_DIRECTORY ${CRAFTING_INTERPRETERS_PATH})
add_test(NAME compiler COMMAND dart tool/bin/test.dart jlox -i ${CMAKE_BINARY_DIR}/cpplox-compiler.sh WORKING_DIRECTORY ${CRAFTING_INTERPRETERS_PATH})