Cmake provides interface library specifically for "header-only library". I would suggest to do the following:
- Create a file structure like the following
third-party\spdlog\include
- Git clone the spdlog repository into the
include
directory with the name spdlog
- Create
third-party\spdlog\CMakeLists.txt
with the following content
find_package(Threads REQUIRED)
add_library(${TARGET_LOGGER} INTERFACE)
# add_library(spdlog::spdlog_header_only ALIAS ${TARGET_LOGGER})
target_include_directories(${TARGET_LOGGER} INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(${TARGET_LOGGER} INTERFACE Threads::Threads)
- Define TARGET_LOGGER in the CMakeLists.txt of your project. Link this target to your project with
target_link_libraries(${TARGET_PROJECT} LINK_PUBLIC ${TARGET_LOGGER})
. Also don't forget to
add_subdirectory(
third-party\spdlog
)
Then, in your project, you can use #include "spdlog/spdlog.h"
to include the library