-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport #1367 to Garden: Fix find Python3 logic and macOS workflow #1370
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,9 +78,30 @@ if (BUILD_SDF) | |
# available during build time | ||
set(GZ_TOOLS_VER 2) | ||
|
||
################################################# | ||
# Find python | ||
if (SKIP_PYBIND11) | ||
message(STATUS "SKIP_PYBIND11 set - disabling python bindings") | ||
find_package(Python3 COMPONENTS Interpreter) | ||
else() | ||
find_package(Python3 COMPONENTS Interpreter Development) | ||
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.4 CONFIG QUIET) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dobule checking: do we prefer to call it with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it changes the formatting of the console messages, and I think it's subjective; I'm flexible on this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up to you, no strong feeling either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this is a backport; I'm going to leave this as is to match the behavior in newer branches |
||
|
||
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() | ||
|
||
################################################# | ||
# Copied from catkin/cmake/empy.cmake | ||
include(GzPython) | ||
function(find_python_module module) | ||
# cribbed from http://www.cmake.org/pipermail/cmake/2011-January/041666.html | ||
string(TOUPPER ${module} module_upper) | ||
|
@@ -130,30 +151,6 @@ if (BUILD_SDF) | |
gz_find_package(gz-utils2 REQUIRED COMPONENTS cli) | ||
set(GZ_UTILS_VER ${gz-utils2_VERSION_MAJOR}) | ||
|
||
######################################## | ||
# Python interfaces | ||
if (NOT PYTHON3_FOUND) | ||
GZ_BUILD_WARNING("Python is missing: Python interfaces are disabled.") | ||
message (STATUS "Searching for Python - not found.") | ||
else() | ||
message (STATUS "Searching for Python - found version ${Python3_VERSION}.") | ||
|
||
if (SKIP_PYBIND11) | ||
message(STATUS "SKIP_PYBIND11 set - disabling python bindings") | ||
else() | ||
set(PYBIND11_PYTHON_VERSION 3) | ||
find_package(pybind11 2.4 QUIET) | ||
|
||
if (${pybind11_FOUND}) | ||
find_package(Python3 ${GZ_PYTHON_VERSION} REQUIRED COMPONENTS Development) | ||
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() | ||
|
||
gz_configure_build(HIDE_SYMBOLS_BY_DEFAULT QUIT_IF_BUILD_ERRORS) | ||
|
||
gz_create_packages() | ||
|
@@ -162,7 +159,7 @@ if (BUILD_SDF) | |
add_subdirectory(conf) | ||
add_subdirectory(doc) | ||
if (pybind11_FOUND AND NOT SKIP_PYBIND11) | ||
add_subdirectory(python) | ||
add_subdirectory(python) | ||
endif() | ||
endif(BUILD_SDF) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we are looking for the Interpreter unconditionally. Both cases of
SKIP_PYBIND11
look for ir. I see that is being used forembedSdf.py
, if it is mandatory could we move it out of the if block to the mainCMakeLists.txt
course.If that is valid, if can probably integrate this block with the add_directory(python) a bit below in this file to avoid extra checks in different locations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the changes in this PR, the
include(GzPython)
line will unconditionally search for the Python interpreter, and then we would separately search for the Development component. I think that can be problematic on systems with multiple versions of python that don't all have the Development component, since it could first find an Interpreter from a non-Development version of Python, and then find a different version of python with the Development component.So my goal here is to unconditionally search for Python3 one time with the full set of components that are needed, either
INTERPRETER
orINTERPRETER DEVELOPMENT
. Does that make sense?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes total sense yes and actually the CMake documentation recommends to do it in an atomic call. Reducing the call to just one outside of the if block and moving the block to merge the
add_directory(python)
would result in:whatever you prefer, the atomic call seems to be the most critical point here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid deviation from newer branches, I'm going to keep this as is