[cmake-developers] Namespaces

Pau Garcia i Quiles pgquiles at elpauer.org
Thu Jan 28 12:47:48 EST 2016


Hello,

I am adding several third-party projects as static libraries in my project.
This is what I do:


CMakeLists.txt
|
\-- 3rdparty
     |
     \---- pugixml
     |
     \---- QtZeroConf
     |
     \---- QtDropBox
     |
     \---- websocketpp


In the root CMakeLists.txt, I have:

add_subdirectory(3rdparty)

And in 3rdparty/CMakeLists.txt:

add_subdirectory(pugixml/scripts)
add_subdirectory(QtZeroConf)
add_subdirectory(QtDropBox)
add_subdirectory(websocketpp)

This is an easy way to work with third-party dependences.

My problem comes from the fact several of these third-party libraries use
common variable names, e. g. BUILD_SHARED, BUILD_TESTS, etc).

Has some kind of namespacing been considered for add_subdirectory?

E. g.

add_subdirectory(QtZeroConf NAMESPACE QTZEROCONF)

Which would lead to all the variables defined QtZeroConf/CMakeLists.txt
having a QTZEROCONF_ prefix, e. g. instead of BUILD_SHARED it would now be
QTZEROCONF_BUILD_SHARED.

Or, as an alternative:

add_subdirectory QtZeroConf NAMESPACE QtZeroConf)

and variables would be prefixed by QtZeroConf::, e. g. BUILD_SHARED would
now be QtZeroConf::BUILD_SHARED.

Does that sound sensible?



-- 
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160128/47a690fa/attachment.html>


More information about the cmake-developers mailing list