Skip to content

Commit

Permalink
Merge pull request OpenDDS#4795 from iguessthislldo/igtd/cmake-subdir
Browse files Browse the repository at this point in the history
Fix Issues from Using OpenDDS in `add_subdirectory` in CMake
  • Loading branch information
jrw972 committed Sep 23, 2024
2 parents d79179d + 8b30379 commit 86bfaba
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
17 changes: 15 additions & 2 deletions cmake/tao_idl_sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -74,11 +82,15 @@ 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)
set(msg_type SEND_ERROR)
endif()
if(arg_EXPECT_FAIL)
return()
endif()
message(FATAL_ERROR
message(${msg_type}
" This file:\n"
" \n"
" ${rel_file}\n"
Expand All @@ -88,6 +100,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}")
Expand Down
7 changes: 7 additions & 0 deletions docs/news.d/cmake-subdir.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. news-prs: 4795
.. news-start-section: Platform Support and Dependencies
.. news-start-section: CMake
- Fixed issues using OpenDDS as a subproject with ``add_subdirectory``.
.. news-end-section
.. news-end-section
2 changes: 1 addition & 1 deletion tests/cmake/generated_global/idl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
13 changes: 7 additions & 6 deletions tests/cmake/idl_compiler_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}")
Expand Down
1 change: 1 addition & 0 deletions tests/cmake/idl_compiler_tests/file.ext
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dummy file