Victor Zverovich | ae4a394 | 2018-07-14 06:34:20 -0700 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.1.0) |
Victor Zverovich | cb99919 | 2012-12-07 09:02:15 -0800 | [diff] [blame] | 2 | |
Victor Zverovich | a9e2615 | 2018-07-17 08:54:22 -0700 | [diff] [blame] | 3 | # Use newer policies if available, up to most recent tested version of CMake. |
Henry Fredrick Schreiner | efd8ee8 | 2018-07-16 12:37:54 +0200 | [diff] [blame] | 4 | if(${CMAKE_VERSION} VERSION_LESS 3.11) |
Victor Zverovich | a9e2615 | 2018-07-17 08:54:22 -0700 | [diff] [blame] | 5 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) |
Henry Fredrick Schreiner | efd8ee8 | 2018-07-16 12:37:54 +0200 | [diff] [blame] | 6 | else() |
Victor Zverovich | a9e2615 | 2018-07-17 08:54:22 -0700 | [diff] [blame] | 7 | cmake_policy(VERSION 3.11) |
Henry Fredrick Schreiner | efd8ee8 | 2018-07-16 12:37:54 +0200 | [diff] [blame] | 8 | endif() |
| 9 | |
Victor Zverovich | 5e1576f | 2016-04-24 07:45:13 -0700 | [diff] [blame] | 10 | # Determine if fmt is built as a subproject (using add_subdirectory) |
vitaut | e49a4e0 | 2016-04-12 07:42:47 -0400 | [diff] [blame] | 11 | # or if it is the master project. |
Mario Werner | c1a4cd0 | 2016-02-03 11:20:19 +0100 | [diff] [blame] | 12 | set(MASTER_PROJECT OFF) |
| 13 | if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
| 14 | set(MASTER_PROJECT ON) |
Henry Fredrick Schreiner | efd8ee8 | 2018-07-16 12:37:54 +0200 | [diff] [blame] | 15 | message(STATUS "CMake version: ${CMAKE_VERSION}") |
Mario Werner | c1a4cd0 | 2016-02-03 11:20:19 +0100 | [diff] [blame] | 16 | endif () |
| 17 | |
Victor Zverovich | 5e4c34b | 2018-01-21 16:36:22 -0800 | [diff] [blame] | 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 | |
Victor Zverovich | 6767965 | 2012-12-07 09:41:02 -0800 | [diff] [blame] | 27 | # Set the default CMAKE_BUILD_TYPE to Release. |
| 28 | # This should be done before the project command since the latter can set |
| 29 | # CMAKE_BUILD_TYPE itself (it does so for nmake). |
Victor Zverovich | 53379df | 2019-03-17 10:50:19 -0700 | [diff] [blame] | 30 | if (MASTER_PROJECT AND NOT CMAKE_BUILD_TYPE) |
Victor Zverovich | 5e4c34b | 2018-01-21 16:36:22 -0800 | [diff] [blame] | 31 | join(doc "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or " |
| 32 | "CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") |
| 33 | set(CMAKE_BUILD_TYPE Release CACHE STRING ${doc}) |
Victor Zverovich | 6767965 | 2012-12-07 09:41:02 -0800 | [diff] [blame] | 34 | endif () |
| 35 | |
vitaut | a5757c8 | 2015-05-12 07:35:29 -0700 | [diff] [blame] | 36 | option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF) |
Victor Zverovich | 8bc0adb | 2019-04-13 06:56:34 -0700 | [diff] [blame] | 37 | option(FMT_WERROR "Halt the compilation with an error on compiler warnings." |
| 38 | OFF) |
vitaut | 75fdfe3 | 2015-08-31 06:49:06 -0700 | [diff] [blame] | 39 | |
| 40 | # Options that control generation of various targets. |
Mario Werner | c1a4cd0 | 2016-02-03 11:20:19 +0100 | [diff] [blame] | 41 | option(FMT_DOC "Generate the doc target." ${MASTER_PROJECT}) |
| 42 | option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT}) |
| 43 | option(FMT_TEST "Generate the test target." ${MASTER_PROJECT}) |
Paul Dreik | 9d97201 | 2019-06-30 09:11:13 +0200 | [diff] [blame] | 44 | option(FMT_FUZZ "Generate the fuzz target." OFF) |
Victor Zverovich | 7042d14 | 2014-06-06 06:35:28 -0700 | [diff] [blame] | 45 | |
Victor Zverovich | 544b927 | 2019-04-17 06:18:53 -0700 | [diff] [blame] | 46 | project(FMT CXX) |
Victor Zverovich | a23a8d1 | 2012-12-07 10:04:01 -0800 | [diff] [blame] | 47 | |
Victor Zverovich | 5e4c34b | 2018-01-21 16:36:22 -0800 | [diff] [blame] | 48 | # Get version from core.h |
| 49 | file(READ include/fmt/core.h core_h) |
| 50 | if (NOT core_h MATCHES "FMT_VERSION ([0-9]+)([0-9][0-9])([0-9][0-9])") |
| 51 | message(FATAL_ERROR "Cannot get FMT_VERSION from core.h.") |
Mario Werner | b52d0bd | 2016-01-29 13:18:02 +0100 | [diff] [blame] | 52 | endif () |
Victor Zverovich | 5e4c34b | 2018-01-21 16:36:22 -0800 | [diff] [blame] | 53 | # Use math to skip leading zeros if any. |
| 54 | math(EXPR CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1}) |
| 55 | math(EXPR CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2}) |
| 56 | math(EXPR CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3}) |
| 57 | join(FMT_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}. |
| 58 | ${CPACK_PACKAGE_VERSION_PATCH}) |
| 59 | message(STATUS "Version: ${FMT_VERSION}") |
Mario Werner | b52d0bd | 2016-01-29 13:18:02 +0100 | [diff] [blame] | 60 | |
Victor Zverovich | eb04e9a | 2014-07-10 09:14:24 -0700 | [diff] [blame] | 61 | message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") |
| 62 | |
Victor Zverovich | 07754c0 | 2015-03-01 16:07:18 -0800 | [diff] [blame] | 63 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 64 | |
Victor Zverovich | 269c3ba | 2014-04-23 17:21:18 -0700 | [diff] [blame] | 65 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} |
Victor Zverovich | 2b35c9e | 2015-02-21 16:02:44 -0800 | [diff] [blame] | 66 | "${CMAKE_CURRENT_SOURCE_DIR}/support/cmake") |
Victor Zverovich | 269c3ba | 2014-04-23 17:21:18 -0700 | [diff] [blame] | 67 | |
Victor Zverovich | d5e918b | 2017-09-28 08:46:47 -0700 | [diff] [blame] | 68 | include(cxx14) |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 69 | include(CheckCXXCompilerFlag) |
Mario Werner | 0fb474b | 2016-01-29 13:03:47 +0100 | [diff] [blame] | 70 | |
Lectem | 6e37c20 | 2019-04-07 12:15:24 +0200 | [diff] [blame] | 71 | set(FMT_REQUIRED_FEATURES cxx_auto_type cxx_variadic_templates) |
| 72 | |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 73 | if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") |
| 74 | set(PEDANTIC_COMPILE_FLAGS -pedantic-errors -Wall -Wextra -pedantic |
Victor Zverovich | 2d2326a | 2018-10-22 21:05:59 -0700 | [diff] [blame] | 75 | -Wold-style-cast -Wundef |
Victor Zverovich | 34030de | 2018-11-06 17:04:33 -0800 | [diff] [blame] | 76 | -Wredundant-decls -Wwrite-strings -Wpointer-arith |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 77 | -Wcast-qual -Wformat=2 -Wmissing-include-dirs |
| 78 | -Wcast-align -Wnon-virtual-dtor |
| 79 | -Wctor-dtor-privacy -Wdisabled-optimization |
Victor Zverovich | f0d0a1e | 2018-08-25 16:08:32 -0700 | [diff] [blame] | 80 | -Winvalid-pch -Woverloaded-virtual |
Victor Zverovich | 3de36e9 | 2019-11-26 09:10:24 -0800 | [diff] [blame] | 81 | -Wconversion -Wswitch-enum |
Sign Bit | 0bbdca5 | 2018-12-20 09:24:19 -0500 | [diff] [blame] | 82 | -Wno-ctor-dtor-privacy -Wno-format-nonliteral -Wno-shadow) |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 83 | if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6) |
Sign Bit | 0bbdca5 | 2018-12-20 09:24:19 -0500 | [diff] [blame] | 84 | set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wnoexcept |
| 85 | -Wno-dangling-else -Wno-unused-local-typedefs) |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 86 | endif () |
| 87 | if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0) |
| 88 | set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wdouble-promotion |
| 89 | -Wtrampolines -Wzero-as-null-pointer-constant -Wuseless-cast |
| 90 | -Wvector-operation-performance -Wsized-deallocation) |
| 91 | endif () |
| 92 | if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) |
| 93 | set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} -Wshift-overflow=2 |
| 94 | -Wnull-dereference -Wduplicated-cond) |
| 95 | endif () |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 96 | set(WERROR_FLAG -Werror) |
| 97 | endif () |
| 98 | |
Victor Zverovich | a11eb3a | 2018-08-22 09:07:17 -0700 | [diff] [blame] | 99 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
Victor Zverovich | 8bc0adb | 2019-04-13 06:56:34 -0700 | [diff] [blame] | 100 | set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -pedantic -Wconversion |
Deniz Evrenci | 96f9142 | 2019-10-12 02:44:20 +0900 | [diff] [blame] | 101 | -Wno-sign-conversion -Wdeprecated -Wweak-vtables) |
Victor Zverovich | 34030de | 2018-11-06 17:04:33 -0800 | [diff] [blame] | 102 | check_cxx_compiler_flag(-Wzero-as-null-pointer-constant HAS_NULLPTR_WARNING) |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 103 | if (HAS_NULLPTR_WARNING) |
Victor Zverovich | 9875147 | 2018-08-22 07:40:06 -0700 | [diff] [blame] | 104 | set(PEDANTIC_COMPILE_FLAGS ${PEDANTIC_COMPILE_FLAGS} |
Victor Zverovich | 34030de | 2018-11-06 17:04:33 -0800 | [diff] [blame] | 105 | -Wzero-as-null-pointer-constant) |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 106 | endif () |
Victor Zverovich | 34030de | 2018-11-06 17:04:33 -0800 | [diff] [blame] | 107 | set(WERROR_FLAG -Werror) |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 108 | endif () |
| 109 | |
| 110 | if (MSVC) |
Victor Zverovich | 6322b47 | 2018-06-06 16:51:35 +0200 | [diff] [blame] | 111 | set(PEDANTIC_COMPILE_FLAGS /W3) |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 112 | set(WERROR_FLAG /WX) |
Mario Werner | b52d0bd | 2016-01-29 13:18:02 +0100 | [diff] [blame] | 113 | endif () |
| 114 | |
Mario Werner | c1a4cd0 | 2016-02-03 11:20:19 +0100 | [diff] [blame] | 115 | if (MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio") |
Victor Zverovich | 269c3ba | 2014-04-23 17:21:18 -0700 | [diff] [blame] | 116 | # If Microsoft SDK is installed create script run-msbuild.bat that |
Jakub Wilk | e0ac51c | 2016-05-01 12:29:21 +0200 | [diff] [blame] | 117 | # calls SetEnv.cmd to set up build environment and runs msbuild. |
Victor Zverovich | 269c3ba | 2014-04-23 17:21:18 -0700 | [diff] [blame] | 118 | # It is useful when building Visual Studio projects with the SDK |
| 119 | # toolchain rather than Visual Studio. |
| 120 | include(FindSetEnv) |
| 121 | if (WINSDK_SETENV) |
| 122 | set(MSBUILD_SETUP "call \"${WINSDK_SETENV}\"") |
| 123 | endif () |
Victor Zverovich | 60c92a7 | 2014-04-29 05:56:47 -0700 | [diff] [blame] | 124 | # Set FrameworkPathOverride to get rid of MSB3644 warnings. |
Victor Zverovich | b6afd93 | 2014-10-06 08:20:52 -0700 | [diff] [blame] | 125 | set(netfxpath "C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.0") |
Victor Zverovich | 269c3ba | 2014-04-23 17:21:18 -0700 | [diff] [blame] | 126 | file(WRITE run-msbuild.bat " |
| 127 | ${MSBUILD_SETUP} |
Victor Zverovich | b6afd93 | 2014-10-06 08:20:52 -0700 | [diff] [blame] | 128 | ${CMAKE_MAKE_PROGRAM} -p:FrameworkPathOverride=\"${netfxpath}\" %*") |
Victor Zverovich | 269c3ba | 2014-04-23 17:21:18 -0700 | [diff] [blame] | 129 | endif () |
| 130 | |
Victor Zverovich | d5d5865 | 2019-06-23 17:10:57 -0700 | [diff] [blame] | 131 | set(strtod_l_headers stdlib.h) |
| 132 | if (APPLE) |
| 133 | set(strtod_l_headers ${strtod_l_headers} xlocale.h) |
| 134 | endif () |
| 135 | |
Victor Zverovich | eaa89e2 | 2014-06-09 09:07:27 -0700 | [diff] [blame] | 136 | include(CheckSymbolExists) |
| 137 | if (WIN32) |
Victor Zverovich | d5d5865 | 2019-06-23 17:10:57 -0700 | [diff] [blame] | 138 | check_symbol_exists(_strtod_l "${strtod_l_headers}" HAVE_STRTOD_L) |
Victor Zverovich | eaa89e2 | 2014-06-09 09:07:27 -0700 | [diff] [blame] | 139 | else () |
Victor Zverovich | d5d5865 | 2019-06-23 17:10:57 -0700 | [diff] [blame] | 140 | check_symbol_exists(strtod_l "${strtod_l_headers}" HAVE_STRTOD_L) |
Victor Zverovich | eaa89e2 | 2014-06-09 09:07:27 -0700 | [diff] [blame] | 141 | endif () |
Victor Zverovich | e1c046c | 2014-09-29 09:27:32 -0700 | [diff] [blame] | 142 | |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 143 | function(add_headers VAR) |
| 144 | set(headers ${${VAR}}) |
| 145 | foreach (header ${ARGN}) |
| 146 | set(headers ${headers} include/fmt/${header}) |
| 147 | endforeach() |
| 148 | set(${VAR} ${headers} PARENT_SCOPE) |
| 149 | endfunction() |
| 150 | |
| 151 | # Define the fmt library, its includes and the needed defines. |
Victor Zverovich | 9393fe2 | 2019-07-25 19:01:21 +0300 | [diff] [blame] | 152 | add_headers(FMT_HEADERS chrono.h color.h compile.h core.h format.h format-inl.h |
Victor Zverovich | 092d2dc | 2019-11-20 07:51:14 -0800 | [diff] [blame] | 153 | locale.h ostream.h posix.h printf.h ranges.h) |
Victor Zverovich | dcde089 | 2019-11-15 05:41:14 -0800 | [diff] [blame] | 154 | set(FMT_SOURCES src/format.cc src/posix.cc) |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 155 | |
Victor Zverovich | 25b72fc | 2019-05-15 08:43:54 -0700 | [diff] [blame] | 156 | add_library(fmt ${FMT_SOURCES} ${FMT_HEADERS} README.rst ChangeLog.rst) |
Victor Zverovich | e02aacc | 2018-03-13 13:03:18 -0400 | [diff] [blame] | 157 | add_library(fmt::fmt ALIAS fmt) |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 158 | |
Victor Zverovich | d5d5865 | 2019-06-23 17:10:57 -0700 | [diff] [blame] | 159 | if (HAVE_STRTOD_L) |
| 160 | target_compile_definitions(fmt PUBLIC FMT_LOCALE) |
| 161 | endif () |
| 162 | |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 163 | if (FMT_WERROR) |
| 164 | target_compile_options(fmt PRIVATE ${WERROR_FLAG}) |
| 165 | endif () |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 166 | if (FMT_PEDANTIC) |
| 167 | target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS}) |
| 168 | endif () |
| 169 | |
Lectem | 6e37c20 | 2019-04-07 12:15:24 +0200 | [diff] [blame] | 170 | target_compile_features(fmt INTERFACE ${FMT_REQUIRED_FEATURES}) |
Lectem | 3de3d76 | 2019-04-02 00:04:03 +0200 | [diff] [blame] | 171 | |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 172 | target_include_directories(fmt PUBLIC |
| 173 | $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
| 174 | $<INSTALL_INTERFACE:include>) |
| 175 | |
| 176 | set_target_properties(fmt PROPERTIES |
Victor Zverovich | 403ae0a | 2018-02-10 07:17:40 -0800 | [diff] [blame] | 177 | VERSION ${FMT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR} |
| 178 | DEBUG_POSTFIX d) |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 179 | |
| 180 | if (BUILD_SHARED_LIBS) |
Vedran Miletić | f7aedc5 | 2019-09-19 21:25:43 +0200 | [diff] [blame] | 181 | if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 182 | # Fix rpmlint warning: |
| 183 | # unused-direct-shlib-dependency /usr/lib/libformat.so.1.1.0 /lib/libm.so.6. |
| 184 | target_link_libraries(fmt -Wl,--as-needed) |
| 185 | endif () |
| 186 | target_compile_definitions(fmt PRIVATE FMT_EXPORT INTERFACE FMT_SHARED) |
| 187 | endif () |
Paul Dreik | 9d97201 | 2019-06-30 09:11:13 +0200 | [diff] [blame] | 188 | if (FMT_SAFE_DURATION_CAST) |
Victor Zverovich | 2711cb1 | 2019-06-30 08:52:15 -0700 | [diff] [blame] | 189 | target_compile_definitions(fmt PUBLIC FMT_SAFE_DURATION_CAST) |
Paul Dreik | 9d97201 | 2019-06-30 09:11:13 +0200 | [diff] [blame] | 190 | endif() |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 191 | |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 192 | add_library(fmt-header-only INTERFACE) |
| 193 | add_library(fmt::fmt-header-only ALIAS fmt-header-only) |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 194 | |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 195 | target_compile_definitions(fmt-header-only INTERFACE FMT_HEADER_ONLY=1) |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 196 | |
Lectem | 6e37c20 | 2019-04-07 12:15:24 +0200 | [diff] [blame] | 197 | target_compile_features(fmt-header-only INTERFACE ${FMT_REQUIRED_FEATURES}) |
Lectem | 3de3d76 | 2019-04-02 00:04:03 +0200 | [diff] [blame] | 198 | |
Elias Kosunen | 691a7a9 | 2018-06-06 16:57:59 +0300 | [diff] [blame] | 199 | target_include_directories(fmt-header-only INTERFACE |
| 200 | $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
| 201 | $<INSTALL_INTERFACE:include>) |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 202 | |
| 203 | # Install targets. |
| 204 | if (FMT_INSTALL) |
Victor Zverovich | c96d646 | 2018-02-10 07:00:14 -0800 | [diff] [blame] | 205 | include(GNUInstallDirs) |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 206 | include(CMakePackageConfigHelpers) |
Victor Zverovich | c96d646 | 2018-02-10 07:00:14 -0800 | [diff] [blame] | 207 | set(FMT_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/fmt CACHE STRING |
Victor Zverovich | 8bc0adb | 2019-04-13 06:56:34 -0700 | [diff] [blame] | 208 | "Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.") |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 209 | set(version_config ${PROJECT_BINARY_DIR}/fmt-config-version.cmake) |
| 210 | set(project_config ${PROJECT_BINARY_DIR}/fmt-config.cmake) |
Cole Mickens | 9d0c9c4 | 2018-10-24 01:33:22 -0700 | [diff] [blame] | 211 | set(pkgconfig ${PROJECT_BINARY_DIR}/fmt.pc) |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 212 | set(targets_export_name fmt-targets) |
| 213 | |
| 214 | set (INSTALL_TARGETS fmt) |
| 215 | if (TARGET fmt-header-only) |
| 216 | set(INSTALL_TARGETS ${INSTALL_TARGETS} fmt-header-only) |
| 217 | endif () |
| 218 | |
Victor Zverovich | c96d646 | 2018-02-10 07:00:14 -0800 | [diff] [blame] | 219 | set(FMT_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING |
| 220 | "Installation directory for libraries, relative to ${CMAKE_INSTALL_PREFIX}.") |
| 221 | |
| 222 | set(FMT_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR}/fmt CACHE STRING |
| 223 | "Installation directory for include files, relative to ${CMAKE_INSTALL_PREFIX}.") |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 224 | |
Olaf Hering | 9e1531c | 2019-03-25 17:16:18 +0100 | [diff] [blame] | 225 | set(FMT_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig CACHE PATH |
Victor Zverovich | 8bc0adb | 2019-04-13 06:56:34 -0700 | [diff] [blame] | 226 | "Installation directory for pkgconfig (.pc) files, relative to ${CMAKE_INSTALL_PREFIX}.") |
Cole Mickens | 9d0c9c4 | 2018-10-24 01:33:22 -0700 | [diff] [blame] | 227 | |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 228 | # Generate the version, config and target files into the build directory. |
| 229 | write_basic_package_version_file( |
| 230 | ${version_config} |
| 231 | VERSION ${FMT_VERSION} |
| 232 | COMPATIBILITY AnyNewerVersion) |
Cole Mickens | 9d0c9c4 | 2018-10-24 01:33:22 -0700 | [diff] [blame] | 233 | configure_file( |
| 234 | "${PROJECT_SOURCE_DIR}/support/cmake/fmt.pc.in" |
| 235 | "${pkgconfig}" |
| 236 | @ONLY) |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 237 | configure_package_config_file( |
| 238 | ${PROJECT_SOURCE_DIR}/support/cmake/fmt-config.cmake.in |
| 239 | ${project_config} |
| 240 | INSTALL_DESTINATION ${FMT_CMAKE_DIR}) |
Victor Zverovich | e02aacc | 2018-03-13 13:03:18 -0400 | [diff] [blame] | 241 | # Use a namespace because CMake provides better diagnostics for namespaced |
| 242 | # imported targets. |
| 243 | export(TARGETS ${INSTALL_TARGETS} NAMESPACE fmt:: |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 244 | FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake) |
| 245 | |
| 246 | # Install version, config and target files. |
| 247 | install( |
| 248 | FILES ${project_config} ${version_config} |
| 249 | DESTINATION ${FMT_CMAKE_DIR}) |
Victor Zverovich | 7bab90e | 2018-03-13 22:45:14 -0400 | [diff] [blame] | 250 | install(EXPORT ${targets_export_name} DESTINATION ${FMT_CMAKE_DIR} |
Victor Zverovich | e02aacc | 2018-03-13 13:03:18 -0400 | [diff] [blame] | 251 | NAMESPACE fmt::) |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 252 | |
| 253 | # Install the library and headers. |
| 254 | install(TARGETS ${INSTALL_TARGETS} EXPORT ${targets_export_name} |
Robert Franke | 159f89e | 2019-11-29 17:01:32 +0100 | [diff] [blame] | 255 | LIBRARY DESTINATION ${FMT_LIB_DIR} |
| 256 | ARCHIVE DESTINATION ${FMT_LIB_DIR} |
| 257 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
Andreas Schönle | 9d4ef94 | 2018-11-19 14:58:17 +0100 | [diff] [blame] | 258 | |
Victor Zverovich | 8bc0adb | 2019-04-13 06:56:34 -0700 | [diff] [blame] | 259 | install(FILES $<TARGET_PDB_FILE:${INSTALL_TARGETS}> |
| 260 | DESTINATION ${FMT_LIB_DIR} OPTIONAL) |
Victor Zverovich | c96d646 | 2018-02-10 07:00:14 -0800 | [diff] [blame] | 261 | install(FILES ${FMT_HEADERS} DESTINATION ${FMT_INC_DIR}) |
Cole Mickens | 9d0c9c4 | 2018-10-24 01:33:22 -0700 | [diff] [blame] | 262 | install(FILES "${pkgconfig}" DESTINATION "${FMT_PKGCONFIG_DIR}") |
Victor Zverovich | 84bd2f1 | 2017-12-03 09:59:55 -0800 | [diff] [blame] | 263 | endif () |
vitaut | b83fd00 | 2015-11-23 08:10:02 -0800 | [diff] [blame] | 264 | |
vitaut | 75fdfe3 | 2015-08-31 06:49:06 -0700 | [diff] [blame] | 265 | if (FMT_DOC) |
Alex Martin | 06c1859 | 2015-08-30 14:23:54 +0200 | [diff] [blame] | 266 | add_subdirectory(doc) |
| 267 | endif () |
Victor Zverovich | 382e25e | 2012-12-18 08:44:00 -0800 | [diff] [blame] | 268 | |
vitaut | 75fdfe3 | 2015-08-31 06:49:06 -0700 | [diff] [blame] | 269 | if (FMT_TEST) |
Alex Martin | 914b978 | 2015-08-19 10:41:37 +0200 | [diff] [blame] | 270 | enable_testing() |
| 271 | add_subdirectory(test) |
Victor Zverovich | a734f67 | 2014-09-18 09:18:18 -0700 | [diff] [blame] | 272 | endif () |
| 273 | |
Victor Zverovich | 2711cb1 | 2019-06-30 08:52:15 -0700 | [diff] [blame] | 274 | # Control fuzzing independent of the unit tests. |
Paul Dreik | 9d97201 | 2019-06-30 09:11:13 +0200 | [diff] [blame] | 275 | if (FMT_FUZZ) |
| 276 | add_subdirectory(test/fuzzing) |
| 277 | endif () |
| 278 | |
Mario Werner | b52d0bd | 2016-01-29 13:18:02 +0100 | [diff] [blame] | 279 | set(gitignore ${PROJECT_SOURCE_DIR}/.gitignore) |
Mario Werner | c1a4cd0 | 2016-02-03 11:20:19 +0100 | [diff] [blame] | 280 | if (MASTER_PROJECT AND EXISTS ${gitignore}) |
Victor Zverovich | 10b2fe0 | 2014-04-14 12:54:03 -0700 | [diff] [blame] | 281 | # Get the list of ignored files from .gitignore. |
vitaut | 22f6114 | 2016-01-13 07:14:32 -0800 | [diff] [blame] | 282 | file (STRINGS ${gitignore} lines) |
Victor Zverovich | 10b2fe0 | 2014-04-14 12:54:03 -0700 | [diff] [blame] | 283 | LIST(REMOVE_ITEM lines /doc/html) |
| 284 | foreach (line ${lines}) |
Victor Zverovich | cb389f9 | 2014-05-13 09:28:53 -0700 | [diff] [blame] | 285 | string(REPLACE "." "[.]" line "${line}") |
Victor Zverovich | 10b2fe0 | 2014-04-14 12:54:03 -0700 | [diff] [blame] | 286 | string(REPLACE "*" ".*" line "${line}") |
| 287 | set(ignored_files ${ignored_files} "${line}$" "${line}/") |
| 288 | endforeach () |
Victor Zverovich | fb67a2f | 2016-05-08 07:28:34 -0700 | [diff] [blame] | 289 | set(ignored_files ${ignored_files} |
vitaut | 005379a | 2015-08-31 08:21:59 -0700 | [diff] [blame] | 290 | /.git /breathe /format-benchmark sphinx/ .buildinfo .doctrees) |
Victor Zverovich | 10b2fe0 | 2014-04-14 12:54:03 -0700 | [diff] [blame] | 291 | |
| 292 | set(CPACK_SOURCE_GENERATOR ZIP) |
| 293 | set(CPACK_SOURCE_IGNORE_FILES ${ignored_files}) |
Victor Zverovich | 848ab63 | 2016-04-24 07:16:33 -0700 | [diff] [blame] | 294 | set(CPACK_SOURCE_PACKAGE_FILE_NAME fmt-${FMT_VERSION}) |
| 295 | set(CPACK_PACKAGE_NAME fmt) |
Mario Werner | b52d0bd | 2016-01-29 13:18:02 +0100 | [diff] [blame] | 296 | set(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README.rst) |
Victor Zverovich | 10b2fe0 | 2014-04-14 12:54:03 -0700 | [diff] [blame] | 297 | include(CPack) |
| 298 | endif () |