diff --git a/rosidl_generator_py/CMakeLists.txt b/rosidl_generator_py/CMakeLists.txt index 07d124a1..1f086462 100644 --- a/rosidl_generator_py/CMakeLists.txt +++ b/rosidl_generator_py/CMakeLists.txt @@ -22,9 +22,6 @@ if(BUILD_TESTING) find_package(test_interface_files REQUIRED) - find_package(python_cmake_module REQUIRED) - find_package(PythonExtra MODULE REQUIRED) - include(cmake/register_py.cmake) include(cmake/rosidl_generator_py_get_typesupports.cmake) diff --git a/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake b/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake index cfc424a7..7db181b1 100644 --- a/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake +++ b/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake @@ -12,13 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -find_package(python_cmake_module REQUIRED) -find_package(PythonExtra REQUIRED) find_package(rmw REQUIRED) find_package(rosidl_runtime_c REQUIRED) find_package(rosidl_typesupport_c REQUIRED) find_package(rosidl_typesupport_interface REQUIRED) +# By default, without the settings below, find_package(Python3) will attempt +# to find the newest python version it can, and additionally will find the +# most specific version. For instance, on a system that has +# /usr/bin/python3.10, /usr/bin/python3.11, and /usr/bin/python3, it will find +# /usr/bin/python3.11, even if /usr/bin/python3 points to /usr/bin/python3.10. +# The behavior we want is to prefer the "system" installed version unless the +# user specifically tells us othewise through the Python3_EXECUTABLE hint. +# Setting CMP0094 to NEW means that the search will stop after the first +# python version is found. Setting Python3_FIND_UNVERSIONED_NAMES means that +# the search will prefer /usr/bin/python3 over /usr/bin/python3.11. And that +# latter functionality is only available in CMake 3.20 or later, so we need +# at least that version. +cmake_minimum_required(VERSION 3.20) +cmake_policy(SET CMP0094 NEW) +set(Python3_FIND_UNVERSIONED_NAMES FIRST) + find_package(Python3 REQUIRED COMPONENTS Interpreter Development NumPy) # Get a list of typesupport implementations from valid rmw implementations. @@ -184,7 +198,9 @@ foreach(_typesupport_impl ${_typesupport_impls}) ${rosidl_generate_interfaces_TARGET}__rosidl_typesupport_c ) - set_target_properties(${_target_name} PROPERTIES DEBUG_POSTFIX "${PythonExtra_POSTFIX}") + if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug") + set_target_properties(${_target_name} PROPERTIES DEBUG_POSTFIX "_d") + endif() # target_compile_options(${_target_name} PRIVATE ${_extension_compile_flags}) # TODO(sloretz) use target_compile_options when python extension passes -Wpedantic set_target_properties(${_target_name} PROPERTIES COMPILE_OPTIONS "${_extension_compile_flags}") diff --git a/rosidl_generator_py/package.xml b/rosidl_generator_py/package.xml index 3aab7c2a..f0454fd1 100644 --- a/rosidl_generator_py/package.xml +++ b/rosidl_generator_py/package.xml @@ -23,7 +23,6 @@ ament_cmake ament_index_python - python_cmake_module rosidl_generator_c rosidl_pycommon rosidl_typesupport_c @@ -53,7 +52,6 @@ ament_lint_common python3-numpy python3-pytest - python_cmake_module rmw rosidl_cmake