Fix add_test for Windows.
authorRyan Volz <rvolz@mit.edu>
Tue, 17 Apr 2018 17:45:38 +0000 (13:45 -0400)
committerA. Maitland Bottoms <bottoms@debian.org>
Sat, 12 May 2018 19:25:04 +0000 (20:25 +0100)
Gbp-Pq: Name 0008-Fix-add_test-for-Windows.patch

cmake/Modules/VolkAddTest.cmake

index 16c04f357eb72caf8f45b576156e499315822dc9..46f35f046e7da21042df047f7feb33ba6d2bc41e 100644 (file)
@@ -176,20 +176,19 @@ function(VOLK_ADD_TEST test_name executable_name)
     #set them in the PATH to run tests.  The following appends the
     #path of a target dependency.
     #
-    #NOTE: get_target_property LOCATION is being deprecated as of
-    #CMake 3.2.0, which just prints a warning & notes that this
-    #functionality will be removed in the future.  Leave it here for
-    #now until someone can figure out how to do this in Windows.
-    foreach(target ${test_name} ${VOLK_TEST_TARGET_DEPS})
-      get_target_property(location "${target}" LOCATION)
-      if(location)
-        get_filename_component(path ${location} PATH)
-        string(REGEX REPLACE "\\$\\(.*\\)" ${CMAKE_BUILD_TYPE} path ${path})
-        list(APPEND libpath ${path})
-      endif(location)
-    endforeach(target)
-
-    list(APPEND libpath ${DLL_PATHS} "%PATH%")
+    #create a list of target directories to be determined by the
+    #"add_test" command, via the $<FOO:BAR> operator; make sure the
+    #test's directory is first, since it ($1) is prepended to PATH.
+    unset(TARGET_DIR_LIST)
+    foreach(target ${executable_name} ${VOLK_TEST_TARGET_DEPS})
+      list(APPEND TARGET_DIR_LIST "$<TARGET_FILE_DIR:${target}>")
+    endforeach()
+    #replace list separator with the path separator (escaped)
+    string(REPLACE ";" "\\\\;" TARGET_DIR_LIST "${TARGET_DIR_LIST}")
+
+    #add command line argument (TARGET_DIR_LIST) to path and append current path
+    list(INSERT libpath 0 "%1")
+    list(APPEND libpath "%PATH%")
 
     #replace list separator with the path separator (escaped)
     string(REPLACE ";" "\\;" libpath "${libpath}")
@@ -204,14 +203,18 @@ function(VOLK_ADD_TEST test_name executable_name)
       file(APPEND ${bat_file} "SET ${environ}\n")
     endforeach(environ)
 
+    set(VOLK_TEST_ARGS "${test_name}")
+
     #redo the test args to have a space between each
     string(REPLACE ";" " " VOLK_TEST_ARGS "${VOLK_TEST_ARGS}")
 
     #finally: append the test name to execute
-    file(APPEND ${bat_file} ${test_name} " " ${VOLK_TEST_ARGS} "\n")
+    file(APPEND ${bat_file} "${executable_name} ${VOLK_TEST_ARGS}\n")
     file(APPEND ${bat_file} "\n")
 
-    add_test(${test_name} ${bat_file})
+    add_test(NAME qa_${test_name}
+        COMMAND ${bat_file} ${TARGET_DIR_LIST}
+    )
   endif(WIN32)
 
 endfunction(VOLK_ADD_TEST)