From e35529c2f57861b0056eaa0915dd9e5ddb6b8bb3 Mon Sep 17 00:00:00 2001 From: Clifford Yapp <238416+starseeker@users.noreply.github.com> Date: Mon, 22 Mar 2021 17:49:49 -0400 Subject: [PATCH] Identify the basic issues with ExtProject_Target Three remaining issues surfaced with the RPATH setting - two minor, one trickier. Minor #1 - Itcl and Itk didn't have the RPATH flag set in their target definitions (fixed). Minor #2 - 3rd party binaries RPATHs don't match those produced by the main CMake build - using bin instead of lib (investigating). More significant is the behavior of CMake's RPATH_CHANGE - it is correctly setting the final path, but it is not clearing the build dir path. So far I've not found a way to make the available commands in CMake do the job, so I'm falling back on a solution similar to that necessary on Apple and using the chrpath utility. The code in this commit works if a system chrpath is present - we'll need to bundle a version in misc/tools to make sure we have the capabilities we need reliably. (chrpath is GPL, so we can't install it or use it as anything except a build tool - unfortunately I've not found a BSD/MIT licensed tool for this type of rpath work...) --- src/other/ext/CMake/ExternalProject_Target.cmake | 12 +++++++++++- src/other/ext/itcl.cmake | 1 + src/other/ext/itk.cmake | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/other/ext/CMake/ExternalProject_Target.cmake b/src/other/ext/CMake/ExternalProject_Target.cmake index 918b5078862..7f634d08ecc 100644 --- a/src/other/ext/CMake/ExternalProject_Target.cmake +++ b/src/other/ext/CMake/ExternalProject_Target.cmake @@ -249,6 +249,7 @@ endfunction(ET_Origin_Path) # /usr/bin/baz -> bin/baz # /usr/bin/mypkg/baz -> bin/mypkg/baz # +find_program(CHRPATH_EXEC chrpath) function(ET_RPath OFILE) get_filename_component(OFPATH "${OFILE}" DIRECTORY) get_filename_component(RRPATH "${CMAKE_INSTALL_PREFIX}/${OFPATH}" REALPATH) @@ -272,7 +273,16 @@ function(ET_RPath OFILE) execute_process(COMMAND install_name_tool -delete_rpath \"${CMAKE_BUILD_RPATH}\" \"\${WPATH}\") execute_process(COMMAND install_name_tool -add_rpath \"${NEW_RPATH}\" \"\${WPATH}\") ") - else (APPLE) + elseif (CHRPATH_EXEC) + # Looks like CMake's built in RPATH logic isn't quite enough for our + # purposes here - it leaves the build RPATH in place even after assigning + # the new path. + # TODO Need to bundle chrpath so we can reliably do this... + install(CODE " + set(WPATH \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${OFILE}\") + execute_process(COMMAND chrpath -r \"${NEW_RPATH}\" \"\${WPATH}\") + ") + else () install(CODE " file(RPATH_CHANGE FILE \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${OFILE}\" diff --git a/src/other/ext/itcl.cmake b/src/other/ext/itcl.cmake index 7208c04ebd6..7917dd04b9b 100644 --- a/src/other/ext/itcl.cmake +++ b/src/other/ext/itcl.cmake @@ -134,6 +134,7 @@ if (BRLCAD_ENABLE_TCL) ExternalProject_Target(SHARED itcl ITCL_BLD ${ITCL_INSTDIR} itcl${ITCL_VERSION}/${ITCL_BASENAME}${CMAKE_SHARED_LIBRARY_SUFFIX} SUBDIR itcl${ITCL_VERSION} + RPATH ) ExternalProject_Target(STATIC itclstub ITCL_BLD ${ITCL_INSTDIR} diff --git a/src/other/ext/itk.cmake b/src/other/ext/itk.cmake index 59cf0c88334..9c04f1cd72f 100644 --- a/src/other/ext/itk.cmake +++ b/src/other/ext/itk.cmake @@ -107,6 +107,7 @@ if (BRLCAD_ENABLE_TK) ExternalProject_Target(SHARED itk ITK_BLD ${ITK_INSTDIR} itk${ITK_VERSION}/${ITK_BASENAME}${CMAKE_SHARED_LIBRARY_SUFFIX} SUBDIR itk${ITK_VERSION} + RPATH ) ExternalProject_ByProducts(itk ITK_BLD ${ITK_INSTDIR} ${INCLUDE_DIR}