git repos / blockattack-game

blame: source/misc/embedded_libs/fmt-11.0.2/CMakeLists.txt

normal view · raw

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