I want to include spdlog into one of my project. It is a header only library. The project that i am building is using cmake. Currently i am using
include_directories('src/logger/spdlog/')
in cmake and including the library as
#include <spdlog/spdlog.h>
in logs.h inside logger folder. I am getting fatal error no such file or directory. What is the correct way to include the same library in my application.
Cmake provides interface library specifically for "header-only library". I would suggest to do the following:
third-party\spdlog\include
include
directory with the name spdlog
third-party\spdlog\CMakeLists.txt
with the following contentfind_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)
target_link_libraries(${TARGET_PROJECT} LINK_PUBLIC ${TARGET_LOGGER})
. Also don't forget toadd_subdirectory(
third-party\spdlog
)
Then, in your project, you can use #include "spdlog/spdlog.h"
to include the library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With