-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
225 lines (188 loc) · 6.2 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
cmake_minimum_required(VERSION 3.30...3.31)
include(cmake/prelude.cmake)
project(cxx_modules_example VERSION 0.1.0 LANGUAGES CXX)
# This property setting also needs to be consistent between the
# installed shared library and its consumer, otherwise most
# toolchains will once again reject the consumer's generated BMI.
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_EXTENSIONS FALSE)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
endif()
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)
if(PROJECT_IS_TOP_LEVEL)
include(cmake/AddUninstallTarget.cmake)
include(cmake/lint-targets.cmake)
include(cmake/spell-targets.cmake)
endif()
# Disable clang-tidy for target
macro(target_disable_clang_tidy TARGET)
find_program(CLANGTIDY clang-tidy)
if(CLANGTIDY)
set_target_properties(${TARGET} PROPERTIES C_CLANG_TIDY "")
set_target_properties(${TARGET} PROPERTIES CXX_CLANG_TIDY "")
endif()
endmacro()
#########################################################################
# cmake-format: off
# include(cmake/CPM.cmake)
# instead of find_package(fmt REQUIRED)
# cpmaddpackage(
# NAME fmt
# GIT_TAG 10.2.1
# GITHUB_REPOSITORY fmtlib/fmt
# SYSTEM YES
# # TODO(CK): OPTIONS "FMT_MODULE ON"
# )
# if(TARGET fmt)
# target_disable_clang_tidy(fmt)
# endif()
add_library(Algo SHARED)
target_sources(Algo
PRIVATE
algo-impl.cpp
PUBLIC
FILE_SET CXX_MODULES
FILES
algo-interface.cppm
)
# CMake requires the language standard to be specified as compile feature
# when a target provides C++23 modules and the target will be installed
target_compile_features(Algo PUBLIC cxx_std_23)
include(GenerateExportHeader)
generate_export_header(Algo
CUSTOM_CONTENT_FROM_VARIABLE
)
target_sources(Algo
PUBLIC
FILE_SET HEADERS
BASE_DIRS
${CMAKE_CURRENT_BINARY_DIR}
FILES
${CMAKE_CURRENT_BINARY_DIR}/algo_export.h
)
if(NOT CMAKE_SKIP_INSTALL_RULES)
include(CPack)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
write_basic_package_version_file("my_package-config-version.cmake" COMPATIBILITY SameMajorVersion)
install(TARGETS Algo
EXPORT my_package-targets
# ... a few details omitted, see the "Deep CMake For Library Authors" talk
FILE_SET CXX_MODULES
# There's currently no convention for this location, see discussion below
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package/src
FILE_SET HEADERS
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # Same as default, could be omitted
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(EXPORT my_package-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package
CXX_MODULES_DIRECTORY .
)
install(
FILES "${PROJECT_BINARY_DIR}/my_package-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package
)
# The following file includes the my_package-targets.cmake file
install(FILES cmake/my_package-config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/my_package
)
endif()
# cmake-format: on
#########################################################################
if(PROJECT_IS_TOP_LEVEL)
enable_testing()
add_subdirectory(example)
# # cmake-format: off
# add_test(using-std-test
# ${CMAKE_CTEST_COMMAND}
# -C ${CMAKE_BUILD_TYPE}
# --build-and-test
# "${CMAKE_CURRENT_SOURCE_DIR}/std"
# "${CMAKE_CURRENT_BINARY_DIR}/std"
# --build-generator ${CMAKE_GENERATOR}
# --build-makeprogram ${CMAKE_MAKE_PROGRAM}
# --build-options
# "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
# "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
# "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
# "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
# )
# cmake-format: on
endif()
##################################################
return() # NOTE: XXX
##################################################
# project(
# cmake-init-modules
# VERSION 0.1.0
# DESCRIPTION "Short description"
# HOMEPAGE_URL "https://example.com/"
# LANGUAGES CXX)
include(cmake/variables.cmake)
# ---- Declare library ----
add_library(cmake-init-modules_cmake-init-modules source/cmake-init-modules.cpp)
add_library(cmake-init-modules::cmake-init-modules ALIAS cmake-init-modules_cmake-init-modules)
include(GenerateExportHeader)
generate_export_header(
cmake-init-modules_cmake-init-modules
BASE_NAME
cmake-init-modules
EXPORT_FILE_NAME
export/cmake-init-modules/cmake-init-modules_export.hpp
CUSTOM_CONTENT_FROM_VARIABLE
pragma_suppress_c4251
)
# cmake-format: off
target_sources(
cmake-init-modules_cmake-init-modules
PUBLIC FILE_SET HEADERS
BASE_DIRS
${PROJECT_BINARY_DIR}/export
${PROJECT_SOURCE_DIR}/include
FILES
include/cmake-init-modules/cmake-init-modules.hpp
${PROJECT_BINARY_DIR}/export/cmake-init-modules/cmake-init-modules_export.hpp
)
# cmake-format: on
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(
cmake-init-modules_cmake-init-modules PUBLIC CMAKE_INIT_MODULES_STATIC_DEFINE
)
endif()
set_target_properties(
cmake-init-modules_cmake-init-modules
PROPERTIES CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN YES
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}"
EXPORT_NAME cmake-init-modules
OUTPUT_NAME cmake-init-modules
)
target_compile_features(cmake-init-modules_cmake-init-modules PUBLIC cxx_std_23)
#XXX target_link_libraries(cmake-init-modules_cmake-init-modules PRIVATE fmt::fmt)
target_link_libraries(
cmake-init-modules_cmake-init-modules PRIVATE $<BUILD_INTERFACE:fmt::fmt-header-only>
)
# ---- Install rules ----
if(NOT CMAKE_SKIP_INSTALL_RULES)
include(cmake/install-rules.cmake)
endif()
# ---- Examples ----
enable_testing()
if(PROJECT_IS_TOP_LEVEL)
option(BUILD_EXAMPLES "Build examples tree." "${cmake-init-modules_DEVELOPER_MODE}")
if(BUILD_EXAMPLES)
add_subdirectory(example)
endif()
endif()
# ---- Developer mode ----
if(NOT cmake-init-modules_DEVELOPER_MODE)
return()
elseif(NOT PROJECT_IS_TOP_LEVEL)
message(AUTHOR_WARNING "Developer mode is intended for developers of cmake-init-modules")
endif()
include(cmake/dev-mode.cmake)