From 8e0c8652906116f4d8138f8482f15acb7cdaad4f Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Tue, 19 Nov 2024 13:15:45 -0600 Subject: [PATCH] Port symlink_install fixes from ament_cmake to catkin 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. --- .../catkin_symlink_install.cmake.in | 6 +++++- .../catkin_symlink_install_files.cmake | 19 ++++++++++++++++++- .../catkin_symlink_install_targets.cmake | 9 +++++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/cmake/symlink_install/catkin_symlink_install.cmake.in b/cmake/symlink_install/catkin_symlink_install.cmake.in index 34fe51ecd..a246bc28a 100644 --- a/cmake/symlink_install/catkin_symlink_install.cmake.in +++ b/cmake/symlink_install/catkin_symlink_install.cmake.in @@ -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}") @@ -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}") diff --git a/cmake/symlink_install/catkin_symlink_install_files.cmake b/cmake/symlink_install/catkin_symlink_install_files.cmake index f4bab3e53..13b824fff 100644 --- a/cmake/symlink_install/catkin_symlink_install_files.cmake +++ b/cmake/symlink_install/catkin_symlink_install_files.cmake @@ -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. @@ -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}_$.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() diff --git a/cmake/symlink_install/catkin_symlink_install_targets.cmake b/cmake/symlink_install/catkin_symlink_install_targets.cmake index 32ae5a9e7..7367088bf 100644 --- a/cmake/symlink_install/catkin_symlink_install_targets.cmake +++ b/cmake/symlink_install/catkin_symlink_install_targets.cmake @@ -73,11 +73,12 @@ function(catkin_symlink_install_targets) "'${target}' is an imported target") endif() list(APPEND target_files "$") - if(WIN32) - get_target_property(target_type "${target}" TYPE) - if("${target_type}" STREQUAL "SHARED_LIBRARY") - list(APPEND target_files "$") + get_target_property(target_type "${target}" TYPE) + if("${target_type}" STREQUAL "SHARED_LIBRARY") + if(NOT WIN32) + list(APPEND target_files "$") endif() + list(APPEND target_files "$") endif() endforeach()