• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1message(STATUS "CMake version: ${CMAKE_VERSION}")
2
3cmake_minimum_required(VERSION 2.8.12)
4
5# Determine if fmt is built as a subproject (using add_subdirectory)
6# or if it is the master project.
7set(MASTER_PROJECT OFF)
8if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
9  set(MASTER_PROJECT ON)
10endif ()
11
12# Joins arguments and places the results in ${result_var}.
13function(join result_var)
14  set(result )
15  foreach (arg ${ARGN})
16    set(result "${result}${arg}")
17  endforeach ()
18  set(${result_var} "${result}" PARENT_SCOPE)
19endfunction()
20
21# Set the default CMAKE_BUILD_TYPE to Release.
22# This should be done before the project command since the latter can set
23# CMAKE_BUILD_TYPE itself (it does so for nmake).
24if (NOT CMAKE_BUILD_TYPE)
25  join(doc "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or "
26           "CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
27  set(CMAKE_BUILD_TYPE Release CACHE STRING ${doc})
28endif ()
29
30option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF)
31
32# Options that control generation of various targets.
33option(FMT_DOC "Generate the doc target." ${MASTER_PROJECT})
34option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT})
35option(FMT_TEST "Generate the test target." ${MASTER_PROJECT})
36option(FMT_USE_CPP11 "Enable the addition of C++11 compiler flags." ON)
37
38project(FMT)
39
40# Starting with cmake 3.0 VERSION is part of the project command.
41file(READ fmt/format.h format_h)
42if (NOT format_h MATCHES "FMT_VERSION ([0-9]+)([0-9][0-9])([0-9][0-9])")
43  message(FATAL_ERROR "Cannot get FMT_VERSION from format.h.")
44endif ()
45# Use math to skip leading zeros if any.
46math(EXPR CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
47math(EXPR CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
48math(EXPR CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
49join(FMT_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.
50                 ${CPACK_PACKAGE_VERSION_PATCH})
51message(STATUS "Version: ${FMT_VERSION}")
52
53message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
54
55set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
56
57set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
58  "${CMAKE_CURRENT_SOURCE_DIR}/support/cmake")
59
60include(cxx11)
61
62if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
63  set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -Wshadow -pedantic)
64endif ()
65
66if (MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio")
67  # If Microsoft SDK is installed create script run-msbuild.bat that
68  # calls SetEnv.cmd to set up build environment and runs msbuild.
69  # It is useful when building Visual Studio projects with the SDK
70  # toolchain rather than Visual Studio.
71  include(FindSetEnv)
72  if (WINSDK_SETENV)
73    set(MSBUILD_SETUP "call \"${WINSDK_SETENV}\"")
74  endif ()
75  # Set FrameworkPathOverride to get rid of MSB3644 warnings.
76  set(netfxpath "C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.0")
77  file(WRITE run-msbuild.bat "
78    ${MSBUILD_SETUP}
79    ${CMAKE_MAKE_PROGRAM} -p:FrameworkPathOverride=\"${netfxpath}\" %*")
80endif ()
81
82include(CheckSymbolExists)
83if (WIN32)
84  check_symbol_exists(open io.h HAVE_OPEN)
85else ()
86  check_symbol_exists(open fcntl.h HAVE_OPEN)
87endif ()
88
89add_subdirectory(fmt)
90
91if (FMT_DOC)
92  add_subdirectory(doc)
93endif ()
94
95if (FMT_TEST)
96  enable_testing()
97  add_subdirectory(test)
98endif ()
99
100set(gitignore ${PROJECT_SOURCE_DIR}/.gitignore)
101if (MASTER_PROJECT AND EXISTS ${gitignore})
102  # Get the list of ignored files from .gitignore.
103  file (STRINGS ${gitignore} lines)
104  LIST(REMOVE_ITEM lines /doc/html)
105  foreach (line ${lines})
106    string(REPLACE "." "[.]" line "${line}")
107    string(REPLACE "*" ".*" line "${line}")
108    set(ignored_files ${ignored_files} "${line}$" "${line}/")
109  endforeach ()
110  set(ignored_files ${ignored_files}
111    /.git /breathe /format-benchmark sphinx/ .buildinfo .doctrees)
112
113  set(CPACK_SOURCE_GENERATOR ZIP)
114  set(CPACK_SOURCE_IGNORE_FILES ${ignored_files})
115  set(CPACK_SOURCE_PACKAGE_FILE_NAME fmt-${FMT_VERSION})
116  set(CPACK_PACKAGE_NAME fmt)
117  set(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README.rst)
118  include(CPack)
119endif ()
120