diff --git a/CMakeLists.txt b/CMakeLists.txt index f9fc1f82..342d4465 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,16 +105,6 @@ else() ) if (NOT Python3_Development_FOUND) GZ_BUILD_WARNING("Python development libraries are missing: Python interfaces are disabled.") - else() - set(PYBIND11_PYTHON_VERSION 3) - find_package(pybind11 2.2 QUIET) - - if (${pybind11_FOUND}) - message (STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.") - else() - GZ_BUILD_WARNING("pybind11 is missing: Python interfaces are disabled.") - message (STATUS "Searching for pybind11 - not found.") - endif() endif() endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0adbed14..85582b6f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,7 +18,7 @@ gz_build_tests(TYPE UNIT SOURCES ${gtest_sources}) add_subdirectory(graph) # Bindings subdirectories -if (pybind11_FOUND AND NOT SKIP_PYBIND11) +if (Python3_Development_FOUND AND NOT SKIP_PYBIND11) add_subdirectory(python_pybind11) endif() diff --git a/src/python_pybind11/CMakeLists.txt b/src/python_pybind11/CMakeLists.txt index af81f33f..89af730d 100644 --- a/src/python_pybind11/CMakeLists.txt +++ b/src/python_pybind11/CMakeLists.txt @@ -3,14 +3,25 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) cmake_minimum_required(VERSION 3.22.1) set(GZ_MATH_VER 8) project(gz-math${GZ_MATH_VER}-python VERSION ${GZ_MATH_VER}) - find_package(Python3 COMPONENTS Interpreter Development REQUIRED) - find_package(pybind11 REQUIRED) find_package(gz-math${PROJECT_VERSION_MAJOR} REQUIRED) set(PROJECT_LIBRARY_TARGET_NAME "gz-math${PROJECT_VERSION_MAJOR}::gz-math${PROJECT_VERSION_MAJOR}") + # require python dependencies to be found + find_package(Python3 COMPONENTS Interpreter Development REQUIRED) + set(CMAKE_REQUIRE_FIND_PACKAGE_pybind11 TRUE) include(GNUInstallDirs) include(CTest) endif() +set(PYBIND11_PYTHON_VERSION 3) +find_package(pybind11 2.2 QUIET) + +if (${pybind11_FOUND}) + message(STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.") +else() + message(WARNING "pybind11 is missing: Python interfaces are disabled.") + return() +endif() + message(STATUS "Building pybind11 interfaces") set(BINDINGS_MODULE_NAME "math${PROJECT_VERSION_MAJOR}") # Split from main extension and converted to pybind11