|
| 1 | +cmake_minimum_required(VERSION 3.20) |
| 2 | +project(image_transport_py) |
| 3 | + |
| 4 | +# Default to C99 |
| 5 | +if(NOT CMAKE_C_STANDARD) |
| 6 | + set(CMAKE_C_STANDARD 99) |
| 7 | +endif() |
| 8 | + |
| 9 | +# Default to C++17 |
| 10 | +if(NOT CMAKE_CXX_STANDARD) |
| 11 | + set(CMAKE_CXX_STANDARD 17) |
| 12 | + set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 13 | +endif() |
| 14 | + |
| 15 | +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 16 | + add_compile_options(-Wall -Wextra -Wpedantic) |
| 17 | +endif() |
| 18 | + |
| 19 | +find_package(ament_cmake REQUIRED) |
| 20 | +find_package(ament_cmake_python REQUIRED) |
| 21 | +find_package(ament_cmake_ros REQUIRED) |
| 22 | +find_package(image_transport REQUIRED) |
| 23 | +find_package(rclcpp REQUIRED) |
| 24 | +find_package(sensor_msgs REQUIRED) |
| 25 | + |
| 26 | +# By default, without the settings below, find_package(Python3) will attempt |
| 27 | +# to find the newest python version it can, and additionally will find the |
| 28 | +# most specific version. For instance, on a system that has |
| 29 | +# /usr/bin/python3.10, /usr/bin/python3.11, and /usr/bin/python3, it will find |
| 30 | +# /usr/bin/python3.11, even if /usr/bin/python3 points to /usr/bin/python3.10. |
| 31 | +# The behavior we want is to prefer the "system" installed version unless the |
| 32 | +# user specifically tells us othewise through the Python3_EXECUTABLE hint. |
| 33 | +# Setting CMP0094 to NEW means that the search will stop after the first |
| 34 | +# python version is found. Setting Python3_FIND_UNVERSIONED_NAMES means that |
| 35 | +# the search will prefer /usr/bin/python3 over /usr/bin/python3.11. And that |
| 36 | +# latter functionality is only available in CMake 3.20 or later, so we need |
| 37 | +# at least that version. |
| 38 | +cmake_policy(SET CMP0094 NEW) |
| 39 | +set(Python3_FIND_UNVERSIONED_NAMES FIRST) |
| 40 | + |
| 41 | +# Find python before pybind11 |
| 42 | +find_package(Python3 REQUIRED COMPONENTS Interpreter Development) |
| 43 | + |
| 44 | +find_package(pybind11_vendor REQUIRED) |
| 45 | +find_package(pybind11 REQUIRED) |
| 46 | + |
| 47 | +ament_python_install_package(${PROJECT_NAME}) |
| 48 | + |
| 49 | +pybind11_add_module(_image_transport MODULE |
| 50 | + src/image_transport_py/pybind_image_transport.cpp |
| 51 | +) |
| 52 | + |
| 53 | +target_include_directories(_image_transport PUBLIC |
| 54 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" |
| 55 | + "$<INSTALL_INTERFACE:include/${PROJECT_NAME}>") |
| 56 | + |
| 57 | +target_link_libraries(_image_transport PUBLIC |
| 58 | + image_transport::image_transport |
| 59 | + rclcpp::rclcpp |
| 60 | + ${sensor_msgs_TARGETS} |
| 61 | +) |
| 62 | + |
| 63 | +# Install cython modules as sub-modules of the project |
| 64 | +install( |
| 65 | + TARGETS |
| 66 | + _image_transport |
| 67 | + DESTINATION "${PYTHON_INSTALL_DIR}/${PROJECT_NAME}" |
| 68 | +) |
| 69 | + |
| 70 | +if(BUILD_TESTING) |
| 71 | + find_package(ament_lint_auto REQUIRED) |
| 72 | + |
| 73 | + list(APPEND AMENT_LINT_AUTO_EXCLUDE |
| 74 | + ament_cmake_cppcheck |
| 75 | + ) |
| 76 | + ament_lint_auto_find_test_dependencies() |
| 77 | + |
| 78 | + if(NOT WIN32) |
| 79 | + ament_cppcheck(LANGUAGE "c++") |
| 80 | + else() |
| 81 | + message(STATUS "Skipping ament_cppcheck on Windows") |
| 82 | + endif() |
| 83 | +endif() |
| 84 | + |
| 85 | +ament_package() |
0 commit comments