From 1ae17d0bf8e2c6495a800b1b050d79b881a5b9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Zatloukal?= Date: Mon, 10 Jun 2024 14:23:12 +0200 Subject: [PATCH] spdlog: Use system library if requested MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: FrantiĊĦek Zatloukal --- CMakeLists.txt | 17 +++++++++++++---- source/utils/CMakeLists.txt | 14 ++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67bcb9c..2dcb024 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,16 @@ else() endif() add_definitions(-DLOADER_VERSION_SHA="${VERSION_SHA}") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog_headers") +if(SYSTEM_SPDLOG) + find_package(spdlog CONFIG) + if(spdlog_FOUND) + message(STATUS "System spdlog found.") + else() + message(FATAL_ERROR "SYSTEM_SPDLOG specified but spdlog wasn't found.") + endif() +else() + include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog_headers") +endif() # Update other relevant variables to include the patch set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") @@ -151,17 +160,17 @@ if(MSVC) # enable exceptions handling set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") - + # enable creation of PDB files for Release Builds set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi") set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") - + # enable CET shadow stack set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /CETCOMPAT") #Use of sccache with MSVC requires workaround of replacing /Zi with /Z7 #https://github.com/mozilla/sccache - if(USE_Z7) #sccache + if(USE_Z7) #sccache string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") diff --git a/source/utils/CMakeLists.txt b/source/utils/CMakeLists.txt index 69c3319..ee9a60a 100644 --- a/source/utils/CMakeLists.txt +++ b/source/utils/CMakeLists.txt @@ -1,10 +1,12 @@ # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: MIT -add_library(utils - STATIC - "logging.h" - "logging.cpp" -) +set(logging_files logging.h logging.cpp) +add_library(utils STATIC ${logging_files}) -target_include_directories(utils PRIVATE ${CMAKE_SOURCE_DIR}/third_party/spdlog_headers/) +if(SYSTEM_SPDLOG) + target_link_libraries(utils PUBLIC spdlog::spdlog) +else() + target_include_directories(utils PUBLIC ${PROJECT_SOURCE_DIR}/third_party/spdlog_headers/) +endif() +set_property(TARGET utils PROPERTY POSITION_INDEPENDENT_CODE ON)