Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/fmt/CMakeLists.txt
7639 views
1
cmake_minimum_required(VERSION 3.8...3.28)
2
3
# Fallback for using newer policies on CMake <3.12.
4
if (${CMAKE_VERSION} VERSION_LESS 3.12)
5
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
6
endif ()
7
8
# Determine if fmt is built as a subproject (using add_subdirectory)
9
# or if it is the master project.
10
if (NOT DEFINED FMT_MASTER_PROJECT)
11
set(FMT_MASTER_PROJECT OFF)
12
# NOTE: source vs current_source detection is unreliable
13
# this heuristic is more generally applicable esp w.r.t FetchContent
14
if (NOT DEFINED PROJECT_NAME)
15
set(FMT_MASTER_PROJECT ON)
16
message(STATUS "CMake version: ${CMAKE_VERSION}")
17
endif ()
18
endif ()
19
20
# Joins arguments and places the results in ${result_var}.
21
function(join result_var)
22
set(result "")
23
foreach (arg ${ARGN})
24
set(result "${result}${arg}")
25
endforeach ()
26
set(${result_var} "${result}" PARENT_SCOPE)
27
endfunction()
28
29
# DEPRECATED! Should be merged into add_module_library.
30
function(enable_module target)
31
if (MSVC)
32
if(NOT CMAKE_GENERATOR STREQUAL "Ninja")
33
set(BMI_DIR "${CMAKE_CURRENT_BINARY_DIR}")
34
file(TO_NATIVE_PATH "${BMI_DIR}/${target}.ifc" BMI)
35
target_compile_options(${target}
36
PRIVATE /interface /ifcOutput ${BMI}
37
INTERFACE /reference fmt=${BMI})
38
set_target_properties(${target} PROPERTIES ADDITIONAL_CLEAN_FILES ${BMI})
39
set_source_files_properties(${BMI} PROPERTIES GENERATED ON)
40
endif()
41
endif ()
42
endfunction()
43
44
set(FMT_USE_CMAKE_MODULES FALSE)
45
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28 AND
46
CMAKE_GENERATOR STREQUAL "Ninja")
47
set(FMT_USE_CMAKE_MODULES TRUE)
48
endif ()
49
50
# Adds a library compiled with C++20 module support.
51
# `enabled` is a CMake variables that specifies if modules are enabled.
52
# If modules are disabled `add_module_library` falls back to creating a
53
# non-modular library.
54
#
55
# Usage:
56
# add_module_library(<name> [sources...] FALLBACK [sources...] [IF enabled])
57
function(add_module_library name)
58
cmake_parse_arguments(AML "" "IF" "FALLBACK" ${ARGN})
59
set(sources ${AML_UNPARSED_ARGUMENTS})
60
61
add_library(${name})
62
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX)
63
64
if (NOT ${${AML_IF}})
65
# Create a non-modular library.
66
target_sources(${name} PRIVATE ${AML_FALLBACK})
67
set_target_properties(${name} PROPERTIES CXX_SCAN_FOR_MODULES OFF)
68
return()
69
endif ()
70
71
# Modules require C++20.
72
target_compile_features(${name} PUBLIC cxx_std_20)
73
if (CMAKE_COMPILER_IS_GNUCXX)
74
target_compile_options(${name} PUBLIC -fmodules-ts)
75
endif ()
76
77
if (FMT_USE_CMAKE_MODULES)
78
target_sources(${name} PUBLIC FILE_SET fmt TYPE CXX_MODULES
79
FILES ${sources})
80
else()
81
# `std` is affected by CMake options and may be higher than C++20.
82
get_target_property(std ${name} CXX_STANDARD)
83
84
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
85
set(pcms)
86
foreach (src ${sources})
87
get_filename_component(pcm ${src} NAME_WE)
88
set(pcm ${pcm}.pcm)
89
90
# Propagate -fmodule-file=*.pcm to targets that link with this library.
91
target_compile_options(
92
${name} PUBLIC -fmodule-file=${CMAKE_CURRENT_BINARY_DIR}/${pcm})
93
94
# Use an absolute path to prevent target_link_libraries prepending -l
95
# to it.
96
set(pcms ${pcms} ${CMAKE_CURRENT_BINARY_DIR}/${pcm})
97
add_custom_command(
98
OUTPUT ${pcm}
99
COMMAND ${CMAKE_CXX_COMPILER}
100
-std=c++${std} -x c++-module --precompile -c
101
-o ${pcm} ${CMAKE_CURRENT_SOURCE_DIR}/${src}
102
"-I$<JOIN:$<TARGET_PROPERTY:${name},INCLUDE_DIRECTORIES>,;-I>"
103
# Required by the -I generator expression above.
104
COMMAND_EXPAND_LISTS
105
DEPENDS ${src})
106
endforeach ()
107
108
# Add .pcm files as sources to make sure they are built before the library.
109
set(sources)
110
foreach (pcm ${pcms})
111
get_filename_component(pcm_we ${pcm} NAME_WE)
112
set(obj ${pcm_we}.o)
113
# Use an absolute path to prevent target_link_libraries prepending -l.
114
set(sources ${sources} ${pcm} ${CMAKE_CURRENT_BINARY_DIR}/${obj})
115
add_custom_command(
116
OUTPUT ${obj}
117
COMMAND ${CMAKE_CXX_COMPILER} $<TARGET_PROPERTY:${name},COMPILE_OPTIONS>
118
-c -o ${obj} ${pcm}
119
DEPENDS ${pcm})
120
endforeach ()
121
endif ()
122
target_sources(${name} PRIVATE ${sources})
123
endif()
124
endfunction()
125
126
include(CMakeParseArguments)
127
128
# Sets a cache variable with a docstring joined from multiple arguments:
129
# set(<variable> <value>... CACHE <type> <docstring>...)
130
# This allows splitting a long docstring for readability.
131
function(set_verbose)
132
# cmake_parse_arguments is broken in CMake 3.4 (cannot parse CACHE) so use
133
# list instead.
134
list(GET ARGN 0 var)
135
list(REMOVE_AT ARGN 0)
136
list(GET ARGN 0 val)
137
list(REMOVE_AT ARGN 0)
138
list(REMOVE_AT ARGN 0)
139
list(GET ARGN 0 type)
140
list(REMOVE_AT ARGN 0)
141
join(doc ${ARGN})
142
set(${var} ${val} CACHE ${type} ${doc})
143
endfunction()
144
145
# Set the default CMAKE_BUILD_TYPE to Release.
146
# This should be done before the project command since the latter can set
147
# CMAKE_BUILD_TYPE itself (it does so for nmake).
148
if (FMT_MASTER_PROJECT AND NOT CMAKE_BUILD_TYPE)
149
set_verbose(CMAKE_BUILD_TYPE Release CACHE STRING
150
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or "
151
"CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
152
endif ()
153
154
project(FMT CXX)
155
include(GNUInstallDirs)
156
set_verbose(FMT_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE STRING
157
"Installation directory for include files, a relative path that "
158
"will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute path.")
159
160
option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF)
161
option(FMT_WERROR "Halt the compilation with an error on compiler warnings."
162
OFF)
163
164
# Options that control generation of various targets.
165
option(FMT_DOC "Generate the doc target." ${FMT_MASTER_PROJECT})
166
option(FMT_INSTALL "Generate the install target." ${FMT_MASTER_PROJECT})
167
option(FMT_TEST "Generate the test target." ${FMT_MASTER_PROJECT})
168
option(FMT_FUZZ "Generate the fuzz target." OFF)
169
option(FMT_CUDA_TEST "Generate the cuda-test target." OFF)
170
option(FMT_OS "Include OS-specific APIs." ON)
171
option(FMT_MODULE "Build a module instead of a traditional library." OFF)
172
option(FMT_SYSTEM_HEADERS "Expose headers with marking them as system." OFF)
173
option(FMT_UNICODE "Enable Unicode support." ON)
174
175
if (FMT_TEST AND FMT_MODULE)
176
# The tests require {fmt} to be compiled as traditional library
177
message(STATUS "Testing is incompatible with build mode 'module'.")
178
endif ()
179
set(FMT_SYSTEM_HEADERS_ATTRIBUTE "")
180
if (FMT_SYSTEM_HEADERS)
181
set(FMT_SYSTEM_HEADERS_ATTRIBUTE SYSTEM)
182
endif ()
183
if (CMAKE_SYSTEM_NAME STREQUAL "MSDOS")
184
set(FMT_TEST OFF)
185
message(STATUS "MSDOS is incompatible with gtest")
186
endif ()
187
188
# Get version from base.h
189
file(READ include/fmt/base.h base_h)
190
if (NOT base_h MATCHES "FMT_VERSION ([0-9]+)([0-9][0-9])([0-9][0-9])")
191
message(FATAL_ERROR "Cannot get FMT_VERSION from base.h.")
192
endif ()
193
# Use math to skip leading zeros if any.
194
math(EXPR CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
195
math(EXPR CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
196
math(EXPR CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
197
join(FMT_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.
198
${CPACK_PACKAGE_VERSION_PATCH})
199
message(STATUS "{fmt} version: ${FMT_VERSION}")
200
201
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
202
203
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
204
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
205
endif ()
206
207
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/support/cmake")
208
209
include(CheckCXXCompilerFlag)
210
include(JoinPaths)
211
212
if (FMT_MASTER_PROJECT AND NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
213
set_verbose(CMAKE_CXX_VISIBILITY_PRESET hidden CACHE STRING
214
"Preset for the export of private symbols")
215
set_property(CACHE CMAKE_CXX_VISIBILITY_PRESET PROPERTY STRINGS
216
hidden default)
217
endif ()
218
219
if (FMT_MASTER_PROJECT AND NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)
220
set_verbose(CMAKE_VISIBILITY_INLINES_HIDDEN ON CACHE BOOL
221
"Whether to add a compile flag to hide symbols of inline functions")
222
endif ()
223
224
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
225
set(PEDANTIC_COMPILE_FLAGS -pedantic-errors -Wall -Wextra -pedantic
226
-Wold-style-cast -Wundef
227
-Wredundant-decls -Wwrite-strings -Wpointer-arith
228
-Wcast-qual -Wformat=2 -Wmissing-include-dirs
229
-Wcast-align
230
-Wctor-dtor-privacy -Wdisabled-optimization
231
-Winvalid-pch -Woverloaded-virtual
232
-Wconversion -Wundef
233
-Wno-ctor-dtor-privacy -Wno-format-nonliteral)
234
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
235
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS}
236
-Wno-dangling-else -Wno-unused-local-typedefs)
237
endif ()
238
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
239
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wdouble-promotion
240
-Wtrampolines -Wzero-as-null-pointer-constant -Wuseless-cast
241
-Wvector-operation-performance -Wsized-deallocation -Wshadow)
242
endif ()
243
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
244
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wshift-overflow=2
245
-Wduplicated-cond)
246
# Workaround for GCC regression
247
# [12/13/14/15 regression] New (since gcc 12) false positive null-dereference in vector.resize
248
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108860
249
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0)
250
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wnull-dereference)
251
endif ()
252
endif ()
253
set(WERROR_FLAG -Werror)
254
endif ()
255
256
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
257
set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -pedantic -Wconversion -Wundef
258
-Wdeprecated -Wweak-vtables -Wshadow
259
-Wno-gnu-zero-variadic-macro-arguments)
260
check_cxx_compiler_flag(-Wzero-as-null-pointer-constant HAS_NULLPTR_WARNING)
261
if (HAS_NULLPTR_WARNING)
262
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS}
263
-Wzero-as-null-pointer-constant)
264
endif ()
265
set(WERROR_FLAG -Werror)
266
endif ()
267
268
if (MSVC)
269
set(PEDANTIC_COMPILE_FLAGS /W3)
270
set(WERROR_FLAG /WX)
271
endif ()
272
273
if (FMT_MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio")
274
# If Microsoft SDK is installed create script run-msbuild.bat that
275
# calls SetEnv.cmd to set up build environment and runs msbuild.
276
# It is useful when building Visual Studio projects with the SDK
277
# toolchain rather than Visual Studio.
278
include(FindSetEnv)
279
if (WINSDK_SETENV)
280
set(MSBUILD_SETUP "call \"${WINSDK_SETENV}\"")
281
endif ()
282
# Set FrameworkPathOverride to get rid of MSB3644 warnings.
283
join(netfxpath
284
"C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\"
285
".NETFramework\\v4.0")
286
file(WRITE run-msbuild.bat "
287
${MSBUILD_SETUP}
288
${CMAKE_MAKE_PROGRAM} -p:FrameworkPathOverride=\"${netfxpath}\" %*")
289
endif ()
290
291
function(add_headers VAR)
292
set(headers ${${VAR}})
293
foreach (header ${ARGN})
294
set(headers ${headers} include/fmt/${header})
295
endforeach()
296
set(${VAR} ${headers} PARENT_SCOPE)
297
endfunction()
298
299
# Define the fmt library, its includes and the needed defines.
300
set(FMT_HEADERS)
301
add_headers(FMT_HEADERS args.h base.h chrono.h color.h compile.h core.h format.h
302
format-inl.h os.h ostream.h printf.h ranges.h std.h
303
xchar.h)
304
set(FMT_SOURCES src/format.cc)
305
306
add_module_library(fmt src/fmt.cc FALLBACK
307
${FMT_SOURCES} ${FMT_HEADERS} README.md ChangeLog.md
308
IF FMT_MODULE)
309
add_library(fmt::fmt ALIAS fmt)
310
if (FMT_MODULE)
311
enable_module(fmt)
312
elseif (FMT_OS)
313
target_sources(fmt PRIVATE src/os.cc)
314
else()
315
target_compile_definitions(fmt PRIVATE FMT_OS=0)
316
endif ()
317
318
if (FMT_WERROR)
319
target_compile_options(fmt PRIVATE ${WERROR_FLAG})
320
endif ()
321
if (FMT_PEDANTIC)
322
target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS})
323
endif ()
324
325
if (cxx_std_11 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
326
target_compile_features(fmt PUBLIC cxx_std_11)
327
else ()
328
message(WARNING "Feature cxx_std_11 is unknown for the CXX compiler")
329
endif ()
330
331
target_include_directories(fmt ${FMT_SYSTEM_HEADERS_ATTRIBUTE} BEFORE PUBLIC
332
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
333
$<INSTALL_INTERFACE:${FMT_INC_DIR}>)
334
335
set(FMT_DEBUG_POSTFIX d CACHE STRING "Debug library postfix.")
336
337
set_target_properties(fmt PROPERTIES
338
VERSION ${FMT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}
339
PUBLIC_HEADER "${FMT_HEADERS}"
340
DEBUG_POSTFIX "${FMT_DEBUG_POSTFIX}"
341
342
# Workaround for Visual Studio 2017:
343
# Ensure the .pdb is created with the same name and in the same directory
344
# as the .lib. Newer VS versions already do this by default, but there is no
345
# harm in setting it for those too. Ignored by other generators.
346
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
347
COMPILE_PDB_NAME "fmt"
348
COMPILE_PDB_NAME_DEBUG "fmt${FMT_DEBUG_POSTFIX}")
349
350
# Set FMT_LIB_NAME for pkg-config fmt.pc. We cannot use the OUTPUT_NAME target
351
# property because it's not set by default.
352
set(FMT_LIB_NAME fmt)
353
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
354
set(FMT_LIB_NAME ${FMT_LIB_NAME}${FMT_DEBUG_POSTFIX})
355
endif ()
356
357
if (BUILD_SHARED_LIBS)
358
target_compile_definitions(fmt PRIVATE FMT_LIB_EXPORT INTERFACE FMT_SHARED)
359
endif ()
360
if (FMT_SAFE_DURATION_CAST)
361
target_compile_definitions(fmt PUBLIC FMT_SAFE_DURATION_CAST)
362
endif ()
363
364
add_library(fmt-header-only INTERFACE)
365
add_library(fmt::fmt-header-only ALIAS fmt-header-only)
366
367
if (NOT MSVC)
368
# Unicode is always supported on compilers other than MSVC.
369
elseif (FMT_UNICODE)
370
# Unicode support requires compiling with /utf-8.
371
target_compile_options(fmt PUBLIC $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/utf-8>)
372
target_compile_options(fmt-header-only INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/utf-8>)
373
else ()
374
target_compile_definitions(fmt PUBLIC FMT_UNICODE=0)
375
endif ()
376
377
target_compile_definitions(fmt-header-only INTERFACE FMT_HEADER_ONLY=1)
378
target_compile_features(fmt-header-only INTERFACE cxx_std_11)
379
380
target_include_directories(fmt-header-only
381
${FMT_SYSTEM_HEADERS_ATTRIBUTE} BEFORE INTERFACE
382
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
383
$<INSTALL_INTERFACE:${FMT_INC_DIR}>)
384
385
# Install targets.
386
if (FMT_INSTALL)
387
include(CMakePackageConfigHelpers)
388
set_verbose(FMT_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/fmt CACHE STRING
389
"Installation directory for cmake files, a relative path that "
390
"will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute "
391
"path.")
392
set(version_config ${PROJECT_BINARY_DIR}/fmt-config-version.cmake)
393
set(project_config ${PROJECT_BINARY_DIR}/fmt-config.cmake)
394
set(pkgconfig ${PROJECT_BINARY_DIR}/fmt.pc)
395
set(targets_export_name fmt-targets)
396
397
set_verbose(FMT_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING
398
"Installation directory for libraries, a relative path that "
399
"will be joined to ${CMAKE_INSTALL_PREFIX} or an absolute path.")
400
401
set_verbose(FMT_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig CACHE STRING
402
"Installation directory for pkgconfig (.pc) files, a relative "
403
"path that will be joined with ${CMAKE_INSTALL_PREFIX} or an "
404
"absolute path.")
405
406
# Generate the version, config and target files into the build directory.
407
write_basic_package_version_file(
408
${version_config}
409
VERSION ${FMT_VERSION}
410
COMPATIBILITY AnyNewerVersion)
411
412
join_paths(libdir_for_pc_file "\${exec_prefix}" "${FMT_LIB_DIR}")
413
join_paths(includedir_for_pc_file "\${prefix}" "${FMT_INC_DIR}")
414
415
configure_file(
416
"${PROJECT_SOURCE_DIR}/support/cmake/fmt.pc.in"
417
"${pkgconfig}"
418
@ONLY)
419
configure_package_config_file(
420
${PROJECT_SOURCE_DIR}/support/cmake/fmt-config.cmake.in
421
${project_config}
422
INSTALL_DESTINATION ${FMT_CMAKE_DIR})
423
424
set(INSTALL_TARGETS fmt fmt-header-only)
425
426
set(INSTALL_FILE_SET)
427
if (FMT_USE_CMAKE_MODULES)
428
set(INSTALL_FILE_SET FILE_SET fmt DESTINATION "${FMT_INC_DIR}/fmt")
429
endif()
430
431
# Install the library and headers.
432
install(TARGETS ${INSTALL_TARGETS}
433
COMPONENT fmt_core
434
EXPORT ${targets_export_name}
435
LIBRARY DESTINATION ${FMT_LIB_DIR}
436
ARCHIVE DESTINATION ${FMT_LIB_DIR}
437
PUBLIC_HEADER DESTINATION "${FMT_INC_DIR}/fmt"
438
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
439
${INSTALL_FILE_SET})
440
441
# Use a namespace because CMake provides better diagnostics for namespaced
442
# imported targets.
443
export(TARGETS ${INSTALL_TARGETS} NAMESPACE fmt::
444
FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
445
446
# Install version, config and target files.
447
install(FILES ${project_config} ${version_config}
448
DESTINATION ${FMT_CMAKE_DIR}
449
COMPONENT fmt_core)
450
install(EXPORT ${targets_export_name} DESTINATION ${FMT_CMAKE_DIR}
451
NAMESPACE fmt::
452
COMPONENT fmt_core)
453
454
install(FILES "${pkgconfig}" DESTINATION "${FMT_PKGCONFIG_DIR}"
455
COMPONENT fmt_core)
456
endif ()
457
458
function(add_doc_target)
459
find_program(DOXYGEN doxygen
460
PATHS "$ENV{ProgramFiles}/doxygen/bin"
461
"$ENV{ProgramFiles\(x86\)}/doxygen/bin")
462
if (NOT DOXYGEN)
463
message(STATUS "Target 'doc' disabled because doxygen not found")
464
return ()
465
endif ()
466
467
find_program(MKDOCS mkdocs)
468
if (NOT MKDOCS)
469
message(STATUS "Target 'doc' disabled because mkdocs not found")
470
return ()
471
endif ()
472
473
set(sources )
474
foreach (source api.md index.md syntax.md get-started.md fmt.css fmt.js)
475
set(sources ${sources} doc/${source})
476
endforeach()
477
478
add_custom_target(
479
doc
480
COMMAND
481
${CMAKE_COMMAND}
482
-E env PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/support/python
483
${MKDOCS} build -f ${CMAKE_CURRENT_SOURCE_DIR}/support/mkdocs.yml
484
# MkDocs requires the site dir to be outside of the doc dir.
485
--site-dir ${CMAKE_CURRENT_BINARY_DIR}/doc-html
486
--no-directory-urls
487
SOURCES ${sources})
488
489
include(GNUInstallDirs)
490
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc-html/
491
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/fmt
492
COMPONENT fmt_doc OPTIONAL)
493
endfunction()
494
495
if (FMT_DOC)
496
add_doc_target()
497
endif ()
498
499
if (FMT_TEST)
500
enable_testing()
501
add_subdirectory(test)
502
endif ()
503
504
# Control fuzzing independent of the unit tests.
505
if (FMT_FUZZ)
506
add_subdirectory(test/fuzzing)
507
508
# The FMT_FUZZ macro is used to prevent resource exhaustion in fuzzing
509
# mode and make fuzzing practically possible. It is similar to
510
# FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION but uses a different name to
511
# avoid interfering with fuzzing of projects that use {fmt}.
512
# See also https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode.
513
target_compile_definitions(fmt PUBLIC FMT_FUZZ)
514
endif ()
515
516
set(gitignore ${PROJECT_SOURCE_DIR}/.gitignore)
517
if (FMT_MASTER_PROJECT AND EXISTS ${gitignore})
518
# Get the list of ignored files from .gitignore.
519
file (STRINGS ${gitignore} lines)
520
list(REMOVE_ITEM lines /doc/html)
521
foreach (line ${lines})
522
string(REPLACE "." "[.]" line "${line}")
523
string(REPLACE "*" ".*" line "${line}")
524
set(ignored_files ${ignored_files} "${line}$" "${line}/")
525
endforeach ()
526
set(ignored_files ${ignored_files} /.git /build/doxyxml .vagrant)
527
528
set(CPACK_SOURCE_GENERATOR ZIP)
529
set(CPACK_SOURCE_IGNORE_FILES ${ignored_files})
530
set(CPACK_SOURCE_PACKAGE_FILE_NAME fmt-${FMT_VERSION})
531
set(CPACK_PACKAGE_NAME fmt)
532
set(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README.md)
533
include(CPack)
534
endif ()
535
536