I have a header-only library project. In my CMakeLists.txt I use INTERFACE library type
I wanted to import this project into CLion, but when I open any of the header files the IDE complains that this file does not belong to any project target
So is there a way to develop a header-only project in CLion?
Test project layout is pretty simple:
% tree foo
foo
├── CMakeLists.txt
└── foo.hpp
And CMakeLists content is
cmake_minimum_required(VERSION 3.8)
project(foo)
add_library(foo INTERFACE)
target_include_directories(foo INTERFACE ${PROJECT_SOURCE_DIR})
target_sources(foo INTERFACE ${PROJECT_SOURCE_DIR}/foo.hpp)
CLion 2017.2 + CMake 3.8
target_sourcesshould solve the problem. I had the same problem and was able to resolve it by addingtarget_sources. I am using${CMAKE_CURRENT_SOURCE_DIR}which resolves to the location where theCMakeLists.txtis located. I then specify the location relative to that directory, something like:${CMAKE_CURRENT_SOURCE_DIR}/path/to/foo.hpp- lanoxx