Skip to content

Commit 009dd6b

Browse files
committed
spdlog: Use system library if found
Signed-off-by: František Zatloukal <[email protected]>
1 parent 494a052 commit 009dd6b

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

CMakeLists.txt

+13-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ else()
7878
endif()
7979
add_definitions(-DLOADER_VERSION_SHA="${VERSION_SHA}")
8080

81-
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog_headers")
81+
if(SYSTEM_SPDLOG)
82+
find_package(spdlog CONFIG)
83+
if(spdlog_FOUND)
84+
message(STATUS "System spdlog found.")
85+
else()
86+
message(FATAL_ERROR "SYSTEM_SPDLOG specified but spdlog wasn't found.")
87+
endif()
88+
else()
89+
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog_headers")
90+
endif()
8291

8392
# Update other relevant variables to include the patch
8493
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
@@ -151,17 +160,17 @@ if(MSVC)
151160

152161
# enable exceptions handling
153162
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
154-
163+
155164
# enable creation of PDB files for Release Builds
156165
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
157166
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
158-
167+
159168
# enable CET shadow stack
160169
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /CETCOMPAT")
161170

162171
#Use of sccache with MSVC requires workaround of replacing /Zi with /Z7
163172
#https://github.com/mozilla/sccache
164-
if(USE_Z7) #sccache
173+
if(USE_Z7) #sccache
165174
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
166175
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
167176
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")

source/utils/CMakeLists.txt

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Copyright (C) 2024 Intel Corporation
22
# SPDX-License-Identifier: MIT
33

4-
add_library(utils
5-
STATIC
6-
"logging.h"
7-
"logging.cpp"
8-
)
4+
set(logging_files logging.h logging.cpp)
5+
add_library(utils STATIC ${logging_files})
96

10-
target_include_directories(utils PRIVATE ${CMAKE_SOURCE_DIR}/third_party/spdlog_headers/)
7+
if(SYSTEM_SPDLOG)
8+
target_link_libraries(utils PUBLIC spdlog::spdlog)
9+
else()
10+
target_include_directories(utils PUBLIC ${PROJECT_SOURCE_DIR}/third_party/spdlog_headers/)
11+
endif()
12+
set_property(TARGET utils PROPERTY POSITION_INDEPENDENT_CODE ON)

0 commit comments

Comments
 (0)