Skip to content

Commit

Permalink
Port symlink_install fixes from ament_cmake to catkin (ros#1199)
Browse files Browse the repository at this point in the history
Symlink installs in catkin are used by colcon to provide a similar
experience to a catkin devel space. To be clear, this code is not used
by catkin itself or catkin_tools.

Specifically, this change includes fixes from the following ament_cmake
commits:
* 8b92e4affbd18b08a703897698960007738ee1b5
* fb1eda91c16a9423a8a96541e878358289e1b2b2
* 69afa32843a95dbed072c3eee282424a214f878a

In my testing, these fixes were necessary to support symlink builds of
the vast majority of ROS 1 packages released to date. Without this
change, there are very common packages in ROS Noetic today which cannot
be built with colcon when catkin symlinking is enabled.
  • Loading branch information
cottsay authored and rhaschke committed Nov 21, 2024
1 parent 5a4540c commit 0b3805c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
6 changes: 5 additions & 1 deletion cmake/symlink_install/catkin_symlink_install.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ function(catkin_symlink_install_targets)
"unused/unsupported arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()

list(REVERSE ARG_TARGET_FILES)
list(REMOVE_DUPLICATES ARG_TARGET_FILES)
list(REVERSE ARG_TARGET_FILES)

# iterate over target files
foreach(file ${ARG_TARGET_FILES})
if(NOT IS_ABSOLUTE "${file}")
Expand All @@ -239,7 +243,7 @@ function(catkin_symlink_install_targets)
get_filename_component(fileext "${file}" EXT)
if(fileext STREQUAL ".a" OR fileext STREQUAL ".lib")
set(destination "${ARG_ARCHIVE_DESTINATION}")
elseif(fileext STREQUAL ".dylib" OR fileext MATCHES "\\.so(\\.[0-9]+)?(\\.[0-9]+)?(\\.[0-9]+)?$")
elseif(fileext MATCHES "(\\.[0-9]+)?(\\.[0-9]+)?(\\.[0-9]+)?\\.dylib$" OR fileext MATCHES "\\.so(\\.[0-9]+)?(\\.[0-9]+)?(\\.[0-9]+)?$")
set(destination "${ARG_LIBRARY_DESTINATION}")
elseif(fileext STREQUAL "" OR fileext STREQUAL ".dll" OR fileext STREQUAL ".exe")
set(destination "${ARG_RUNTIME_DESTINATION}")
Expand Down
19 changes: 18 additions & 1 deletion cmake/symlink_install/catkin_symlink_install_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set(__CATKIN_SYMLINK_INSTALL_FILES_INDEX "0"
CACHE INTERNAL "Index for unique symlink install files")

#
# Reimplement CMake install(FILES) command to use symlinks instead of copying
# resources.
Expand Down Expand Up @@ -42,8 +45,22 @@ function(catkin_symlink_install_files files_keyword)

if(index EQUAL -1)
string(REPLACE ";" "\" \"" argn_quoted "\"${ARGN}\"")

# generate unique files
set(generated_file_base
"${CMAKE_CURRENT_BINARY_DIR}/catkin_symlink_install_files_${__CATKIN_SYMLINK_INSTALL_FILES_INDEX}")
set(generated_file_generator_suffix "${generated_file_base}_$<CONFIG>.cmake")
set(generated_file_variable_suffix "${generated_file_base}_\${CMAKE_INSTALL_CONFIG_NAME}.cmake")
math(EXPR __CATKIN_SYMLINK_INSTALL_FILES_INDEX
"${__CATKIN_SYMLINK_INSTALL_FILES_INDEX} + 1")
set(__CATKIN_SYMLINK_INSTALL_FILES_INDEX "${__CATKIN_SYMLINK_INSTALL_FILES_INDEX}"
CACHE INTERNAL "Index for unique symlink install files")

file(GENERATE OUTPUT "${generated_file_generator_suffix}"
CONTENT
"catkin_symlink_install_files(CURRENT_SOURCE_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\" FILES ${argn_quoted})\n")
catkin_symlink_install_append_install_code(
"catkin_symlink_install_files(CURRENT_SOURCE_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\" FILES ${argn_quoted})"
"include(\"${generated_file_variable_suffix}\")"
COMMENTS "install(FILES ${argn_quoted})"
)
endif()
Expand Down
9 changes: 5 additions & 4 deletions cmake/symlink_install/catkin_symlink_install_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ function(catkin_symlink_install_targets)
"'${target}' is an imported target")
endif()
list(APPEND target_files "$<TARGET_FILE:${target}>")
if(WIN32)
get_target_property(target_type "${target}" TYPE)
if("${target_type}" STREQUAL "SHARED_LIBRARY")
list(APPEND target_files "$<TARGET_LINKER_FILE:${target}>")
get_target_property(target_type "${target}" TYPE)
if("${target_type}" STREQUAL "SHARED_LIBRARY")
if(NOT WIN32)
list(APPEND target_files "$<TARGET_SONAME_FILE:${target}>")
endif()
list(APPEND target_files "$<TARGET_LINKER_FILE:${target}>")
endif()
endforeach()

Expand Down

0 comments on commit 0b3805c

Please sign in to comment.