From 51c03c165cebd0d439df6af70ed9242d3af156a3 Mon Sep 17 00:00:00 2001 From: Fred Hornsey Date: Tue, 10 Sep 2024 13:23:30 -0500 Subject: [PATCH] Fix Issues from Using OpenDDS in add_subdirectory --- cmake/tao_idl_sources.cmake | 18 ++++++++++++++++-- .../cmake/generated_global/idl/CMakeLists.txt | 2 +- tests/cmake/idl_compiler_tests/CMakeLists.txt | 13 +++++++------ tests/cmake/idl_compiler_tests/file.ext | 1 + tests/cmake/include_subdir/CMakeLists.txt | 2 +- 5 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 tests/cmake/idl_compiler_tests/file.ext diff --git a/cmake/tao_idl_sources.cmake b/cmake/tao_idl_sources.cmake index 330e2d4ca67..44e7439c45e 100644 --- a/cmake/tao_idl_sources.cmake +++ b/cmake/tao_idl_sources.cmake @@ -45,7 +45,15 @@ endfunction() function(_opendds_get_generated_output target file) set(no_value_options MKDIR) - set(single_value_options INCLUDE_BASE O_OPT DIR_PATH_VAR FILE_PATH_VAR PREFIX_PATH_VAR FAIL_VAR) + set(single_value_options + INCLUDE_BASE + O_OPT + DIR_PATH_VAR + FILE_PATH_VAR + PREFIX_PATH_VAR + FAIL_VAR + EXPECT_FAIL + ) set(multi_value_options) cmake_parse_arguments(arg "${no_value_options}" "${single_value_options}" "${multi_value_options}" ${ARGN}) @@ -74,11 +82,16 @@ function(_opendds_get_generated_output target file) endif() file(RELATIVE_PATH rel_file "${real_include_base}" "${real_file}") if(rel_file MATCHES "^\\.\\.") + set(msg_type FATAL_ERROR) if(arg_FAIL_VAR) set(${arg_FAIL_VAR} TRUE PARENT_SCOPE) + endif() + if(arg_EXPECT_FAIL) return() + else() + set(msg_type SEND_ERROR) endif() - message(FATAL_ERROR + message(${msg_type} " This file:\n" " \n" " ${rel_file}\n" @@ -88,6 +101,7 @@ function(_opendds_get_generated_output target file) " \n" " ${arg_INCLUDE_BASE}\n" " (${real_include_base})\n") + return() endif() get_filename_component(rel_dir "${rel_file}" DIRECTORY) set(output_dir "${output_dir}/${rel_dir}") diff --git a/tests/cmake/generated_global/idl/CMakeLists.txt b/tests/cmake/generated_global/idl/CMakeLists.txt index 583297d40fa..8e816fd93ee 100644 --- a/tests/cmake/generated_global/idl/CMakeLists.txt +++ b/tests/cmake/generated_global/idl/CMakeLists.txt @@ -26,4 +26,4 @@ set_target_properties(${messenger} PROPERTIES OUTPUT_NAME messenger ) opendds_target_sources(${messenger} PUBLIC "${dst}/Messenger.idl") -target_link_libraries(${messenger} OpenDDS::Dcps) +target_link_libraries(${messenger} PUBLIC OpenDDS::Dcps) diff --git a/tests/cmake/idl_compiler_tests/CMakeLists.txt b/tests/cmake/idl_compiler_tests/CMakeLists.txt index 859b233e082..dc4dc9304be 100644 --- a/tests/cmake/idl_compiler_tests/CMakeLists.txt +++ b/tests/cmake/idl_compiler_tests/CMakeLists.txt @@ -18,7 +18,7 @@ macro(subtest name) set(target "${PROJECT_NAME}_${name}") # TODO: Add target when generation is per-target set(target_gen "${opendds_gen}") - # Directory has to exist for get_filename_component(REAPATH) to consistently + # Directory has to exist for get_filename_component(REALPATH) to consistently # resolve it. file(MAKE_DIRECTORY "${target_gen}") get_filename_component(target_gen "${target_gen}" REALPATH) @@ -97,18 +97,19 @@ function(assert_generated_output file) if(arg_O_OPT) list(APPEND args O_OPT "${arg_O_OPT}") endif() + if(arg_EXPECT_FAIL) + set(expect_failed TRUE) + else() + set(expect_failed FALSE) + endif() _opendds_get_generated_output(${target} "${file}" DIR_PATH_VAR dir_path FILE_PATH_VAR file_path PREFIX_PATH_VAR prefix_path FAIL_VAR failed + EXPECT_FAIL ${expect_failed} ${args}) - if(arg_EXPECT_FAIL) - set(expect_failed TRUE) - else() - set(expect_failed FALSE) - endif() get_filename_component(filename "${file}" NAME) set(expect_dir_path "${arg_EXPECT}") set(expect_file_path "${expect_dir_path}/${filename}") diff --git a/tests/cmake/idl_compiler_tests/file.ext b/tests/cmake/idl_compiler_tests/file.ext new file mode 100644 index 00000000000..6254c096ec3 --- /dev/null +++ b/tests/cmake/idl_compiler_tests/file.ext @@ -0,0 +1 @@ +Dummy file diff --git a/tests/cmake/include_subdir/CMakeLists.txt b/tests/cmake/include_subdir/CMakeLists.txt index 9f7e93307bf..0b2ddd7c727 100644 --- a/tests/cmake/include_subdir/CMakeLists.txt +++ b/tests/cmake/include_subdir/CMakeLists.txt @@ -9,4 +9,4 @@ opendds_target_sources(${PROJECT_NAME} "subdir/b.idl" OPENDDS_IDL_OPTIONS "-Isubdir" ) -target_link_libraries(${PROJECT_NAME} OpenDDS::Dcps) +target_link_libraries(${PROJECT_NAME} PUBLIC OpenDDS::Dcps)