From aa7635deebd0e213d98f5d981d122d31d6c0d6df Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Sat, 19 Mar 2022 22:44:41 +0100 Subject: [PATCH 1/2] Replace deprecated PythonInterp with Python3 Signed-off-by: Bi0T1N --- cmake/IgnCodeCheck.cmake | 4 ++-- cmake/IgnPython.cmake | 30 ++++++++++++++++++++++-------- cmake/IgnUtils.cmake | 5 ++--- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/cmake/IgnCodeCheck.cmake b/cmake/IgnCodeCheck.cmake index 636db326..f9b81843 100644 --- a/cmake/IgnCodeCheck.cmake +++ b/cmake/IgnCodeCheck.cmake @@ -44,9 +44,9 @@ function(ign_setup_target_for_codecheck) DEPENDS cppcheck ) - if(PYTHONINTERP_FOUND) + if(Python3_Interpreter_FOUND) add_custom_target(cpplint - COMMAND ${PYTHON_EXECUTABLE} ${IGNITION_CMAKE_CODECHECK_DIR}/cpplint.py --extensions=cc,hh --quiet `${CPPCHECK_FIND}` + COMMAND ${Python3_EXECUTABLE} ${IGNITION_CMAKE_CODECHECK_DIR}/cpplint.py --extensions=cc,hh --quiet `${CPPCHECK_FIND}` ) add_dependencies(codecheck cpplint) diff --git a/cmake/IgnPython.cmake b/cmake/IgnPython.cmake index 064f7ea2..b2ca87de 100644 --- a/cmake/IgnPython.cmake +++ b/cmake/IgnPython.cmake @@ -12,14 +12,28 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Copied from ament/ament_cmake: ament_cmake/ament_cmake_core/cmake/core/python.cmake +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.19") + set(PYTHON_VERSION "" CACHE STRING + "Specify specific Python3 version to use ('major.minor' or 'versionMin...[<]versionMax')") -set(PYTHON_VERSION "" CACHE STRING - "Specify specific Python version to use ('major.minor' or 'major')") + find_package(Python3 ${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(PYTHON_VERSION "" CACHE STRING + "Specify specific Python version to use ('major.minor' or 'major')") -# if not specified otherwise use Python 3 -if(NOT PYTHON_VERSION) - set(PYTHON_VERSION "3") -endif() + # if not specified otherwise use Python 3 + if(NOT PYTHON_VERSION) + set(PYTHON_VERSION "3") + endif() -find_package(PythonInterp ${PYTHON_VERSION} QUIET) + find_package(PythonInterp ${PYTHON_VERSION} QUIET) + + if(PYTHONINTERP_FOUND) + set(Python3_Interpreter_FOUND ${PYTHONINTERP_FOUND}) + set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) + endif() +endif() \ No newline at end of file diff --git a/cmake/IgnUtils.cmake b/cmake/IgnUtils.cmake index 8dda557c..c05006ec 100644 --- a/cmake/IgnUtils.cmake +++ b/cmake/IgnUtils.cmake @@ -1695,7 +1695,6 @@ macro(ign_build_tests) # Find the Python interpreter for running the # check_test_ran.py script - include(IgnPython) # Build all the tests @@ -1715,10 +1714,10 @@ macro(ign_build_tests) set_tests_properties(${target_name} PROPERTIES TIMEOUT 240) - if(PYTHONINTERP_FOUND) + if(Python3_Interpreter_FOUND) # Check that the test produced a result and create a failure if it didn't. # Guards against crashed and timed out tests. - add_test(check_${target_name} ${PYTHON_EXECUTABLE} ${IGNITION_CMAKE_TOOLS_DIR}/check_test_ran.py + add_test(check_${target_name} ${Python3_EXECUTABLE} ${IGNITION_CMAKE_TOOLS_DIR}/check_test_ran.py ${CMAKE_BINARY_DIR}/test_results/${target_name}.xml) endif() endforeach() From 2f2ff471ce5a5db274811cdbdc798f8556f8f3db Mon Sep 17 00:00:00 2001 From: Bi0T1N Date: Wed, 23 Mar 2022 13:06:13 +0100 Subject: [PATCH 2/2] Rename PYTHON_VERSION to IGN_PYTHON_VERSION Signed-off-by: Bi0T1N --- cmake/IgnPython.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmake/IgnPython.cmake b/cmake/IgnPython.cmake index b2ca87de..57e4362a 100644 --- a/cmake/IgnPython.cmake +++ b/cmake/IgnPython.cmake @@ -13,24 +13,24 @@ # limitations under the License. if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.19") - set(PYTHON_VERSION "" CACHE STRING + set(IGN_PYTHON_VERSION "" CACHE STRING "Specify specific Python3 version to use ('major.minor' or 'versionMin...[<]versionMax')") - find_package(Python3 ${PYTHON_VERSION} QUIET) + find_package(Python3 ${IGN_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(PYTHON_VERSION "" CACHE STRING + set(IGN_PYTHON_VERSION "" CACHE STRING "Specify specific Python version to use ('major.minor' or 'major')") # if not specified otherwise use Python 3 - if(NOT PYTHON_VERSION) - set(PYTHON_VERSION "3") + if(NOT IGN_PYTHON_VERSION) + set(IGN_PYTHON_VERSION "3") endif() - find_package(PythonInterp ${PYTHON_VERSION} QUIET) + find_package(PythonInterp ${IGN_PYTHON_VERSION} QUIET) if(PYTHONINTERP_FOUND) set(Python3_Interpreter_FOUND ${PYTHONINTERP_FOUND})