I have a quite large CMake-based project and found that while generating solution for Visual Studio on Windows I got current project home directory as an include directory. E.g. here's content of root directory:
- A
- impl
- source.cpp
- header.h
- CMakeLists.txt
- B
- CMakeLists.txt
In source.cpp I accidentally wrote #include "header.h" instead of #include <A/header.h>. And such solution was successfully compiled since the directory A for some reason was added to the list called "Additional Include Directories" in Visual Studio project (i.e. in command-line added as one more /I option).
Same source slice gives error on Linux build similar to header.h not found (and it's expected behavior).
Which steps should I take to find the source why does CMake adds target A's root directory to the list of include_directories. I used the answer to print a list of project related include directories. CMake version is 3.27.1.
You may want to print the
[INTERFACE_]INCLUDE_DIRECTORIESvia a custom target using generator expressions. This could allow you to go through the dependencies recursively until you find the root of the issue. This will not help you detect the use of theinclude_directoriescommand though.print_target_info.cmake
CMakeLists.txt
This allows you to see the info in the command line output when building the target
print_target_info.In addition you could use the
--graphviz=...option to make identifying dependencies easier, perhaps even spotting differences between both platforms