[CMake] Custom-target is in Visual Studio not added to default build in case custom-target is not part of sub-directory tree of project (solution)

William Deurwaarder William.Deurwaarder at tomtom.com
Fri Apr 11 09:00:02 EDT 2014


Hi,

Summary: What is the reason that custom-targets that are needed by a project and its dependencies are not added to the default-build in Visual Studio in case that target is defined out-side the sub-directory tree of this project?

I have the following directory-structure:

root/A -> in this CMakeLists.txt a custom-target is defined
root/B -> in this CMakeLists.txt a static-library is defined which depends on A (A will generate files for this library)
root/C -> in this CMakeLists.txt the executable is defined which depends on B (there is no dependency added for A; of course that could be done in this case but my real case is much more complex and I do not want to explicit lists all custom-target dependencies here)
root -> in this CMakeLists.txt all three sub-directories are added.

The real case is much more complex and I cannot add A under C, or put C in the root, etc.

With Linux and make this works fine. For Windows and Visual Studio the solution-file of C (in directory of C) does not add A to the default-build (although it is added as a dependency for B). This means that A is not executed which results in compiler-errors as B misses files that should have been generated by A.

Looking into the code I see that the line to add A to the default-build (IsPartOfDefaultBuild) is conditional for UTILITY-targets (it is only added if there is a direct dependency that means or is part of the sub-directory of C or has a direct dependency which is added by add_dependencies). My question is what is the reason to exclude A from the default-build in case it has a transitive dependency (via B)? Would it be possible to change that so in case A is needed via a transitive dependency A is also included to the default-build.

Thanks for your insight and answers,

William Deurwaarder


More information about the CMake mailing list