Skip to content

Commit

Permalink
Remove python_cmake_module and set hints (#204)
Browse files Browse the repository at this point in the history
* Stop using python_cmake_module.

We really don't need it anymore, and can just use the
builtin find_package(Python3).

* Set hints to find the python version we actually want.

The comment in the commit explains the reasoning behind it.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette authored Oct 3, 2024
1 parent 1fbd99b commit acf97aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 0 additions & 3 deletions rosidl_generator_py/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}")
Expand Down
2 changes: 0 additions & 2 deletions rosidl_generator_py/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

<buildtool_export_depend>ament_cmake</buildtool_export_depend>
<buildtool_export_depend>ament_index_python</buildtool_export_depend>
<buildtool_export_depend>python_cmake_module</buildtool_export_depend>
<buildtool_export_depend>rosidl_generator_c</buildtool_export_depend>
<buildtool_export_depend>rosidl_pycommon</buildtool_export_depend>
<buildtool_export_depend>rosidl_typesupport_c</buildtool_export_depend>
Expand Down Expand Up @@ -53,7 +52,6 @@
<test_depend>ament_lint_common</test_depend>
<test_depend>python3-numpy</test_depend>
<test_depend>python3-pytest</test_depend>
<test_depend>python_cmake_module</test_depend>
<test_depend>rmw</test_depend>
<test_depend>rosidl_cmake</test_depend>

Expand Down

0 comments on commit acf97aa

Please sign in to comment.