Search code examples
c++cmakelibraries

How to have library name preceding header name on a #include?


I'm using cmake to compile a project with the following structure:

Root

  • LibA
    • inc
    • src
  • LibB
    • inc
    • src
  • main.cpp

I have CMakeLists on each LibX, each src and Root folders.

My project is compiling and working as expected. But I would like to include headers as: include "{LibX}/{header}.h" instead of just "{header}.h" or instead of putting the absolute/relative path to the header.

Since I'm setting all the include directories in CMakeLists, I can simply include a header with its name, but that's not really the best solution.

For example, my main.cpp depends on LibA and LibB, and LibA depends on LibB, which is a math library. It would be good to know from which library I'm including a header every time.

Thank you


Solution

  • Root/LibA/inc/LibA/MyHeaderFileFromA.h

    #include <LibA/MyHeaderFileFromA.h>
    

    there you go