-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
247 lines (214 loc) · 6.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
## qilang CMake project
## ====================
##
## Parameters
## ----------
## QILANG_VERSION
## ~~~~~~~~~~~~~~
## A version number that will be used for this project. If this variable is
## undefined, CMake will read the project version number from the
## `project.json` file in the source directory.
##
## Targets
## -------
## The targets defined by the project are:
## - `qilang::qicc`: executable.
##
## All targets are defined for:
## - qilang as a CMake subproject (through `add_subdirectory`).
## - a build directory of the project.
## - an installation of the project.
##
## The last two cases are implemented by generating package configuration
## files (`X-config.cmake`) in the build directory and in the installation
## directory.
cmake_minimum_required(VERSION 3.23)
# - Parse project description file
file(READ "${CMAKE_CURRENT_LIST_DIR}/project.json" project_json)
# - Define the project version number.
if(NOT QILANG_VERSION)
string(JSON QILANG_VERSION GET "${project_json}" version)
endif()
include(cmake/ParseVersion.cmake)
parse_version(QILANG "${QILANG_VERSION}")
message(STATUS "Project version is ${QILANG_VERSION_FULL} (interpreted as ${QILANG_VERSION} for CMake)")
project(qilang VERSION "${QILANG_VERSION}")
include(CTest)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(cmake/BuildType.cmake)
include(cmake/MakePackageConfigFile.cmake)
# Enable more warnings. This is set globally for every targets of this project,
# but is not reflected on the interface of this project libraries. Consumers
# of these libraries are free to add (or not) these flags themselves.
if(MSVC)
add_compile_options(/W3)
else()
add_compile_options(-Wall -Wextra)
endif()
set(QI_WITH_TESTS "${BUILD_TESTING}")
##############################################################################
# External Packages
##############################################################################
find_package(BISON MODULE REQUIRED)
find_package(FLEX MODULE REQUIRED)
find_package(
Boost REQUIRED
COMPONENTS
filesystem
program_options
)
find_package(qi REQUIRED)
##############################################################################
# Convenience library: cxx_standard
##############################################################################
add_library(cxx_standard INTERFACE)
# The project requires at least C++17.
target_compile_features(
cxx_standard
INTERFACE
cxx_std_17
)
##############################################################################
# Flex & Bison targets
##############################################################################
bison_target(
parse
src/grammar.y
"${CMAKE_CURRENT_BINARY_DIR}/grammar.tab.cpp"
COMPILE_FLAGS "-Wall -t -g=graph.txt -v -d"
)
flex_target(
lex
src/token.l
"${CMAKE_CURRENT_BINARY_DIR}/lex.y.cpp"
COMPILE_FLAGS "--batch"
)
add_flex_bison_dependency(lex parse)
##############################################################################
# Library: qilang
##############################################################################
add_library(qilang STATIC)
target_sources(
qilang
PUBLIC
FILE_SET source_headers
TYPE HEADERS
FILES
qilang/api.hpp
qilang/node.hpp
qilang/visitor.hpp
qilang/parser.hpp
qilang/formatter.hpp
qilang/packagemanager.hpp
qilang/docparser.hpp
qilang/pathformatter.hpp
PRIVATE
src/codegen.cpp
src/node.cpp
src/parser.cpp
src/parser_p.hpp
src/formatter_p.hpp
src/format_doc.cpp
src/format_qilang.cpp
src/format_sexpr.cpp
src/format_cpp_interface.cpp
src/format_cpp_local.cpp
src/format_cpp_remote.cpp
src/format_cpp_gmock.cpp
src/format_anyvalue.cpp
src/cpptype.hpp
src/cpptype.cpp
src/packagemanager.cpp
src/qilang_signature.cpp
src/qilang_metaobject.cpp
src/docparser.cpp
src/pathformatter.cpp
${BISON_parse_OUTPUTS}
${FLEX_lex_OUTPUTS}
)
target_include_directories(
qilang
PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/src"
)
target_link_libraries(
qilang
PRIVATE
cxx_standard
qi::qi
Boost::headers
Boost::filesystem
Boost::program_options
)
target_compile_definitions(
qilang
PRIVATE
YYDEBUG=1
)
##############################################################################
# Executable: qilang
##############################################################################
add_executable(qicc)
add_executable(qilang::qicc ALIAS qicc)
target_sources(
qicc
PRIVATE
src/qic_main.cpp
)
target_link_libraries(
qicc
PRIVATE
qilang
qi::qi
Boost::filesystem
Boost::program_options
)
# Common code used by code generated by qicc.
set(QILANG_COMMON_GEN_BEGIN "R\"gencodeutility(\n")
set(QILANG_COMMON_GEN_END "\n)gencodeutility\"")
configure_file(
qilang/gencodeutility.hpp.in
qilang/detail/gencodeutility.txt
@ONLY
)
##############################################################################
# Installation
##############################################################################
install(
TARGETS qicc
EXPORT qilang-targets
COMPONENT runtime
)
make_package_config_file(qilang-targets qilang COMPONENT devel)
##############################################################################
# qilang-tools
##############################################################################
set(
qilang-tools_install_cmakedir
"${CMAKE_INSTALL_LIBDIR}/cmake/qilang-tools"
CACHE STRING
"Path where qilang-tools CMake files are to be installed."
)
set(
qilang-tools_config_file_path
"${CMAKE_CURRENT_BINARY_DIR}/qilang-tools-config.cmake"
)
configure_file(
cmake/qilang-tools-config.cmake
"${qilang-tools_config_file_path}"
COPYONLY
)
install(
FILES
"${qilang-tools_config_file_path}"
DESTINATION "${qilang-tools_install_cmakedir}"
COMPONENT devel
)
##############################################################################
# Tests
##############################################################################
if(BUILD_TESTING)
add_subdirectory(tests)
endif()