From e79cec788e007c81767f48308019be93464d1444 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 15 Feb 2020 19:33:06 +0100 Subject: [PATCH] Prepare a test to find an installed libspdlog The example should be able to build as a standalone project too if external libfmt was used. Require the minimum fmt version with find_package(). TODO: Require the minimum spdlog version with find_package() at standalone example. --- CMakeLists.txt | 34 +++++++++++++++++----------------- example/CMakeLists.txt | 13 +++++++++---- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c414f0e..fda320e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ endif() set(CMAKE_CXX_EXTENSIONS OFF) if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN") - set(CMAKE_CXX_EXTENSIONS ON) + set(CMAKE_CXX_EXTENSIONS ON) endif() @@ -148,9 +148,9 @@ target_link_libraries(spdlog_header_only INTERFACE Threads::Threads) # Use fmt package if using external fmt #--------------------------------------------------------------------------------------- if(SPDLOG_FMT_EXTERNAL OR SPDLOG_FMT_EXTERNAL_HO) - if (NOT TARGET fmt::fmt) - find_package(fmt REQUIRED) - endif () + if(NOT TARGET fmt::fmt) + find_package(fmt 6.1.2 REQUIRED) + endif() target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL) target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL) @@ -170,19 +170,18 @@ endif() # Misc definitions according to tweak options #--------------------------------------------------------------------------------------- if(SPDLOG_WCHAR_SUPPORT) - target_compile_definitions(spdlog PUBLIC SPDLOG_WCHAR_TO_UTF8_SUPPORT) - target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_TO_UTF8_SUPPORT) - endif() - - if(SPDLOG_WCHAR_FILENAMES) - target_compile_definitions(spdlog PUBLIC SPDLOG_WCHAR_FILENAMES) - target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_FILENAMES) - endif() + target_compile_definitions(spdlog PUBLIC SPDLOG_WCHAR_TO_UTF8_SUPPORT) + target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_TO_UTF8_SUPPORT) +endif() - if(SPDLOG_NO_EXCEPTIONS) - target_compile_definitions(spdlog PUBLIC SPDLOG_NO_EXCEPTIONS) +if(SPDLOG_WCHAR_FILENAMES) + target_compile_definitions(spdlog PUBLIC SPDLOG_WCHAR_FILENAMES) + target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_FILENAMES) +endif() - target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_EXCEPTIONS) +if(SPDLOG_NO_EXCEPTIONS) + target_compile_definitions(spdlog PUBLIC SPDLOG_NO_EXCEPTIONS) + target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_EXCEPTIONS) if(NOT MSVC) target_compile_options(spdlog PRIVATE -fno-exceptions) @@ -276,8 +275,9 @@ if (SPDLOG_INSTALL) FILE ${config_targets_file}) include(CMakePackageConfigHelpers) - configure_file("${project_config_in}" "${project_config_out}" @ONLY) - + configure_package_config_file("${project_config_in}" "${project_config_out}" + INSTALL_DESTINATION ${export_dest_dir} + ) write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion) install(FILES "${project_config_out}" diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index a2330174..068bb892 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,14 +1,19 @@ # Copyright(c) 2019 spdlog authors # Distributed under the MIT License (http://opensource.org/licenses/MIT) -cmake_minimum_required(VERSION 3.1) -project(spdlog_examples CXX) +cmake_minimum_required(VERSION 3.2) -include(../cmake/utils.cmake) +project(spdlog_examples CXX) if(NOT TARGET spdlog) # Stand-alone build - find_package(spdlog REQUIRED) + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + #XXX MAYBE: include(../cmake/clang-tidy.cmake) + include(../cmake/utils.cmake) + #TODO spdlog_extract_version() + + find_package(spdlog ${SPDLOG_VERSION} REQUIRED) endif() #---------------------------------------------------------------------------------------