Skip to content

Commit

Permalink
Deprecate GzPython.cmake (#431)
Browse files Browse the repository at this point in the history
It's better to call find_package(Python3) directly so the
user has better control over which COMPONENTS are requested.

Update GzBuildTests.cmake and GzCodeCheck.cmake to
stop using GzPython.

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored Jun 1, 2024
1 parent 78947cf commit a1c15f7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
3 changes: 3 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ release will remove the deprecated code.
The change deprecates the HIDDEN_SYMBOLS_BY_DEFAULT flag that can be
removed.

1. **Deprecated**: `GzPython.cmake`
**Replacement**: Use `find_package(Python3)` to find Python3 and the
`Python3_EXECUTABLE` variable instead of `PYTHON_EXECUTABLE`.

## Gazebo CMake 2.X to 3.X

Expand Down
4 changes: 3 additions & 1 deletion cmake/GzBuildTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ macro(gz_build_tests)

# Find the Python interpreter for running the
# check_test_ran.py script
include(GzPython)
if(NOT Python3_Interpreter_FOUND)
find_package(Python3 COMPONENTS Interpreter)
endif()

# Build all the tests
foreach(target_name ${test_list})
Expand Down
4 changes: 3 additions & 1 deletion cmake/GzCodeCheck.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Setup the codecheck target, which will run cppcheck and cppplint.
# This function is private to gz-cmake.
function(_gz_setup_target_for_codecheck)
include(GzPython)
if(NOT Python3_Interpreter_FOUND)
find_package(Python3 COMPONENTS Interpreter)
endif()

find_program(CPPCHECK_PATH cppcheck)
find_program(FIND_PATH find)
Expand Down
27 changes: 4 additions & 23 deletions cmake/GzPython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.19")
set(GZ_PYTHON_VERSION "" CACHE STRING
"Specify specific Python3 version to use ('major.minor' or 'versionMin...[<]versionMax')")
message(WARNING "GzPython is deprecated, use find_package(Python3) instead.")

find_package(Python3 ${GZ_PYTHON_VERSION} QUIET)
elseif(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12")
# no support for finding specific versions
find_package(Python3 QUIET)
else()
# TODO: remove this block as soon as the CMake version can safely be bumped to => 3.12
set(GZ_PYTHON_VERSION "" CACHE STRING
"Specify specific Python version to use ('major.minor' or 'major')")
set(GZ_PYTHON_VERSION "" CACHE STRING
"Specify specific Python3 version to use ('major.minor' or 'versionMin...[<]versionMax')")

# if not specified otherwise use Python 3
if(NOT GZ_PYTHON_VERSION)
set(GZ_PYTHON_VERSION "3")
endif()

find_package(PythonInterp ${GZ_PYTHON_VERSION} QUIET)

if(PYTHONINTERP_FOUND)
set(Python3_Interpreter_FOUND ${PYTHONINTERP_FOUND})
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
endif()
endif()
find_package(Python3 ${GZ_PYTHON_VERSION} QUIET)

# Tick-tock PYTHON_EXECUTABLE until Python3_EXECUTABLE is released
# TODO(jrivero) gz-cmake4: start the deprecation cycle of PYTHON_EXECUTABLE
Expand Down

0 comments on commit a1c15f7

Please sign in to comment.