[CMake] Transitive linking and static libraries

Matthew Woehlke matthew.woehlke at kitware.com
Thu Oct 17 15:40:55 EDT 2013


On 2013-10-17 12:58, James Bigler wrote:
> It doesn't seem to work.
>
> I can't use target_link_libraries on an imported target.
>
> add_library(imported_lib STATIC IMPORTED GLOBAL)
> set_target_properties(imported_lib PROPERTIES IMPOARTED_LOCATION
> "${imported_lib_location}")
> target_link_libraries(imported_lib other_lib)
>
> Produces an error:
>
> Attempt to add link library [imported_lib_location] to target imported_lib
> which is not built in this directory.

You don't actually want to relink the imported library, just set its 
interface libraries:

   set_target_properties(imported_lib PROPERTIES
     IMPORTED_LOCATION "${imported_lib_location}"
     IMPORTED_LINK_INTERFACE_LIBRARIES other_lib)

-- 
Matthew



More information about the CMake mailing list