Skip to content

Commit

Permalink
Adapt package finding logic
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters committed Oct 29, 2024
1 parent 97ad436 commit a48b893
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
23 changes: 2 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ endif()
if (SKIP_PYBIND11)
message(STATUS "SKIP_PYBIND11 set - disabling python bindings")
else()
<<<<<<< HEAD
#include(GzPython) TODO: allow to specify for what it should search and then
# the code below can be removed; e.g. pybind needs Interpreter and Development components
# see https://pybind11.readthedocs.io/en/stable/cmake/index.html#new-findpython-mode
Expand All @@ -112,36 +111,18 @@ else()
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
find_package(PythonLibs QUIET)
# we found the interpreter but did we also find the libs? both are required
set(Python3_FOUND ${PYTHONLIBS_FOUND})
set(Python3_Development_FOUND ${PYTHONLIBS_FOUND})
set(Python3_VERSION ${PYTHONLIBS_VERSION_STRING})
endif()
else()
find_package(Python3 QUIET COMPONENTS Interpreter Development)
endif()

if (NOT Python3_FOUND)
if (NOT Python3_Development_FOUND)
GZ_BUILD_WARNING("Python3 is missing: Python interfaces are disabled.")
message (STATUS "Searching for Python3 - not found.")
else()
message (STATUS "Searching for Python3 - found version ${Python3_VERSION}.")

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()
=======
find_package(Python3 REQUIRED
COMPONENTS Interpreter
OPTIONAL_COMPONENTS Development
)
if (NOT Python3_Development_FOUND)
GZ_BUILD_WARNING("Python development libraries are missing: Python interfaces are disabled.")
>>>>>>> 17deea2b (Permit building python bindings separately from gz-math library (#636))
endif()
endif()

Expand Down
21 changes: 9 additions & 12 deletions src/python_pybind11/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
<<<<<<< HEAD
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
# TODO: remove once the minimum CMake version is increased
if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
# pybind11 logic for setting up a debug build when both a debug and release
# python interpreter are present in the system seems to be pretty much broken.
# This works around the issue.
set(PYTHON_LIBRARIES "${PYTHON_DEBUG_LIBRARIES}")
endif()
=======
# Detect if we are doing a standalone build of the bindings, using an external gz-math
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
cmake_minimum_required(VERSION 3.22.1)
set(GZ_MATH_VER 8)
set(GZ_MATH_VER 7)
project(gz-math${GZ_MATH_VER}-python VERSION ${GZ_MATH_VER})
find_package(gz-math${PROJECT_VERSION_MAJOR} REQUIRED)
set(PROJECT_LIBRARY_TARGET_NAME "gz-math${PROJECT_VERSION_MAJOR}::gz-math${PROJECT_VERSION_MAJOR}")
Expand All @@ -20,6 +10,14 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(CMAKE_REQUIRE_FIND_PACKAGE_pybind11 TRUE)
include(GNUInstallDirs)
include(CTest)
elseif(${CMAKE_VERSION} VERSION_LESS "3.12.0")
# TODO: remove once the minimum CMake version is increased
if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
# pybind11 logic for setting up a debug build when both a debug and release
# python interpreter are present in the system seems to be pretty much broken.
# This works around the issue.
set(PYTHON_LIBRARIES "${PYTHON_DEBUG_LIBRARIES}")
endif()
endif()

set(PYBIND11_PYTHON_VERSION 3)
Expand All @@ -30,7 +28,6 @@ if (${pybind11_FOUND})
else()
message(WARNING "pybind11 is missing: Python interfaces are disabled.")
return()
>>>>>>> 17deea2b (Permit building python bindings separately from gz-math library (#636))
endif()

message(STATUS "Building pybind11 interfaces")
Expand Down

0 comments on commit a48b893

Please sign in to comment.