Skip to content

Commit cf3e495

Browse files
committed
Upgrade to fmtlib 8.1.1
1 parent 4e55000 commit cf3e495

33 files changed

+9491
-6237
lines changed

3rdparty/fmt_/CMakeLists.txt

+81-27
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,34 @@ endif()
77

88
# Determine if fmt is built as a subproject (using add_subdirectory)
99
# 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 ()
1416
endif ()
1517

1618
# Joins arguments and places the results in ${result_var}.
1719
function(join result_var)
18-
set(result )
20+
set(result "")
1921
foreach (arg ${ARGN})
2022
set(result "${result}${arg}")
2123
endforeach ()
2224
set(${result_var} "${result}" PARENT_SCOPE)
2325
endfunction()
2426

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+
2538
include(CMakeParseArguments)
2639

2740
# Sets a cache variable with a docstring joined from multiple arguments:
@@ -44,7 +57,7 @@ endfunction()
4457
# Set the default CMAKE_BUILD_TYPE to Release.
4558
# This should be done before the project command since the latter can set
4659
# 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)
4861
set_verbose(CMAKE_BUILD_TYPE Release CACHE STRING
4962
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or "
5063
"CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
@@ -61,12 +74,33 @@ option(FMT_WERROR "Halt the compilation with an error on compiler warnings."
6174
OFF)
6275

6376
# 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})
6780
option(FMT_FUZZ "Generate the fuzz target." OFF)
6881
option(FMT_CUDA_TEST "Generate the cuda-test target." OFF)
6982
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 ()
70104

71105
# Get version from core.h
72106
file(READ include/fmt/core.h core_h)
@@ -102,6 +136,18 @@ if (${index} GREATER -1)
102136
endif ()
103137
message(STATUS "Required features: ${FMT_REQUIRED_FEATURES}")
104138

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+
105151
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
106152
set(PEDANTIC_COMPILE_FLAGS -pedantic-errors -Wall -Wextra -pedantic
107153
-Wold-style-cast -Wundef
@@ -110,16 +156,16 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
110156
-Wcast-align
111157
-Wctor-dtor-privacy -Wdisabled-optimization
112158
-Winvalid-pch -Woverloaded-virtual
113-
-Wconversion -Wswitch-enum -Wundef
159+
-Wconversion -Wundef
114160
-Wno-ctor-dtor-privacy -Wno-format-nonliteral)
115161
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}
117163
-Wno-dangling-else -Wno-unused-local-typedefs)
118164
endif ()
119165
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
120166
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wdouble-promotion
121167
-Wtrampolines -Wzero-as-null-pointer-constant -Wuseless-cast
122-
-Wvector-operation-performance -Wsized-deallocation)
168+
-Wvector-operation-performance -Wsized-deallocation -Wshadow)
123169
endif ()
124170
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
125171
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wshift-overflow=2
@@ -130,7 +176,8 @@ endif ()
130176

131177
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
132178
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)
134181
check_cxx_compiler_flag(-Wzero-as-null-pointer-constant HAS_NULLPTR_WARNING)
135182
if (HAS_NULLPTR_WARNING)
136183
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS}
@@ -144,7 +191,7 @@ if (MSVC)
144191
set(WERROR_FLAG /WX)
145192
endif ()
146193

147-
if (MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio")
194+
if (FMT_MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio")
148195
# If Microsoft SDK is installed create script run-msbuild.bat that
149196
# calls SetEnv.cmd to set up build environment and runs msbuild.
150197
# It is useful when building Visual Studio projects with the SDK
@@ -183,9 +230,12 @@ function(add_headers VAR)
183230
endfunction()
184231

185232
# 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)
189239
set(FMT_SOURCES src/format.cc src/os.cc)
190240
else()
191241
set(FMT_SOURCES src/format.cc)
@@ -199,7 +249,7 @@ if (HAVE_STRTOD_L)
199249
endif ()
200250

201251
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)
203253
if (${FMT_HAS_MBIG_OBJ})
204254
target_compile_options(fmt PUBLIC "-Wa,-mbig-obj")
205255
endif()
@@ -211,10 +261,13 @@ endif ()
211261
if (FMT_PEDANTIC)
212262
target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS})
213263
endif ()
264+
if (FMT_MODULE)
265+
enable_module(fmt)
266+
endif ()
214267

215268
target_compile_features(fmt INTERFACE ${FMT_REQUIRED_FEATURES})
216269

217-
target_include_directories(fmt PUBLIC
270+
target_include_directories(fmt ${FMT_SYSTEM_HEADERS_ATTRIBUTE} PUBLIC
218271
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
219272
$<INSTALL_INTERFACE:${FMT_INC_DIR}>)
220273

@@ -250,7 +303,7 @@ add_library(fmt::fmt-header-only ALIAS fmt-header-only)
250303
target_compile_definitions(fmt-header-only INTERFACE FMT_HEADER_ONLY=1)
251304
target_compile_features(fmt-header-only INTERFACE ${FMT_REQUIRED_FEATURES})
252305

253-
target_include_directories(fmt-header-only INTERFACE
306+
target_include_directories(fmt-header-only ${FMT_SYSTEM_HEADERS_ATTRIBUTE} INTERFACE
254307
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
255308
$<INSTALL_INTERFACE:${FMT_INC_DIR}>)
256309

@@ -294,6 +347,13 @@ if (FMT_INSTALL)
294347
INSTALL_DESTINATION ${FMT_CMAKE_DIR})
295348

296349
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+
297357
# Use a namespace because CMake provides better diagnostics for namespaced
298358
# imported targets.
299359
export(TARGETS ${INSTALL_TARGETS} NAMESPACE fmt::
@@ -306,12 +366,6 @@ if (FMT_INSTALL)
306366
install(EXPORT ${targets_export_name} DESTINATION ${FMT_CMAKE_DIR}
307367
NAMESPACE fmt::)
308368

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-
315369
install(FILES $<TARGET_PDB_FILE:${INSTALL_TARGETS}>
316370
DESTINATION ${FMT_LIB_DIR} OPTIONAL)
317371
install(FILES ${FMT_HEADERS} DESTINATION "${FMT_INC_DIR}/fmt")
@@ -340,7 +394,7 @@ if (FMT_FUZZ)
340394
endif ()
341395

342396
set(gitignore ${PROJECT_SOURCE_DIR}/.gitignore)
343-
if (MASTER_PROJECT AND EXISTS ${gitignore})
397+
if (FMT_MASTER_PROJECT AND EXISTS ${gitignore})
344398
# Get the list of ignored files from .gitignore.
345399
file (STRINGS ${gitignore} lines)
346400
list(REMOVE_ITEM lines /doc/html)

0 commit comments

Comments
 (0)