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)
|
2019-02-06 13:38:26 +08:00
|
|
|
option(SPDLOG_INSTALL "Generate the install target." ${SPDLOG_MASTER_PROJECT})
|
2019-03-23 19:31:57 +08:00
|
|
|
option(SPDLOG_BUILD_LITE "Build spdlog lite" ${SPDLOG_MASTER_PROJECT})
|
|
|
|
|
2018-08-13 06:22:35 +08:00
|
|
|
|
2019-02-02 01:12:58 +08:00
|
|
|
if(SPDLOG_FMT_EXTERNAL AND NOT TARGET fmt::fmt)
|
2018-12-18 00:18:16 +08:00
|
|
|
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()
|
|
|
|
|
2019-03-23 19:31:57 +08:00
|
|
|
if(SPDLOG_BUILD_LITE)
|
|
|
|
add_subdirectory(lite)
|
|
|
|
add_subdirectory(lite-example)
|
|
|
|
endif()
|
|
|
|
|
2017-08-24 22:55:55 +08:00
|
|
|
#---------------------------------------------------------------------------------------
|
|
|
|
# Install/export targets and files
|
|
|
|
#---------------------------------------------------------------------------------------
|
2019-02-06 13:38:26 +08:00
|
|
|
if(SPDLOG_INSTALL)
|
|
|
|
# set files and directories
|
|
|
|
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")
|
|
|
|
set(version_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
|
|
|
|
set(project_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
|
|
|
|
set(targets_config "${PROJECT_NAME}Targets.cmake")
|
|
|
|
set(pkg_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc")
|
|
|
|
set(targets_export_name "${PROJECT_NAME}Targets")
|
|
|
|
set(namespace "${PROJECT_NAME}::")
|
|
|
|
|
|
|
|
# generate package version file
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
write_basic_package_version_file(
|
|
|
|
"${version_config}" COMPATIBILITY SameMajorVersion
|
|
|
|
)
|
|
|
|
|
|
|
|
# configure pkg config file
|
|
|
|
configure_file("cmake/spdlog.pc.in" "${pkg_config}" @ONLY)
|
|
|
|
# configure spdlogConfig.cmake file
|
|
|
|
configure_file("cmake/Config.cmake.in" "${project_config}" @ONLY)
|
|
|
|
|
|
|
|
# install targets
|
|
|
|
install(
|
|
|
|
TARGETS spdlog
|
|
|
|
EXPORT "${targets_export_name}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# install headers
|
|
|
|
install(
|
|
|
|
DIRECTORY "${HEADER_BASE}/${PROJECT_NAME}"
|
|
|
|
DESTINATION "${include_install_dir}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# install project config and version file
|
|
|
|
install(
|
|
|
|
FILES "${project_config}" "${version_config}"
|
|
|
|
DESTINATION "${config_install_dir}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# install pkg config file
|
|
|
|
install(
|
|
|
|
FILES "${pkg_config}"
|
|
|
|
DESTINATION "${pkgconfig_install_dir}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# install targets config file
|
|
|
|
install(
|
|
|
|
EXPORT "${targets_export_name}"
|
|
|
|
NAMESPACE "${namespace}"
|
|
|
|
DESTINATION "${config_install_dir}"
|
|
|
|
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})
|
|
|
|
|
2019-02-06 13:38:26 +08:00
|
|
|
endif()
|
|
|
|
|
2017-08-24 22:55:06 +08:00
|
|
|
file(GLOB_RECURSE spdlog_include_SRCS "${HEADER_BASE}/*.h")
|
|
|
|
add_custom_target(spdlog_headers_for_ide SOURCES ${spdlog_include_SRCS})
|