2016-04-24 14:45:13 +00:00
|
|
|
# Define the fmt library, its includes and the needed defines.
|
2016-02-09 16:43:39 +00:00
|
|
|
# format.cc is added to FMT_HEADERS for the header-only configuration.
|
2016-05-06 14:37:20 +00:00
|
|
|
set(FMT_HEADERS format.h format.cc ostream.h ostream.cc time.h)
|
2016-01-29 15:39:03 +00:00
|
|
|
if (HAVE_OPEN)
|
2016-02-03 08:59:55 +00:00
|
|
|
set(FMT_HEADERS ${FMT_HEADERS} posix.h)
|
|
|
|
set(FMT_SOURCES ${FMT_SOURCES} posix.cc)
|
2016-01-29 15:39:03 +00:00
|
|
|
endif ()
|
|
|
|
|
2016-05-06 14:37:20 +00:00
|
|
|
add_library(fmt ${FMT_SOURCES} ${FMT_HEADERS} ../ChangeLog.rst)
|
2016-04-24 14:45:13 +00:00
|
|
|
|
|
|
|
option(FMT_CPPFORMAT "Build cppformat library for backward compatibility." OFF)
|
|
|
|
if (FMT_CPPFORMAT)
|
|
|
|
message(WARNING "The cppformat library is deprecated, use fmt instead.")
|
|
|
|
add_library(cppformat ${FMT_SOURCES} ${FMT_HEADERS})
|
|
|
|
endif ()
|
2016-01-29 15:39:03 +00:00
|
|
|
|
2016-02-09 16:43:39 +00:00
|
|
|
# Starting with cmake 3.1 the CXX_STANDARD property can be used instead.
|
2016-04-24 14:45:13 +00:00
|
|
|
target_compile_options(fmt PUBLIC ${CPP11_FLAG})
|
2016-01-29 15:39:03 +00:00
|
|
|
if (FMT_PEDANTIC)
|
2016-04-24 14:45:13 +00:00
|
|
|
target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
2016-01-29 15:39:03 +00:00
|
|
|
endif ()
|
|
|
|
|
2016-04-24 14:45:13 +00:00
|
|
|
target_include_directories(fmt INTERFACE
|
2016-01-29 15:39:03 +00:00
|
|
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
|
|
|
|
$<INSTALL_INTERFACE:include>)
|
|
|
|
|
2016-04-24 14:45:13 +00:00
|
|
|
set_target_properties(fmt PROPERTIES
|
2016-04-24 14:16:33 +00:00
|
|
|
VERSION ${FMT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})
|
2016-01-29 15:39:03 +00:00
|
|
|
|
|
|
|
if (BUILD_SHARED_LIBS)
|
|
|
|
if (UNIX AND NOT APPLE)
|
|
|
|
# Fix rpmlint warning:
|
|
|
|
# unused-direct-shlib-dependency /usr/lib/libformat.so.1.1.0 /lib/libm.so.6.
|
2016-04-24 14:45:13 +00:00
|
|
|
target_link_libraries(fmt -Wl,--as-needed)
|
2016-01-29 15:39:03 +00:00
|
|
|
endif ()
|
2016-04-24 14:45:13 +00:00
|
|
|
target_compile_definitions(fmt PRIVATE FMT_EXPORT INTERFACE FMT_SHARED)
|
2016-01-29 15:39:03 +00:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# additionally define a header only library when cmake is new enough
|
|
|
|
if (CMAKE_VERSION VERSION_GREATER 3.1.0 OR CMAKE_VERSION VERSION_EQUAL 3.1.0)
|
2016-04-24 14:45:13 +00:00
|
|
|
add_library(fmt-header-only INTERFACE)
|
2016-01-29 15:39:03 +00:00
|
|
|
|
2016-04-24 14:45:13 +00:00
|
|
|
target_compile_definitions(fmt-header-only INTERFACE FMT_HEADER_ONLY=1)
|
2016-01-29 15:39:03 +00:00
|
|
|
|
2016-04-24 14:45:13 +00:00
|
|
|
target_include_directories(fmt-header-only INTERFACE
|
2016-01-29 15:39:03 +00:00
|
|
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
|
|
|
|
$<INSTALL_INTERFACE:include>)
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
# Install targets.
|
|
|
|
if (FMT_INSTALL)
|
|
|
|
include(CMakePackageConfigHelpers)
|
2016-04-24 14:45:13 +00:00
|
|
|
set(FMT_CMAKE_DIR lib/cmake/fmt CACHE STRING
|
2016-04-06 07:33:13 +00:00
|
|
|
"Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.")
|
2016-04-24 14:45:13 +00:00
|
|
|
set(version_config ${PROJECT_BINARY_DIR}/fmt-config-version.cmake)
|
|
|
|
set(project_config ${PROJECT_BINARY_DIR}/fmt-config.cmake)
|
|
|
|
set(targets_export_name fmt-targets)
|
2016-01-29 15:39:03 +00:00
|
|
|
|
2016-04-24 14:45:13 +00:00
|
|
|
set (INSTALL_TARGETS fmt)
|
|
|
|
if (TARGET fmt-header-only)
|
|
|
|
set(INSTALL_TARGETS ${INSTALL_TARGETS} fmt-header-only)
|
2016-01-29 15:57:45 +00:00
|
|
|
endif ()
|
|
|
|
|
2016-01-29 15:39:03 +00:00
|
|
|
set(FMT_LIB_DIR lib CACHE STRING
|
|
|
|
"Installation directory for libraries, relative to ${CMAKE_INSTALL_PREFIX}.")
|
|
|
|
|
|
|
|
# Generate the version, config and target files into the build directory.
|
|
|
|
write_basic_package_version_file(
|
|
|
|
${version_config}
|
2016-04-24 14:16:33 +00:00
|
|
|
VERSION ${FMT_VERSION}
|
2016-01-29 15:39:03 +00:00
|
|
|
COMPATIBILITY AnyNewerVersion)
|
|
|
|
configure_package_config_file(
|
2016-04-24 14:45:13 +00:00
|
|
|
${PROJECT_SOURCE_DIR}/support/cmake/fmt-config.cmake.in
|
2016-01-29 15:39:03 +00:00
|
|
|
${project_config}
|
2016-04-06 07:33:13 +00:00
|
|
|
INSTALL_DESTINATION ${FMT_CMAKE_DIR})
|
2016-01-29 15:57:45 +00:00
|
|
|
export(TARGETS ${INSTALL_TARGETS} FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
|
2016-01-29 15:39:03 +00:00
|
|
|
|
|
|
|
# Install version, config and target files.
|
|
|
|
install(
|
|
|
|
FILES ${project_config} ${version_config}
|
2016-04-06 07:33:13 +00:00
|
|
|
DESTINATION ${FMT_CMAKE_DIR})
|
|
|
|
install(EXPORT ${targets_export_name} DESTINATION ${FMT_CMAKE_DIR})
|
2016-01-29 15:39:03 +00:00
|
|
|
|
2016-02-09 23:40:26 +00:00
|
|
|
# Install the library and headers.
|
2016-01-29 15:57:45 +00:00
|
|
|
install(TARGETS ${INSTALL_TARGETS} EXPORT ${targets_export_name} DESTINATION ${FMT_LIB_DIR})
|
2016-04-24 16:18:15 +00:00
|
|
|
install(FILES ${FMT_HEADERS} DESTINATION include/fmt)
|
2016-04-24 14:45:13 +00:00
|
|
|
if (FMT_CPPFORMAT)
|
|
|
|
install(TARGETS cppformat DESTINATION ${FMT_LIB_DIR})
|
|
|
|
endif ()
|
2016-01-29 15:39:03 +00:00
|
|
|
endif ()
|