[cmake-developers] Allow ALIAS of IMPORTED targets

Stephen Kelly steveire at gmail.com
Mon Sep 14 13:34:10 EDT 2015


Michael Scott wrote:

> Hi,
> 
> I'm planning on having a look at the CMake issue "Allow ALIAS of
> IMPORTED targets", 0015569. After reading the thread between yourself
> and Marc, I wanted to ask a couple of things before I start going
> further with it.

Thanks for working on this.

> The proposed change would be for the add_library and add_executable
> commands only right?

Yes, I guess so.

> Having a quick look at the code for those two commands, they
> specifically check for a combination of ALIAS and IMPORTED and don't
> allow it. I'm guessing that the required changes to allow both
> simultaneously wouldn't be to just remove this check, there would be
> other areas to modify as well right?

Perhaps. Finding that out is the real task :). I don't have all the answers 
to it. The specific disallowing of ALIAS and IMPORTED together by issuing an 
error was a way to defer finding those answers while not being required to 
maintain compatibility with a particular behavior. I didn't want finding 
those answers to delay getting the ALIAS feature in, because it was useful 
already as it was.

Now, we have time to consider all of the implications of allowing this as 
part of the design.

For example, if an ALIAS can be IMPORTED, does it makes sense that it can be 
exported with export() and install(EXPORT)?

If we have 

 add_library(CoreStatic ${Core_SRCS})
 add_library(MyNS::Core ALIAS CoreStatic)

and I export both of them with the NAMESPACE 'MyNS::', do I end up with 

 MyNS::MyNS::Core 

?

Or would the exporting code strip of everything before a '::' in the alias 
name?

Or should exporting ALIAS targets still be disallowed?

The two use cases described in 
 
 http://thread.gmane.org/gmane.comp.programming.tools.cmake.user/52452

seem like they would not benefit from exporting ALIAS targets.

A reasonable way forward might be:

* Keep the restriction that ALIAS targets may not be exported.
* Remove the code disallowing ALIAS IMPORTED targets.
* Remove the unit test proving it is not allowed
* Add new unit tests that it basically works
* Add a unit test for using an ALIAS with try_compile(LINK_LIBRARIES)
* (Anything else that comes up along the way)

Thanks,

Steve.




More information about the cmake-developers mailing list