Revision: 77721
http://sourceforge.net/p/brlcad/code/77721
Author: starseeker
Date: 2020-11-10 20:43:56 +0000 (Tue, 10 Nov 2020)
Log Message:
-----------
Empty arguments still disappear when passing through the function (essentially,
ARGN is not a literal representation of the argv array originally passed to the
function call) so we still need this workaround code.
Modified Paths:
--------------
brlcad/trunk/CMakeLists.txt
Modified: brlcad/trunk/CMakeLists.txt
===================================================================
--- brlcad/trunk/CMakeLists.txt 2020-11-10 20:18:29 UTC (rev 77720)
+++ brlcad/trunk/CMakeLists.txt 2020-11-10 20:43:56 UTC (rev 77721)
@@ -359,12 +359,116 @@
set_target_properties(unit PROPERTIES FOLDER "BRL-CAD Validation Testing")
endif (NOT TARGET unit)
-# we wrap the CMake add_test() function in order to automatically
-# set up test dependencies for the 'unit' and 'check' test targets.
+# we wrap the CMake add_test() function in order to automatically set up test
+# dependencies for the 'unit' and 'check' test targets.
+#
+# this function extravagantly tries to work around a bug in CMake where we
+# cannot pass an empty string through this wrapper to add_test(). passed as a
+# list (e.g., via ARGN, ARGV, or manually composed), the empty string is
+# skipped(!). passed as a string, it is all treated as command name with no
+# arguments.
+#
+# manual workaround used here involves invoking _add_test() with all args
+# individually recreated/specified (i.e., not as a list) as this preserves
+# empty strings. this approach means we cannot generalize and only support a
+# limited variety of empty string arguments, but we do test and halt if someone
+# unknowingly tries.
function(BRLCAD_ADD_TEST NAME test_name COMMAND test_prog)
- add_test(NAME ${test_name} COMMAND ${test_prog} ${ARGN})
+ # find any occurrences of empty strings
+ set(idx 0)
+ set(matches)
+ foreach (ARG IN LISTS ARGV)
+ # need 'x' to avoid older cmake seeing "COMMAND" "STREQUAL" ""
+ if ("x${ARG}" STREQUAL "x")
+ list(APPEND matches ${idx})
+ endif ("x${ARG}" STREQUAL "x")
+ math(EXPR idx "${idx} + 1")
+ endforeach()
+ # make sure we don't exceed current support
+ list(LENGTH matches cnt)
+ if ("${cnt}" GREATER 1)
+ message(FATAL_ERROR "ERROR: encountered ${cnt} > 1 empty string being
passed to add_test(${test_name}). Expand support in the top-level
CMakeLists.txt file (grep add_test) or pass fewer empty strings.")
+ endif ("${cnt}" GREATER 1)
+
+ # if there are empty strings, we need to manually recreate their calling
+ if ("${cnt}" GREATER 0)
+
+ list(GET matches 0 empty)
+ if ("${empty}" EQUAL 4)
+ foreach (i 1)
+ if (ARGN)
+ list(REMOVE_AT ARGN 0)
+ endif (ARGN)
+ endforeach ()
+ add_test(NAME ${test_name} COMMAND ${test_prog} "" ${ARGN})
+ elseif ("${empty}" EQUAL 5)
+ foreach (i 1 2)
+ if (ARGN)
+ list(REMOVE_AT ARGN 0)
+ endif (ARGN)
+ endforeach ()
+ add_test(NAME ${test_name} COMMAND ${test_prog} ${ARGV4} "" ${ARGN})
+ elseif ("${empty}" EQUAL 6)
+ foreach (i 1 2 3)
+ if (ARGN)
+ list(REMOVE_AT ARGN 0)
+ endif (ARGN)
+ endforeach ()
+ add_test(NAME ${test_name} COMMAND ${test_prog} ${ARGV4} ${ARGV5} ""
${ARGN})
+ elseif ("${empty}" EQUAL 7)
+ foreach (i 1 2 3 4)
+ if (ARGN)
+ list(REMOVE_AT ARGN 0)
+ endif (ARGN)
+ endforeach ()
+ add_test(NAME ${test_name} COMMAND ${test_prog} ${ARGV4} ${ARGV5}
${ARGV6} "" ${ARGN})
+ elseif ("${empty}" EQUAL 8)
+ foreach (i 1 2 3 4 5)
+ if (ARGN)
+ list(REMOVE_AT ARGN 0)
+ endif (ARGN)
+ endforeach ()
+ add_test(NAME ${test_name} COMMAND ${test_prog} ${ARGV4} ${ARGV5}
${ARGV6} ${ARGV7} "" ${ARGN})
+ elseif ("${empty}" EQUAL 9)
+ foreach (i 1 2 3 4 5 6)
+ if (ARGN)
+ list(REMOVE_AT ARGN 0)
+ endif (ARGN)
+ endforeach ()
+ add_test(NAME ${test_name} COMMAND ${test_prog} ${ARGV4} ${ARGV5}
${ARGV6} ${ARGV7} ${ARGV8} "" ${ARGN})
+ elseif ("${empty}" EQUAL 10)
+ foreach (i 1 2 3 4 5 6)
+ if (ARGN)
+ list(REMOVE_AT ARGN 0)
+ endif (ARGN)
+ endforeach ()
+ add_test(NAME ${test_name} COMMAND ${test_prog} ${ARGV4} ${ARGV5}
${ARGV6} ${ARGV7} ${ARGV8} ${ARGV9} "" ${ARGN})
+ elseif ("${empty}" EQUAL 11)
+ foreach (i 1 2 3 4 5 6)
+ if (ARGN)
+ list(REMOVE_AT ARGN 0)
+ endif (ARGN)
+ endforeach ()
+ add_test(NAME ${test_name} COMMAND ${test_prog} ${ARGV4} ${ARGV5}
${ARGV6} ${ARGV7} ${ARGV8} ${ARGV9} ${ARGV10} "" ${ARGN})
+
+
+ # ADD_EMPTY_HERE: insert support for addition argv positions
+ # as extra elseif tests here using the preceding pattern. be
+ # sure to update the index in the following else clause fatal
+ # error message too.
+
+ else ("${empty}" EQUAL 4)
+ message(FATAL_ERROR "ERROR: encountered an empty string passed to
add_test(${test_name}) as ARGV${empty} > ARGV9. Expand support in the
top-level CMakeLists.txt file (grep ADD_EMPTY_HERE).")
+ endif ("${empty}" EQUAL 4)
+
+ else ("${cnt}" GREATER 0)
+ # no empty strings, no worries
+ add_test(NAME ${test_name} COMMAND ${test_prog} ${ARGN})
+ endif ("${cnt}" GREATER 0)
+
+
# There are a variety of criteria that disqualify test_prog as a
# dependency - check and return if we hit any of them.
if (NOT TARGET ${test_prog})
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits