Skip to content

Commit

Permalink
Fix CATKIN_SYMLINK_INSTALL with add_subdirectory() (#1102)
Browse files Browse the repository at this point in the history
* Fix CATKIN_SYMLINK_INSTALL with add_subdirectory()

catkin_symlink_install_files/directory/programs() use generated
functions that store the value of CMAKE_CURRENT_SOURCE_DIR at the time
they are generated. This value is incorrect when install() rules are
called from a directory using `add_subdirectory()` as is the case in
gencpp. This fixes the issue by passing the current source directory to
the generated functions at the time that they're called.

Signed-off-by: Shane Loretz<sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Document CURRENT_SOURCE_DIR arg and alphabetical order

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Quote to avoid variable expansion

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
  • Loading branch information
sloretz authored and dirk-thomas committed Jul 14, 2020
1 parent 3e1c655 commit 77ca28c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
21 changes: 15 additions & 6 deletions cmake/symlink_install/catkin_symlink_install.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/symlink_install_manifest.txt")
# Reimplement CMake install(DIRECTORY) command to use symlinks instead of
# copying resources.
#
# :param CURRENT_SOURCE_DIR: the value of CMAKE_CURRENT_SOURCE_DIR from where
# this function is called
# :type CURRENT_SOURCE_DIR: a path
# :param ARGN: the same arguments as the CMake install command.
# :type ARGN: various
#
function(catkin_symlink_install_directory)
cmake_parse_arguments(ARG "OPTIONAL" "DESTINATION" "DIRECTORY;PATTERN;PATTERN_EXCLUDE" ${ARGN})
cmake_parse_arguments(ARG "OPTIONAL" "CURRENT_SOURCE_DIR;DESTINATION" "DIRECTORY;PATTERN;PATTERN_EXCLUDE" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "catkin_symlink_install_directory() called with "
"unused/unsupported arguments: ${ARG_UNPARSED_ARGUMENTS}")
Expand All @@ -34,7 +37,7 @@ function(catkin_symlink_install_directory)
foreach(dir ${ARG_DIRECTORY})
# make dir an absolute path
if(NOT IS_ABSOLUTE "${dir}")
set(dir "@CMAKE_CURRENT_SOURCE_DIR@/${dir}")
set(dir "${ARG_CURRENT_SOURCE_DIR}/${dir}")
endif()

if(EXISTS "${dir}")
Expand Down Expand Up @@ -104,11 +107,14 @@ endfunction()
# Reimplement CMake install(FILES) command to use symlinks instead of copying
# resources.
#
# :param CURRENT_SOURCE_DIR: the value of CMAKE_CURRENT_SOURCE_DIR from where
# this function is called
# :type CURRENT_SOURCE_DIR: a path
# :param ARGN: the same arguments as the CMake install command.
# :type ARGN: various
#
function(catkin_symlink_install_files)
cmake_parse_arguments(ARG "OPTIONAL" "DESTINATION;RENAME" "FILES" ${ARGN})
cmake_parse_arguments(ARG "OPTIONAL" "CURRENT_SOURCE_DIR;DESTINATION;RENAME" "FILES" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "catkin_symlink_install_files() called with "
"unused/unsupported arguments: ${ARG_UNPARSED_ARGUMENTS}")
Expand All @@ -134,7 +140,7 @@ function(catkin_symlink_install_files)
foreach(file ${ARG_FILES})
# make file an absolute path
if(NOT IS_ABSOLUTE "${file}")
set(file "@CMAKE_CURRENT_SOURCE_DIR@/${file}")
set(file "${ARG_CURRENT_SOURCE_DIR}/${file}")
endif()

if(EXISTS "${file}")
Expand All @@ -159,11 +165,14 @@ endfunction()
# Reimplement CMake install(PROGRAMS) command to use symlinks instead of copying
# resources.
#
# :param CURRENT_SOURCE_DIR: the value of CMAKE_CURRENT_SOURCE_DIR from where
# this function is called
# :type CURRENT_SOURCE_DIR: a path
# :param ARGN: the same arguments as the CMake install command.
# :type ARGN: various
#
function(catkin_symlink_install_programs)
cmake_parse_arguments(ARG "OPTIONAL" "DESTINATION" "PROGRAMS" ${ARGN})
cmake_parse_arguments(ARG "OPTIONAL" "CURRENT_SOURCE_DIR;DESTINATION" "PROGRAMS" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "catkin_symlink_install_programs() called with "
"unused/unsupported arguments: ${ARG_UNPARSED_ARGUMENTS}")
Expand All @@ -181,7 +190,7 @@ function(catkin_symlink_install_programs)
foreach(file ${ARG_PROGRAMS})
# make file an absolute path
if(NOT IS_ABSOLUTE "${file}")
set(file "@CMAKE_CURRENT_SOURCE_DIR@/${file}")
set(file "${ARG_CURRENT_SOURCE_DIR}/${file}")
endif()

if(EXISTS "${file}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function(catkin_symlink_install_directory directory_keyword)

string(REPLACE ";" "\" \"" argn_quoted "\"${argn}\"")
catkin_symlink_install_append_install_code(
"catkin_symlink_install_directory(DIRECTORY ${argn_quoted})"
"catkin_symlink_install_directory(CURRENT_SOURCE_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\" DIRECTORY ${argn_quoted})"
COMMENTS "install(DIRECTORY ${argn_quoted})"
)
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/symlink_install/catkin_symlink_install_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function(catkin_symlink_install_files files_keyword)
if(index EQUAL -1)
string(REPLACE ";" "\" \"" argn_quoted "\"${ARGN}\"")
catkin_symlink_install_append_install_code(
"catkin_symlink_install_files(FILES ${argn_quoted})"
"catkin_symlink_install_files(CURRENT_SOURCE_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\" FILES ${argn_quoted})"
COMMENTS "install(FILES ${argn_quoted})"
)
endif()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function(catkin_symlink_install_programs programs_keyword)
if(index EQUAL -1)
string(REPLACE ";" "\" \"" argn_quoted "\"${ARGN}\"")
catkin_symlink_install_append_install_code(
"catkin_symlink_install_programs(PROGRAMS ${argn_quoted})"
"catkin_symlink_install_programs(CURRENT_SOURCE_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\" PROGRAMS ${argn_quoted})"
COMMENTS "install(PROGRAMS ${argn_quoted})"
)
endif()
Expand Down

0 comments on commit 77ca28c

Please sign in to comment.