Home | History | Annotate | Download | only in fmtlib
      1 message(STATUS "CMake version: ${CMAKE_VERSION}")
      2 
      3 cmake_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.
      7 set(MASTER_PROJECT OFF)
      8 if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
      9   set(MASTER_PROJECT ON)
     10 endif ()
     11 
     12 # Joins arguments and places the results in ${result_var}.
     13 function(join result_var)
     14   set(result )
     15   foreach (arg ${ARGN})
     16     set(result "${result}${arg}")
     17   endforeach ()
     18   set(${result_var} "${result}" PARENT_SCOPE)
     19 endfunction()
     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).
     24 if (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})
     28 endif ()
     29 
     30 option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF)
     31 
     32 # Options that control generation of various targets.
     33 option(FMT_DOC "Generate the doc target." ${MASTER_PROJECT})
     34 option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT})
     35 option(FMT_TEST "Generate the test target." ${MASTER_PROJECT})
     36 option(FMT_USE_CPP11 "Enable the addition of C++11 compiler flags." ON)
     37 
     38 project(FMT)
     39 
     40 # Starting with cmake 3.0 VERSION is part of the project command.
     41 file(READ fmt/format.h format_h)
     42 if (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.")
     44 endif ()
     45 # Use math to skip leading zeros if any.
     46 math(EXPR CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
     47 math(EXPR CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
     48 math(EXPR CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
     49 join(FMT_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.
     50                  ${CPACK_PACKAGE_VERSION_PATCH})
     51 message(STATUS "Version: ${FMT_VERSION}")
     52 
     53 message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
     54 
     55 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
     56 
     57 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
     58   "${CMAKE_CURRENT_SOURCE_DIR}/support/cmake")
     59 
     60 include(cxx11)
     61 
     62 if (CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
     63   set(PEDANTIC_COMPILE_FLAGS -Wall -Wextra -Wshadow -pedantic)
     64 endif ()
     65 
     66 if (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}\" %*")
     80 endif ()
     81 
     82 include(CheckSymbolExists)
     83 if (WIN32)
     84   check_symbol_exists(open io.h HAVE_OPEN)
     85 else ()
     86   check_symbol_exists(open fcntl.h HAVE_OPEN)
     87 endif ()
     88 
     89 add_subdirectory(fmt)
     90 
     91 if (FMT_DOC)
     92   add_subdirectory(doc)
     93 endif ()
     94 
     95 if (FMT_TEST)
     96   enable_testing()
     97   add_subdirectory(test)
     98 endif ()
     99 
    100 set(gitignore ${PROJECT_SOURCE_DIR}/.gitignore)
    101 if (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)
    119 endif ()
    120