-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
137 lines (106 loc) · 4.35 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
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
# Nix dependencies
file(GLOB NIX_STORE_LIB LIST_DIRECTORIES true "/nix/store/*/lib/cmake/*")
message(DEBUG NIX_STORE_LIB=${NIX_STORE_LIB})
list(APPEND CMAKE_PREFIX_PATH ${NIX_STORE_LIB})
file(GLOB NIX_STORE_BIN LIST_DIRECTORIES true "/nix/store/*/bin/")
message(DEBUG NIX_STORE_BIN=${NIX_STORE_BIN})
list(APPEND CMAKE_PROGRAM_PATH ${NIX_STORE_BIN})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/VERSION FILC_VERSION)
project(
filc
VERSION ${FILC_VERSION}
LANGUAGES CXX
)
include(FetchContent)
cmake_policy(SET CMP0135 NEW)
include(commands)
# _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-.
# Library
## Coverage config
add_library(additional_config INTERFACE)
option(CODE_COVERAGE "Enable coverage reporting" OFF)
if (CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# No optimization + debug info + coverage flags
target_compile_options(additional_config INTERFACE -O0 -g --coverage)
target_link_options(additional_config INTERFACE --coverage)
else ()
# Full optimization
target_compile_options(additional_config INTERFACE -O3)
endif ()
## Cxxopts
find_package(cxxopts 3.2.0 REQUIRED CONFIG)
message(STATUS "Found cxxopts ${cxxopts_PACKAGE_VERSION}")
message(STATUS "Located in: ${cxxopts_DIR}")
get_target_property(cxxopts_INCLUDE_DIR cxxopts::cxxopts INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "Included from: ${cxxopts_INCLUDE_DIR}")
## Antlr4
find_package(antlr4-runtime 4.13.0 REQUIRED CONFIG)
message(STATUS "Found antlr ${ANTLR_VERSION}")
message(STATUS "Located in: ${antlr4-runtime_DIR}")
message(STATUS "Included from: ${ANTLR4_INCLUDE_DIR}")
find_program(ANTLR_EXECUTABLE antlr REQUIRED)
message(STATUS "Found antlr: ${ANTLR_EXECUTABLE}")
antlr_target(Lexer ${PROJECT_SOURCE_DIR}/src/grammar/FilLexer.g4 LEXER
PACKAGE filc)
antlr_target(Parser ${PROJECT_SOURCE_DIR}/src/grammar/FilParser.g4 PARSER
PACKAGE filc
DEPENDS_ANTLR Lexer
COMPILE_FLAGS -lib ${ANTLR_Lexer_OUTPUT_DIR})
## LLVM
find_package(LLVM 18.1.8 REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Located in: ${LLVM_DIR}")
include_directories(${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS})
llvm_map_components_to_libnames(llvm_libs analysis support core object irreader executionengine scalaropts instcombine orcjit runtimedyld)
foreach(target ${LLVM_TARGETS_TO_BUILD})
list(APPEND llvm_targets "LLVM${target}CodeGen")
endforeach()
## filc lib
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS filc_lib
"${PROJECT_SOURCE_DIR}/src/*.cpp"
"${PROJECT_SOURCE_DIR}/src/**/*.cpp"
)
message(DEBUG SRC_FILES=${SRC_FILES})
add_library(filc_lib ${SRC_FILES} ${ANTLR_Lexer_CXX_OUTPUTS} ${ANTLR_Parser_CXX_OUTPUTS})
target_link_libraries(filc_lib PRIVATE additional_config cxxopts::cxxopts antlr4_static ${llvm_libs} ${llvm_targets})
target_include_directories(filc_lib PUBLIC
"${PROJECT_SOURCE_DIR}/include"
${cxxopts_INCLUDE_DIR}
${ANTLR4_INCLUDE_DIR}
${ANTLR_Lexer_OUTPUT_DIR}
${ANTLR_Parser_OUTPUT_DIR}
${LLVM_INCLUDE_DIRS})
target_compile_definitions(filc_lib
PUBLIC FILC_VERSION="${FILC_VERSION}"
)
target_compile_options(filc_lib PUBLIC -Wall)
# _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-.
# Executable
add_executable(filc main.cpp)
target_link_libraries(filc PRIVATE filc_lib)
target_compile_options(filc PUBLIC -Wall -O3)
add_custom_target(filc_path ALL "echo" $<TARGET_FILE:filc> ">" "filc.path")
add_dependencies(filc_path filc)
# _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-.
# Tests
option(BUILD_TESTING "Build the testing tree." OFF)
if (BUILD_TESTING AND (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR))
message(DEBUG "Build test tree")
enable_testing()
add_subdirectory(tests)
endif ()
# _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-.
# Packaging
if (CMAKE_BUILD_TYPE STREQUAL "Release")
message(DEBUG "Build install tree")
install(TARGETS filc)
include(packaging)
filc_package()
endif ()