I’m using include()-s all around even for the same module or file, eg. include(TinyHelpers), I’m including it in the main CMakeLists.txt file at the top as it’s needed there, but I’m also including it in deeper modules or add_subtirectory()-ies.
One example for all, I have include(TinyTestCommon) in every test project ~46, I can remove all of them and instead use one include in the tests/CMakeLists.txt or a little deeper in my case like:
include(TinyTestCommon)
add_subdirectory(functional)
add_subdirectory(unit)
In C++ you can #include in a deeper header file and then you can omit this #include in the parent file (this works in CMake too).
But in CMake, you can include() in top-level CMakeLists.txt and you don’t have to include() anywhere else then (this doesn’t work eg. in C++).
Now I’m wondering if it’s a good idea to remove include()-s I described in the paragraph above.
I suppose that CMake simply includes everywhere and doesn’t track whether the include is already in the scope, which means it can also increase performance? (No performance gain, I tried to remove ~56 include()-s and no performance gain).
But anyway should I look at it like they are duplicate includes or like every project should be self-contained and should be able to configure standalone?
Even when I removed all includes and they are only in the parent files I’m still able to rebuild sub-projects which doesn’t contain these includes like:
cmake.exe --build <buildPath> --target mysql_querybuilder
This only supports the claim they are duplicate includes as I’m still able to build these sub-projects without these includes.
I searched in Scott book, docs, and also forum and found nothing about this problem.
How do you manage your includes?