|
| 1 | +cmake_minimum_required(VERSION 3.5) |
| 2 | +project(dynmsg) |
| 3 | + |
| 4 | +# Default to C99 |
| 5 | +if(NOT CMAKE_C_STANDARD) |
| 6 | + set(CMAKE_C_STANDARD 99) |
| 7 | +endif() |
| 8 | + |
| 9 | +# Default to C++14 |
| 10 | +if(NOT CMAKE_CXX_STANDARD) |
| 11 | + set(CMAKE_CXX_STANDARD 14) |
| 12 | +endif() |
| 13 | + |
| 14 | +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 15 | + # -fPIC for building a static lib (yaml-cpp) that later gets linked into a dynamic lib |
| 16 | + add_compile_options(-Wall -Wextra -Wpedantic -fPIC) |
| 17 | + set(FLAG_NO_WARNINGS "-w") |
| 18 | +endif() |
| 19 | + |
| 20 | +# find dependencies |
| 21 | +find_package(ament_cmake REQUIRED) |
| 22 | +find_package(rcutils REQUIRED) |
| 23 | +find_package(rosidl_runtime_c REQUIRED) |
| 24 | +find_package(rosidl_runtime_cpp REQUIRED) |
| 25 | +find_package(rosidl_typesupport_introspection_c REQUIRED) |
| 26 | +find_package(rosidl_typesupport_introspection_cpp REQUIRED) |
| 27 | +find_package(yaml_cpp_vendor REQUIRED) |
| 28 | + |
| 29 | +# See config.hpp.in |
| 30 | +option(DYNMSG_VALUE_ONLY "Write message member value directly instead default+value" ON) |
| 31 | +option(DYNMSG_YAML_CPP_BAD_INT8_HANDLING "Work around buggy [u]int8_t handling by yaml-cpp" ON) |
| 32 | +option(DYNMSG_PARSER_DEBUG "Enable debugging-related logs for YAML->msg conversion" OFF) |
| 33 | +configure_file(include/${PROJECT_NAME}/config.hpp.in include/${PROJECT_NAME}/config.hpp) |
| 34 | + |
| 35 | +add_library(dynmsg STATIC |
| 36 | + src/msg_parser_c.cpp |
| 37 | + src/msg_parser_cpp.cpp |
| 38 | + src/message_reading_c.cpp |
| 39 | + src/message_reading_cpp.cpp |
| 40 | + src/typesupport.cpp |
| 41 | + src/vector_utils.cpp |
| 42 | + src/string_utils.cpp |
| 43 | + src/yaml_utils.cpp |
| 44 | +) |
| 45 | +ament_target_dependencies(dynmsg |
| 46 | + rcutils |
| 47 | + rosidl_runtime_c |
| 48 | + rosidl_runtime_cpp |
| 49 | + rosidl_typesupport_introspection_c |
| 50 | + rosidl_typesupport_introspection_cpp |
| 51 | + yaml_cpp_vendor |
| 52 | +) |
| 53 | +target_include_directories(dynmsg PUBLIC |
| 54 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" |
| 55 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>" |
| 56 | + "$<INSTALL_INTERFACE:include>" |
| 57 | +) |
| 58 | +ament_export_include_directories(include) |
| 59 | +ament_export_libraries(dynmsg) |
| 60 | +ament_export_targets(dynmsg HAS_LIBRARY_TARGET) |
| 61 | +ament_export_dependencies(rcutils) |
| 62 | +ament_export_dependencies(rosidl_runtime_c) |
| 63 | +ament_export_dependencies(rosidl_runtime_cpp) |
| 64 | +ament_export_dependencies(rosidl_typesupport_introspection_c) |
| 65 | +ament_export_dependencies(rosidl_typesupport_introspection_cpp) |
| 66 | +ament_export_dependencies(yaml_cpp_vendor) |
| 67 | + |
| 68 | +install( |
| 69 | + DIRECTORY include/ ${CMAKE_CURRENT_BINARY_DIR}/include/ |
| 70 | + DESTINATION include |
| 71 | + PATTERN "*.in" EXCLUDE |
| 72 | +) |
| 73 | +install( |
| 74 | + TARGETS dynmsg |
| 75 | + EXPORT dynmsg |
| 76 | + LIBRARY DESTINATION lib |
| 77 | + ARCHIVE DESTINATION lib |
| 78 | + RUNTIME DESTINATION bin |
| 79 | + INCLUDES DESTINATION include |
| 80 | +) |
| 81 | + |
| 82 | +if(BUILD_TESTING) |
| 83 | + find_package(ament_lint_auto REQUIRED) |
| 84 | + ament_lint_auto_find_test_dependencies() |
| 85 | + |
| 86 | + find_package(ament_cmake_gtest REQUIRED) |
| 87 | + find_package(std_msgs REQUIRED) |
| 88 | + |
| 89 | + ament_add_gtest(wide_strings test/test_wide_strings.cpp) |
| 90 | + target_link_libraries(wide_strings dynmsg) |
| 91 | + |
| 92 | + ament_add_gtest(test_vector_utils test/test_vector_utils.cpp) |
| 93 | + target_link_libraries(test_vector_utils dynmsg) |
| 94 | + |
| 95 | + ament_add_gtest(test_typesupport test/test_typesupport.cpp) |
| 96 | + target_link_libraries(test_typesupport dynmsg) |
| 97 | + ament_target_dependencies(test_typesupport std_msgs) |
| 98 | +endif() |
| 99 | + |
| 100 | +ament_package() |
0 commit comments