2017-08-24 22:55:06 +08:00
|
|
|
#
|
|
|
|
# Copyright(c) 2015 Ruslan Baratov.
|
|
|
|
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
#
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.1)
|
2019-01-18 18:13:07 +08:00
|
|
|
project(spdlog VERSION 1.3.1 LANGUAGES CXX)
|
2017-08-24 22:55:06 +08:00
|
|
|
include(CMakeDependentOption)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2018-08-13 06:22:35 +08:00
|
|
|
#---------------------------------------------------------------------------------------
|
|
|
|
# set default build to release
|
|
|
|
#---------------------------------------------------------------------------------------
|
2018-08-15 03:33:47 +08:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
2018-08-13 06:22:35 +08:00
|
|
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
|
|
|
|
endif()
|
|
|
|
|
2018-08-15 03:33:47 +08:00
|
|
|
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
2018-08-13 06:22:35 +08:00
|
|
|
|
2017-08-24 22:55:55 +08:00
|
|
|
#---------------------------------------------------------------------------------------
|
|
|
|
# compiler config
|
|
|
|
#---------------------------------------------------------------------------------------
|
2017-08-24 22:55:06 +08:00
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
2018-08-11 04:20:52 +08:00
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
2017-08-24 22:55:06 +08:00
|
|
|
|
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
2018-08-15 03:33:47 +08:00
|
|
|
add_compile_options("-Wall")
|
|
|
|
add_compile_options("-Wextra")
|
2018-08-17 05:32:13 +08:00
|
|
|
add_compile_options("-Wconversion")
|
2018-08-16 00:09:37 +08:00
|
|
|
add_compile_options("-pedantic")
|
2018-08-18 07:19:52 +08:00
|
|
|
add_compile_options("-Wfatal-errors")
|
2017-08-24 22:55:06 +08:00
|
|
|
endif()
|
|
|
|
|
2018-08-13 06:22:35 +08:00
|
|
|
#---------------------------------------------------------------------------------------
|
|
|
|
# address sanitizers check
|
|
|
|
#---------------------------------------------------------------------------------------
|
2018-08-12 20:32:07 +08:00
|
|
|
include(cmake/sanitizers.cmake)
|
|
|
|
|
2017-08-24 22:55:55 +08:00
|
|
|
#---------------------------------------------------------------------------------------
|
|
|
|
# spdlog target
|
|
|
|
#---------------------------------------------------------------------------------------
|
2017-08-24 22:55:06 +08:00
|
|
|
add_library(spdlog INTERFACE)
|
2018-08-11 04:20:52 +08:00
|
|
|
add_library(spdlog::spdlog ALIAS spdlog)
|
2017-08-24 22:55:06 +08:00
|
|
|
|
2018-09-13 04:10:33 +08:00
|
|
|
# Check if spdlog is being used directly or via add_subdirectory
|
|
|
|
set(SPDLOG_MASTER_PROJECT OFF)
|
|
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
2019-01-23 17:03:03 +08:00
|
|
|
set(SPDLOG_MASTER_PROJECT ON)
|
2018-09-13 04:10:33 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
option(SPDLOG_BUILD_EXAMPLES "Build examples" ${SPDLOG_MASTER_PROJECT})
|
2019-01-23 17:03:03 +08:00
|
|
|
option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" OFF)
|
2018-12-02 18:25:46 +08:00
|
|
|
option(SPDLOG_BUILD_TESTS "Build tests" ${SPDLOG_MASTER_PROJECT})
|
2018-12-18 00:18:16 +08:00
|
|
|
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
|
2018-08-13 06:22:35 +08:00
|
|
|
|
2018-12-18 00:18:16 +08:00
|
|
|
if(SPDLOG_FMT_EXTERNAL)
|
|
|
|
find_package(fmt REQUIRED CONFIG)
|
|
|
|
endif()
|
2017-08-24 22:55:06 +08:00
|
|
|
|
|
|
|
target_include_directories(
|
|
|
|
spdlog
|
|
|
|
INTERFACE
|
|
|
|
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
|
|
|
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
|
|
|
)
|
|
|
|
|
2018-12-18 00:18:16 +08:00
|
|
|
if(SPDLOG_FMT_EXTERNAL)
|
|
|
|
target_compile_definitions(spdlog INTERFACE SPDLOG_FMT_EXTERNAL)
|
|
|
|
target_link_libraries(spdlog INTERFACE fmt::fmt)
|
|
|
|
endif()
|
|
|
|
|
2017-08-24 22:55:06 +08:00
|
|
|
set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
|
|
|
|
|
|
|
if(SPDLOG_BUILD_EXAMPLES)
|
|
|
|
add_subdirectory(example)
|
|
|
|
endif()
|
|
|
|
|
2018-12-02 18:25:46 +08:00
|
|
|
if(SPDLOG_BUILD_TESTS)
|
|
|
|
include(CTest)
|
2017-08-24 22:55:06 +08:00
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|
|
|
|
|
2018-08-13 06:22:35 +08:00
|
|
|
if(SPDLOG_BUILD_BENCH)
|
|
|
|
add_subdirectory(bench)
|
|
|
|
endif()
|
|
|
|
|
2017-08-24 22:55:55 +08:00
|
|
|
#---------------------------------------------------------------------------------------
|
|
|
|
# Install/export targets and files
|
|
|
|
#---------------------------------------------------------------------------------------
|
2017-08-24 22:57:07 +08:00
|
|
|
# set files and directories
|
2017-08-24 22:55:06 +08:00
|
|
|
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
|
|
|
set(include_install_dir "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
|
|
set(pkgconfig_install_dir "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
2019-01-28 16:48:45 +08:00
|
|
|
set(version_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
|
2018-12-18 00:18:16 +08:00
|
|
|
set(project_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
|
|
|
|
set(targets_config "${PROJECT_NAME}Targets.cmake")
|
2019-01-28 16:48:45 +08:00
|
|
|
set(pkg_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc")
|
2017-08-24 22:55:06 +08:00
|
|
|
set(targets_export_name "${PROJECT_NAME}Targets")
|
|
|
|
set(namespace "${PROJECT_NAME}::")
|
|
|
|
|
2017-08-24 22:57:07 +08:00
|
|
|
# generate package version file
|
2017-08-24 22:55:06 +08:00
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
write_basic_package_version_file(
|
|
|
|
"${version_config}" COMPATIBILITY SameMajorVersion
|
|
|
|
)
|
|
|
|
|
2017-08-24 22:57:07 +08:00
|
|
|
# configure pkg config file
|
2017-08-24 22:55:06 +08:00
|
|
|
configure_file("cmake/spdlog.pc.in" "${pkg_config}" @ONLY)
|
2018-12-18 00:18:16 +08:00
|
|
|
# configure spdlogConfig.cmake file
|
|
|
|
configure_file("cmake/Config.cmake.in" "${project_config}" @ONLY)
|
2017-08-24 22:55:06 +08:00
|
|
|
|
2017-08-24 22:57:07 +08:00
|
|
|
# install targets
|
2017-08-24 22:55:06 +08:00
|
|
|
install(
|
|
|
|
TARGETS spdlog
|
|
|
|
EXPORT "${targets_export_name}"
|
|
|
|
)
|
|
|
|
|
2017-08-24 22:57:07 +08:00
|
|
|
# install headers
|
2017-08-24 22:55:06 +08:00
|
|
|
install(
|
|
|
|
DIRECTORY "${HEADER_BASE}/${PROJECT_NAME}"
|
|
|
|
DESTINATION "${include_install_dir}"
|
|
|
|
)
|
|
|
|
|
2018-12-18 00:18:16 +08:00
|
|
|
# install project config and version file
|
2017-08-24 22:55:06 +08:00
|
|
|
install(
|
2018-12-18 00:18:16 +08:00
|
|
|
FILES "${project_config}" "${version_config}"
|
2017-08-24 22:55:06 +08:00
|
|
|
DESTINATION "${config_install_dir}"
|
|
|
|
)
|
|
|
|
|
2017-08-24 22:57:07 +08:00
|
|
|
# install pkg config file
|
2017-08-24 22:55:06 +08:00
|
|
|
install(
|
|
|
|
FILES "${pkg_config}"
|
|
|
|
DESTINATION "${pkgconfig_install_dir}"
|
|
|
|
)
|
|
|
|
|
2018-12-18 00:18:16 +08:00
|
|
|
# install targets config file
|
2017-08-24 22:55:06 +08:00
|
|
|
install(
|
|
|
|
EXPORT "${targets_export_name}"
|
|
|
|
NAMESPACE "${namespace}"
|
|
|
|
DESTINATION "${config_install_dir}"
|
2018-12-18 00:18:16 +08:00
|
|
|
FILE ${targets_config}
|
2017-08-24 22:55:06 +08:00
|
|
|
)
|
|
|
|
|
2018-12-18 00:18:16 +08:00
|
|
|
# export build directory targets file
|
2017-08-24 22:55:06 +08:00
|
|
|
export(
|
|
|
|
EXPORT ${targets_export_name}
|
|
|
|
NAMESPACE "${namespace}"
|
2018-12-18 00:18:16 +08:00
|
|
|
FILE ${targets_config}
|
2017-08-24 22:55:06 +08:00
|
|
|
)
|
|
|
|
|
2017-08-24 22:57:07 +08:00
|
|
|
# register project in CMake user registry
|
2017-08-24 22:55:06 +08:00
|
|
|
export(PACKAGE ${PROJECT_NAME})
|
|
|
|
|
|
|
|
file(GLOB_RECURSE spdlog_include_SRCS "${HEADER_BASE}/*.h")
|
|
|
|
add_custom_target(spdlog_headers_for_ide SOURCES ${spdlog_include_SRCS})
|