Search code examples
c++c++11cmakeclanginclude-path

Cmake add include paths to clang


I am currently developing in C++ with Atom from GitHub. I found the addon autocomplete-clang which adds an autocomplete feature to Atom. My problem is, that I use cmake to build my program and I also use a project structure like this:

- Sensors
-- src
-- inc
- LowLevel
-- src
-- inc
- System
-- src
-- inc

I only use #include "someHeaderFromSystem.h" in the someSourceFileFromLowLevel.cxx in my code. This means, that clang does not find the include files.

Is there a way to tell clang where to find the files, which does not change any global system variable?


Solution

  • Add set(CMAKE_EXPORT_COMPILE_COMMANDS ON) to the CMakeLists.txt file which generates the file compile_commands.json. With this file the include directives are working correctly.