[cmake-developers] Namespaces
Stephen Kelly
steveire at gmail.com
Thu Jan 28 13:17:11 EST 2016
Pau Garcia i Quiles wrote:
> add_subdirectory(pugixml/scripts)
> add_subdirectory(QtZeroConf)
> add_subdirectory(QtDropBox)
> add_subdirectory(websocketpp)
>
> This is an easy way to work with third-party dependences.
Unfortunately this is 'easy, obvious and wrong'.
> My problem comes from the fact several of these third-party libraries use
> common variable names, e. g. BUILD_SHARED, BUILD_TESTS, etc).
And indeed this is why.
> Has some kind of namespacing been considered for add_subdirectory?
>
> E. g.
>
> add_subdirectory(QtZeroConf NAMESPACE QTZEROCONF)
And what if someone builds your project with -DBUILD_SHARED=ON? Are you
going to use
set(QTZEROCONF_BUILD_SHARED ${BUILD_SHARED})
add_subdirectory(QtZeroConf NAMESPACE QTZEROCONF)
for every variable you're wrapping? Or do you want cmake to do that for
every variable in scope when the directory is added? How would cmake decide
which variables to namespace?
You should use ExternalProject instead, or fork the buildsystem of those
projects to integrate them into your project. Not that I recommend the
latter for you though :). That's what cmake does when integrating 3rd party
code.
Thanks,
Steve.
More information about the cmake-developers
mailing list