Fix/findpython development embed #565
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title: Fix
Python::Pythonmissing when building bindings viaSP3_add_python_module(CMake FindPythonDevelopment.Embed)Summary
This PR fixes a CMake configuration/build failure seen when downstream plugins (e.g. Cosserat) use SofaPython3’s
SP3_add_python_module()helper and it internally callspython_add_library().Problem
On newer CMake/FindPython (observed with CMake 3.28 + Python 3.12 on Ubuntu),
python_add_library()requires the imported targetPython::Pythonto be defined. In some configurations,Python::Pythonis not created becausefind_package(Python … COMPONENTS Development.Embed …)was never requested, leading to:This then causes a cascade (e.g. missing
CosseratBindingsalias target).Solution
Make
SP3_add_python_module()self-contained by ensuringPython::Pythonexists before callingpython_add_library():Python::Pythonis not already defined, explicitly call:find_package(Python REQUIRED COMPONENTS Interpreter Development Development.Module Development.Embed)This guarantees the required
Python::Pythontarget is present and prevents downstream projects from needing to add extra FindPython boilerplate.Testing
Tested locally by building SOFA with SofaPython3 and the Cosserat plugin bindings enabled. After applying this change:
Python::Python/Development.Embederror)