1
- cmake_minimum_required (VERSION 3.1...3.18 )
1
+ cmake_minimum_required (VERSION 3.1.0 )
2
2
3
- # Fallback for using newer policies on CMake <3.12 .
4
- if (${CMAKE_VERSION} VERSION_LESS 3.12 )
3
+ # Use newer policies if available, up to most recent tested version of CMake .
4
+ if (${CMAKE_VERSION} VERSION_LESS 3.11 )
5
5
cmake_policy (VERSION ${CMAKE_MAJOR_VERSION} .${CMAKE_MINOR_VERSION} )
6
+ else ()
7
+ cmake_policy (VERSION 3.11 )
6
8
endif ()
7
9
8
10
# Determine if fmt is built as a subproject (using add_subdirectory)
9
11
# or if it is the master project.
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 ()
12
+ set (MASTER_PROJECT OFF )
13
+ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR )
14
+ set (MASTER_PROJECT ON )
15
+ message (STATUS "CMake version: ${CMAKE_VERSION} " )
16
16
endif ()
17
17
18
18
# Joins arguments and places the results in ${result_var}.
19
19
function (join result_var )
20
- set (result "" )
20
+ set (result )
21
21
foreach (arg ${ARGN} )
22
22
set (result "${result}${arg} " )
23
23
endforeach ()
24
24
set (${result_var} "${result} " PARENT_SCOPE )
25
25
endfunction ()
26
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
-
38
27
include (CMakeParseArguments )
39
28
40
29
# Sets a cache variable with a docstring joined from multiple arguments:
@@ -57,7 +46,7 @@ endfunction()
57
46
# Set the default CMAKE_BUILD_TYPE to Release.
58
47
# This should be done before the project command since the latter can set
59
48
# CMAKE_BUILD_TYPE itself (it does so for nmake).
60
- if (FMT_MASTER_PROJECT AND NOT CMAKE_BUILD_TYPE )
49
+ if (MASTER_PROJECT AND NOT CMAKE_BUILD_TYPE )
61
50
set_verbose (CMAKE_BUILD_TYPE Release CACHE STRING
62
51
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or "
63
52
"CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." )
@@ -66,41 +55,20 @@ endif ()
66
55
project (FMT CXX )
67
56
include (GNUInstallDirs )
68
57
set_verbose (FMT_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE STRING
69
- "Installation directory for include files, a relative path that "
70
- "will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute path." )
58
+ "Installation directory for include files, a relative path "
59
+ "that will be joined to ${CMAKE_INSTALL_PREFIX} , or an arbitrary absolute path." )
71
60
72
61
option (FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF )
73
62
option (FMT_WERROR "Halt the compilation with an error on compiler warnings."
74
63
OFF )
75
64
76
65
# Options that control generation of various targets.
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 } )
66
+ option (FMT_DOC "Generate the doc target." ${MASTER_PROJECT } )
67
+ option (FMT_INSTALL "Generate the install target." ${MASTER_PROJECT } )
68
+ option (FMT_TEST "Generate the test target." ${MASTER_PROJECT } )
80
69
option (FMT_FUZZ "Generate the fuzz target." OFF )
81
70
option (FMT_CUDA_TEST "Generate the cuda-test target." OFF )
82
71
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 ()
104
72
105
73
# Get version from core.h
106
74
file (READ include /fmt/core.h core_h )
@@ -136,36 +104,24 @@ if (${index} GREATER -1)
136
104
endif ()
137
105
message (STATUS "Required features: ${FMT_REQUIRED_FEATURES} " )
138
106
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
-
151
107
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
152
108
set (PEDANTIC_COMPILE_FLAGS -pedantic-errors -Wall -Wextra -pedantic
153
109
-Wold-style-cast -Wundef
154
110
-Wredundant-decls -Wwrite-strings -Wpointer-arith
155
111
-Wcast-qual -Wformat=2 -Wmissing-include-dirs
156
- -Wcast-align
112
+ -Wcast-align -Wnon-virtual-dtor
157
113
-Wctor-dtor-privacy -Wdisabled-optimization
158
114
-Winvalid-pch -Woverloaded-virtual
159
- -Wconversion -Wundef
160
- -Wno-ctor-dtor-privacy -Wno-format-nonliteral )
115
+ -Wconversion -Wswitch-enum
116
+ -Wno-ctor-dtor-privacy -Wno-format-nonliteral -Wno-shadow )
161
117
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6 )
162
- set (PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS}
118
+ set (PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wnoexcept
163
119
-Wno-dangling-else -Wno-unused-local-typedefs )
164
120
endif ()
165
121
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0 )
166
122
set (PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wdouble-promotion
167
123
-Wtrampolines -Wzero-as-null-pointer-constant -Wuseless-cast
168
- -Wvector-operation-performance -Wsized-deallocation -Wshadow )
124
+ -Wvector-operation-performance -Wsized-deallocation )
169
125
endif ()
170
126
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0 )
171
127
set (PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wshift-overflow=2
@@ -175,9 +131,8 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
175
131
endif ()
176
132
177
133
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
178
- set (PEDANTIC_COMPILE_FLAGS -Wall -Wextra -pedantic -Wconversion -Wundef
179
- -Wdeprecated -Wweak-vtables -Wshadow
180
- -Wno-gnu-zero-variadic-macro-arguments )
134
+ set (PEDANTIC_COMPILE_FLAGS -Wall -Wextra -pedantic -Wconversion
135
+ -Wno-sign-conversion -Wdeprecated -Wweak-vtables )
181
136
check_cxx_compiler_flag (-Wzero-as-null-pointer-constant HAS_NULLPTR_WARNING )
182
137
if (HAS_NULLPTR_WARNING )
183
138
set (PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS}
@@ -191,7 +146,7 @@ if (MSVC)
191
146
set (WERROR_FLAG /WX )
192
147
endif ()
193
148
194
- if (FMT_MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio" )
149
+ if (MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio" )
195
150
# If Microsoft SDK is installed create script run-msbuild.bat that
196
151
# calls SetEnv.cmd to set up build environment and runs msbuild.
197
152
# It is useful when building Visual Studio projects with the SDK
@@ -230,12 +185,9 @@ function(add_headers VAR)
230
185
endfunction ()
231
186
232
187
# Define the fmt library, its includes and the needed defines.
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 )
188
+ add_headers (FMT_HEADERS chrono.h color.h compile.h core.h format.h format-inl.h
189
+ locale.h os.h ostream.h posix.h printf.h ranges.h )
190
+ if (FMT_OS )
239
191
set (FMT_SOURCES src/format.cc src/os.cc )
240
192
else ()
241
193
set (FMT_SOURCES src/format.cc )
@@ -249,10 +201,7 @@ if (HAVE_STRTOD_L)
249
201
endif ()
250
202
251
203
if (MINGW )
252
- check_cxx_compiler_flag ("-Wa,-mbig-obj" FMT_HAS_MBIG_OBJ )
253
- if (${FMT_HAS_MBIG_OBJ} )
254
- target_compile_options (fmt PUBLIC "-Wa,-mbig-obj" )
255
- endif ()
204
+ target_compile_options (fmt PUBLIC "-Wa,-mbig-obj" )
256
205
endif ()
257
206
258
207
if (FMT_WERROR )
@@ -261,13 +210,10 @@ endif ()
261
210
if (FMT_PEDANTIC )
262
211
target_compile_options (fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS} )
263
212
endif ()
264
- if (FMT_MODULE )
265
- enable_module (fmt )
266
- endif ()
267
213
268
214
target_compile_features (fmt INTERFACE ${FMT_REQUIRED_FEATURES} )
269
215
270
- target_include_directories (fmt ${FMT_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC
216
+ target_include_directories (fmt PUBLIC
271
217
$< BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include>
272
218
$< INSTALL_INTERFACE:${FMT_INC_DIR} > )
273
219
@@ -285,8 +231,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
285
231
endif ()
286
232
287
233
if (BUILD_SHARED_LIBS )
288
- if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND
289
- NOT EMSCRIPTEN )
234
+ if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND NOT EMSCRIPTEN )
290
235
# Fix rpmlint warning:
291
236
# unused-direct-shlib-dependency /usr/lib/libformat.so.1.1.0 /lib/libm.so.6.
292
237
target_link_libraries (fmt -Wl,--as-needed )
@@ -303,30 +248,28 @@ add_library(fmt::fmt-header-only ALIAS fmt-header-only)
303
248
target_compile_definitions (fmt-header-only INTERFACE FMT_HEADER_ONLY=1 )
304
249
target_compile_features (fmt-header-only INTERFACE ${FMT_REQUIRED_FEATURES} )
305
250
306
- target_include_directories (fmt-header-only ${FMT_SYSTEM_HEADERS_ATTRIBUTE} INTERFACE
251
+ target_include_directories (fmt-header-only INTERFACE
307
252
$< BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include>
308
253
$< INSTALL_INTERFACE:${FMT_INC_DIR} > )
309
254
310
255
# Install targets.
311
256
if (FMT_INSTALL )
312
257
include (CMakePackageConfigHelpers )
313
258
set_verbose (FMT_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR} /cmake/fmt CACHE STRING
314
- "Installation directory for cmake files, a relative path that "
315
- "will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute "
316
- "path." )
259
+ "Installation directory for cmake files, a relative path "
260
+ "that will be joined to ${CMAKE_INSTALL_PREFIX} , or an arbitrary absolute path." )
317
261
set (version_config ${PROJECT_BINARY_DIR} /fmt-config-version.cmake )
318
262
set (project_config ${PROJECT_BINARY_DIR} /fmt-config.cmake )
319
263
set (pkgconfig ${PROJECT_BINARY_DIR} /fmt.pc )
320
264
set (targets_export_name fmt-targets )
321
265
322
266
set_verbose (FMT_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING
323
- "Installation directory for libraries, a relative path that "
324
- "will be joined to ${CMAKE_INSTALL_PREFIX} or an absolute path." )
267
+ "Installation directory for libraries, a relative path "
268
+ "that will be joined to ${CMAKE_INSTALL_PREFIX} , or an arbitrary absolute path." )
325
269
326
270
set_verbose (FMT_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR} /pkgconfig CACHE PATH
327
- "Installation directory for pkgconfig (.pc) files, a relative "
328
- "path that will be joined with ${CMAKE_INSTALL_PREFIX} or an "
329
- "absolute path." )
271
+ "Installation directory for pkgconfig (.pc) files, a relative path "
272
+ "that will be joined to ${CMAKE_INSTALL_PREFIX} , or an arbitrary absolute path." )
330
273
331
274
# Generate the version, config and target files into the build directory.
332
275
write_basic_package_version_file (
@@ -347,13 +290,6 @@ if (FMT_INSTALL)
347
290
INSTALL_DESTINATION ${FMT_CMAKE_DIR} )
348
291
349
292
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
-
357
293
# Use a namespace because CMake provides better diagnostics for namespaced
358
294
# imported targets.
359
295
export (TARGETS ${INSTALL_TARGETS} NAMESPACE fmt::
@@ -366,6 +302,12 @@ if (FMT_INSTALL)
366
302
install (EXPORT ${targets_export_name} DESTINATION ${FMT_CMAKE_DIR}
367
303
NAMESPACE fmt:: )
368
304
305
+ # Install the library and headers.
306
+ install (TARGETS ${INSTALL_TARGETS} EXPORT ${targets_export_name}
307
+ LIBRARY DESTINATION ${FMT_LIB_DIR}
308
+ ARCHIVE DESTINATION ${FMT_LIB_DIR}
309
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
310
+
369
311
install (FILES $< TARGET_PDB_FILE:${INSTALL_TARGETS} >
370
312
DESTINATION ${FMT_LIB_DIR} OPTIONAL )
371
313
install (FILES ${FMT_HEADERS} DESTINATION "${FMT_INC_DIR} /fmt" )
@@ -384,17 +326,11 @@ endif ()
384
326
# Control fuzzing independent of the unit tests.
385
327
if (FMT_FUZZ )
386
328
add_subdirectory (test /fuzzing )
387
-
388
- # The FMT_FUZZ macro is used to prevent resource exhaustion in fuzzing
389
- # mode and make fuzzing practically possible. It is similar to
390
- # FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION but uses a different name to
391
- # avoid interfering with fuzzing of projects that use {fmt}.
392
- # See also https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode.
393
329
target_compile_definitions (fmt PUBLIC FMT_FUZZ )
394
330
endif ()
395
331
396
332
set (gitignore ${PROJECT_SOURCE_DIR} /.gitignore )
397
- if (FMT_MASTER_PROJECT AND EXISTS ${gitignore} )
333
+ if (MASTER_PROJECT AND EXISTS ${gitignore} )
398
334
# Get the list of ignored files from .gitignore.
399
335
file (STRINGS ${gitignore} lines )
400
336
list (REMOVE_ITEM lines /doc/html )
0 commit comments