-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCMakeLists.txt
208 lines (158 loc) · 5.94 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
# Copyright (c) 2025 Roberto Raggi <roberto.raggi@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cmake_minimum_required(VERSION 3.16)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/package.json" PACKAGE_JSON)
string(JSON version GET ${PACKAGE_JSON} version)
project(cplusplus VERSION ${version})
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
include(FetchContent)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(ExternalProject)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/package.json" package_json)
# option to install tools
option(CXX_INSTALL_TOOLS "Install tools" ON)
option(CXX_INSTALL_WASI_SYSROOT "Install wasi sysroot" OFF)
option(CXX_ENABLE_FLATBUFFERS "Enable flatbuffers" ON)
option(CXX_ENABLE_MLIR "Enable MLIR" OFF)
option(CXX_LIBCXX_WITH_CLANG "Link with libc++" OFF)
option(CXX_BUILD_TESTS "Build tests" ON)
option(CXX_INTERPROCEDURAL_OPTIMIZATION "Enable interprocedural optimization" OFF)
find_package(Threads)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CXX_LIBCXX_WITH_CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
# if CMAKE_SYSTEM_NAME is WASI disable the exceptions, and the tests
if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
set(CXX_BUILD_TESTS OFF)
# set the executable suffix to .wasm
set(CMAKE_EXECUTABLE_SUFFIX ".wasm")
endif()
#
# google test
#
if(CXX_BUILD_TESTS)
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.tar.gz
)
FetchContent_MakeAvailable(googletest)
include(GoogleTest)
endif()
#
# utfcpp
#
FetchContent_Declare(
utfcpp
URL https://github.com/nemtrif/utfcpp/archive/refs/tags/v4.0.5.tar.gz
PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/patches/utfcpp.patch
)
FetchContent_MakeAvailable(utfcpp)
FetchContent_GetProperties(utfcpp)
#
# nlohmann_json
#
FetchContent_Declare(
nlohmann_json
URL https://github.com/nlohmann/json/releases/download/v3.11.3/include.zip
URL_HASH SHA256=a22461d13119ac5c78f205d3df1db13403e58ce1bb1794edc9313677313f4a9d
)
FetchContent_MakeAvailable(nlohmann_json)
add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
set_target_properties(nlohmann_json::nlohmann_json PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_json_SOURCE_DIR}/single_include")
FetchContent_Declare(
wasi_sysroot
URL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sysroot-25.0.tar.gz
)
FetchContent_MakeAvailable(wasi_sysroot)
FetchContent_GetProperties(wasi_sysroot)
if (CXX_ENABLE_FLATBUFFERS)
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "" FORCE)
set(FLATBUFFERS_BUILD_FLATLIB OFF CACHE BOOL "" FORCE)
set(FLATBUFFERS_INSTALL OFF CACHE BOOL "" FORCE)
if (FLATBUFFERS_FLATC_EXECUTABLE)
set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "" FORCE)
endif()
FetchContent_Declare(
flatbuffers
URL https://github.com/google/flatbuffers/archive/refs/tags/v24.12.23.tar.gz
)
FetchContent_MakeAvailable(flatbuffers)
FetchContent_GetProperties(flatbuffers)
add_library(flatbuffers::header-only INTERFACE IMPORTED)
set_target_properties(flatbuffers::header-only PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${flatbuffers_SOURCE_DIR}/include")
endif()
if (CXX_BUILD_TESTS)
enable_testing()
endif()
if (NOT KWGEN_EXECUTABLE AND CMAKE_SYSTEM_NAME STREQUAL "WASI")
ExternalProject_Add(
kwgen_host
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools/kwgen
INSTALL_COMMAND ""
)
ExternalProject_Get_property(kwgen_host BINARY_DIR)
add_executable(kwgen IMPORTED)
set_target_properties(kwgen PROPERTIES IMPORTED_LOCATION "${BINARY_DIR}/kwgen")
add_dependencies(kwgen kwgen_host)
else()
add_subdirectory(tools/kwgen)
endif()
add_subdirectory(src)
if (CXX_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cxxConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cxx
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cxxConfigVersion.cmake"
VERSION "${version}"
COMPATIBILITY AnyNewerVersion
)
install(
EXPORT cxxTargets
FILE cxxTargets.cmake
NAMESPACE cxx::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cxx
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/cxxConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cxxConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cxx
)
set(CLANGD_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/clangd.in")
if (EMSCRIPTEN)
set(CLANGD_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/clangd_emscripten.in")
endif()
configure_file(
${CLANGD_CONFIG_FILE}
${CMAKE_CURRENT_SOURCE_DIR}/.clangd
@ONLY
)