-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
132 lines (102 loc) · 4.01 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
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
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)
# _.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-.
# 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
FetchContent_Declare(
cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG 3bf268481da8208d171d8908e6491459de3651d7 #v3.2.0
)
FetchContent_MakeAvailable(cxxopts)
message(DEBUG cxxopts="${cxxopts_SOURCE_DIR}/include")
## Antlr4
add_definitions(-DANTLR4CPP_STATIC)
set(ANTLR4_WITH_STATIC_CRT OFF)
set(ANTLR4_TAG 4.13.2)
set(ANTLR4_ZIP_REPOSITORY https://github.com/antlr/antlr4/archive/refs/tags/${ANTLR4_TAG}.zip)
set(ANTLR_EXECUTABLE ${PROJECT_SOURCE_DIR}/bin/antlr-${ANTLR4_TAG}-complete.jar)
include(ExternalAntlr4Cpp)
include_directories(${ANTLR4_INCLUDE_DIRS})
find_package(ANTLR REQUIRED)
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 REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake 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
"${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_SOURCE_DIR}/include"
${ANTLR4_INCLUDE_DIRS}
${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 ()