-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
88 lines (70 loc) · 2.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
cmake_minimum_required(VERSION 3.13.4)
project(ParaCL)
find_package(BISON 3.7 REQUIRED)
find_package(FLEX REQUIRED)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
set(INTERP_NAME "${PROJECT_NAME}i")
set(COMPILE_NAME "${PROJECT_NAME}")
message(STATUS "Interp: ${INTERP_NAME}")
# option for debug (debug info)
set(PR_DEBUG_OPTIONS -g)
# option for release (optimization)
set(PR_RELEASE_OPTIONS -O2)
# some useful warnings
set(WARN_OPTIONS
-Wall
#-Wextra commented because it causes warnings at llvm library code
-Wunused -Wpedantic # classic
-Wno-old-style-cast #-Waggressive-loop-optimizations
-Wunreachable-code)
flex_target(flex_o
grammar/scanner.l
${CMAKE_CURRENT_BINARY_DIR}/lex.yy.cc
)
bison_target(bison_o
grammar/compiler.y
${CMAKE_CURRENT_BINARY_DIR}/compiler.tab.cc
COMPILE_FLAGS "--defines=${CMAKE_CURRENT_BINARY_DIR}/compiler.tab.hh")
add_flex_bison_dependency(flex_o bison_o)
add_executable(${INTERP_NAME}
driver/driver.cc
parser/parser.cc
AST/Node.cc
AST/Interp.cc
CLI/CLI.cc
main.cc
${BISON_bison_o_OUTPUTS}
${FLEX_flex_o_OUTPUTS}
)
add_executable(${COMPILE_NAME}
driver/driver.cc
parser/parser.cc
AST/Node.cc
AST/Interp.cc
CLI/CLI.cc
main.cc
${BISON_bison_o_OUTPUTS}
${FLEX_flex_o_OUTPUTS}
)
set(TARGETS ${COMPILE_NAME} ${INTERP_NAME})
# use llvm-config --components and some guessing to determine components
llvm_map_components_to_libnames(llvm_libs support core codegen irreader)
foreach(TARGET ${TARGETS})
target_compile_features(${TARGET} PRIVATE cxx_std_17)
target_compile_options(${TARGET} PRIVATE ${WARN_OPTIONS})
target_include_directories(${TARGET} PRIVATE ${LLVM_INCLUDE_DIRS})
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${TARGET} PRIVATE parser)
target_include_directories(${TARGET} PRIVATE AST)
target_include_directories(${TARGET} PRIVATE CLI)
target_include_directories(${TARGET} PRIVATE driver)
# Specify compiler options for debug and release
target_compile_options(${TARGET} PRIVATE "$<$<CONFIG:DEBUG>:${PR_DEBUG_OPTIONS}>")
target_compile_options(${TARGET} PRIVATE "$<$<CONFIG:RELEASE>:${PR_RELEASE_OPTIONS}>")
target_link_libraries(${TARGET} ${llvm_libs})
endforeach()
target_compile_definitions(${COMPILE_NAME} PRIVATE CODEGEN=1)
target_compile_definitions(${INTERP_NAME} PRIVATE CODEGEN=0)