|
28 | 28 | # :type EXECUTOR: string |
29 | 29 | # :param RESOURCE_INDEX: the ament resource index to register the components |
30 | 30 | # :type RESOURCE_INDEX: string |
| 31 | +# :param NO_UNDEFINED_SYMBOLS: add linker flags to deny undefined symbols |
| 32 | +# :type NO_UNDEFINED_SYMBOLS: option |
31 | 33 | # |
32 | 34 | macro(rclcpp_components_register_node target) |
33 | | - cmake_parse_arguments(ARGS "" "PLUGIN;EXECUTABLE;EXECUTOR;RESOURCE_INDEX" "" ${ARGN}) |
| 35 | + cmake_parse_arguments(ARGS "NO_UNDEFINED_SYMBOLS" "PLUGIN;EXECUTABLE;EXECUTOR;RESOURCE_INDEX" "" ${ARGN}) |
34 | 36 | if(ARGS_UNPARSED_ARGUMENTS) |
35 | 37 | message(FATAL_ERROR "rclcpp_components_register_node() called with unused " |
36 | 38 | "arguments: ${ARGS_UNPARSED_ARGUMENTS}") |
@@ -67,6 +69,26 @@ macro(rclcpp_components_register_node target) |
67 | 69 | "${_RCLCPP_COMPONENTS_${resource_index}__NODES}${component};${_path}/$<TARGET_FILE_NAME:${target}>\n") |
68 | 70 | list(APPEND _RCLCPP_COMPONENTS_PACKAGE_RESOURCE_INDICES ${resource_index}) |
69 | 71 |
|
| 72 | + if(ARGS_NO_UNDEFINED_SYMBOLS AND WIN32) |
| 73 | + message(WARNING "NO_UNDEFINED_SYMBOLS is enabled for target \"${target}\", but this is unsupported on windows.") |
| 74 | + elseif(ARGS_NO_UNDEFINED_SYMBOLS AND NOT WIN32) |
| 75 | + check_cxx_compiler_flag("-Wl,--no-undefined" linker_supports_no_undefined) |
| 76 | + if(linker_supports_no_undefined) |
| 77 | + target_link_options("${target}" PRIVATE "-Wl,--no-undefined") |
| 78 | + else() |
| 79 | + message(WARNING "NO_UNDEFINED_SYMBOLS is enabled for target \"${target}\",\ |
| 80 | + but the linker does not support the \"--no-undefined\" flag.") |
| 81 | + endif() |
| 82 | + |
| 83 | + check_cxx_compiler_flag("-Wl,--no-allow-shlib-undefined" linker_supports_no_allow_shlib_undefined) |
| 84 | + if(linker_supports_no_allow_shlib_undefined) |
| 85 | + target_link_options("${target}" PRIVATE "-Wl,--no-allow-shlib-undefined") |
| 86 | + else() |
| 87 | + message(WARNING "NO_UNDEFINED_SYMBOLS is enabled for target \"${target}\",\ |
| 88 | + but the linker does not support the \"--no-allow-shlib-undefined\" flag.") |
| 89 | + endif() |
| 90 | + endif() |
| 91 | + |
70 | 92 | configure_file(${rclcpp_components_NODE_TEMPLATE} |
71 | 93 | ${PROJECT_BINARY_DIR}/rclcpp_components/node_main_configured_${node}.cpp.in) |
72 | 94 | file(GENERATE OUTPUT ${PROJECT_BINARY_DIR}/rclcpp_components/node_main_${node}.cpp |
|
0 commit comments