|
| 1 | +cmake_minimum_required(VERSION 3.5) |
| 2 | +project(system_monitor) |
| 3 | + |
| 4 | +## Compile as C++14, supported in ROS Melodic and newer |
| 5 | +if(NOT CMAKE_CXX_STANDARD) |
| 6 | + set(CMAKE_CXX_STANDARD 14) |
| 7 | + set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 8 | + set(CMAKE_CXX_EXTENSIONS OFF) |
| 9 | +endif() |
| 10 | +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 11 | + add_compile_options(-Wall -Wextra -Wpedantic -Werror) |
| 12 | +endif() |
| 13 | + |
| 14 | +find_package(ament_cmake_auto REQUIRED) |
| 15 | +ament_auto_find_build_dependencies() |
| 16 | + |
| 17 | +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 18 | +find_package(NVML) |
| 19 | +find_package(fmt REQUIRED) |
| 20 | +set(LIBRARIES fmt) |
| 21 | + |
| 22 | +########### |
| 23 | +## Build ## |
| 24 | +########### |
| 25 | + |
| 26 | +## Specify additional locations of header files |
| 27 | + |
| 28 | +find_path(LIBNL3_INCLUDE_DIRS |
| 29 | + NAMES netlink/netlink.h |
| 30 | + PATH_SUFFIXES libnl3 |
| 31 | +) |
| 32 | + |
| 33 | +if(NVML_FOUND) |
| 34 | + include_directories( |
| 35 | + include |
| 36 | + ${LIBNL3_INCLUDE_DIRS} |
| 37 | + ${NVML_INCLUDE_DIRS} |
| 38 | + ) |
| 39 | +else() |
| 40 | + include_directories( |
| 41 | + include |
| 42 | + ${LIBNL3_INCLUDE_DIRS} |
| 43 | + ) |
| 44 | +endif() |
| 45 | + |
| 46 | +## Declare a C++ executable |
| 47 | + |
| 48 | +if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") |
| 49 | + set(CMAKE_CPU_PLATFORM "intel") |
| 50 | + add_definitions(-D_CPU_INTEL_) |
| 51 | +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm") |
| 52 | + if(CMAKE_HOST_SYSTEM_VERSION MATCHES ".*raspi.*") |
| 53 | + set(CMAKE_CPU_PLATFORM "raspi") |
| 54 | + add_definitions(-D_CPU_RASPI_) |
| 55 | + elseif(CMAKE_HOST_SYSTEM_VERSION MATCHES ".*tegra.*") |
| 56 | + set(CMAKE_CPU_PLATFORM "tegra") |
| 57 | + add_definitions(-D_CPU_TEGRA_) |
| 58 | + else() |
| 59 | + set(CMAKE_CPU_PLATFORM "arm") |
| 60 | + add_definitions(-D_CPU_ARM_) |
| 61 | + endif() |
| 62 | +else() |
| 63 | + set(CMAKE_CPU_PLATFORM "unknown") |
| 64 | +endif() |
| 65 | + |
| 66 | +if(NVML_FOUND) |
| 67 | + set(CMAKE_GPU_PLATFORM "nvml") |
| 68 | + add_definitions(-D_GPU_NVML_) |
| 69 | + set(GPU_LIBRARY ${NVML_LIBRARIES}) |
| 70 | +else() |
| 71 | + if(CMAKE_CPU_PLATFORM STREQUAL "tegra") |
| 72 | + set(CMAKE_GPU_PLATFORM "tegra") |
| 73 | + add_definitions(-D_GPU_TEGRA_) |
| 74 | + else() |
| 75 | + set(CMAKE_GPU_PLATFORM "unknown") |
| 76 | + endif() |
| 77 | +endif() |
| 78 | + |
| 79 | +message(STATUS "HOST_SYSTEM_VERSION: " ${CMAKE_HOST_SYSTEM_VERSION}) |
| 80 | +message(STATUS "SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR}) |
| 81 | +message(STATUS "CPU PLATFORM: " ${CMAKE_CPU_PLATFORM}) |
| 82 | +message(STATUS "GPU PLATFORM: " ${CMAKE_GPU_PLATFORM}) |
| 83 | + |
| 84 | +set(CPU_MONITOR_SOURCE |
| 85 | + src/cpu_monitor/cpu_monitor_base.cpp |
| 86 | + src/cpu_monitor/${CMAKE_CPU_PLATFORM}_cpu_monitor.cpp |
| 87 | +) |
| 88 | + |
| 89 | +ament_auto_add_library(cpu_monitor_lib SHARED |
| 90 | + ${CPU_MONITOR_SOURCE} |
| 91 | +) |
| 92 | + |
| 93 | +ament_auto_add_library(hdd_monitor_lib SHARED |
| 94 | + src/hdd_monitor/hdd_monitor.cpp |
| 95 | +) |
| 96 | + |
| 97 | +ament_auto_add_library(mem_monitor_lib SHARED |
| 98 | + src/mem_monitor/mem_monitor.cpp |
| 99 | +) |
| 100 | + |
| 101 | +ament_auto_add_library(net_monitor_lib SHARED |
| 102 | + src/net_monitor/net_monitor.cpp |
| 103 | + src/net_monitor/nl80211.cpp |
| 104 | +) |
| 105 | + |
| 106 | +ament_auto_add_library(ntp_monitor_lib SHARED |
| 107 | + src/ntp_monitor/ntp_monitor.cpp |
| 108 | +) |
| 109 | + |
| 110 | +ament_auto_add_library(process_monitor_lib SHARED |
| 111 | + src/process_monitor/process_monitor.cpp |
| 112 | +) |
| 113 | + |
| 114 | +set(GPU_MONITOR_SOURCE |
| 115 | + src/gpu_monitor/gpu_monitor_base.cpp |
| 116 | + src/gpu_monitor/${CMAKE_GPU_PLATFORM}_gpu_monitor.cpp |
| 117 | +) |
| 118 | +ament_auto_add_library(gpu_monitor_lib SHARED |
| 119 | + ${GPU_MONITOR_SOURCE} |
| 120 | +) |
| 121 | + |
| 122 | +ament_auto_add_executable(msr_reader |
| 123 | + reader/msr_reader/msr_reader.cpp |
| 124 | +) |
| 125 | + |
| 126 | +ament_auto_add_executable(hdd_reader |
| 127 | + reader/hdd_reader/hdd_reader.cpp |
| 128 | +) |
| 129 | + |
| 130 | +find_library(NL3 nl-3 REQUIRED) |
| 131 | +find_library(NLGENL3 nl-genl-3 REQUIRED) |
| 132 | +list(APPEND NL_LIBS ${NL3} ${NLGENL3}) |
| 133 | + |
| 134 | +find_package(Boost REQUIRED COMPONENTS |
| 135 | + serialization |
| 136 | + thread |
| 137 | + filesystem |
| 138 | + regex |
| 139 | +) |
| 140 | + |
| 141 | +## Specify libraries to link a library or executable target against |
| 142 | +target_link_libraries(cpu_monitor_lib ${Boost_LIBRARIES} ${LIBRARIES}) |
| 143 | +target_link_libraries(hdd_monitor_lib ${Boost_LIBRARIES} ${LIBRARIES}) |
| 144 | +target_link_libraries(mem_monitor_lib ${LIBRARIES}) |
| 145 | +target_link_libraries(net_monitor_lib ${NL_LIBS} ${LIBRARIES}) |
| 146 | +target_link_libraries(ntp_monitor_lib ${Boost_LIBRARIES} ${LIBRARIES}) |
| 147 | +target_link_libraries(process_monitor_lib ${LIBRARIES}) |
| 148 | +target_link_libraries(gpu_monitor_lib ${GPU_LIBRARY} ${Boost_LIBRARIES} ${LIBRARIES}) |
| 149 | +target_link_libraries(msr_reader ${Boost_LIBRARIES} ${LIBRARIES}) |
| 150 | +target_link_libraries(hdd_reader ${Boost_LIBRARIES} ${LIBRARIES}) |
| 151 | + |
| 152 | +rclcpp_components_register_node(cpu_monitor_lib |
| 153 | + PLUGIN "CPUMonitor" |
| 154 | + EXECUTABLE cpu_monitor |
| 155 | +) |
| 156 | + |
| 157 | +rclcpp_components_register_node(hdd_monitor_lib |
| 158 | + PLUGIN "HDDMonitor" |
| 159 | + EXECUTABLE hdd_monitor |
| 160 | +) |
| 161 | + |
| 162 | +rclcpp_components_register_node(mem_monitor_lib |
| 163 | + PLUGIN "MemMonitor" |
| 164 | + EXECUTABLE mem_monitor |
| 165 | +) |
| 166 | + |
| 167 | +rclcpp_components_register_node(net_monitor_lib |
| 168 | + PLUGIN "NetMonitor" |
| 169 | + EXECUTABLE net_monitor |
| 170 | +) |
| 171 | + |
| 172 | +rclcpp_components_register_node(ntp_monitor_lib |
| 173 | + PLUGIN "NTPMonitor" |
| 174 | + EXECUTABLE ntp_monitor |
| 175 | +) |
| 176 | + |
| 177 | +rclcpp_components_register_node(process_monitor_lib |
| 178 | + PLUGIN "ProcessMonitor" |
| 179 | + EXECUTABLE process_monitor |
| 180 | +) |
| 181 | + |
| 182 | +rclcpp_components_register_node(gpu_monitor_lib |
| 183 | + PLUGIN "GPUMonitor" |
| 184 | + EXECUTABLE gpu_monitor |
| 185 | +) |
| 186 | + |
| 187 | +# TODO(yunus.caliskan): Port the tests to ROS2, robustify the tests. |
| 188 | +if(BUILD_TESTING) |
| 189 | + find_package(ament_lint_auto REQUIRED) |
| 190 | + ament_lint_auto_find_test_dependencies() |
| 191 | + |
| 192 | + # ament_add_gtest(test_cpu_monitor |
| 193 | + # test/src/cpu_monitor/test_${CMAKE_CPU_PLATFORM}_cpu_monitor.cpp |
| 194 | + # ${CPU_MONITOR_SOURCE} |
| 195 | + # ) |
| 196 | + |
| 197 | + # ament_target_dependencies(test_cpu_monitor |
| 198 | + # "rclcpp" |
| 199 | + # "diagnostic_msgs" |
| 200 | + # ) |
| 201 | + |
| 202 | + # target_include_directories(test_cpu_monitor |
| 203 | + # PRIVATE "include" |
| 204 | + # ) |
| 205 | + |
| 206 | + # target_link_libraries(test_cpu_monitor ${Boost_LIBRARIES} ${LIBRARIES}) |
| 207 | + |
| 208 | + # ament_add_gtest(test_hdd_monitor |
| 209 | + # test/src/hdd_monitor/test_hdd_monitor.cpp |
| 210 | + # src/hdd_monitor/hdd_monitor.cpp |
| 211 | + # ) |
| 212 | + |
| 213 | + # ament_target_dependencies(test_hdd_monitor |
| 214 | + # "rclcpp" |
| 215 | + # "diagnostic_msgs" |
| 216 | + # ) |
| 217 | + |
| 218 | + # target_include_directories(test_hdd_monitor |
| 219 | + # PRIVATE "include" |
| 220 | + # ) |
| 221 | + |
| 222 | + # target_link_libraries(test_hdd_monitor ${Boost_LIBRARIES} ${LIBRARIES} |
| 223 | + # ) |
| 224 | + |
| 225 | + # ament_add_gtest(test_mem_monitor |
| 226 | + # test/src/mem_monitor/test_mem_monitor.cpp |
| 227 | + # src/mem_monitor/mem_monitor.cpp |
| 228 | + # ) |
| 229 | + |
| 230 | + # ament_target_dependencies(test_mem_monitor |
| 231 | + # "rclcpp" |
| 232 | + # "diagnostic_msgs" |
| 233 | + # ) |
| 234 | + |
| 235 | + # target_include_directories(test_mem_monitor |
| 236 | + # PRIVATE "include" |
| 237 | + # ) |
| 238 | + |
| 239 | + # target_link_libraries(test_mem_monitor ${Boost_LIBRARIES} ${LIBRARIES}) |
| 240 | + |
| 241 | + # ament_add_gtest(test_net_monitor |
| 242 | + # test/src/net_monitor/test_net_monitor.cpp |
| 243 | + # src/net_monitor/net_monitor.cpp |
| 244 | + # src/net_monitor/nl80211.cpp |
| 245 | + # ) |
| 246 | + |
| 247 | + # ament_target_dependencies(test_net_monitor |
| 248 | + # "rclcpp" |
| 249 | + # "diagnostic_msgs" |
| 250 | + # ) |
| 251 | + |
| 252 | + # target_include_directories(test_net_monitor |
| 253 | + # PRIVATE "include" |
| 254 | + # ) |
| 255 | + |
| 256 | + # target_link_libraries(test_net_monitor ${Boost_LIBRARIES} ${NL_LIBS} ${LIBRARIES}) |
| 257 | + |
| 258 | + # ament_add_gtest(test_ntp_monitor |
| 259 | + # test/src/ntp_monitor/test_ntp_monitor.cpp |
| 260 | + # src/ntp_monitor/ntp_monitor.cpp |
| 261 | + # ) |
| 262 | + |
| 263 | + # ament_target_dependencies(test_ntp_monitor |
| 264 | + # "rclcpp" |
| 265 | + # "diagnostic_msgs" |
| 266 | + # ) |
| 267 | + |
| 268 | + # target_include_directories(test_ntp_monitor |
| 269 | + # PRIVATE "include" |
| 270 | + # ) |
| 271 | + |
| 272 | + # target_link_libraries(test_ntp_monitor ${Boost_LIBRARIES} ${LIBRARIES}) |
| 273 | + |
| 274 | + # ament_add_gtest(test_process_monitor |
| 275 | + # test/src/process_monitor/test_process_monitor.cpp |
| 276 | + # src/process_monitor/process_monitor.cpp |
| 277 | + # ) |
| 278 | + |
| 279 | + # ament_target_dependencies(test_process_monitor |
| 280 | + # "rclcpp" |
| 281 | + # "diagnostic_msgs" |
| 282 | + # ) |
| 283 | + |
| 284 | + # target_include_directories(test_process_monitor |
| 285 | + # PRIVATE "include" |
| 286 | + # ) |
| 287 | + |
| 288 | + # target_link_libraries(test_process_monitor ${Boost_LIBRARIES} ${LIBRARIES}) |
| 289 | + |
| 290 | + # ament_add_gtest(test_gpu_monitor |
| 291 | + # test/src/gpu_monitor/test_${CMAKE_GPU_PLATFORM}_gpu_monitor.cpp |
| 292 | + # ${GPU_MONITOR_SOURCE} |
| 293 | + # ) |
| 294 | + |
| 295 | + # ament_target_dependencies(test_gpu_monitor |
| 296 | + # "rclcpp" |
| 297 | + # "diagnostic_msgs" |
| 298 | + # ) |
| 299 | + |
| 300 | + # target_include_directories(test_gpu_monitor |
| 301 | + # PRIVATE "include" |
| 302 | + # ) |
| 303 | + |
| 304 | + # target_link_libraries(test_gpu_monitor ${GPU_LIBRARY} ${LIBRARIES}) |
| 305 | + |
| 306 | +endif() |
| 307 | + |
| 308 | +############# |
| 309 | +## Install ## |
| 310 | +############# |
| 311 | + |
| 312 | +ament_auto_package(INSTALL_TO_SHARE |
| 313 | + launch |
| 314 | + config |
| 315 | +) |
0 commit comments