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