From 97aefa64752d3c6f48537e14ea77deeb2bcad4f1 Mon Sep 17 00:00:00 2001 From: Daniel Ingram Date: Sat, 22 Oct 2022 13:47:58 -0400 Subject: [PATCH 1/3] Allow forwarding of working directory and launch file args to add_rostest from gtest wrapper function --- tools/rostest/cmake/rostest-extras.cmake.em | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/rostest/cmake/rostest-extras.cmake.em b/tools/rostest/cmake/rostest-extras.cmake.em index 69b06fdf76..bd42ea28c5 100644 --- a/tools/rostest/cmake/rostest-extras.cmake.em +++ b/tools/rostest/cmake/rostest-extras.cmake.em @@ -64,7 +64,7 @@ endfunction() # The remaining arguments are the same as for add_rostest_gtest # and add_rostest_gmock # -function(_add_rostest_google_test type target launch_file) +function(_add_rostest_google_test type target launch_file working_directory args) if (NOT "${type}" STREQUAL "gtest" AND NOT "${type}" STREQUAL "gmock") message(FATAL_ERROR "Invalid use of _add_rostest_google_test function, " @@ -82,7 +82,7 @@ function(_add_rostest_google_test type target launch_file) if(TARGET tests) add_dependencies(tests ${target}) endif() - add_rostest(${launch_file} DEPENDENCIES ${target}) + add_rostest(${launch_file} DEPENDENCIES ${target} WORKING_DIRECTORY ${working_directory} ARGS ${args}) endif() endfunction() @@ -102,7 +102,8 @@ endfunction() # :type ARGN: list of files # function(add_rostest_gtest target launch_file) - _add_rostest_google_test("gtest" ${target} ${launch_file} ${ARGN}) + cmake_parse_arguments(_rostest_gtest "" "WORKING_DIRECTORY" "ARGS" ${ARGN}) + _add_rostest_google_test("gtest" ${target} ${launch_file} ${_rostest_gtest_WORKING_DIRECTORY} ${_rostest_gtest_ARGS}) endfunction() # From ca7ab3f0b8b24d18953e3f21c5eab06683282b77 Mon Sep 17 00:00:00 2001 From: Daniel Ingram Date: Sat, 22 Oct 2022 14:17:35 -0400 Subject: [PATCH 2/3] Well, this will get me the working directory at least. Not sure how to deal with launch file args vs ARGN --- tools/rostest/cmake/rostest-extras.cmake.em | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/rostest/cmake/rostest-extras.cmake.em b/tools/rostest/cmake/rostest-extras.cmake.em index bd42ea28c5..8712762133 100644 --- a/tools/rostest/cmake/rostest-extras.cmake.em +++ b/tools/rostest/cmake/rostest-extras.cmake.em @@ -64,7 +64,7 @@ endfunction() # The remaining arguments are the same as for add_rostest_gtest # and add_rostest_gmock # -function(_add_rostest_google_test type target launch_file working_directory args) +function(_add_rostest_google_test type target launch_file working_directory) if (NOT "${type}" STREQUAL "gtest" AND NOT "${type}" STREQUAL "gmock") message(FATAL_ERROR "Invalid use of _add_rostest_google_test function, " @@ -82,7 +82,7 @@ function(_add_rostest_google_test type target launch_file working_directory args if(TARGET tests) add_dependencies(tests ${target}) endif() - add_rostest(${launch_file} DEPENDENCIES ${target} WORKING_DIRECTORY ${working_directory} ARGS ${args}) + add_rostest(${launch_file} DEPENDENCIES ${target} WORKING_DIRECTORY ${working_directory}) endif() endfunction() @@ -102,8 +102,8 @@ endfunction() # :type ARGN: list of files # function(add_rostest_gtest target launch_file) - cmake_parse_arguments(_rostest_gtest "" "WORKING_DIRECTORY" "ARGS" ${ARGN}) - _add_rostest_google_test("gtest" ${target} ${launch_file} ${_rostest_gtest_WORKING_DIRECTORY} ${_rostest_gtest_ARGS}) + cmake_parse_arguments(_rostest_gtest "" "WORKING_DIRECTORY" "" ${ARGN}) + _add_rostest_google_test("gtest" ${target} ${launch_file} {_rostest_gtest_WORKING_DIRECTORY} ${ARGN}) endfunction() # From 86b1e7c48e8caff3bc6abbc9c29f98ac283f39a2 Mon Sep 17 00:00:00 2001 From: Daniel Ingram Date: Sat, 22 Oct 2022 17:15:19 -0400 Subject: [PATCH 3/3] No clue if this is acceptable cmake, but it does not feel like it is --- tools/rostest/cmake/rostest-extras.cmake.em | 23 ++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tools/rostest/cmake/rostest-extras.cmake.em b/tools/rostest/cmake/rostest-extras.cmake.em index 8712762133..490d0ec62d 100644 --- a/tools/rostest/cmake/rostest-extras.cmake.em +++ b/tools/rostest/cmake/rostest-extras.cmake.em @@ -64,7 +64,7 @@ endfunction() # The remaining arguments are the same as for add_rostest_gtest # and add_rostest_gmock # -function(_add_rostest_google_test type target launch_file working_directory) +function(_add_rostest_google_test type target launch_file) if (NOT "${type}" STREQUAL "gtest" AND NOT "${type}" STREQUAL "gmock") message(FATAL_ERROR "Invalid use of _add_rostest_google_test function, " @@ -76,13 +76,27 @@ function(_add_rostest_google_test type target launch_file working_directory) message(FATAL_ERROR "add_rostest_${type}() needs at least one file argument to compile a ${type_upper} executable") endif() if(${type_upper}_FOUND) + set(single_value_args "WORKING_DIRECTORY") + set(multi_value_args "ARGS") + + cmake_parse_arguments(_arg "" "${single_value_args}" "${multi_value_args}" ${ARGN}) + + set(extra_args "") + set(sources "${ARGN}") + foreach(arg IN ITEMS ${single_value_args} ${multi_value_args}) + if(DEFINED _arg_${arg}) + string(REPLACE "${arg};${_arg_${arg}}" "" sources "${sources}") + string(APPEND extra_args "${arg};${_arg_${arg}};") + endif(DEFINED _arg_${arg}) + endforeach() + include_directories(${${type_upper}_INCLUDE_DIRS}) - add_executable(${target} EXCLUDE_FROM_ALL ${ARGN}) + add_executable(${target} EXCLUDE_FROM_ALL ${sources}) target_link_libraries(${target} ${${type_upper}_LIBRARIES}) if(TARGET tests) add_dependencies(tests ${target}) endif() - add_rostest(${launch_file} DEPENDENCIES ${target} WORKING_DIRECTORY ${working_directory}) + add_rostest(${launch_file} DEPENDENCIES ${target} ${extra_args}) endif() endfunction() @@ -102,8 +116,7 @@ endfunction() # :type ARGN: list of files # function(add_rostest_gtest target launch_file) - cmake_parse_arguments(_rostest_gtest "" "WORKING_DIRECTORY" "" ${ARGN}) - _add_rostest_google_test("gtest" ${target} ${launch_file} {_rostest_gtest_WORKING_DIRECTORY} ${ARGN}) + _add_rostest_google_test("gtest" ${target} ${launch_file} ${ARGN}) endfunction() #