-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
72 lines (52 loc) · 2.69 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
# CMAKE header.
cmake_minimum_required(VERSION 3.13.4)
project(LLVM-Lab)
project(LLVM-Lab)
set(CMAKE_CXX_STANDARD 17)
set(LLVM_PATH "/opt/homebrew/opt/llvm@17")
# Set binary output destination.
set(BINARY_OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BINARY_OUTPUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BINARY_OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BINARY_OUTPUT_DIR})
# Include project sources.
include_directories("src")
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp" "src/*.c")
# Get LLVM linker flags.
execute_process(COMMAND llvm-config --ldflags --system-libs --libs all OUTPUT_VARIABLE LLVM_FLAGS)
# Get rid of whitespace and replace newlines with spaces.
string(STRIP ${LLVM_FLAGS} LLVM_FLAGS)
string(REPLACE "\n" " " LLVM_FLAGS ${LLVM_FLAGS})
link_directories(${LLVM_PATH}/lib)
include_directories(${LLVM_PATH}/include)
add_definitions(
-D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -std=c++11 -frtti" )
# Append LLVM linker flags to CMAKE_EXE_LINKER_FLAGS
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LLVM_FLAGS}")
# Set binary output destination.
set(BINARY_OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BINARY_OUTPUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BINARY_OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BINARY_OUTPUT_DIR})
# Include project sources.
include_directories("src/files")
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "src/files/*.cpp" "src/files/*.c")
# Get LLVM linker flags.
execute_process(COMMAND llvm-config --ldflags --system-libs --libs all OUTPUT_VARIABLE LLVM_FLAGS)
# Get rid of whitespace and replace newlines with spaces.
string(STRIP "${LLVM_FLAGS}" LLVM_FLAGS)
string(REPLACE "\n" " " LLVM_FLAGS "${LLVM_FLAGS}")
# Find bison: add -Wcounterexamples flag to bison
find_package(BISON)
BISON_TARGET(Parser "src/files/frontend/parser.y" "${CMAKE_CURRENT_BINARY_DIR}/parser.tab.cc" DEFINES_FILE "${CMAKE_CURRENT_BINARY_DIR}/parser.tab.hh"
COMPILE_FLAGS "-Wcounterexamples")
#Find flex:
find_package(FLEX)
FLEX_TARGET(Lexer "src/files/frontend/lexer.l" "${CMAKE_CURRENT_BINARY_DIR}/lex.yy.cc" )
ADD_FLEX_BISON_DEPENDENCY(Lexer Parser)
# Finally link the program with LLVM.
add_executable(${PROJECT_NAME} ${SOURCES} src/expressions/multiplication.cpp src/expressions/multiplication.h src/expressions/division.cpp src/expressions/division.h src/expressions/negative.cpp src/expressions/negative.h src/statements/return.cpp src/statements/return.h src/expressions/or.cpp src/expressions/or.h ${FLEX_Lexer_OUTPUTS} ${BISON_Parser_OUTPUTS})
target_link_libraries(${PROJECT_NAME} "${LLVM_FLAGS}")