mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-24 09:31:34 +08:00
CMake improvements
This commit is contained in:
parent
5709cb10d1
commit
30bd80bd85
@ -3,18 +3,17 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(spdlog VERSION 1.3.1 LANGUAGES CXX)
|
||||
include(CMakeDependentOption)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# set default build to release
|
||||
# Set default build to release
|
||||
#---------------------------------------------------------------------------------------
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
|
||||
endif()
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# compiler config
|
||||
# Compiler config
|
||||
#---------------------------------------------------------------------------------------
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
@ -35,6 +34,7 @@ endif ()
|
||||
option(SPDLOG_BUILD_EXAMPLES "Build examples" ON)
|
||||
option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" OFF)
|
||||
option(SPDLOG_BUILD_TESTS "Build tests" OFF)
|
||||
option(SPDLOG_BUILD_HO_TESTS "Build tests using the header only version" OFF)
|
||||
option(SPDLOG_INSTALL "Generate the install target." ${SPDLOG_MASTER_PROJECT})
|
||||
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
|
||||
|
||||
@ -42,27 +42,46 @@ message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# IDE support for headers
|
||||
#---------------------------------------------------------------------------------------
|
||||
set(SPDLOG_HEADERS_DIR "${CMAKE_CURRENT_LIST_DIR}/include")
|
||||
file(GLOB SPDLOG_TOP_HEADERS "${SPDLOG_HEADERS_DIR}/spdlog/*.h")
|
||||
file(GLOB SPDLOG_DETAILS_HEADERS "${SPDLOG_HEADERS_DIR}/spdlog/details/*.h")
|
||||
file(GLOB SPDLOG_SINKS_HEADERS "${SPDLOG_HEADERS_DIR}/spdlog/sinks/*.h")
|
||||
file(GLOB SPDLOG_FMT_HEADERS "${SPDLOG_HEADERS_DIR}/spdlog/fmt/*.h")
|
||||
file(GLOB SPDLOG_FMT_BUNDELED_HEADERS "${SPDLOG_HEADERS_DIR}/spdlog/fmt/bundled/*.h")
|
||||
set(SPDLOG_ALL_HEADERS ${SPDLOG_TOP_HEADERS} ${SPDLOG_DETAILS_HEADERS} ${SPDLOG_SINKS_HEADERS} ${SPDLOG_FMT_HEADERS} ${SPDLOG_FMT_BUNDELED_HEADERS})
|
||||
|
||||
source_group("Header Files\\spdlog" FILES ${SPDLOG_TOP_HEADERS})
|
||||
source_group("Header Files\\spdlog\\details" FILES ${SPDLOG_DETAILS_HEADERS})
|
||||
source_group("Header Files\\spdlog\\sinks" FILES ${SPDLOG_SINKS_HEADERS})
|
||||
source_group("Header Files\\spdlog\\fmt" FILES ${SPDLOG_FMT_HEADERS})
|
||||
source_group("Header Files\\spdlog\\fmt\\bundled\\" FILES ${SPDLOG_FMT_BUNDELED_HEADERS})
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Static library version
|
||||
#---------------------------------------------------------------------------------------
|
||||
add_library(spdlog STATIC src/spdlog.cpp)
|
||||
add_library(spdlog STATIC src/spdlog.cpp ${SPDLOG_ALL_HEADERS})
|
||||
add_library(spdlog::spdlog ALIAS spdlog)
|
||||
|
||||
target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB)
|
||||
target_include_directories(spdlog PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
target_link_libraries(spdlog PUBLIC Threads::Threads)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Header only version
|
||||
#---------------------------------------------------------------------------------------
|
||||
add_library(spdlog_header_only INTERFACE)
|
||||
add_library(spdlog::spdlog_header_only ALIAS spdlog_header_only)
|
||||
|
||||
target_include_directories(spdlog_header_only INTERFACE
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
target_link_libraries(spdlog_header_only INTERFACE Threads::Threads)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Turn on compiler warnings and sanitizers if we build our own project
|
||||
#---------------------------------------------------------------------------------------
|
||||
@ -146,5 +165,4 @@ if (SPDLOG_INSTALL)
|
||||
#---------------------------------------------------------------------------------------
|
||||
include(cmake/SpdlogCPack.cmake)
|
||||
|
||||
endif ()
|
||||
|
||||
endif ()
|
@ -2,7 +2,7 @@
|
||||
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(SpdlogBench CXX)
|
||||
project(spdlog_bench CXX)
|
||||
|
||||
if(NOT TARGET spdlog)
|
||||
# Stand-alone build
|
||||
@ -21,7 +21,6 @@ target_link_libraries(async_bench PRIVATE spdlog::spdlog)
|
||||
add_executable(latency latency.cpp)
|
||||
target_link_libraries(latency PRIVATE benchmark::benchmark spdlog::spdlog)
|
||||
|
||||
|
||||
add_executable(formatter-bench formatter-bench.cpp)
|
||||
target_link_libraries(formatter-bench PRIVATE benchmark::benchmark spdlog::spdlog)
|
||||
|
||||
|
@ -2,15 +2,9 @@
|
||||
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(SpdlogExamples CXX)
|
||||
project(spdlog_examples CXX)
|
||||
|
||||
if(TARGET spdlog)
|
||||
# If we're running this example as part of the primary spdlog applciation
|
||||
# then add an alias. This allows us to use the same "spdlog::spdlog"
|
||||
# below that a user would use (with the namespace)
|
||||
add_library(spdlog::spdlog ALIAS spdlog)
|
||||
add_library(spdlog::spdlog_header_only ALIAS spdlog_header_only)
|
||||
else()
|
||||
if(NOT TARGET spdlog)
|
||||
# Stand-alone build
|
||||
find_package(spdlog REQUIRED)
|
||||
endif()
|
||||
|
@ -15,10 +15,19 @@ set(SPDLOG_UTESTS_SOURCES
|
||||
test_sink.h
|
||||
test_fmt_helper.cpp)
|
||||
|
||||
add_executable(spdlog-utests ${SPDLOG_UTESTS_SOURCES})
|
||||
target_link_libraries(spdlog-utests spdlog)
|
||||
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME spdlog-utests COMMAND spdlog-utests)
|
||||
|
||||
# The compiled library tests
|
||||
if(SPDLOG_BUILD_TESTS)
|
||||
add_executable(spdlog-utests ${SPDLOG_UTESTS_SOURCES})
|
||||
target_link_libraries(spdlog-utests spdlog)
|
||||
add_test(NAME spdlog-utests COMMAND spdlog-utests)
|
||||
endif()
|
||||
|
||||
# The header-only library version tests
|
||||
if(SPDLOG_BUILD_HO_TESTS)
|
||||
add_executable(spdlog-utests-ho ${SPDLOG_UTESTS_SOURCES})
|
||||
target_link_libraries(spdlog-utests-ho spdlog::spdlog_header_only)
|
||||
add_test(NAME spdlog-utests-ho COMMAND spdlog-utests-ho)
|
||||
endif()
|
Loading…
Reference in New Issue
Block a user