@@ -7,21 +7,34 @@ endif()
7
7
8
8
# Determine if fmt is built as a subproject (using add_subdirectory)
9
9
# or if it is the master project.
10
- set (MASTER_PROJECT OFF )
11
- if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR )
12
- set (MASTER_PROJECT ON )
13
- message (STATUS "CMake version: ${CMAKE_VERSION} " )
10
+ if (NOT DEFINED FMT_MASTER_PROJECT)
11
+ set (FMT_MASTER_PROJECT OFF )
12
+ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR )
13
+ set (FMT_MASTER_PROJECT ON )
14
+ message (STATUS "CMake version: ${CMAKE_VERSION} " )
15
+ endif ()
14
16
endif ()
15
17
16
18
# Joins arguments and places the results in ${result_var}.
17
19
function (join result_var)
18
- set (result )
20
+ set (result "" )
19
21
foreach (arg ${ARGN} )
20
22
set (result "${result}${arg} " )
21
23
endforeach ()
22
24
set (${result_var} "${result} " PARENT_SCOPE)
23
25
endfunction ()
24
26
27
+ function (enable_module target )
28
+ if (MSVC )
29
+ set (BMI ${CMAKE_CURRENT_BINARY_DIR} /${target} .ifc)
30
+ target_compile_options (${target}
31
+ PRIVATE /interface /ifcOutput ${BMI}
32
+ INTERFACE /reference fmt=${BMI} )
33
+ endif ()
34
+ set_target_properties (${target} PROPERTIES ADDITIONAL_CLEAN_FILES ${BMI} )
35
+ set_source_files_properties (${BMI} PROPERTIES GENERATED ON )
36
+ endfunction ()
37
+
25
38
include (CMakeParseArguments)
26
39
27
40
# Sets a cache variable with a docstring joined from multiple arguments:
@@ -44,7 +57,7 @@ endfunction()
44
57
# Set the default CMAKE_BUILD_TYPE to Release.
45
58
# This should be done before the project command since the latter can set
46
59
# CMAKE_BUILD_TYPE itself (it does so for nmake).
47
- if (MASTER_PROJECT AND NOT CMAKE_BUILD_TYPE )
60
+ if (FMT_MASTER_PROJECT AND NOT CMAKE_BUILD_TYPE )
48
61
set_verbose(CMAKE_BUILD_TYPE Release CACHE STRING
49
62
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or "
50
63
"CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." )
@@ -61,12 +74,33 @@ option(FMT_WERROR "Halt the compilation with an error on compiler warnings."
61
74
OFF )
62
75
63
76
# Options that control generation of various targets.
64
- option (FMT_DOC "Generate the doc target." ${MASTER_PROJECT } )
65
- option (FMT_INSTALL "Generate the install target." ${MASTER_PROJECT } )
66
- option (FMT_TEST "Generate the test target." ${MASTER_PROJECT } )
77
+ option (FMT_DOC "Generate the doc target." ${FMT_MASTER_PROJECT } )
78
+ option (FMT_INSTALL "Generate the install target." ${FMT_MASTER_PROJECT } )
79
+ option (FMT_TEST "Generate the test target." ${FMT_MASTER_PROJECT } )
67
80
option (FMT_FUZZ "Generate the fuzz target." OFF )
68
81
option (FMT_CUDA_TEST "Generate the cuda-test target." OFF )
69
82
option (FMT_OS "Include core requiring OS (Windows/Posix) " ON )
83
+ option (FMT_MODULE "Build a module instead of a traditional library." OFF )
84
+ option (FMT_SYSTEM_HEADERS "Expose headers with marking them as system." OFF )
85
+
86
+ set (FMT_CAN_MODULE OFF )
87
+ if (CMAKE_CXX_STANDARD GREATER 17 AND
88
+ # msvc 16.10-pre4
89
+ MSVC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.29.30035)
90
+ set (FMT_CAN_MODULE OFF )
91
+ endif ()
92
+ if (NOT FMT_CAN_MODULE)
93
+ set (FMT_MODULE OFF )
94
+ message (STATUS "Module support is disabled." )
95
+ endif ()
96
+ if (FMT_TEST AND FMT_MODULE)
97
+ # The tests require {fmt} to be compiled as traditional library
98
+ message (STATUS "Testing is incompatible with build mode 'module'." )
99
+ endif ()
100
+ set (FMT_SYSTEM_HEADERS_ATTRIBUTE "" )
101
+ if (FMT_SYSTEM_HEADERS)
102
+ set (FMT_SYSTEM_HEADERS_ATTRIBUTE SYSTEM )
103
+ endif ()
70
104
71
105
# Get version from core.h
72
106
file (READ include /fmt/core.h core_h)
@@ -102,6 +136,18 @@ if (${index} GREATER -1)
102
136
endif ()
103
137
message (STATUS "Required features: ${FMT_REQUIRED_FEATURES} " )
104
138
139
+ if (FMT_MASTER_PROJECT AND NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
140
+ set_verbose(CMAKE_CXX_VISIBILITY_PRESET hidden CACHE STRING
141
+ "Preset for the export of private symbols" )
142
+ set_property (CACHE CMAKE_CXX_VISIBILITY_PRESET PROPERTY STRINGS
143
+ hidden default)
144
+ endif ()
145
+
146
+ if (FMT_MASTER_PROJECT AND NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)
147
+ set_verbose(CMAKE_VISIBILITY_INLINES_HIDDEN ON CACHE BOOL
148
+ "Whether to add a compile flag to hide symbols of inline functions" )
149
+ endif ()
150
+
105
151
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
106
152
set (PEDANTIC_COMPILE_FLAGS -pedantic-errors -Wall -Wextra -pedantic
107
153
-Wold-style-cast -Wundef
@@ -110,16 +156,16 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
110
156
-Wcast-align
111
157
-Wctor-dtor-privacy -Wdisabled-optimization
112
158
-Winvalid-pch -Woverloaded-virtual
113
- -Wconversion -Wswitch-enum - Wundef
159
+ -Wconversion -Wundef
114
160
-Wno-ctor-dtor-privacy -Wno-format-nonliteral)
115
161
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
116
- set (PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wnoexcept
162
+ set (PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS}
117
163
-Wno-dangling-else -Wno-unused-local-typedefs)
118
164
endif ()
119
165
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
120
166
set (PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wdouble-promotion
121
167
-Wtrampolines -Wzero-as-null-pointer-constant -Wuseless-cast
122
- -Wvector-operation-performance -Wsized-deallocation)
168
+ -Wvector-operation-performance -Wsized-deallocation -Wshadow )
123
169
endif ()
124
170
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
125
171
set (PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wshift-overflow=2
@@ -130,7 +176,8 @@ endif ()
130
176
131
177
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
132
178
set (PEDANTIC_COMPILE_FLAGS -Wall -Wextra -pedantic -Wconversion -Wundef
133
- -Wdeprecated -Wweak-vtables)
179
+ -Wdeprecated -Wweak-vtables -Wshadow
180
+ -Wno-gnu-zero-variadic-macro-arguments)
134
181
check_cxx_compiler_flag(-Wzero-as-null-pointer-constant HAS_NULLPTR_WARNING)
135
182
if (HAS_NULLPTR_WARNING)
136
183
set (PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS}
@@ -144,7 +191,7 @@ if (MSVC)
144
191
set (WERROR_FLAG /WX)
145
192
endif ()
146
193
147
- if (MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio" )
194
+ if (FMT_MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio" )
148
195
# If Microsoft SDK is installed create script run-msbuild.bat that
149
196
# calls SetEnv.cmd to set up build environment and runs msbuild.
150
197
# It is useful when building Visual Studio projects with the SDK
@@ -183,9 +230,12 @@ function(add_headers VAR)
183
230
endfunction ()
184
231
185
232
# Define the fmt library, its includes and the needed defines.
186
- add_headers(FMT_HEADERS chrono.h color.h compile.h core.h format.h format-inl.h
187
- locale.h os.h ostream.h posix.h printf.h ranges.h)
188
- if (FMT_OS)
233
+ add_headers(FMT_HEADERS args.h chrono.h color.h compile.h core.h format.h
234
+ format-inl.h locale.h os.h ostream.h printf.h ranges.h
235
+ xchar.h)
236
+ if (FMT_MODULE)
237
+ set (FMT_SOURCES src/fmt.cc)
238
+ elseif (FMT_OS)
189
239
set (FMT_SOURCES src/format.cc src/os.cc)
190
240
else ()
191
241
set (FMT_SOURCES src/format.cc)
@@ -199,7 +249,7 @@ if (HAVE_STRTOD_L)
199
249
endif ()
200
250
201
251
if (MINGW)
202
- check_cxx_compiler_flag("Wa,-mbig-obj" FMT_HAS_MBIG_OBJ)
252
+ check_cxx_compiler_flag("- Wa,-mbig-obj" FMT_HAS_MBIG_OBJ)
203
253
if (${FMT_HAS_MBIG_OBJ} )
204
254
target_compile_options (fmt PUBLIC "-Wa,-mbig-obj" )
205
255
endif ()
@@ -211,10 +261,13 @@ endif ()
211
261
if (FMT_PEDANTIC)
212
262
target_compile_options (fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS} )
213
263
endif ()
264
+ if (FMT_MODULE)
265
+ enable_module(fmt)
266
+ endif ()
214
267
215
268
target_compile_features (fmt INTERFACE ${FMT_REQUIRED_FEATURES} )
216
269
217
- target_include_directories (fmt PUBLIC
270
+ target_include_directories (fmt ${FMT_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC
218
271
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
219
272
$<INSTALL_INTERFACE:${FMT_INC_DIR} >)
220
273
@@ -250,7 +303,7 @@ add_library(fmt::fmt-header-only ALIAS fmt-header-only)
250
303
target_compile_definitions (fmt-header-only INTERFACE FMT_HEADER_ONLY=1)
251
304
target_compile_features (fmt-header-only INTERFACE ${FMT_REQUIRED_FEATURES} )
252
305
253
- target_include_directories (fmt-header-only INTERFACE
306
+ target_include_directories (fmt-header-only ${FMT_SYSTEM_HEADERS_ATTRIBUTE} INTERFACE
254
307
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
255
308
$<INSTALL_INTERFACE:${FMT_INC_DIR} >)
256
309
@@ -294,6 +347,13 @@ if (FMT_INSTALL)
294
347
INSTALL_DESTINATION ${FMT_CMAKE_DIR} )
295
348
296
349
set (INSTALL_TARGETS fmt fmt-header-only)
350
+
351
+ # Install the library and headers.
352
+ install (TARGETS ${INSTALL_TARGETS} EXPORT ${targets_export_name}
353
+ LIBRARY DESTINATION ${FMT_LIB_DIR}
354
+ ARCHIVE DESTINATION ${FMT_LIB_DIR}
355
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
356
+
297
357
# Use a namespace because CMake provides better diagnostics for namespaced
298
358
# imported targets.
299
359
export (TARGETS ${INSTALL_TARGETS} NAMESPACE fmt::
@@ -306,12 +366,6 @@ if (FMT_INSTALL)
306
366
install (EXPORT ${targets_export_name} DESTINATION ${FMT_CMAKE_DIR}
307
367
NAMESPACE fmt::)
308
368
309
- # Install the library and headers.
310
- install (TARGETS ${INSTALL_TARGETS} EXPORT ${targets_export_name}
311
- LIBRARY DESTINATION ${FMT_LIB_DIR}
312
- ARCHIVE DESTINATION ${FMT_LIB_DIR}
313
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
314
-
315
369
install (FILES $<TARGET_PDB_FILE:${INSTALL_TARGETS} >
316
370
DESTINATION ${FMT_LIB_DIR} OPTIONAL )
317
371
install (FILES ${FMT_HEADERS} DESTINATION "${FMT_INC_DIR} /fmt" )
@@ -340,7 +394,7 @@ if (FMT_FUZZ)
340
394
endif ()
341
395
342
396
set (gitignore ${PROJECT_SOURCE_DIR} /.gitignore)
343
- if (MASTER_PROJECT AND EXISTS ${gitignore} )
397
+ if (FMT_MASTER_PROJECT AND EXISTS ${gitignore} )
344
398
# Get the list of ignored files from .gitignore.
345
399
file (STRINGS ${gitignore} lines)
346
400
list (REMOVE_ITEM lines /doc /html)
0 commit comments