diff --git a/CMake/SofaPython3Tools.cmake b/CMake/SofaPython3Tools.cmake index d3302db2..a5635943 100644 --- a/CMake/SofaPython3Tools.cmake +++ b/CMake/SofaPython3Tools.cmake @@ -69,7 +69,6 @@ function(SP3_add_python_package) ) endforeach() - message(STATUS "Python package ${A_SOURCE_DIRECTORY} added to directory ${SP3_PYTHON_PACKAGES_DIRECTORY}/${A_TARGET_DIRECTORY}") endfunction() # - Create a target for a python module binding code with pybind11 support. @@ -239,9 +238,4 @@ function(SP3_add_python_module) ) endforeach() - - if (NOT A_QUIET) - message(STATUS "Python module '${MODULE_NAME}' added to ${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}") - endif () - endfunction() diff --git a/CMakeLists.txt b/CMakeLists.txt index aee9d14b..2779322f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 3.12) project(SofaPython3) # Manually define VERSION -set(SOFAPYTHON3_VERSION_MAJOR 1) -set(SOFAPYTHON3_VERSION_MINOR 0) +set(SOFAPYTHON3_VERSION_MAJOR 20) +set(SOFAPYTHON3_VERSION_MINOR 12) set(SOFAPYTHON3_VERSION_PATCH 0) set(SOFAPYTHON3_VERSION ${SOFAPYTHON3_VERSION_MAJOR}.${SOFAPYTHON3_VERSION_MINOR}.${SOFAPYTHON3_VERSION_PATCH}) @@ -19,6 +19,18 @@ else() unset(SP3_COMPILED_AS_SUBPROJECT) endif () +# If the plugin is compiled within SOFA, add an option to deactivate it, in which case the remaining +# of this file won't run and therefore will not generate any error if the requirements (python, pybind11) +# are not found. +if (SP3_COMPILED_AS_SOFA_SUBPROJECT) + option(PLUGIN_SOFAPYTHON3 "Build the SofaPython3 plugin." ON) + if (NOT PLUGIN_SOFAPYTHON3) + return() + else() + message("Adding plugin SofaPython3") + endif() +endif() + # CMAKE TOOLS list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") include(SofaPython3Tools) @@ -89,12 +101,16 @@ set(SP3_PYTHON_PACKAGES_DIRECTORY This will be prepend to LIBRARY_OUTPUT_DIRECTORY (default to site-packages)" ) -# Get the Python's user site packages directory, or FASLE if not found +# Get the Python's user site packages directory, or FALSE if not found SP3_get_python_user_site() -CMAKE_DEPENDENT_OPTION( + +# Add an option to automatically create links towards the python packages of SP3 +# into the python's user site packages directory. +option( SP3_LINK_TO_USER_SITE "Install python packages to python's user site directory. The directory path can be changed by setting SP3_PYTHON_PACKAGES_LINK_DIRECTORY." - ON "PYTHON_USER_SITE" OFF) + OFF +) set(SP3_PYTHON_PACKAGES_LINK_DIRECTORY "${PYTHON_USER_SITE}" @@ -103,13 +119,17 @@ set(SP3_PYTHON_PACKAGES_LINK_DIRECTORY (default to $(python3 -m site --user-site))" ) -message("-- Python version: ${PYTHON_VERSION_STRING}") -message("-- Python executable: ${PYTHON_EXECUTABLE}") -message("-- Python include dirs: ${PYTHON_INCLUDE_DIRS}") -message("-- Python libraries: ${PYTHON_LIBRARIES}") -message("-- Python user site: ${PYTHON_USER_SITE}") -message("-- pybind11 version: ${pybind11_VERSION}") -message("-- pybind11 config: ${pybind11_CONFIG}") +message(STATUS "Python: + Version: ${PYTHON_VERSION_STRING} + Executable: ${PYTHON_EXECUTABLE} + Headers: ${PYTHON_INCLUDE_DIRS} + Libraries: ${PYTHON_LIBRARIES} + User site: ${PYTHON_USER_SITE}" +) +message(STATUS "pybind11: + Version: ${pybind11_VERSION} + Config: ${pybind11_CONFIG}" +) # When using python3 from XCode on MacOS, the RPath is wrongly set to XCode frameworks directory: # LC_LOAD_DYLIB @rpath/Python3.framework/Versions/3.7/Python3 @@ -134,10 +154,10 @@ if (NOT SP3_COMPILED_AS_SUBPROJECT) message(STATUS "SOFA Framework:\n\tVersion: ${SofaFramework_VERSION}\n\tLocation: ${SOFA_ROOT_DIR}") endif() -sofa_add_plugin(Plugin SofaPython3 ON) -sofa_add_plugin(bindings SofaPython3_Bindings ON) -sofa_add_plugin(examples SofaPython3_Examples ON) -sofa_add_plugin(docs SofaPython3_Docs ON) +add_subdirectory(Plugin) +add_subdirectory(bindings) +add_subdirectory(examples) +add_subdirectory(docs) SP3_add_python_package( SOURCE_DIRECTORY diff --git a/Plugin/CMakeLists.txt b/Plugin/CMakeLists.txt index 871a4e2c..d7d9ea21 100644 --- a/Plugin/CMakeLists.txt +++ b/Plugin/CMakeLists.txt @@ -77,6 +77,13 @@ if (CMAKE_SYSTEM_NAME STREQUAL Windows ) target_compile_definitions(${PROJECT_NAME} PUBLIC "-DHAVE_SNPRINTF") endif() +set_target_properties( + ${PROJECT_NAME} + PROPERTIES + CXX_VISIBILITY_PRESET "hidden" + CUDA_VISIBILITY_PRESET "hidden" +) + # Install header files foreach(header ${HEADER_FILES}) file(RELATIVE_PATH relative_path "${CMAKE_CURRENT_SOURCE_DIR}/src" "${header}") diff --git a/bindings/Sofa/SofaPython3_SofaConfig.cmake.in b/bindings/Sofa/SofaPython3_SofaConfig.cmake.in deleted file mode 100644 index 85e89c32..00000000 --- a/bindings/Sofa/SofaPython3_SofaConfig.cmake.in +++ /dev/null @@ -1,5 +0,0 @@ -#CMake package configuration file for the @PROJECT_NAME@ plugin - -@PACKAGE_INIT@ - -set(SOFAPYTHON3_BINDING_SOFA_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/package/Sofa") diff --git a/bindings/Sofa/tests/Core/PythonRestShapeForceField.py b/bindings/Sofa/tests/Core/PythonRestShapeForceField.py index a3fcab6b..79d7b15b 100644 --- a/bindings/Sofa/tests/Core/PythonRestShapeForceField.py +++ b/bindings/Sofa/tests/Core/PythonRestShapeForceField.py @@ -38,6 +38,7 @@ def RestShapeObject(impl, name="unnamed", position=[]): return node def createScene(node): + node.addObject("RequiredPlugin", name="SofaBaseLinearSolver") node.addObject("RequiredPlugin", name="SofaImplicitOdeSolver") node.addObject("DefaultAnimationLoop", name="loop") node.addObject("EulerImplicitSolver") diff --git a/runFromPython.py b/runFromPython.py deleted file mode 100644 index ba28caf2..00000000 --- a/runFromPython.py +++ /dev/null @@ -1,39 +0,0 @@ -# encoding: utf-8 -#!/usr/bin/python3 -import sys -import os - -if "SOFA_ROOT" not in os.environ: - print("WARNING: missing SOFA_ROOT in you environment variable. ") - sys.exit(-1) - -sys.path.append(os.path.abspath("./bindings/Sofa/package")) -sys.path.append(os.path.abspath("./bindings/SofaRuntime/package")) -sys.path.append(os.path.abspath("./bindings/SofaTypes/package")) - -import Sofa -import SofaRuntime - -## Register all the common component in the factory. -SofaRuntime.importPlugin("SofaAllCommonComponents") - -class MyController(Sofa.Controller): - def __init__(self, *args, **kwargs): - Sofa.Controller.__init__(self,*args, **kwargs) - print("INITED") - - def onEvent(self, event): - print("Event: "+event) - - -root = Sofa.Node("myroot") -root.addChild("child1") -root.addObject(MyController()) - -Sofa.Simulation.init(root) -Sofa.Simulation.print(root) -for i in range(0, 10): - print("step: "+str(i)) - Sofa.Simulation.animate(root, 0.1) - - diff --git a/runSimu.py b/runSimu.py deleted file mode 100644 index 6a9ad25d..00000000 --- a/runSimu.py +++ /dev/null @@ -1,34 +0,0 @@ -# encoding: utf-8 -#!/usr/bin/python3 -import sys -import os - -if "SOFA_ROOT" not in os.environ: - print("WARNING: missing SOFA_ROOT in you environment variable. ") - sys.exit(-1) - -sys.path.append(os.path.abspath("./bindings/Sofa/package")) -sys.path.append(os.path.abspath("./bindings/SofaRuntime/package")) -sys.path.append(os.path.abspath("./bindings/SofaTypes/package")) - -import Sofa -import SofaRuntime - -## Register all the common component in the factory. -SofaRuntime.importPlugin("SofaAllCommonComponents") - -if len(sys.argv) != 2: - print("USAGE: python3 runSimu.py scene.py") - sys.exit(-1) - -## Version 1 -print("READY FOR INIT 0") -s = SofaRuntime.loadSimulationFromFile(sys.argv[1]) -s.init() -for i in range(10): - print("Iteration: ...") - s.animate(0.1) - - - - diff --git a/sofaenv.py b/sofaenv.py deleted file mode 100644 index bf0d9ffd..00000000 --- a/sofaenv.py +++ /dev/null @@ -1,19 +0,0 @@ -#encoding: utf-8 -#!/usr/bin/python3 - -import sys -import os - - #if "SOFA_ROOT" not in os.environ: - # print("WARNING: missing SOFA_ROOT in you environment variable. ") - # sys.exit(-1) - -#sys.path.append(os.path.abspath("./bindings/Sofa/package")) -#sys.path.append(os.path.abspath("./bindings/SofaRuntime/package")) -#sys.path.append(os.path.abspath("./bindings/SofaTypes/package")) - -#import Sofa -#import SofaRuntime - - -