Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 46 additions & 34 deletions CMake/SofaPython3Tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ function(SP3_add_python_module)
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}"
)

sofa_get_target_dependencies(DEPENDS_ALL ${A_TARGET})

# Compute the installation RPATHs from the target's SP3 dependencies since they are not installed in a same directory
# and are not automatically added from the cmake option INSTALL_RPATH_USE_LINK_PATH.
# 1. Get all dependencies that are
Expand All @@ -198,18 +200,23 @@ function(SP3_add_python_module)
# We compute its path relative to this target output file
# Ex: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/site-packages/Sofa --> $ORIGIN/../Sofa
# 3. Add the relative path computed in 2 to the list of RPATHS
set(${A_TARGET}_DEPENDENCIES_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBRARY_OUTPUT_DIRECTORY}")
foreach(DEPENDENCY ${A_DEPENDS})
if (TARGET ${DEPENDENCY})
get_target_property(DEPENDENCY_LIBRARY_OUTPUT_DIRECTORY "${DEPENDENCY}" LIBRARY_OUTPUT_DIRECTORY)
if (DEPENDENCY_LIBRARY_OUTPUT_DIRECTORY)
file(RELATIVE_PATH dependency_path_from_packages "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}" "${DEPENDENCY_LIBRARY_OUTPUT_DIRECTORY}")
if (NOT "${dependency_path_from_packages}" STREQUAL "" AND NOT "${dependency_path_from_packages}" STREQUAL "../")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "$ORIGIN/../${dependency_path_from_packages}")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "$$ORIGIN/../${dependency_path_from_packages}")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "@loader_path/../${dependency_path_from_packages}")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "@executable_path/../${dependency_path_from_packages}")
endif()
get_target_property(${A_TARGET}_DEPENDENCIES_RPATH ${A_TARGET} "INSTALL_RPATH")
foreach(DEPENDENCY ${DEPENDS_ALL})
if(NOT TARGET ${DEPENDENCY})
continue()
endif()
get_target_property(aliased_dep ${DEPENDENCY} ALIASED_TARGET)
if(aliased_dep)
set(DEPENDENCY ${aliased_dep})
endif()
get_target_property(DEPENDENCY_LIBRARY_OUTPUT_DIRECTORY "${DEPENDENCY}" LIBRARY_OUTPUT_DIRECTORY)
if (DEPENDENCY_LIBRARY_OUTPUT_DIRECTORY)
file(RELATIVE_PATH dependency_path_from_packages "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}" "${DEPENDENCY_LIBRARY_OUTPUT_DIRECTORY}")
if (NOT "${dependency_path_from_packages}" STREQUAL "" AND NOT "${dependency_path_from_packages}" STREQUAL "../")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "$ORIGIN/../${dependency_path_from_packages}")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "$$ORIGIN/../${dependency_path_from_packages}")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "@loader_path/../${dependency_path_from_packages}")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "@executable_path/../${dependency_path_from_packages}")
endif()
endif()
endforeach()
Expand All @@ -227,28 +234,33 @@ function(SP3_add_python_module)
# 1. First, compute the relative path from the current target towards the "plugins" relocatable directory of SOFA
# 2. Append to the previous computed path the RELOCATABLE_INSTALL_DIR target property of the dependency since the
# latter is formulated with respect to the "plugins" relocatable (e.g. "plugins/SofaBoundaryConditions/lib")
foreach(DEPENDENCY ${A_DEPENDS})
if (TARGET ${DEPENDENCY})
get_target_property(DEPENDENCY_RELOCATABLE_INSTALL_DIR "${DEPENDENCY}" RELOCATABLE_INSTALL_DIR)
if (DEPENDENCY_RELOCATABLE_INSTALL_DIR)
# Get the relative path from this binding module to the install lib directory
# For example, for lib/python3/site-packages/Sofa/Core.***.so, the relative path will be
# "../../.."
file(RELATIVE_PATH relative_towards_plugins_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# Here, we assume that the SP3 plugin will be installed in the SOFA plugins directory (i.e. $SOFA_ROOT/plugins)
# Hence, we need to compute the relative path from this plugins directory to the current binding
# modules, for example, plugins/SofaPython3/lib/python3/site-packages/Sofa/Core.***.so
# will become "../../../../../.." (three levels upper than the previous computed relative path)
set(relative_towards_plugins_dir "${relative_towards_plugins_dir}../../..")

# Alright, now we have the path from the current target towards the "plugins" relocatable directory of SOFA
# We can compute the relative path from the current target towards the dependency relocatable path.
set(relative_towards_dependency_dir "${relative_towards_plugins_dir}/${DEPENDENCY_RELOCATABLE_INSTALL_DIR}")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "$ORIGIN/${relative_towards_dependency_dir}/lib")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "$$ORIGIN/${relative_towards_dependency_dir}/lib")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "@loader_path/${relative_towards_dependency_dir}/lib")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "@executable_path/${relative_towards_dependency_dir}/lib")
endif()
foreach(DEPENDENCY ${DEPENDS_ALL})
if(NOT TARGET ${DEPENDENCY})
continue()
endif()
get_target_property(aliased_dep ${DEPENDENCY} ALIASED_TARGET)
if(aliased_dep)
set(DEPENDENCY ${aliased_dep})
endif()
get_target_property(DEPENDENCY_RELOCATABLE_INSTALL_DIR "${DEPENDENCY}" RELOCATABLE_INSTALL_DIR)
if (DEPENDENCY_RELOCATABLE_INSTALL_DIR)
# Get the relative path from this binding module to the install lib directory
# For example, for lib/python3/site-packages/Sofa/Core.***.so, the relative path will be
# "../../.."
file(RELATIVE_PATH relative_towards_plugins_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# Here, we assume that the SP3 plugin will be installed in the SOFA plugins directory (i.e. $SOFA_ROOT/plugins)
# Hence, we need to compute the relative path from this plugins directory to the current binding
# modules, for example, plugins/SofaPython3/lib/python3/site-packages/Sofa/Core.***.so
# will become "../../../../../.." (three levels upper than the previous computed relative path)
set(relative_towards_plugins_dir "${relative_towards_plugins_dir}../../..")

# Alright, now we have the path from the current target towards the "plugins" relocatable directory of SOFA
# We can compute the relative path from the current target towards the dependency relocatable path.
set(relative_towards_dependency_dir "${relative_towards_plugins_dir}/${DEPENDENCY_RELOCATABLE_INSTALL_DIR}")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "$ORIGIN/${relative_towards_dependency_dir}/lib")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "$$ORIGIN/${relative_towards_dependency_dir}/lib")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "@loader_path/${relative_towards_dependency_dir}/lib")
list(APPEND ${A_TARGET}_DEPENDENCIES_RPATH "@executable_path/${relative_towards_dependency_dir}/lib")
endif()
endforeach()

Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.12)

project(SofaPython3 VERSION 20.12.0)

find_package(SofaFramework REQUIRED)

# Detect if SofaPython3 is a subproject of another project (eg. when compiled within Sofa)
if (NOT "${CMAKE_PROJECT_NAME}" STREQUAL "${PROJECT_NAME}")
set(SP3_COMPILED_AS_SUBPROJECT 1)
Expand Down Expand Up @@ -159,8 +161,6 @@ if (APPLE)
set(CMAKE_BUILD_RPATH "/Applications/Xcode.app/Contents/Developer/Library/Frameworks")
endif()

find_package(SofaFramework REQUIRED)

if (NOT SP3_COMPILED_AS_SUBPROJECT)
get_filename_component(SOFA_ROOT_DIR "${SofaFramework_DIR}/../../.." ABSOLUTE)
message(STATUS "SOFA Framework:\n\tVersion: ${SofaFramework_VERSION}\n\tLocation: ${SOFA_ROOT_DIR}")
Expand Down
32 changes: 13 additions & 19 deletions SofaPython3Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,20 @@

set(SP3_WITH_SOFAEXPORTER @SP3_WITH_SOFAEXPORTER@)

if (SofaPython3_FIND_COMPONENTS)
foreach(component ${SofaPython3_FIND_COMPONENTS})
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/${component}Config.cmake")
# For requested component, execute its "config" script
set_and_check(config_file ${CMAKE_CURRENT_LIST_DIR}/${component}Config.cmake)
include(${config_file})
set(SofaPython3_${component}_FOUND True)
else()
set(SofaPython3_FOUND False)
set(SofaPython3_NOT_FOUND_MESSAGE "Unsupported component: ${component}.")
endif()
endforeach()
else()
foreach(component Plugin Bindings)
# For all available components, execute its "config" script
set_and_check(config_file "${CMAKE_CURRENT_LIST_DIR}/${component}Config.cmake")
include(${config_file})
set(Caribou_${component}_FOUND True)
endforeach()
if(NOT SofaPython3_FIND_COMPONENTS)
set(SofaPython3_FIND_COMPONENTS Plugin Bindings)
endif()
foreach(component ${SofaPython3_FIND_COMPONENTS})
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${component}Config.cmake")
# For requested component, execute its "config" script
set_and_check(config_file ${CMAKE_CURRENT_LIST_DIR}/${component}Config.cmake)
include(${config_file})
set(SofaPython3_${component}_FOUND True)
else()
set(SofaPython3_FOUND False)
set(SofaPython3_NOT_FOUND_MESSAGE "Unsupported component: ${component}.")
endif()
endforeach()

# Check that the component/target is there.
check_required_components(@PROJECT_NAME@)