Search code examples
c++cmakespdlog

cmake include header only library


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.


Solution

  • First, don't use single quotes ' but double quotes " or just plain strings if they don't contain spaces.

    I would advice you to use find_path instead of adding includes directly. There you can add PATH_SUFFIXES. You get a message during configuration if the header is not found, which makes it easier to spot errors.
    Documentation: https://cmake.org/cmake/help/v3.6/command/find_path.html