Skip to content

Commit d374404

Browse files
committed
Fix find Python3 logic and macOS workflow (#1367)
* Find Python3 with find_package instead of GzPython, adapting the approach from gz-sim. * macos workflow: use brew --prefix, not /usr/local * macos workflow: set Python3_EXECUTABLE cmake var Signed-off-by: Steve Peters <[email protected]>
1 parent 4ca24c9 commit d374404

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

.github/workflows/macos.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ jobs:
1919
# Workaround for https://github.com/actions/setup-python/issues/577
2020
- name: Clean up python binaries
2121
run: |
22-
rm -f /usr/local/bin/2to3*;
23-
rm -f /usr/local/bin/idle3*;
24-
rm -f /usr/local/bin/pydoc3*;
25-
rm -f /usr/local/bin/python3*;
26-
rm -f /usr/local/bin/python3*-config;
22+
rm -f $(brew --prefix)/bin/2to3*;
23+
rm -f $(brew --prefix)/bin/idle3*;
24+
rm -f $(brew --prefix)/bin/pydoc3*;
25+
rm -f $(brew --prefix)/bin/python3*;
26+
rm -f $(brew --prefix)/bin/python3*-config;
2727
- name: Install base dependencies
2828
env:
2929
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
@@ -50,8 +50,8 @@ jobs:
5050
- name: cmake
5151
working-directory: build
5252
run: |
53-
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python
54-
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/${PACKAGE}/HEAD
53+
export PYTHONPATH=$PYTHONPATH:$(brew --prefix)/lib/python
54+
cmake .. -DCMAKE_INSTALL_PREFIX=$(brew --prefix)/Cellar/${PACKAGE}/HEAD -DPython3_EXECUTABLE=$(brew --prefix)/bin/python3
5555
- run: make
5656
working-directory: build
5757
- run: make test

CMakeLists.txt

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,33 @@ if (BUILD_SDF)
7878
# available during build time
7979
set(GZ_TOOLS_VER 2)
8080

81+
#################################################
82+
# Find python
83+
if (SKIP_PYBIND11)
84+
message(STATUS "SKIP_PYBIND11 set - disabling python bindings")
85+
find_package(Python3 REQUIRED COMPONENTS Interpreter)
86+
else()
87+
find_package(Python3 REQUIRED
88+
COMPONENTS Interpreter
89+
OPTIONAL_COMPONENTS Development
90+
)
91+
if (NOT Python3_Development_FOUND)
92+
GZ_BUILD_WARNING("Python development libraries are missing: Python interfaces are disabled.")
93+
else()
94+
set(PYBIND11_PYTHON_VERSION 3)
95+
find_package(pybind11 2.4 CONFIG QUIET)
96+
97+
if (pybind11_FOUND)
98+
message (STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.")
99+
else()
100+
GZ_BUILD_WARNING("pybind11 is missing: Python interfaces are disabled.")
101+
message (STATUS "Searching for pybind11 - not found.")
102+
endif()
103+
endif()
104+
endif()
105+
81106
#################################################
82107
# Copied from catkin/cmake/empy.cmake
83-
include(GzPython)
84108
function(find_python_module module)
85109
# cribbed from http://www.cmake.org/pipermail/cmake/2011-January/041666.html
86110
string(TOUPPER ${module} module_upper)
@@ -121,29 +145,6 @@ if (BUILD_SDF)
121145
gz_find_package(gz-utils2 REQUIRED COMPONENTS cli)
122146
set(GZ_UTILS_VER ${gz-utils2_VERSION_MAJOR})
123147

124-
########################################
125-
# Python interfaces
126-
if (NOT PYTHON3_FOUND)
127-
GZ_BUILD_ERROR("Python is missing - Needed to build/embed xml schemas")
128-
else()
129-
message (STATUS "Searching for Python - found version ${Python3_VERSION}.")
130-
131-
if (SKIP_PYBIND11)
132-
message(STATUS "SKIP_PYBIND11 set - disabling python bindings")
133-
else()
134-
set(PYBIND11_PYTHON_VERSION 3)
135-
find_package(pybind11 2.4 QUIET)
136-
137-
if (${pybind11_FOUND})
138-
find_package(Python3 ${GZ_PYTHON_VERSION} REQUIRED COMPONENTS Development)
139-
message (STATUS "Searching for pybind11 - found version ${pybind11_VERSION}.")
140-
else()
141-
GZ_BUILD_WARNING("pybind11 is missing: Python interfaces are disabled.")
142-
message (STATUS "Searching for pybind11 - not found.")
143-
endif()
144-
endif()
145-
endif()
146-
147148
gz_configure_build(HIDE_SYMBOLS_BY_DEFAULT QUIT_IF_BUILD_ERRORS)
148149

149150
gz_create_packages()

0 commit comments

Comments
 (0)