Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell CLion to use header include path with prefix

Tags:

c++

cmake

clion

I have a project layout as follows:

  • workspace
    • project_a
      • project_a -> .h files here
      • Root -> .cxx files here
    • project_b
      • project_b -> .h files here
      • Root -> .cxx files here

I cannot change the directory layout due to the build system that we're using. Headers are included as

#include "project_a/some_header.h

also from the corresponding .cxx file. I've created a CMakeLists.txt file in the root directory, that adds all my projects via include_directories(project_a project_b), which should be the path prefixed before the one given in the #include. CLion does not manage to find and index any of my files.

Additionally, I have an automatically generated directory of headers of structure

  • include
    • lib_a -> .h files
    • lib_b -> .h files

and I've set them up accordingly, but it also does not work.

Does CLion not manage to resolve the prefixed path in the #include or why is this not working?

like image 995
paulgessinger Avatar asked Oct 23 '25 17:10

paulgessinger


1 Answers

In CMakeList.txt, which should be located in parent folder, "workspace" folder in that situation, add

set(INCLUDE_DIRECTORIES ./)

If, for example, there is a parent folder, that holds include files:

  • workspace
    • includes_folder
      • project_a
        • a.h
    • b.h: #include <project_a/a.h>

Then CMakeList.txt should contain

set(INCLUDE_DIRECTORIES ./)
include_directories(includes_folder)
like image 196
PolyGlot Avatar answered Oct 26 '25 05:10

PolyGlot