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

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu Mar 8 15:49:28 EST 2018


On 2018-03-08 20:05+0100 Nils Gladitz wrote:

> On 08.03.2018 19:50, Alan W. Irwin wrote:
>> So what are the actual benefits of namespacing the exported targets
>> associated with libraries? 
>
> On the consumer side it makes linking to targets less error prone.
>
> When you link to a library target without a namespace and e.g. get the name 
> or scope wrong CMake will silently assume that you want to link a library by 
> name (e.g. in context of gcc "foo" becomes "-lfoo").
> When the library and its headers happens to be in the compiler's standard 
> search directories this might not even get caught at build time right away.
>
> When the library target has a namespace CMake will require the given name to 
> be a target and will fail during generation if the target is not actually 
> available.

Hi Nils:

Thanks for that explanation which convinced me this particular "best
practice" is worth implementing along with the rest mentioned in
<https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/>.

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