CLion does not find libraries included via add_subdirectory()

已完成

I have a CMake-based project that uses FMT library, which I include in CMakeList.txt like this:

# fmt (FMT)
add_subdirectory(../../../../local/libs/external/fmt/9.1.0 build/projects/libs/fmt) 

Then in a source file I have:

#include <fmt/format.h>
#include <fmt/ostream.h>

And CLion puts “fmt” in red - and says it “Cannot find directory 'fmt' in search paths:”.

However, the program compiles and links properly. So the CMakeList.txt is fine (as it compiles), but still CLion does not find the library.

(If I add “include” folder of the FMT to include_directories then it works, but I use add_subdirectory exactly for the purpose of not adding library sources manually. And works for compilation without adding to include_directories  -  as one would expect).

How to solve it for CLion?

 

0

Ok, I found a solution (which is a bit my fault). 

You need to add 

target_link_libraries(global PRIVATE  fmt::fmt)

To the target that you use in CLion. If the library is included with add_subdirectory but it not used in linking, then CLion doesn't see it.

 

0

请先登录再写评论。