[CMake] Scope of imported targets

Mathias Gaunard mathias.gaunard at ens-lyon.org
Fri Jul 27 21:17:42 EDT 2012


On 28/07/2012 01:43, James Bigler wrote:
> Is there are particular reason why imported targets don't have global
> scope (doc says current directory and below), but regular targets do
> (seen everywhere)?
>
> This seems really inconsistent to me.
>
> I'm trying to build a custom library from other pieces using my own set
> of commands.  I can't use add_custom_target directly since I can't use
> the resulting target in target_link_libraries.  I then found a link
> where it suggested to use add_library(IMPORTED) and set the file with
> the results of my custom target.  Unfortunately, this library lives in a
> sub directory and it can't be seen outside like the original library
> used to.
>
> Now, I'm kind of stuck.  I want a library type target, but IMPORTED
> doesn't provide the correct scoping (i.e. global).

Personally, the only reliable way I've found to be able do what you want 
is to create a dummy library and then overwrite it by the custom one 
generated by a add_custom_command POST_BUILD command.



More information about the CMake mailing list