Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/fmt/CMakeLists.txt
4243 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
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
209
"${CMAKE_CURRENT_SOURCE_DIR}/support/cmake")
210
211
include(CheckCXXCompilerFlag)
212
include(JoinPaths)
213
214
if (FMT_MASTER_PROJECT AND NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
215
set_verbose(CMAKE_CXX_VISIBILITY_PRESET hidden CACHE STRING
216
"Preset for the export of private symbols")
217
set_property(CACHE CMAKE_CXX_VISIBILITY_PRESET PROPERTY STRINGS
218
hidden default)
219
endif ()
220
221
if (FMT_MASTER_PROJECT AND NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)
222
set_verbose(CMAKE_VISIBILITY_INLINES_HIDDEN ON CACHE BOOL
223
"Whether to add a compile flag to hide symbols of inline functions")
224
endif ()
225
226
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
227
set(PEDANTIC_COMPILE_FLAGS -pedantic-errors -Wall -Wextra -pedantic
228
-Wold-style-cast -Wundef
229
-Wredundant-decls -Wwrite-strings -Wpointer-arith
230
-Wcast-qual -Wformat=2 -Wmissing-include-dirs
231
-Wcast-align
232
-Wctor-dtor-privacy -Wdisabled-optimization
233
-Winvalid-pch -Woverloaded-virtual
234
-Wconversion -Wundef
235
-Wno-ctor-dtor-privacy -Wno-format-nonliteral)
236
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6)
237
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS}
238
-Wno-dangling-else -Wno-unused-local-typedefs)
239
endif ()
240
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
241
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wdouble-promotion
242
-Wtrampolines -Wzero-as-null-pointer-constant -Wuseless-cast
243
-Wvector-operation-performance -Wsized-deallocation -Wshadow)
244
endif ()
245
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
246
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wshift-overflow=2
247
-Wduplicated-cond)
248
# Workaround for GCC regression
249
# [12/13/14/15 regression] New (since gcc 12) false positive null-dereference in vector.resize
250
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108860
251
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0)
252
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wnull-dereference)
253
endif ()
254
endif ()
255
set(WERROR_FLAG -Werror)
256
endif ()
257
258
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
259
set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -pedantic -Wconversion -Wundef
260
-Wdeprecated -Wweak-vtables -Wshadow
261
-Wno-gnu-zero-variadic-macro-arguments)
262
check_cxx_compiler_flag(-Wzero-as-null-pointer-constant HAS_NULLPTR_WARNING)
263
if (HAS_NULLPTR_WARNING)
264
set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS}
265
-Wzero-as-null-pointer-constant)
266
endif ()
267
set(WERROR_FLAG -Werror)
268
endif ()
269
270
if (MSVC)
271
set(PEDANTIC_COMPILE_FLAGS /W3)
272
set(WERROR_FLAG /WX)
273
endif ()
274
275
if (FMT_MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio")
276
# If Microsoft SDK is installed create script run-msbuild.bat that
277
# calls SetEnv.cmd to set up build environment and runs msbuild.
278
# It is useful when building Visual Studio projects with the SDK
279
# toolchain rather than Visual Studio.
280
include(FindSetEnv)
281
if (WINSDK_SETENV)
282
set(MSBUILD_SETUP "call \"${WINSDK_SETENV}\"")
283
endif ()
284
# Set FrameworkPathOverride to get rid of MSB3644 warnings.
285
join(netfxpath
286
"C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\"
287
".NETFramework\\v4.0")
288
file(WRITE run-msbuild.bat "
289
${MSBUILD_SETUP}
290
${CMAKE_MAKE_PROGRAM} -p:FrameworkPathOverride=\"${netfxpath}\" %*")
291
endif ()
292
293
function(add_headers VAR)
294
set(headers ${${VAR}})
295
foreach (header ${ARGN})
296
set(headers ${headers} include/fmt/${header})
297
endforeach()
298
set(${VAR} ${headers} PARENT_SCOPE)
299
endfunction()
300
301
# Define the fmt library, its includes and the needed defines.
302
set(FMT_HEADERS)
303
add_headers(FMT_HEADERS args.h base.h chrono.h color.h compile.h core.h format.h
304
format-inl.h os.h ostream.h printf.h ranges.h std.h
305
xchar.h)
306
set(FMT_SOURCES src/format.cc)
307
308
add_module_library(fmt src/fmt.cc FALLBACK
309
${FMT_SOURCES} ${FMT_HEADERS} README.md ChangeLog.md
310
IF FMT_MODULE)
311
add_library(fmt::fmt ALIAS fmt)
312
if (FMT_MODULE)
313
enable_module(fmt)
314
elseif (FMT_OS)
315
target_sources(fmt PRIVATE src/os.cc)
316
else()
317
target_compile_definitions(fmt PRIVATE FMT_OS=0)
318
endif ()
319
320
if (FMT_WERROR)
321
target_compile_options(fmt PRIVATE ${WERROR_FLAG})
322
endif ()
323
if (FMT_PEDANTIC)
324
target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS})
325
endif ()
326
327
if (cxx_std_11 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
328
target_compile_features(fmt PUBLIC cxx_std_11)
329
else ()
330
message(WARNING "Feature cxx_std_11 is unknown for the CXX compiler")
331
endif ()
332
333
target_include_directories(fmt ${FMT_SYSTEM_HEADERS_ATTRIBUTE} BEFORE PUBLIC
334
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
335
$<INSTALL_INTERFACE:${FMT_INC_DIR}>)
336
337
set(FMT_DEBUG_POSTFIX d CACHE STRING "Debug library postfix.")
338
339
set_target_properties(fmt PROPERTIES
340
VERSION ${FMT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}
341
PUBLIC_HEADER "${FMT_HEADERS}"
342
DEBUG_POSTFIX "${FMT_DEBUG_POSTFIX}"
343
344
# Workaround for Visual Studio 2017:
345
# Ensure the .pdb is created with the same name and in the same directory
346
# as the .lib. Newer VS versions already do this by default, but there is no
347
# harm in setting it for those too. Ignored by other generators.
348
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
349
COMPILE_PDB_NAME "fmt"
350
COMPILE_PDB_NAME_DEBUG "fmt${FMT_DEBUG_POSTFIX}")
351
352
# Set FMT_LIB_NAME for pkg-config fmt.pc. We cannot use the OUTPUT_NAME target
353
# property because it's not set by default.
354
set(FMT_LIB_NAME fmt)
355
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
356
set(FMT_LIB_NAME ${FMT_LIB_NAME}${FMT_DEBUG_POSTFIX})
357
endif ()
358
359
if (BUILD_SHARED_LIBS)
360
target_compile_definitions(fmt PRIVATE FMT_LIB_EXPORT INTERFACE FMT_SHARED)
361
endif ()
362
if (FMT_SAFE_DURATION_CAST)
363
target_compile_definitions(fmt PUBLIC FMT_SAFE_DURATION_CAST)
364
endif ()
365
366
add_library(fmt-header-only INTERFACE)
367
add_library(fmt::fmt-header-only ALIAS fmt-header-only)
368
369
if (NOT MSVC)
370
# Unicode is always supported on compilers other than MSVC.
371
elseif (FMT_UNICODE)
372
# Unicode support requires compiling with /utf-8.
373
target_compile_options(fmt PUBLIC $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/utf-8>)
374
target_compile_options(fmt-header-only INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/utf-8>)
375
else ()
376
target_compile_definitions(fmt PUBLIC FMT_UNICODE=0)
377
endif ()
378
379
target_compile_definitions(fmt-header-only INTERFACE FMT_HEADER_ONLY=1)
380
target_compile_features(fmt-header-only INTERFACE cxx_std_11)
381
382
target_include_directories(fmt-header-only
383
${FMT_SYSTEM_HEADERS_ATTRIBUTE} BEFORE INTERFACE
384
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
385
$<INSTALL_INTERFACE:${FMT_INC_DIR}>)
386
387
# Install targets.
388
if (FMT_INSTALL)
389
include(CMakePackageConfigHelpers)
390
set_verbose(FMT_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/fmt CACHE STRING
391
"Installation directory for cmake files, a relative path that "
392
"will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute "
393
"path.")
394
set(version_config ${PROJECT_BINARY_DIR}/fmt-config-version.cmake)
395
set(project_config ${PROJECT_BINARY_DIR}/fmt-config.cmake)
396
set(pkgconfig ${PROJECT_BINARY_DIR}/fmt.pc)
397
set(targets_export_name fmt-targets)
398
399
set_verbose(FMT_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING
400
"Installation directory for libraries, a relative path that "
401
"will be joined to ${CMAKE_INSTALL_PREFIX} or an absolute path.")
402
403
set_verbose(FMT_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig CACHE STRING
404
"Installation directory for pkgconfig (.pc) files, a relative "
405
"path that will be joined with ${CMAKE_INSTALL_PREFIX} or an "
406
"absolute path.")
407
408
# Generate the version, config and target files into the build directory.
409
write_basic_package_version_file(
410
${version_config}
411
VERSION ${FMT_VERSION}
412
COMPATIBILITY AnyNewerVersion)
413
414
join_paths(libdir_for_pc_file "\${exec_prefix}" "${FMT_LIB_DIR}")
415
join_paths(includedir_for_pc_file "\${prefix}" "${FMT_INC_DIR}")
416
417
configure_file(
418
"${PROJECT_SOURCE_DIR}/support/cmake/fmt.pc.in"
419
"${pkgconfig}"
420
@ONLY)
421
configure_package_config_file(
422
${PROJECT_SOURCE_DIR}/support/cmake/fmt-config.cmake.in
423
${project_config}
424
INSTALL_DESTINATION ${FMT_CMAKE_DIR})
425
426
set(INSTALL_TARGETS fmt fmt-header-only)
427
428
set(INSTALL_FILE_SET)
429
if (FMT_USE_CMAKE_MODULES)
430
set(INSTALL_FILE_SET FILE_SET fmt DESTINATION "${FMT_INC_DIR}/fmt")
431
endif()
432
433
# Install the library and headers.
434
install(TARGETS ${INSTALL_TARGETS}
435
COMPONENT fmt-core
436
EXPORT ${targets_export_name}
437
LIBRARY DESTINATION ${FMT_LIB_DIR}
438
ARCHIVE DESTINATION ${FMT_LIB_DIR}
439
PUBLIC_HEADER DESTINATION "${FMT_INC_DIR}/fmt"
440
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
441
${INSTALL_FILE_SET})
442
443
# Use a namespace because CMake provides better diagnostics for namespaced
444
# imported targets.
445
export(TARGETS ${INSTALL_TARGETS} NAMESPACE fmt::
446
FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
447
448
# Install version, config and target files.
449
install(FILES ${project_config} ${version_config}
450
DESTINATION ${FMT_CMAKE_DIR}
451
COMPONENT fmt-core)
452
install(EXPORT ${targets_export_name} DESTINATION ${FMT_CMAKE_DIR}
453
NAMESPACE fmt::
454
COMPONENT fmt-core)
455
456
install(FILES "${pkgconfig}" DESTINATION "${FMT_PKGCONFIG_DIR}"
457
COMPONENT fmt-core)
458
endif ()
459
460
function(add_doc_target)
461
find_program(DOXYGEN doxygen
462
PATHS "$ENV{ProgramFiles}/doxygen/bin"
463
"$ENV{ProgramFiles\(x86\)}/doxygen/bin")
464
if (NOT DOXYGEN)
465
message(STATUS "Target 'doc' disabled because doxygen not found")
466
return ()
467
endif ()
468
469
find_program(MKDOCS mkdocs)
470
if (NOT MKDOCS)
471
message(STATUS "Target 'doc' disabled because mkdocs not found")
472
return ()
473
endif ()
474
475
set(sources )
476
foreach (source api.md index.md syntax.md get-started.md fmt.css fmt.js)
477
set(sources ${sources} doc/${source})
478
endforeach()
479
480
add_custom_target(
481
doc
482
COMMAND
483
${CMAKE_COMMAND}
484
-E env PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/support/python
485
${MKDOCS} build -f ${CMAKE_CURRENT_SOURCE_DIR}/support/mkdocs.yml
486
# MkDocs requires the site dir to be outside of the doc dir.
487
--site-dir ${CMAKE_CURRENT_BINARY_DIR}/doc-html
488
--no-directory-urls
489
SOURCES ${sources})
490
491
include(GNUInstallDirs)
492
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc-html/
493
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/fmt
494
COMPONENT fmt-doc OPTIONAL)
495
endfunction()
496
497
if (FMT_DOC)
498
add_doc_target()
499
endif ()
500
501
if (FMT_TEST)
502
enable_testing()
503
add_subdirectory(test)
504
endif ()
505
506
# Control fuzzing independent of the unit tests.
507
if (FMT_FUZZ)
508
add_subdirectory(test/fuzzing)
509
510
# The FMT_FUZZ macro is used to prevent resource exhaustion in fuzzing
511
# mode and make fuzzing practically possible. It is similar to
512
# FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION but uses a different name to
513
# avoid interfering with fuzzing of projects that use {fmt}.
514
# See also https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode.
515
target_compile_definitions(fmt PUBLIC FMT_FUZZ)
516
endif ()
517
518
set(gitignore ${PROJECT_SOURCE_DIR}/.gitignore)
519
if (FMT_MASTER_PROJECT AND EXISTS ${gitignore})
520
# Get the list of ignored files from .gitignore.
521
file (STRINGS ${gitignore} lines)
522
list(REMOVE_ITEM lines /doc/html)
523
foreach (line ${lines})
524
string(REPLACE "." "[.]" line "${line}")
525
string(REPLACE "*" ".*" line "${line}")
526
set(ignored_files ${ignored_files} "${line}$" "${line}/")
527
endforeach ()
528
set(ignored_files ${ignored_files} /.git /build/doxyxml .vagrant)
529
530
set(CPACK_SOURCE_GENERATOR ZIP)
531
set(CPACK_SOURCE_IGNORE_FILES ${ignored_files})
532
set(CPACK_SOURCE_PACKAGE_FILE_NAME fmt-${FMT_VERSION})
533
set(CPACK_PACKAGE_NAME fmt)
534
set(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README.md)
535
include(CPack)
536
endif ()
537
538