[CMake] What are the actual benefits of namespaced targets?

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu Mar 8 13:50:13 EST 2018


I am currently trying to update three CMake-based build systems (for
PLplot, ephcom, and te_gen) to use best practices following the really
useful example of best practice given at
<https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/>.

That example uses the NAMESPACE signature for the
install(EXPORT ... ) command to export its targets.  I realize that is
a quite common practice, but I don't understand the motivation for
this practice. After all, the library names (and therefore the
un-namespaced associated targets) already are virtually guaranteed to
be unique (since two projects with two different libraries with a
common library name would be an invitation to nameclash disaster). So
what are the actual benefits of namespacing the exported targets
associated with libraries?

The reason why I ask is namespaced targets would add some (small)
complexity to my build systems.  For example, I would need to define a
namespaced ALIAS target for each library in my build tree to use
common CMake logic to refer to that library in the build systems for
both my build tree and install tree.  (I use that common-code practice
for all three of the above projects.) Defining such ALIAS targets
should be absolutely straightforward, but I want to make sure the
actual namespaced target benefits outweigh this small added
complexity.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list