-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCmakeLists.txt
129 lines (109 loc) · 2.96 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
# Specify minimum CMake version required
cmake_minimum_required(VERSION 3.10)
# Define project name and version
project(leic VERSION 1.0)
# Set C++ standard requirements
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# WSL/Linux compiler selection
if(EXISTS "/usr/bin/clang++")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
message(STATUS "Using Clang compiler")
else()
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
message(STATUS "Using GCC compiler")
endif()
# Find packages
find_package(GTest REQUIRED)
find_package(LLVM REQUIRED CONFIG)
# LLVM setup
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
# Define source files (excluding main.cpp and test files)
set(LIB_SOURCES
src/ast.cpp
src/lexer.cpp
src/ast_printer.cpp
src/parser.cpp
src/error_handler.cpp
src/semantic_visitor.cpp
src/source_reader.cpp
src/symbol_table.cpp
src/codegen_visitor.cpp
src/compiler.cpp
src/type_helper.cpp
)
# Create a library target for the compiler components
add_library(lei_compiler_lib ${LIB_SOURCES})
# Set up include directories for the library
target_include_directories(lei_compiler_lib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# Configure LLVM libraries
llvm_map_components_to_libnames(llvm_libs
Support
Core
IRReader
native
MCJIT
ExecutionEngine
RuntimeDyld
TransformUtils
Analysis
ScalarOpts
InstCombine
Target
X86CodeGen
X86AsmParser
X86Desc
MC
Object
BitWriter
)
# Link LLVM libraries to our library target
target_link_libraries(lei_compiler_lib PRIVATE ${llvm_libs})
# Create the main executable
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE lei_compiler_lib ${llvm_libs})
# Enable testing
enable_testing()
# Define test executables
set(TEST_SOURCES
tests/lexer_tests.cpp
tests/parser_tests.cpp
tests/semantic_analyzer_tests.cpp
)
# Create test targets
foreach(test_source ${TEST_SOURCES})
# Get the filename without extension
get_filename_component(test_name ${test_source} NAME_WE)
# Create test executable
add_executable(${test_name} ${test_source})
# Link with our library and GTest
target_link_libraries(${test_name}
PRIVATE
lei_compiler_lib
GTest::GTest
GTest::Main
)
# Add the test to CTest
add_test(NAME ${test_name} COMMAND ${test_name})
endforeach()
# Set compiler warning flags
target_compile_options(lei_compiler_lib PRIVATE
-Wall
-Wextra
-Wpedantic
-fPIC
)
# Configure output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# Installation rules
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
)