From 369e8d1a57dc5c75a888c827678ce98fd10c7500 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Fri, 24 May 2024 13:33:55 -0700 Subject: [PATCH 1/2] Deprecate GzPython.cmake It's better to call find_package(Python3) directly so the user has better control over which COMPONENTS are requested. Signed-off-by: Steve Peters --- Migration.md | 3 +++ cmake/GzPython.cmake | 27 ++++----------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/Migration.md b/Migration.md index 5e60c5ba..5a2fda66 100644 --- a/Migration.md +++ b/Migration.md @@ -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 diff --git a/cmake/GzPython.cmake b/cmake/GzPython.cmake index 6ce0f118..7a6f2333 100644 --- a/cmake/GzPython.cmake +++ b/cmake/GzPython.cmake @@ -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 From bf2f08e8e083ec0e68b7eb9dacfa6666edba87dc Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Fri, 24 May 2024 20:04:28 -0700 Subject: [PATCH 2/2] Use find_package(Python3) instead of GzPython Update GzBuildTests.cmake and GzCodeCheck.cmake to stop using GzPython. Signed-off-by: Steve Peters --- cmake/GzBuildTests.cmake | 4 +++- cmake/GzCodeCheck.cmake | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/GzBuildTests.cmake b/cmake/GzBuildTests.cmake index 335dc767..b86eea58 100644 --- a/cmake/GzBuildTests.cmake +++ b/cmake/GzBuildTests.cmake @@ -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}) diff --git a/cmake/GzCodeCheck.cmake b/cmake/GzCodeCheck.cmake index 22931cbf..dabbfcf3 100644 --- a/cmake/GzCodeCheck.cmake +++ b/cmake/GzCodeCheck.cmake @@ -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)