[CMake] add_subdirectory namespaces

Jason Beach jason.m.beach at gmail.com
Wed Jul 24 07:29:06 EDT 2019


I've been reorganizing / updating our software cmake build. It currently
uses a mixture of Externa Projects and normal target definitions that
depend on the external projects (which has you probably know causes much
sorrow and grief).  One of my goals in the reorganization was to replace
all the ExternalProjectAdd statements with FetchContent, however I soon
discovered that some of the external projects declare targets with the same
name (i.e. an uninstall target).  These external projects are third party
libraries that are not under our control.

It appears there's been a suggestion to add namespaces to the
add_subdirectory command:
https://gitlab.kitware.com/cmake/cmake/issues/16414

Is that going anywhere?  It seems like that would address FetchContent's
main limitation. I guess for the time being I'll use ExternalProject for
thirdparty libraries not under our control and FetchContent for libraries
that are and do a true super build instead of the muddled sort of
arrangement we have now.

One other kind of not-so-random question-the documentation on the Project
statement is fine if it's in the toplevel CMakeLists.txt (in which case it
defines some project level variables, etc.) but it's silent about what
happens if it's not in the top level CMakeLists.txt.  i.e. if I add a
library via add_subdirectory or FetchContent and that library's toplevel
CMakeLists.txt has the project statement, what happens when it's executed?
Is it silently ignored?

Thanks,
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190724/984ed73b/attachment.html>


More information about the CMake mailing list