[cmake-developers] Local target aliases

Egor Pugin egor.pugin at gmail.com
Mon Dec 12 13:49:41 EST 2016


> If your trees are so huge or import so many other third-party projects that name collisions are a problem

They are. I'm predicting possible collisions, but it's ok for now.

> ... ExternalProject.

Not much suitable.

---

Ok, I'll try to do some workarounds. Thanks for the replies.

On 12 December 2016 at 20:02, Brad King <brad.king at kitware.com> wrote:
> On 12/12/2016 11:35 AM, Egor Pugin wrote:
>> So, the original proposal is to make ALIAS & OBJECT targets local. And
>> explicit GLOBAL keyword will make them global again.
>
> An OBJECT library is just like any other target as far as the generated
> build system is concerned, so it needs a globally unique name like any
> other.  The purpose of ALIAS targets is this:
>
> ```
> # some/subdir/CMakeLists.txt
> add_library(lib1 lib1.cpp)
> install(TARGETS lib1 EXPORT lib1Export ${dest_args})
> install(EXPORT lib1Export NAMESPACE Upstream:: ${other_args})
> add_library(Upstream::lib1 ALIAS lib1)
> ```
>
> Then other code in the project can use the name `Upstream::lib1` as
> if it had imported that target (e.g. for test trees that may build
> inside the project or externally).  The other code is not necessarily
> in the same directory, so the global visibility of ALIAS targets is
> an intentional design decision.  Since the aliased target has a globally
> unique name, so would the ALIAS if it is only used to prefix a namespace.
>
> If your trees are so huge or import so many other third-party projects
> that name collisions are a problem, then I suggest breaking it down
> using ExternalProject.
>
> -Brad



-- 
Egor Pugin


More information about the cmake-developers mailing list