MantisBT - CMake
View Issue Details
0014311CMakeCMakepublic2013-07-25 05:192016-06-10 14:31
Nikita Krupenko 
Kitware Robot 
normalmajoralways
closedmoved 
x86Windows7
CMake 2.8.11.2 
 
0014311: CMake cannot install imported targets
I use ExternalProject for building non-Cmake projects and add imported targets for that projects. For example:

ExternalProject_add(mylib_proj ...)
add_library(mylib SHARED IMPORTED)
set_target_properties(mylib PROPERTIES IMPORTED_LOCATION ...)
add_dependencies(mylib mylib_proj)

I can link with that library, but CMake cannot install them. This code

install(TARGETS mylib DESTINATION ...)

produces following error:

CMake Error at CMakeLists.txt:48 (install):
  install TARGETS given target "mylib" which does not exist in this
  directory.

Because of broken install packaging using CPack also not working.
No tags attached.
Issue History
2013-07-25 05:19Nikita KrupenkoNew Issue
2013-07-25 08:32Brad KingNote Added: 0033603
2013-07-25 08:32Brad KingStatusnew => backlog
2013-07-25 08:38Nikita KrupenkoNote Added: 0033604
2013-07-25 08:44Nikita KrupenkoNote Added: 0033605
2013-07-25 08:53Brad KingNote Added: 0033606
2015-11-05 01:39Kishore JonnalagaddaNote Added: 0039836
2016-04-18 01:17Alex TurbovNote Added: 0040877
2016-05-12 15:09AleXoundOSNote Added: 0041062
2016-06-10 14:29Kitware RobotNote Added: 0042326
2016-06-10 14:29Kitware RobotStatusbacklog => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0033603)
Brad King   
2013-07-25 08:32   
Imported targets were originally designed for importing from an existing installation of some external package so installing did not make sense at the time. Later this interaction with ExternalProject was invented.

ExternalProject_add supports an INSTALL_COMMAND step to use the external build-system's own install rules. If it doesn't have any then you could also use install(SCRIPT) or install(CODE) add custom install code for them.
(0033604)
Nikita Krupenko   
2013-07-25 08:38   
How can I pack this imported targets with CPack? To do so, I must use the install() command.
(0033605)
Nikita Krupenko   
2013-07-25 08:44   
I also found one solution:

get_target_property(MYLIB_LOCATION mylib LOCATION)
install(FILES ${MYLIB_LOCATION} DESTINATION ...)

This works, but maybe install command can be improved to handle imported targets.
(0033606)
Brad King   
2013-07-25 08:53   
Since the example includes

 set_target_properties(mylib PROPERTIES IMPORTED_LOCATION ...)

where the "..." knows the location already you don't need to get the LOCATION property.
(0039836)
Kishore Jonnalagadda   
2015-11-05 01:39   
This is also useful when including prebuilt library binaries in the project.

add_library(prebuilt STATIC IMPORTED)
set_property(TARGET prebuilt PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libprebuilt.a)

install(TARGETS other_built_targets prebuilt
    EXPORT project-export
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
)

Making prebuilt an imported target makes in convenient to use in the project and treats it further like any other target.
(0040877)
Alex Turbov   
2016-04-18 01:17   
+1 for the last comment from Kishore Jonnalagadda!
I have exacly the same case now :(
(0041062)
AleXoundOS   
2016-05-12 15:09   
+1 for Kishore Jonnalagadda's comment
(0042326)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.