Skip to content

Commit 3c162b7

Browse files
authored
CMake: avoid searching Python files multiple times (#517)
* Dont search for python and pybind11 if already found previously * remove unsupported keyword Global (need cmake 3.24) * restore global keyword while testing cmake version * Update Bindings.SofaConfig.cmake.in
1 parent d84b6cb commit 3c162b7

4 files changed

Lines changed: 30 additions & 17 deletions

File tree

SofaPython3Config.cmake.in

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
99
include(SofaPython3Tools)
1010

1111
# Find Python3
12-
if(NOT Python_FOUND)
13-
find_package(Python @PythonMAJMIN@ EXACT QUIET REQUIRED COMPONENTS Interpreter Development)
12+
if(NOT TARGET Python::Python)
13+
if(CMAKE_VERSION VERSION_LESS "3.24.0")
14+
find_package(Python @PythonMAJMIN@ EXACT QUIET REQUIRED COMPONENTS Interpreter Development)
15+
else()
16+
find_package(Python @PythonMAJMIN@ EXACT QUIET REQUIRED COMPONENTS Interpreter Development GLOBAL)
17+
endif()
1418
endif()
1519

1620
# Find pybind11
17-
if(NOT pybind11_FOUND)
21+
if(NOT TARGET pybind11)
1822
# Save PYTHON_* vars
1923
set(PYTHON_VERSION_RESET "${PYTHON_VERSION}")
2024
set(PYTHON_EXECUTABLE_RESET "${PYTHON_EXECUTABLE}")
@@ -40,7 +44,11 @@ if(NOT pybind11_FOUND)
4044
set(PYTHON_INCLUDE_DIR "${Python_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
4145
endif()
4246

43-
find_package(pybind11 @pybind11_VERSION@ QUIET REQUIRED CONFIG)
47+
if(CMAKE_VERSION VERSION_LESS "3.24.0")
48+
find_package(pybind11 @pybind11_VERSION@ QUIET REQUIRED CONFIG)
49+
else()
50+
find_package(pybind11 @pybind11_VERSION@ QUIET REQUIRED CONFIG GLOBAL)
51+
endif()
4452

4553
# Reset PYTHON_* vars
4654
set(PYTHON_VERSION "${PYTHON_VERSION_RESET}" CACHE STRING "" FORCE)

bindings/BindingsConfig.cmake.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55

66
set(SP3_WITH_SOFAEXPORTER @SP3_WITH_SOFAEXPORTER@)
77

8-
find_package(SofaPython3 QUIET REQUIRED COMPONENTS
8+
find_package(Sofa.Config QUIET REQUIRED)
9+
10+
sofa_find_package(SofaPython3 QUIET REQUIRED COMPONENTS
911
Bindings.Modules
1012
Bindings.Sofa
1113
Bindings.SofaGui
1214
Bindings.SofaRuntime
1315
Bindings.SofaTypes
1416
)
1517
if(SP3_WITH_SOFAEXPORTER)
16-
find_package(SofaPython3 QUIET REQUIRED COMPONENTS Bindings.SofaExporter)
18+
sofa_find_package(SofaPython3 QUIET REQUIRED COMPONENTS Bindings.SofaExporter)
1719
endif()
1820

1921
# If we are importing this config file and the target is not yet there this is indicating that

bindings/Modules/Bindings.ModulesConfig.cmake.in

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
@PACKAGE_GUARD@
44
@PACKAGE_INIT@
55

6-
find_package(SofaPython3 QUIET REQUIRED COMPONENTS Plugin Bindings.Sofa)
6+
find_package(Sofa.Config QUIET REQUIRED)
7+
sofa_find_package(SofaPython3 QUIET REQUIRED COMPONENTS Plugin Bindings.Sofa)
78

89
# Required by Bindings.Modules.SofaBaseTopology
9-
find_package(Sofa.Component.Topology.Container.Grid QUIET REQUIRED)
10+
sofa_find_package(Sofa.Component.Topology.Container.Grid QUIET REQUIRED)
1011

1112
# Required by Bindings.Modules.SofaDeformable
12-
find_package(Sofa.Component.SolidMechanics.Spring QUIET REQUIRED)
13+
sofa_find_package(Sofa.Component.SolidMechanics.Spring QUIET REQUIRED)
1314

1415
# Required by Bindings.Modules.SofaLinearSolver
15-
find_package(Sofa.Component.LinearSolver.Iterative QUIET REQUIRED)
16+
sofa_find_package(Sofa.Component.LinearSolver.Iterative QUIET REQUIRED)
1617

1718
# If we are importing this config file and the target is not yet there this is indicating that
1819
# target is an imported one. So we include it

bindings/Sofa/Bindings.SofaConfig.cmake.in

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
@PACKAGE_GUARD@
44
@PACKAGE_INIT@
55

6-
find_package(SofaPython3 QUIET REQUIRED COMPONENTS Plugin)
6+
find_package(Sofa.Config QUIET REQUIRED)
7+
8+
sofa_find_package(SofaPython3 QUIET REQUIRED COMPONENTS Plugin)
79

810
# Required by Bindings.Sofa.Helper, Bindings.Sofa.Types
9-
find_package(Sofa.Core QUIET REQUIRED)
11+
sofa_find_package(Sofa.Core QUIET REQUIRED)
1012

1113
# Required by Bindings.Sofa.Core
12-
find_package(Sofa.Simulation.Core QUIET REQUIRED)
14+
sofa_find_package(Sofa.Simulation.Core QUIET REQUIRED)
1315

1416
# Required by Bindings.Sofa.Core
15-
find_package(Sofa.Component.Visual QUIET REQUIRED)
16-
find_package(Sofa.Component.Collision.Response.Contact QUIET REQUIRED)
17-
find_package(Sofa.SimpleApi QUIET REQUIRED)
17+
sofa_find_package(Sofa.Component.Visual QUIET REQUIRED)
18+
sofa_find_package(Sofa.Component.Collision.Response.Contact QUIET REQUIRED)
19+
sofa_find_package(Sofa.SimpleApi QUIET REQUIRED)
1820

1921
# Required by Bindings.Sofa.Simulation
20-
find_package(Sofa.Simulation.Graph QUIET REQUIRED)
22+
sofa_find_package(Sofa.Simulation.Graph QUIET REQUIRED)
2123

2224
# If we are importing this config file and the target is not yet there this is indicating that
2325
# target is an imported one. So we include it

0 commit comments

Comments
 (0)