-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
172 lines (146 loc) · 5.42 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
cmake_minimum_required(VERSION 3.20)
# Temporary workaround for clang 14
# https://github.com/llvm/llvm-project/issues/53950
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)
set(tolc_languages CXX)
else()
set(tolc_languages C CXX)
endif()
project(
tolc
VERSION 0.7.0
LANGUAGES ${tolc_languages})
configure_file(docs/ReleaseNotes/version.in
${CMAKE_CURRENT_LIST_DIR}/docs/ReleaseNotes/version @ONLY)
include(FetchContent)
FetchContent_Declare(
cmake_modules
GIT_REPOSITORY https://github.com/Tolc-Software/cmake-modules.git
GIT_TAG main)
FetchContent_MakeAvailable(cmake_modules)
# Basis of all shared CMake modules
set(modules ${cmake_modules_SOURCE_DIR}/cmake)
# Define add_{warnings,options}
include(${modules}/WarningsAndOptions.cmake)
# Need a special options since the used version of Boost::asio
# doesn't support C++20 on MacOS
include(cmake/Options.cmake)
# Define options such as ccache
include(${modules}/ProjectSettings.cmake)
include(${modules}/Sanitizers.cmake)
include(${modules}/StaticAnalyzers.cmake)
include(${modules}/GetFrontend.cmake)
get_frontend(NAME Frontend.py VERSION v0.7.0)
copy_frontend_docs(NAME Frontend.py SRC_DIR ${frontend.py_SOURCE_DIR} COPY_TO
${CMAKE_CURRENT_LIST_DIR}/docs/packaging/docs/python)
get_frontend(NAME Frontend.wasm VERSION v0.6.0)
copy_frontend_docs(
NAME Frontend.wasm SRC_DIR ${frontend.wasm_SOURCE_DIR} COPY_TO
${CMAKE_CURRENT_LIST_DIR}/docs/packaging/docs/webassembly)
get_frontend(NAME Frontend.swift VERSION v0.2.0)
copy_frontend_docs(
NAME Frontend.swift SRC_DIR ${frontend.swift_SOURCE_DIR} COPY_TO
${CMAKE_CURRENT_LIST_DIR}/docs/packaging/docs/objc)
include(${modules}/GetParser.cmake)
get_parser(VERSION v0.6.0)
# Set the include path for the system library in the variable
# We are using the standard library shipped
# with the downloaded llvm for include paths in the parsing
set(PARSER_LLVM_DIR ${parser_SOURCE_DIR}/lib/Parser)
get_parser_system_include(
VARIABLE
SYSTEM_INCLUDE_PATHS
PARSER_SOURCE_DIR
${parser_SOURCE_DIR}
LIBCPP_ROOT_DIR
${parser_SOURCE_DIR}/lib/Parser
LLVM_VERSION
${PARSER_LLVM_VERSION})
# These uppercase variables will be used when configuring getSystemIncludes.cpp
set(SYSTEM_INCLUDES "")
set(TOKEN_STRING "{replaceme}")
# Used as a root directory for system header files to be placed next to tolc executable
set(relativeIncludeDir system_include)
foreach(include ${SYSTEM_INCLUDE_PATHS})
string(REPLACE ${parser_SOURCE_DIR}/lib/Parser
${TOKEN_STRING}/${relativeIncludeDir} formated_include
${include})
list(APPEND SYSTEM_INCLUDES ${formated_include})
endforeach()
include(${modules}/copyLLVMIncludes.cmake)
# Copy the llvm headers relative to the tolc executable
# (will always be ${CMAKE_CURRENT_BINARY_DIR} as long as
# this is called in the same file as the add_executable)
copy_llvm_includes(
OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/system_include LLVM_DIR
${PARSER_LLVM_DIR} LLVM_VERSION ${PARSER_LLVM_VERSION})
include(FetchContent)
FetchContent_Declare(
cli11_content
GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git
GIT_TAG v2.1.1)
FetchContent_Populate(cli11_content)
include(${modules}/ConanHelpers.cmake)
# Create the profile from variables known during configure
setup_conan_profile(VARIABLE tolc_conan_profile)
find_conan_packages(REQUIRES spdlog/1.9.2 fmt/8.1.1 PROFILE
${tolc_conan_profile})
include(${modules}/GetBoost.cmake)
get_boost(VERSION 1.77.0)
configure_file(
src/TolcInternal/getSystemIncludes.cpp.in
${CMAKE_CURRENT_LIST_DIR}/src/TolcInternal/getSystemIncludes.cpp @ONLY)
add_library(
TolcInternal
src/CommandLine/parse.cpp
src/Log/postJSON.cpp
src/Log/log.cpp
src/TolcInternal/buildConfig.cpp
src/TolcInternal/getExecutableDirectoryPath.cpp
src/TolcInternal/getSystemIncludes.cpp
src/TolcInternal/run.cpp)
target_include_directories(TolcInternal PUBLIC src)
target_include_directories(TolcInternal SYSTEM
PRIVATE ${cli11_content_SOURCE_DIR}/include)
target_link_libraries(TolcInternal
PUBLIC
Tolc::Parser
Tolc::Frontend.py
Tolc::Frontend.wasm
Tolc::Frontend.swift
spdlog::spdlog
fmt::fmt)
set_target_properties(TolcInternal
PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)
add_warnings(TARGET TolcInternal)
tolc_add_options(TARGET TolcInternal)
target_link_boost(TARGET TolcInternal)
# Do not try to link against static libraries (only using headers for now)
target_compile_definitions(TolcInternal PRIVATE BOOST_ALL_NO_LIB)
# Prefer std::filesystem over boost::filesystem
target_compile_definitions(TolcInternal PRIVATE BOOST_DLL_USE_STD_FS)
add_executable(tolc src/tolc.main.cpp)
target_link_libraries(tolc PRIVATE TolcInternal)
set_target_properties(tolc PROPERTIES CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS
OFF)
# Only build tests and benchmarks if building this project directly
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
option(ENABLE_TESTING "Build the testing tree" OFF)
if(ENABLE_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
option(ENABLE_BENCHMARKS "Build the benchmarks" OFF)
if(ENABLE_BENCHMARKS)
# TODO: Add benchmarks
endif()
option(ENABLE_PACKAGING "Enables install and packaging via CPack" OFF)
if(ENABLE_PACKAGING)
add_subdirectory(tools/packaging)
if(ENABLE_TESTING)
add_subdirectory(tests/packaging)
endif()
endif()
endif()