|
| 1 | +cmake_minimum_required(VERSION 3.5) |
| 2 | +project(zed_aruco_localization) |
| 3 | + |
| 4 | +## Generate symbols for IDE indexer |
| 5 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 6 | + |
| 7 | +################################################ |
| 8 | +# Check the ROS2 version |
| 9 | + |
| 10 | +set(ROS2_FOUND FALSE) |
| 11 | +if(DEFINED ENV{ROS_DISTRO}) |
| 12 | + set(FOUND_ROS2_DISTRO $ENV{ROS_DISTRO}) |
| 13 | + set(ROS2_FOUND TRUE) |
| 14 | + #message("* Found ROS2 ${FOUND_ROS2_DISTRO}") |
| 15 | +else() |
| 16 | + message("* ROS2 distro variable not set. Trying to figure it out...") |
| 17 | + set(ROS2_DISTROS "ardent;crystal;dashing;eloquent;foxy;galactic;humble;rolling") |
| 18 | + set(ROS2_FOUND FALSE) |
| 19 | + foreach(distro ${ROS2_DISTROS}) |
| 20 | + if(NOT ROS2_FOUND) |
| 21 | + find_path(RCLCPP_H rclcpp.hpp PATHS /opt/ros/${distro}/include/rclcpp) |
| 22 | + if(RCLCPP_H) |
| 23 | + message("* Found ROS2 ${distro}") |
| 24 | + set(FOUND_ROS2_DISTRO ${distro}) |
| 25 | + set(ROS2_FOUND TRUE) |
| 26 | + endif() |
| 27 | + endif() |
| 28 | + endforeach() |
| 29 | +endif() |
| 30 | + |
| 31 | +if(ROS2_FOUND) |
| 32 | + if(${FOUND_ROS2_DISTRO} STREQUAL "humble") |
| 33 | + #message("* ROS2 ${FOUND_ROS2_DISTRO} is officially supported by this package.") |
| 34 | + add_definitions(-DFOUND_HUMBLE) |
| 35 | + elseif(${FOUND_ROS2_DISTRO} STREQUAL "iron") |
| 36 | + #message("* ROS2 ${FOUND_ROS2_DISTRO} is officially supported by this package.") |
| 37 | + add_definitions(-DFOUND_IRON) |
| 38 | + else() |
| 39 | + message("*** WARNING *** ROS2 ${FOUND_ROS2_DISTRO} is not officially supported by the package '${PROJECT_NAME}'. Correct operation is not guaranteed.") |
| 40 | + endif() |
| 41 | +else() |
| 42 | + message("*** WARNING *** ROS2 distro is unknown. This package could not work correctly.") |
| 43 | +endif() |
| 44 | +################################################ |
| 45 | + |
| 46 | +# Default to C99 |
| 47 | +if(NOT CMAKE_C_STANDARD) |
| 48 | +set(CMAKE_C_STANDARD 99) |
| 49 | +endif() |
| 50 | + |
| 51 | +# Default to C++14 |
| 52 | +if(NOT CMAKE_CXX_STANDARD) |
| 53 | +set(CMAKE_CXX_STANDARD 14) |
| 54 | +endif() |
| 55 | + |
| 56 | +#if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 57 | +# add_compile_options(-Wall -Wextra -Wpedantic) |
| 58 | +#endif() |
| 59 | + |
| 60 | +# if CMAKE_BUILD_TYPE is not specified, take 'Release' as default |
| 61 | +if(NOT CMAKE_BUILD_TYPE) |
| 62 | + set(CMAKE_BUILD_TYPE Release) |
| 63 | +endif() |
| 64 | + |
| 65 | +if(CMAKE_BUILD_TYPE MATCHES Release) |
| 66 | + #message(" * Release Mode") |
| 67 | + add_compile_options(-Wno-deprecated-declarations) |
| 68 | +endif() |
| 69 | + |
| 70 | +if(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) |
| 71 | + #message(" * Release with Debug Info Mode") |
| 72 | + add_compile_options(-Wno-deprecated-declarations) |
| 73 | +endif() |
| 74 | + |
| 75 | +if(CMAKE_BUILD_TYPE MATCHES Debug) |
| 76 | + message(" * Debug Mode") |
| 77 | +endif() |
| 78 | + |
| 79 | +############################################# |
| 80 | +# Dependencies |
| 81 | + |
| 82 | +find_package(OpenCV 4 REQUIRED) |
| 83 | +find_package(ZED 4 REQUIRED) |
| 84 | +find_package(CUDA REQUIRED) |
| 85 | + |
| 86 | +set(DEPENDENCIES_COMP |
| 87 | + rclcpp |
| 88 | + rclcpp_components |
| 89 | + builtin_interfaces |
| 90 | + sensor_msgs |
| 91 | + image_transport |
| 92 | + zed_interfaces |
| 93 | + tf2 |
| 94 | + tf2_ros |
| 95 | + tf2_geometry_msgs |
| 96 | +) |
| 97 | + |
| 98 | +find_package(ament_cmake_auto REQUIRED) |
| 99 | +ament_auto_find_build_dependencies() |
| 100 | + |
| 101 | +find_package(rcutils REQUIRED) |
| 102 | +find_package(rclcpp REQUIRED) |
| 103 | +find_package(rclcpp_components REQUIRED) |
| 104 | +find_package(builtin_interfaces REQUIRED) |
| 105 | +find_package(sensor_msgs REQUIRED) |
| 106 | +find_package(image_transport REQUIRED) |
| 107 | +find_package(tf2 REQUIRED) |
| 108 | +find_package(tf2_ros REQUIRED) |
| 109 | +find_package(tf2_geometry_msgs REQUIRED) |
| 110 | +find_package(zed_components) |
| 111 | + |
| 112 | +if(BUILD_TESTING) |
| 113 | +find_package(ament_lint_auto REQUIRED) |
| 114 | +ament_lint_auto_find_test_dependencies() |
| 115 | +endif() |
| 116 | + |
| 117 | +############################################################################### |
| 118 | +#Add all files in subdirectories of the project in |
| 119 | +# a dummy_target so qtcreator have access to all files |
| 120 | +file(GLOB_RECURSE all_files ${CMAKE_SOURCE_DIR}/*) |
| 121 | +add_custom_target(all_${PROJECT_NAME}_files SOURCES ${all_files}) |
| 122 | + |
| 123 | +# create ament index resource which references the libraries in the binary dir |
| 124 | +set(node_plugins "") |
| 125 | + |
| 126 | +if( ${FOUND_ROS2_DISTRO} STREQUAL "humble" OR ${FOUND_ROS2_DISTRO} STREQUAL "iron") |
| 127 | + ############################################################################### |
| 128 | + # SOURCES |
| 129 | + |
| 130 | + set(INC |
| 131 | + ${CMAKE_CURRENT_SOURCE_DIR}/src/include/aruco_loc_visibility_control.hpp |
| 132 | + ) |
| 133 | + |
| 134 | + set(INC_COMP |
| 135 | + ${CMAKE_CURRENT_SOURCE_DIR}/src/component/include/zed_aruco_localization_component.hpp |
| 136 | + ${CMAKE_CURRENT_SOURCE_DIR}/src/component/include/aruco.hpp |
| 137 | + ) |
| 138 | + |
| 139 | + set(SRC_COMP |
| 140 | + ${CMAKE_CURRENT_SOURCE_DIR}/src/component/src/zed_aruco_localization_component.cpp |
| 141 | + ${CMAKE_CURRENT_SOURCE_DIR}/src/component/src/aruco.cpp |
| 142 | + ) |
| 143 | + |
| 144 | + ############################################################################### |
| 145 | + # Bin and Install |
| 146 | + |
| 147 | + # Component |
| 148 | + add_library(${PROJECT_NAME}_component SHARED |
| 149 | + ${INC} |
| 150 | + ${INC_COMP} |
| 151 | + ${SRC_COMP} |
| 152 | + ) |
| 153 | + target_compile_definitions(${PROJECT_NAME}_component |
| 154 | + PRIVATE "COMPOSITION_BUILDING_DLL" |
| 155 | + ) |
| 156 | + target_include_directories(${PROJECT_NAME}_component |
| 157 | + PUBLIC |
| 158 | + ${CMAKE_CURRENT_SOURCE_DIR}/src/include |
| 159 | + ${CMAKE_CURRENT_SOURCE_DIR}/src/component/include |
| 160 | + ${OpenCV_INCLUDE_DIRS} |
| 161 | + ) |
| 162 | + target_link_libraries(${PROJECT_NAME}_component |
| 163 | + ${OpenCV_LIBS} |
| 164 | + ) |
| 165 | + ament_target_dependencies(${PROJECT_NAME}_component |
| 166 | + ${DEPENDENCIES_COMP} |
| 167 | + ) |
| 168 | + |
| 169 | + rclcpp_components_register_nodes(${PROJECT_NAME}_component "stereolabs::ZedArucoLoc") |
| 170 | + set(node_plugins "${node_plugins}stereolabs::ZedArucoLoc;$<TARGET_FILE:${PROJECT_NAME}_component>\n") |
| 171 | + |
| 172 | + # Install components |
| 173 | + install(TARGETS ${PROJECT_NAME}_component |
| 174 | + ARCHIVE DESTINATION lib |
| 175 | + LIBRARY DESTINATION lib |
| 176 | + RUNTIME DESTINATION lib/${PROJECT_NAME} |
| 177 | + ) |
| 178 | + |
| 179 | + # Install header files |
| 180 | + install( |
| 181 | + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/include/ |
| 182 | + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/component/include/ |
| 183 | + DESTINATION include/${PROJECT_NAME}/ |
| 184 | + ) |
| 185 | + |
| 186 | + # Install LAUNCH files |
| 187 | + install(DIRECTORY |
| 188 | + launch config rviz2 |
| 189 | + DESTINATION share/${PROJECT_NAME} |
| 190 | + ) |
| 191 | + |
| 192 | + ament_export_include_directories(include) |
| 193 | + ament_export_libraries(${PROJECT_NAME}_component) |
| 194 | + ament_export_dependencies(${DEPENDENCIES_COMP}) |
| 195 | +endif() |
| 196 | + |
| 197 | + |
| 198 | +ament_package() |
0 commit comments