Skip to content

Commit 5264e37

Browse files
authored
Port symlink_install fixes from ament_cmake to catkin (#1199)
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.
1 parent 24e9b0a commit 5264e37

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

cmake/symlink_install/catkin_symlink_install.cmake.in

+5-1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ function(catkin_symlink_install_targets)
227227
"unused/unsupported arguments: ${ARG_UNPARSED_ARGUMENTS}")
228228
endif()
229229

230+
list(REVERSE ARG_TARGET_FILES)
231+
list(REMOVE_DUPLICATES ARG_TARGET_FILES)
232+
list(REVERSE ARG_TARGET_FILES)
233+
230234
# iterate over target files
231235
foreach(file ${ARG_TARGET_FILES})
232236
if(NOT IS_ABSOLUTE "${file}")
@@ -239,7 +243,7 @@ function(catkin_symlink_install_targets)
239243
get_filename_component(fileext "${file}" EXT)
240244
if(fileext STREQUAL ".a" OR fileext STREQUAL ".lib")
241245
set(destination "${ARG_ARCHIVE_DESTINATION}")
242-
elseif(fileext STREQUAL ".dylib" OR fileext MATCHES "\\.so(\\.[0-9]+)?(\\.[0-9]+)?(\\.[0-9]+)?$")
246+
elseif(fileext MATCHES "(\\.[0-9]+)?(\\.[0-9]+)?(\\.[0-9]+)?\\.dylib$" OR fileext MATCHES "\\.so(\\.[0-9]+)?(\\.[0-9]+)?(\\.[0-9]+)?$")
243247
set(destination "${ARG_LIBRARY_DESTINATION}")
244248
elseif(fileext STREQUAL "" OR fileext STREQUAL ".dll" OR fileext STREQUAL ".exe")
245249
set(destination "${ARG_RUNTIME_DESTINATION}")

cmake/symlink_install/catkin_symlink_install_files.cmake

+18-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
set(__CATKIN_SYMLINK_INSTALL_FILES_INDEX "0"
16+
CACHE INTERNAL "Index for unique symlink install files")
17+
1518
#
1619
# Reimplement CMake install(FILES) command to use symlinks instead of copying
1720
# resources.
@@ -42,8 +45,22 @@ function(catkin_symlink_install_files files_keyword)
4245

4346
if(index EQUAL -1)
4447
string(REPLACE ";" "\" \"" argn_quoted "\"${ARGN}\"")
48+
49+
# generate unique files
50+
set(generated_file_base
51+
"${CMAKE_CURRENT_BINARY_DIR}/catkin_symlink_install_files_${__CATKIN_SYMLINK_INSTALL_FILES_INDEX}")
52+
set(generated_file_generator_suffix "${generated_file_base}_$<CONFIG>.cmake")
53+
set(generated_file_variable_suffix "${generated_file_base}_\${CMAKE_INSTALL_CONFIG_NAME}.cmake")
54+
math(EXPR __CATKIN_SYMLINK_INSTALL_FILES_INDEX
55+
"${__CATKIN_SYMLINK_INSTALL_FILES_INDEX} + 1")
56+
set(__CATKIN_SYMLINK_INSTALL_FILES_INDEX "${__CATKIN_SYMLINK_INSTALL_FILES_INDEX}"
57+
CACHE INTERNAL "Index for unique symlink install files")
58+
59+
file(GENERATE OUTPUT "${generated_file_generator_suffix}"
60+
CONTENT
61+
"catkin_symlink_install_files(CURRENT_SOURCE_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\" FILES ${argn_quoted})\n")
4562
catkin_symlink_install_append_install_code(
46-
"catkin_symlink_install_files(CURRENT_SOURCE_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\" FILES ${argn_quoted})"
63+
"include(\"${generated_file_variable_suffix}\")"
4764
COMMENTS "install(FILES ${argn_quoted})"
4865
)
4966
endif()

cmake/symlink_install/catkin_symlink_install_targets.cmake

+5-4
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ function(catkin_symlink_install_targets)
7373
"'${target}' is an imported target")
7474
endif()
7575
list(APPEND target_files "$<TARGET_FILE:${target}>")
76-
if(WIN32)
77-
get_target_property(target_type "${target}" TYPE)
78-
if("${target_type}" STREQUAL "SHARED_LIBRARY")
79-
list(APPEND target_files "$<TARGET_LINKER_FILE:${target}>")
76+
get_target_property(target_type "${target}" TYPE)
77+
if("${target_type}" STREQUAL "SHARED_LIBRARY")
78+
if(NOT WIN32)
79+
list(APPEND target_files "$<TARGET_SONAME_FILE:${target}>")
8080
endif()
81+
list(APPEND target_files "$<TARGET_LINKER_FILE:${target}>")
8182
endif()
8283
endforeach()
8384

0 commit comments

Comments
 (0)