ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

With the help of @wjwwood we came up with this workaround solution that still seems reliable. From what I can tell, CMake does not have proper support for exporting or installing shared targets, as per this convo:

Imported targets were originally designed for importing from an existing installation of some external package so installing did not make sense at the time.

In the first package's CMakeLists.txt that contains the pre-compiled shared object that you want to share:

set(foo_LOCATION ${PROJECT_SOURCE_DIR}/lib/libfoo.so)
add_library(${PROJECT_NAME} SHARED IMPORTED)
set_property(TARGET ${PROJECT_NAME} PROPERTY IMPORTED_LOCATION ${foo_LOCATION})

# Unfortuantly an imported target is not copied to the devel/lib folder, so we do it manually
# so that installation of a catkin workspace is not required
# See http://answers.ros.org/question/223866/cmakecatkin-how-to-export-imported-target/
file(COPY ${foo_LOCATION}
  DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)

# Mark imported library for installation using a workaround since imported
# targets do not have proper support for installation in CMakeLists
install(FILES ${foo_LOCATION} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

And in the second packge's CMakeLists.txt the foo library is automatically linked using the normal

target_link_libraries(bar
  ${catkin_LIBRARIES}
)

With the help of @wjwwood we came up with this workaround solution that still seems reliable. From what I can tell, CMake does not have proper support for exporting or installing shared targets, as per this convo:

Imported targets were originally designed for importing from an existing installation of some external package so installing did not make sense at the time.

Our Solution:

In the first package's CMakeLists.txt that contains the pre-compiled shared object that you want to share:

set(foo_LOCATION ${PROJECT_SOURCE_DIR}/lib/libfoo.so)
add_library(${PROJECT_NAME} SHARED IMPORTED)
set_property(TARGET ${PROJECT_NAME} PROPERTY IMPORTED_LOCATION ${foo_LOCATION})

# Unfortuantly an imported target is not copied to the devel/lib folder, so we do it manually
# so that installation of a catkin workspace is not required
# See http://answers.ros.org/question/223866/cmakecatkin-how-to-export-imported-target/
file(COPY ${foo_LOCATION}
  DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)

# Mark imported library for installation using a workaround since imported
# targets do not have proper support for installation in CMakeLists
install(FILES ${foo_LOCATION} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

And in the second packge's CMakeLists.txt the foo library is automatically linked using the normal

target_link_libraries(bar
  ${catkin_LIBRARIES}
)

With the help of @wjwwood we came up with this workaround solution that still seems reliable. From what I can tell, CMake does not have proper support for exporting or installing shared targets, as per this convo:

Imported targets were originally designed for importing from an existing installation of some external package so installing did not make sense at the time.

Our Solution:

In the first package's CMakeLists.txt that contains the pre-compiled shared object that you want to share:share, you need the following. Note that in this example ${PROJECT_NAME} and "foo" must be the same name, since we are using ${PROJECT_NAME} as the name of the library. This can be changed though.

set(foo_LOCATION ${PROJECT_SOURCE_DIR}/lib/libfoo.so)
add_library(${PROJECT_NAME} SHARED IMPORTED)
set_property(TARGET ${PROJECT_NAME} PROPERTY IMPORTED_LOCATION ${foo_LOCATION})

# Unfortuantly an imported target is not copied to the devel/lib folder, so we do it manually
# so that installation of a catkin workspace is not required
# See http://answers.ros.org/question/223866/cmakecatkin-how-to-export-imported-target/
file(COPY ${foo_LOCATION}
  DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)

# Mark imported library for installation using a workaround since imported
# targets do not have proper support for installation in CMakeLists
install(FILES ${foo_LOCATION} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

And in the second packge's CMakeLists.txt the foo library is automatically linked using the normal

target_link_libraries(bar
  ${catkin_LIBRARIES}
)

With the help of @wjwwood we came up with this workaround solution that still seems reliable. From what I can tell, CMake does not have proper support for exporting or installing shared imported targets, as per this convo:

Imported targets were originally designed for importing from an existing installation of some external package so installing did not make sense at the time.

Our Solution:

In the first package's CMakeLists.txt that contains the pre-compiled shared object that you want to share, you need the following. Note that in this example ${PROJECT_NAME} and "foo" must be the same name, since we are using ${PROJECT_NAME} as the name of the library. This can be changed though.

set(foo_LOCATION ${PROJECT_SOURCE_DIR}/lib/libfoo.so)
add_library(${PROJECT_NAME} SHARED IMPORTED)
set_property(TARGET ${PROJECT_NAME} PROPERTY IMPORTED_LOCATION ${foo_LOCATION})

# Unfortuantly an imported target is not copied to the devel/lib folder, so we do it manually
# so that installation of a catkin workspace is not required
# See http://answers.ros.org/question/223866/cmakecatkin-how-to-export-imported-target/
file(COPY ${foo_LOCATION}
  DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)

# Mark imported library for installation using a workaround since imported
# targets do not have proper support for installation in CMakeLists
install(FILES ${foo_LOCATION} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

And in the second packge's CMakeLists.txt the foo library is automatically linked using the normal

target_link_libraries(bar
  ${catkin_LIBRARIES}
)

With the help of @wjwwood we came up with this workaround solution that still seems reliable. From what I can tell, CMake does not have proper support for exporting or installing imported targets, as per this convo:

Imported targets were originally designed for importing from an existing installation of some external package so installing did not make sense at the time.

Our Solution:

In the first package's CMakeLists.txt that contains the pre-compiled shared object that you want to share, you need the following. Note that in this example ${PROJECT_NAME} and "foo" must be the same name, since we are using ${PROJECT_NAME} as the name of the library. This can be changed though.

# Configure Locations
set(foo_LOCATION ${PROJECT_SOURCE_DIR}/lib/libfoo.so)
set(foo_DESTINATION ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION})
MESSAGE( STATUS "foo_LOCATION:         " ${foo_LOCATION} )
MESSAGE( STATUS "foo_DESTINATION:      " ${foo_DESTINATION} )

# Foo library
add_library(${PROJECT_NAME} SHARED IMPORTED)
set_property(TARGET ${PROJECT_NAME} PROPERTY IMPORTED_LOCATION ${foo_LOCATION})

# Unfortuantly an imported target is not copied to the devel/lib folder, so we do it manually
# so that installation of a catkin workspace is not required
# See http://answers.ros.org/question/223866/cmakecatkin-how-to-export-imported-target/
file(COPY ${foo_LOCATION}
  DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)
${foo_DESTINATION}
)


# Mark imported library for installation using a workaround since imported
# targets do not have proper support for installation in CMakeLists
install(FILES ${foo_LOCATION} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

And in the second packge's CMakeLists.txt the foo library is automatically linked using the normal

target_link_libraries(bar
  ${catkin_LIBRARIES}
)

With the help of @wjwwood we came up with this workaround solution that still seems reliable. From what I can tell, CMake does not have proper support for exporting or installing imported targets, as per this convodiscussion:

Imported targets were originally designed for importing from an existing installation of some external package so installing did not make sense at the time.

Our Solution:

In the first package's CMakeLists.txt that contains the pre-compiled shared object that you want to share, you need the following. Note that in this example ${PROJECT_NAME} and "foo" must be the same name, since we are using ${PROJECT_NAME} as the name of the library. This can be changed though.

# Configure Locations
set(foo_LOCATION ${PROJECT_SOURCE_DIR}/lib/libfoo.so)
set(foo_DESTINATION ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION})
${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/lib${PROJECT_NAME}.so)
MESSAGE( STATUS "foo_LOCATION:         " ${foo_LOCATION} )
MESSAGE( STATUS "foo_DESTINATION:      " ${foo_DESTINATION} )

# Foo library
add_library(${PROJECT_NAME} SHARED IMPORTED)
set_property(TARGET ${PROJECT_NAME} PROPERTY IMPORTED_LOCATION ${foo_LOCATION})

# Unfortuantly an imported target is not copied to the devel/lib folder, so we do it manually
# so that installation of a catkin workspace is not required
# See http://answers.ros.org/question/223866/cmakecatkin-how-to-export-imported-target/
file(COPY ${foo_LOCATION}
  DESTINATION ${foo_DESTINATION}
)


# Mark imported library for installation using a workaround since imported
# targets do not have proper support for installation in CMakeLists
install(FILES ${foo_LOCATION} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

And in the second packge's CMakeLists.txt the foo library is automatically linked using the normal

target_link_libraries(bar
  ${catkin_LIBRARIES}
)