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
38 changes: 21 additions & 17 deletions CMake/SofaPython3Tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,27 @@ endfunction()
#
# SP3_add_python_module(TARGET MODULE_NAME DESTINATION SOURCES PYTHON_VERSION DEPENDS QUIET)
# TARGET - (input) The name of the generated target. Only used when cpp files are included in the sources.
# PACKAGE_NAME - (input) The name of the package that will contain this module.
# MODULE_NAME - (input) The name of the module.
# PACKAGE - (input) The name of the cmake package that will contain this target. Note that the package must
# be created later on during the cmake configure stage using the macro sofa_create_package(),
# or be manually created using cmake's install command with "Targets" as suffix, e.g.:
# install(EXPORT ${PACKAGE}Targets).
# MODULE - (input) The name of the module. This is the name that will be used in python to do the actual
# import of the python module containing the bindings, i.e. "from MODULE import *".
# DESTINATION - (input) The output directory that will contain the compiled module.
# For the build tree, it will be ${SP3_PYTHON_PACKAGES_BUILD_DIRECTORY}/${DESTINATION}.
# For the install tree, it will be ${SP3_PYTHON_PACKAGES_INSTALL_DIRECTORY}/${DESTINATION}.
# The default is ${PACKAGE_NAME}
# For the build tree, it will be ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_BUILD_DIRECTORY}/${DESTINATION}.
# For the install tree, it will be ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_INSTALL_DIRECTORY}/${DESTINATION}.
# SOURCES - (input) list of source files that will be compiled with pybind11 support.
# HEADERS - (input) list of header files that will be installed after the build.
# DEPENDS - (input) set of target the generated target will depends on.
# QUIET - (input) if set, not information messages will be printed out.
function(SP3_add_python_module)
set(options QUIET)
set(oneValueArgs TARGET PACKAGE_NAME MODULE_NAME DESTINATION PYTHON_VERSION )
set(oneValueArgs TARGET PACKAGE MODULE DESTINATION PYTHON_VERSION )
set(multiValueArgs SOURCES HEADERS DEPENDS)

cmake_parse_arguments(A "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if (NOT A_DESTINATION)
set(DESTINATION "${A_PACKAGE_NAME}")
endif ()
set(DESTINATION "${A_DESTINATION}")

# Fetch the current path relative to /bindings/*/src
# Must test if the result is nested into the CMAKE_CURRENT_SOURCE_DIR (case where src exists outside the plugin directory)
Expand All @@ -108,11 +109,11 @@ function(SP3_add_python_module)
endif()


if (NOT DEFINED A_MODULE_NAME)
if (NOT DEFINED A_MODULE)
message(FATAL_ERROR "A module name must be provided.")
endif()

set(MODULE_NAME ${A_MODULE_NAME})
set(MODULE_NAME ${A_MODULE})

if (NOT DEFINED A_TARGET)
set(A_TARGET ${MODULE_NAME})
Expand Down Expand Up @@ -295,12 +296,15 @@ function(SP3_add_python_module)
endif()


install(TARGETS ${A_TARGET}
EXPORT BindingsTargets
RUNTIME DESTINATION "lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" COMPONENT applications
LIBRARY DESTINATION "lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" COMPONENT libraries
ARCHIVE DESTINATION "lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" COMPONENT libraries
)
if (A_PACKAGE)
install(
TARGETS ${A_TARGET}
EXPORT ${A_PACKAGE}Targets
RUNTIME DESTINATION "lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" COMPONENT applications
LIBRARY DESTINATION "lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" COMPONENT libraries
ARCHIVE DESTINATION "lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" COMPONENT libraries
)
endif()

foreach(header ${A_HEADERS})
file(RELATIVE_PATH path_from_package "${path_to_src}" "${header}")
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ if(PYTHON_EXECUTABLE)
set(python_version_flag "EXACT")
endif()
endif()
message("${PROJECT_NAME}: Searching Python ${python_version} ${python_version_flag}")
find_package(Python ${python_version} ${python_version_flag} COMPONENTS Interpreter Development REQUIRED)
set(PYTHON_VERSION ${Python_VERSION})
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
Expand Down Expand Up @@ -191,6 +190,12 @@ sofa_create_package(
RELOCATABLE "plugins"
)

install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/CMake/SofaPython3Tools.cmake"
DESTINATION lib/cmake/SofaPython3
COMPONENT headers
)

if (SP3_LINK_TO_USER_SITE AND SP3_PYTHON_PACKAGES_LINK_DIRECTORY)
file(GLOB directories RELATIVE "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/*")
# Create the site-package link directory if it doesn't exists yet
Expand Down
1 change: 0 additions & 1 deletion Plugin/PluginConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
find_package(pybind11 CONFIG REQUIRED)
find_package(SofaFramework REQUIRED)
find_package(SofaSimulation REQUIRED)
find_package(SofaGeneral REQUIRED)

# If we are importing this config file and the target is not yet there this is indicating that
# target is an imported one. So we include it
Expand Down
20 changes: 20 additions & 0 deletions SofaPython3Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@
@PACKAGE_INIT@

set(SP3_WITH_SOFAEXPORTER @SP3_WITH_SOFAEXPORTER@)
set(SP3_PYTHON_PACKAGES_DIRECTORY @SP3_PYTHON_PACKAGES_DIRECTORY@)

include("${CMAKE_CURRENT_LIST_DIR}/SofaPython3Tools.cmake")

# Find Python3 executable and set PYTHON_EXECUTABLE before finding pybind11
# to be sure that pybind11 relies on the right Python version
set(python_version @PYBIND11_PYTHON_VERSION@)
set(python_version_flag @python_version_flag@)

find_package(Python ${python_version} ${python_version_flag} COMPONENTS Interpreter Development REQUIRED)

set(PYTHON_VERSION ${Python_VERSION})
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
set(PYTHON_LIBRARIES ${Python_LIBRARIES})
set(PYTHON_INCLUDE_DIRS ${Python_INCLUDE_DIRS})
set(PYTHON_LIBRARY ${Python_LIBRARY})
set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIR})

# Set the minimum pybind11 version to 2.3 (before that the pybind11::embed target did not exist)
find_package(pybind11 2.3 CONFIG QUIET REQUIRED)

if (SofaPython3_FIND_COMPONENTS)
foreach(component ${SofaPython3_FIND_COMPONENTS})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ find_package(SofaBaseTopology REQUIRED)

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE_NAME Sofa
MODULE_NAME SofaBaseTopology
PACKAGE Bindings
MODULE SofaBaseTopology
DESTINATION Sofa
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS SofaBaseTopology SofaPython3::Plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ find_package(SofaDeformable REQUIRED)

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE_NAME Sofa
MODULE_NAME SofaDeformable
PACKAGE Bindings
MODULE SofaDeformable
DESTINATION Sofa
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS SofaBase SofaDeformable SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
Expand Down
5 changes: 3 additions & 2 deletions bindings/Sofa/src/SofaPython3/Sofa/Components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ find_package(SofaFramework REQUIRED)

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE_NAME Sofa
MODULE_NAME Components
PACKAGE Bindings
MODULE Components
DESTINATION Sofa
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS SofaCore SofaHelper SofaSimulationCore SofaPython3::Plugin
Expand Down
5 changes: 3 additions & 2 deletions bindings/Sofa/src/SofaPython3/Sofa/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ find_package(SofaBaseUtils REQUIRED)

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE_NAME Sofa
MODULE_NAME Core
PACKAGE Bindings
MODULE Core
DESTINATION Sofa
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS SofaBaseUtils SofaBaseCollision SofaCore SofaHelper SofaSimulationCore SofaDefaultType SofaBaseVisual SofaPython3::Plugin
Expand Down
5 changes: 3 additions & 2 deletions bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ find_package(SofaFramework REQUIRED)

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE_NAME Sofa
MODULE_NAME Helper
PACKAGE Bindings
MODULE Helper
DESTINATION Sofa
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS SofaCore SofaHelper SofaPython3::Plugin
Expand Down
5 changes: 3 additions & 2 deletions bindings/Sofa/src/SofaPython3/Sofa/Simulation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ find_package(SofaSimulation REQUIRED)

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE_NAME Sofa
MODULE_NAME Simulation
PACKAGE Bindings
MODULE Simulation
DESTINATION Sofa
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS SofaCore SofaSimulationCore SofaSimulationGraph SofaPython3::Plugin
Expand Down
5 changes: 3 additions & 2 deletions bindings/Sofa/src/SofaPython3/Sofa/Types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ find_package(SofaFramework REQUIRED)

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE_NAME Sofa
MODULE_NAME Types
PACKAGE Bindings
MODULE Types
DESTINATION Sofa
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS SofaCore SofaDefaultType SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
Expand Down
3 changes: 2 additions & 1 deletion bindings/SofaExporter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ find_package(SofaExporter REQUIRED)

SP3_add_python_module(
TARGET ${PROJECT_NAME}
MODULE_NAME SofaExporter
PACKAGE Bindings
MODULE SofaExporter
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS SofaExporter SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
Expand Down
5 changes: 3 additions & 2 deletions bindings/SofaGui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ find_package(SofaFramework REQUIRED)

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE_NAME Sofa
MODULE_NAME Gui
PACKAGE Bindings
MODULE Gui
DESTINATION Sofa
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS SofaCore SofaGuiCommon SofaGuiMain SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
Expand Down
5 changes: 3 additions & 2 deletions bindings/SofaRuntime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ SP3_add_python_package(

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE_NAME SofaRuntime
MODULE_NAME SofaRuntime
PACKAGE Bindings
MODULE SofaRuntime
DESTINATION SofaRuntime
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS SofaCore SofaHelper SofaSimulationCore SofaSimulationGraph SofaSimulationCommon SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
Expand Down
5 changes: 3 additions & 2 deletions bindings/SofaTypes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ find_package(SofaFramework REQUIRED)

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE_NAME SofaTypes
MODULE_NAME SofaTypes
PACKAGE Bindings
MODULE SofaTypes
DESTINATION SofaTypes
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
DEPENDS SofaDefaultType SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
Expand Down