Skip to content

Commit

Permalink
[SofaMacros] FIX plugins RPATH (#1619)
Browse files Browse the repository at this point in the history
* [SofaMacros] FIX rpath for modules and plugins

* [tools] FIX Windows postinstall fixup for dll finding
  • Loading branch information
guparan committed Dec 8, 2020
1 parent bec3752 commit 31611aa
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ if(UNIX)

# see https://cmake.org/Wiki/CMake_RPATH_handling for $ORIGIN doc
set(CMAKE_INSTALL_RPATH
"../lib"
"$ORIGIN/../lib"
"$$ORIGIN/../lib"
)
Expand Down
8 changes: 8 additions & 0 deletions SofaKernel/SofaFramework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ set(SOFA_VERSION "${Sofa_VERSION_MAJOR}${Sofa_VERSION_MINOR}${Sofa_VERSION_PATCH
set_property(GLOBAL PROPERTY __GlobalTargetList__ "")
set_property(GLOBAL PROPERTY __GlobalTargetNameList__ "")

# Help RELOCATABLE plugins to resolve their dependencies.
# See SofaMacrosInstall.cmake for usage of this property.
define_property(TARGET
PROPERTY "RELOCATABLE_INSTALL_DIR"
BRIEF_DOCS "Install directory of RELOCATABLE target"
FULL_DOCS "Install directory of RELOCATABLE target"
)

# Options
option(SOFA_DETECTIONOUTPUT_FREEMOTION "Compile Sofa with the DETECTIONOUTPUT_FREEMOTION macro defined." OFF)
option(SOFA_NO_OPENGL "Compile Sofa with no OpenGL support. (This will define the SOFA_NO_OPENGL macro.)" OFF)
Expand Down
8 changes: 8 additions & 0 deletions SofaKernel/SofaFramework/SofaFrameworkConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ endif()
list(APPEND CMAKE_INCLUDE_PATH "${SOFA_ROOT}/include/extlibs/WinDepPack")
list(APPEND CMAKE_MODULE_PATH "${SOFA_ROOT}/lib/cmake/Modules")

# Help RELOCATABLE plugins to resolve their dependencies.
# See SofaMacrosInstall.cmake for usage of this property.
define_property(TARGET
PROPERTY "RELOCATABLE_INSTALL_DIR"
BRIEF_DOCS "Install directory of RELOCATABLE target"
FULL_DOCS "Install directory of RELOCATABLE target"
)

include(SofaMacros)

set(SOFAFRAMEWORK_TARGETS @SOFAFRAMEWORK_TARGETS@)
Expand Down
51 changes: 51 additions & 0 deletions SofaKernel/SofaFramework/SofaMacrosInstall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ macro(sofa_auto_set_target_properties)
string(TOUPPER "${ARG_PACKAGE_NAME}" SOFA_PACKAGE_NAME_UPPER)

foreach(target ${ARG_TARGETS}) # Most of the time there is only one target
# Handle eventual alias
get_target_property(aliased_target ${target} ALIASED_TARGET)
if(aliased_target)
set(target ${aliased_target})
endif()

string(TOUPPER "${target}" sofa_target_name_upper)
set(${sofa_target_name_upper}_TARGET "${sofa_target_name_upper}")

Expand Down Expand Up @@ -248,6 +254,51 @@ macro(sofa_auto_set_target_properties)
endif()
#get_target_property(target_include_dirs ${target} "INCLUDE_DIRECTORIES")
#message("${ARG_PACKAGE_NAME}: target_include_dirs = ${target_include_dirs}")

set_target_properties(${target} PROPERTIES RELOCATABLE_INSTALL_DIR "${ARG_RELOCATABLE}/${ARG_PACKAGE_NAME}")

get_target_property(target_deps ${target} "LINK_LIBRARIES")
get_target_property(target_rpath ${target} "INSTALL_RPATH")
foreach(dep ${target_deps})
if(TARGET ${dep})
get_target_property(aliased_dep ${dep} ALIASED_TARGET)
if(aliased_dep)
set(dep ${aliased_dep})
endif()
get_target_property(dep_type ${dep} TYPE)
if("${dep_type}" STREQUAL "SHARED_LIBRARY")
get_target_property(dep_reloc_install_dir ${dep} "RELOCATABLE_INSTALL_DIR")
if(dep_reloc_install_dir)
# the dependency is relocatable
if(ARG_RELOCATABLE)
# current target is relocatable
list(APPEND target_rpath
"$ORIGIN/../../../${dep_reloc_install_dir}/lib"
"$$ORIGIN/../../../${dep_reloc_install_dir}/lib"
)
else()
# current target is NOT relocatable
list(APPEND target_rpath
"$ORIGIN/../${dep_reloc_install_dir}/lib"
"$$ORIGIN/../${dep_reloc_install_dir}/lib"
)
endif()
else()
# the dependency is NOT relocatable
if(ARG_RELOCATABLE)
# current target is relocatable
list(APPEND target_rpath
"$ORIGIN/../../../lib"
"$$ORIGIN/../../../lib"
)
endif()
endif()
endif()
endif()
endforeach()
list(REMOVE_DUPLICATES target_rpath)
set_target_properties(${target} PROPERTIES INSTALL_RPATH "${target_rpath}")

endforeach()
endmacro()

Expand Down
8 changes: 7 additions & 1 deletion tools/postinstall-fixup/windows-postinstall-fixup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!bash

usage() {
echo "Usage: windows-postinstall-fixup.sh <build-dir> <install-dir>"
Expand Down Expand Up @@ -27,3 +27,9 @@ for plugin in \
; do
grep "$plugin" "$INSTALL_DIR/bin/plugin_list.conf.default" >> "$INSTALL_DIR/bin/plugin_list.conf"
done

# Link all plugin libs in install/bin to make them easily findable
cd "$INSTALL_DIR" && find "plugins" -name "*.dll" | while read lib; do
libname="$(basename $lib)"
ln -s "../$lib" "bin/$libname"
done

0 comments on commit 31611aa

Please sign in to comment.