0

I am working on a project where we need to find the internal dependencies of a C/C++ project. To do so, I need to find the include paths for each source directory of the project.

If the project is built with a Makefile then I can use make -n to know exactly which -I options are used for what file.

If the project is instead built with a CMakeLists.txt file then I have no idea on how to proceed. CMake uses

include_directories([AFTER|BEFORE] [SYSTEM] dir1 [dir2 ...])  # OR....

target_include_directories(<target> [SYSTEM] [BEFORE]
  <INTERFACE|PUBLIC|PRIVATE> [items1...]
  [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...]))

to denote what include directories to use, but excluding the trivial case where the directory is specified directly, I have no idea how to find the include paths.

So my question is, does anyone know how to extract the include paths used for each folder/file from a CMakeLists.txt?

Thanks!

Darius Sas
  • 11
  • 4
  • You don't need to parse the CMakeLists.txt to get that information, but can use the compiler flags of the `-M` family to obtain a list of the header dependencies of each source file. Here's a solution which does this using `make`: http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ – πάντα ῥεῖ Oct 17 '20 at 09:22
  • Also to know what's used by CMake, you can just output the contents of the `INCLUDE_DIRECTORIES` variable using the `MESSAGE()` command.. – πάντα ῥεῖ Oct 17 '20 at 09:25
  • https://cmake.org/cmake/help/v3.5/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html – Alan Birtles Oct 17 '20 at 09:37
  • You could also run "include what you use" to minimize the dependencies. – Botje Oct 17 '20 at 10:45

0 Answers0