[CMake] EXCLUDE_FROM_ALL vs. EXCLUDE_FROM_DEFAULT_BUILD

Sebastian Kienzl seb at knzl.de
Fri Oct 28 06:14:15 EDT 2016


Hello all,

I like "EXCLUDE_FROM_ALL", because with the Make-generator I can define
library-targets that will not be built with "make all" *unless* another
target depends on it.

This way, I can define libraries that will only be built if another
target depends on it.

Maybe that's not exactly the idea of EXCLUDE_FROM_ALL, but it is
convenient this way.


However, I don't see how exactly the same can be achieved with
Visual Studio.

Yes, I could tell developers to build the "ALL_BUILD" project instead
of hitting F7 (to build the solution) but that's not convenient.


Why is this a problem for us?

Because a library that no one depends on may actually not even build
under Windows and we don't want to clutter our CMakeLists with

if(WIN32)
   add_subdirectory(...)
endif()
.

Build times is another thing.


This issue has already been filed:

https://gitlab.kitware.com/cmake/cmake/issues/12379

and discussed in these threads:

http://public.kitware.com/pipermail/cmake/2011-August/045662.html
http://public.kitware.com/pipermail/cmake/2013-February/053528.html


I can think of two solutions, the latter being the cleaner IMO:

1. A property on a library-target that inhibits generation of the
   respective Visual Studio project if no other target depends on it.

2. Being able to mark targets as being "non-standalone" in the sense
   that they'll be ignored by the generator if no other targets depends
   on them.


For our case I found myself this workaround:
https://gist.github.com/sebknzl/ff6524420890fe6fdbdbc7d3264b103a


Thanks for your attention and greetings from Munich,
Sebastian Kienzl



More information about the CMake mailing list