CLion and add_library (target interface)

I have a library project for header only. In my CMakeLists.txt I use the 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 goal

So is there a way to develop a project for headers only in CLion?

The layout of the test project is quite simple:

% tree foo
foo
├── CMakeLists.txt
└── foo.hpp

And the contents of CMakeLists

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

+6
source share
1 answer

I had the same problem after updating my CLion. You are very close, but you need to add another line:

add_library(target INTERFACE)
target_sources(target INTERFACE ${my_header_list})
target_include_directories(target INTERFACE ${CMAKE_SOURCE_DIR})

- . :

|-- myLib
  |-- CMakeLists.txt
  |-- myLib
    |-- foo.hpp
    |-- bar.hpp
    |-- etc...

, this.

+1

All Articles