Skip to content

Commit

Permalink
[Build] Refactor RPATH config for executables
Browse files Browse the repository at this point in the history
Part of OpenAssetIO#739. Overriding our default RPATH to work for executables is
duplicated, and would be further duplicated once we split the
`openassetio-python-bridge` tests.

So add a conditional in the initial configuration of RPATHs in
`set_default_target_properties`, rather than overriding it after the
fact.

Signed-off-by: David Feltell <david.feltell@foundry.com>
  • Loading branch information
feltech committed Nov 22, 2022
1 parent a05ecb2 commit 1040f1f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 43 deletions.
20 changes: 17 additions & 3 deletions cmake/DefaultTargetProperties.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,24 @@ function(openassetio_set_default_target_properties target_name)
# RPATH wrangling.

if (UNIX)
if (APPLE)
set(rpath "@loader_path")
get_target_property(target_type ${target_name} TYPE)
if (${target_type} STREQUAL EXECUTABLE)
file(RELATIVE_PATH
install_dir_rel_to_lib
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})

if (APPLE)
set(rpath "@executable_path/${install_dir_rel_to_lib}")
else ()
set(rpath "$ORIGIN/${install_dir_rel_to_lib}")
endif ()
else ()
set(rpath "$ORIGIN")
if (APPLE)
set(rpath "@loader_path")
else ()
set(rpath "$ORIGIN")
endif ()
endif ()

set_target_properties(
Expand Down
20 changes: 0 additions & 20 deletions src/openassetio-core-c/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,6 @@ target_include_directories(
)


#-----------------------------------------------------------------------
# Override RPATH to locate libs

if (UNIX)
# Calculate relative path from install to lib directory.
file(RELATIVE_PATH
install_dir_rel_to_lib
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})

if (APPLE)
set(rpath "@executable_path/${install_dir_rel_to_lib}")
else ()
set(rpath "$ORIGIN/${install_dir_rel_to_lib}")
endif ()

set_target_properties(openassetio-core-c-test-exe PROPERTIES INSTALL_RPATH "${rpath}")
endif ()


#-----------------------------------------------------------------------
# Create CTest target

Expand Down
20 changes: 0 additions & 20 deletions src/openassetio-core/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,6 @@ target_link_libraries(
)


#-----------------------------------------------------------------------
# Override RPATH to locate libs

if (UNIX)
# Calculate relative path from install to lib directory.
file(RELATIVE_PATH
install_dir_rel_to_lib
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})

if (APPLE)
set(rpath "@executable_path/${install_dir_rel_to_lib}")
else ()
set(rpath "$ORIGIN/${install_dir_rel_to_lib}")
endif ()

set_target_properties(openassetio-core-cpp-test-exe PROPERTIES INSTALL_RPATH "${rpath}")
endif ()


#-----------------------------------------------------------------------
# Create CTest target

Expand Down

0 comments on commit 1040f1f

Please sign in to comment.