[test-suite] r286277 - cmake: Move logic from llvm_test_executable() to llvm_{single|multi}source()

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 8 11:46:02 PST 2016


Author: matze
Date: Tue Nov  8 13:46:02 2016
New Revision: 286277

URL: http://llvm.org/viewvc/llvm-project?rev=286277&view=rev
Log:
cmake: Move logic from llvm_test_executable() to llvm_{single|multi}source()

- Move the PREFIX prepending logic to llvm_{single|multi}source(). Now
  the target name of llvm_test_executable() is always the same as the
  first argument.
- Move llvm_test_traditional() to llvm_{single|multi}source(). I'd
  rather see external projects use the functions from TestFile.cmake
  directly.

Modified:
    test-suite/trunk/External/CUDA/CMakeLists.txt
    test-suite/trunk/cmake/modules/SingleMultiSource.cmake

Modified: test-suite/trunk/External/CUDA/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/External/CUDA/CMakeLists.txt?rev=286277&r1=286276&r2=286277&view=diff
==============================================================================
--- test-suite/trunk/External/CUDA/CMakeLists.txt (original)
+++ test-suite/trunk/External/CUDA/CMakeLists.txt Tue Nov  8 13:46:02 2016
@@ -30,15 +30,16 @@ macro(create_one_local_test Name FileGlo
   if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${Name}.reference_output)
     set(NO_REFERENCE_OUTPUT 1)
     set(REFERENCE_OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${Name}.reference_output)
+    llvm_test_traditional(${_executable})
   else()
     # otherwise just run the executable.
     llvm_test_run()
   endif()
-  llvm_test_executable(${_executable} ${_sources} TARGET_VAR _target)
+  llvm_test_executable(${_executable} ${_sources})
   if(VariantLibs)
-    target_link_libraries(${_target} ${VariantLibs})
+    target_link_libraries(${_executable} ${VariantLibs})
   endif()
-  add_dependencies(cuda-tests-simple-${VariantSuffix} ${_target})
+  add_dependencies(cuda-tests-simple-${VariantSuffix} ${_executable})
 endmacro()
 
 # Create targets for CUDA tests that are part of the test suite.
@@ -67,10 +68,10 @@ macro(create_one_thrust_test TestSource)
   thrust_make_test_name(_TestName ${TestSourcePath})
   set(_executable thrust-${_TestName}-${VariantSuffix})
   llvm_test_run(--verbose ${_ExtraThrustTestArgs})
-  llvm_test_executable(${_executable} ${TestSource} TARGET_VAR _target)
-  target_link_libraries(${_target} ${VariantLibs})
-  target_compile_options(${_target} PUBLIC ${THRUST_CPPFLAGS})
-  list(APPEND THRUST_VARIANT_TESTS ${_target})
+  llvm_test_executable(${_executable} ${TestSource})
+  target_link_libraries(${_executable} ${VariantLibs})
+  target_compile_options(${_executable} PUBLIC ${THRUST_CPPFLAGS})
+  list(APPEND THRUST_VARIANT_TESTS ${_executable})
 endmacro()
 
 function(create_thrust_tests VariantSuffix)
@@ -104,10 +105,9 @@ function(create_thrust_tests VariantSuff
     # overhead, so it's actually way slower than running all tests
     # sequentially.
     llvm_test_run(--verbose ${_ExtraThrustTestArgs})
-    llvm_test_executable(${_ThrustMainTarget} ${ThrustTestFramework} ${ThrustAllTestSources}
-                         TARGET_VAR _target)
-    target_compile_options(${_target} PUBLIC ${THRUST_CPPFLAGS})
-    target_link_libraries(${_target} ${VariantLibs})
+    llvm_test_executable(${_ThrustMainTarget} ${ThrustTestFramework} ${ThrustAllTestSources})
+    target_compile_options(${_ThrustMainTarget} PUBLIC ${THRUST_CPPFLAGS})
+    target_link_libraries(${_ThrustMainTarget} ${VariantLibs})
   endif()
   add_dependencies(cuda-tests-${VariantSuffix} cuda-tests-thrust-${VariantSuffix})
   add_dependencies(cuda-tests-thrust ${_ThrustMainTarget})

Modified: test-suite/trunk/cmake/modules/SingleMultiSource.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/SingleMultiSource.cmake?rev=286277&r1=286276&r2=286277&view=diff
==============================================================================
--- test-suite/trunk/cmake/modules/SingleMultiSource.cmake (original)
+++ test-suite/trunk/cmake/modules/SingleMultiSource.cmake Tue Nov  8 13:46:02 2016
@@ -2,20 +2,18 @@
 #
 # Defines helpers to add executables and tests. The entry points to this
 # file are:
-#   `llvm_test_executable(executable [PREFIX p] [TARGET_VAR VarName] sources...)`,
-#   `llvm_singlesource([PREFIX p] [TARGETS VarName])`, and
-#   `llvm_multisource()`
+#   `llvm_test_executable(executable sources...)`,
+#   `llvm_singlesource([PREFIX p] [TARGET_VAR VarName])`, and
+#   `llvm_multisource([PREFIX p] [TARGET_VAR VarName])`
 #
-# llvm_test_executable(name [PREFIX p] [TARGET_VAR Var] sources...)
+# llvm_test_executable(name sources...)
 #   Main macro for test creation.
 #   name -- base name for the test target to create
-#   PREFIX p - executable name prefix
-#   TARGET_VAR VarName - set ${VarName} = new target name
-#   source.. -- list of files to compile.
+#   sources... -- list of files to compile.
 #
 # Following convenience macros provide shortcuts for common test cases:
 #
-# llvm_singlesource([PREFIX p] [TARGET_VAR Var] [sources...])
+# llvm_singlesource([PREFIX p] [TARGET_VAR VarName])
 #
 #   Invokes llvm_test_executable() for each c/c++ source file.  If
 #   'sources is emptyno sources are specified, creates test executables
@@ -24,8 +22,8 @@
 #   If optional TARGET_VAR is specified, the variable is set to
 #   list of all created targets.
 #
-# llvm_multisource(executable)
-#   Invokes llvm_test_executable(executable [sources...])
+# llvm_multisource([PREFIX p] [TARGET_VAR VarName])
+#   Invokes llvm_test_executable(${PROG} [sources...])
 #
 ##===----------------------------------------------------------------------===##
 
@@ -72,7 +70,7 @@ endmacro()
 # Traditionally CMakeLists.txt files would set RUN_OPTIONS, STDIN_FILENAME,
 # SMALL_PROBLEM_SIZE, HASH_PROGRAM_OUTPUT, etc.
 # Create llvm_test_run() and llvm_test_verify() invocation for that.
-function(llvm_test_traditional testfile executable name)
+function(llvm_test_traditional name)
   if(STDIN_FILENAME)
     list(APPEND RUN_OPTIONS "< ${STDIN_FILENAME}")
   endif()
@@ -122,7 +120,7 @@ function(llvm_test_traditional testfile
       llvm_test_verify("${DIFFPROG} %o ${REFERENCE_OUTPUT}")
     endif()
   endif()
-  llvm_add_test(${testfile} ${executable})
+  set(TESTSCRIPT "${TESTSCRIPT}" PARENT_SCOPE)
 endfunction()
 
 macro (test_suite_add_build_dependencies executable)
@@ -132,14 +130,8 @@ macro (test_suite_add_build_dependencies
   add_dependencies(${executable} timeit-host fpcmp-host)
 endmacro()
 
-macro(llvm_test_executable name)
-  cmake_parse_arguments(_LTARG "" "PREFIX;TARGET_VAR" "" ${ARGN})
-  set(executable ${_LTARG_PREFIX}${name})
-  unset("${_LTARG_TARGET_VAR}")
-  add_executable(${executable} ${_LTARG_UNPARSED_ARGUMENTS})
-  if(_LTARG_TARGET_VAR)
-    set(${_LTARG_TARGET_VAR} ${executable})
-  endif()
+macro(llvm_test_executable executable)
+  add_executable(${executable} ${ARGN})
   append_compile_flags(${executable} ${CFLAGS})
   append_compile_flags(${executable} ${CPPFLAGS})
   append_compile_flags(${executable} ${CXXFLAGS})
@@ -153,14 +145,7 @@ macro(llvm_test_executable name)
   endif()
 
   set_property(GLOBAL APPEND PROPERTY TEST_SUITE_TARGETS ${executable})
-
-  # Fall back to old style involving RUN_OPTIONS and STDIN_FILENAME if
-  # llvm_test_run() was not called yet.
-  if(NOT TESTSCRIPT)
-    llvm_test_traditional(${executable_path}.test ${executable_path} ${name})
-  else()
-    llvm_add_test(${executable_path}.test ${executable_path})
-  endif()
+  llvm_add_test(${executable_path}.test ${executable_path})
   test_suite_add_build_dependencies(${executable})
 endmacro()
 
@@ -168,10 +153,6 @@ endmacro()
 # file in *.{c,cpp,cc} is treated as its own test.
 macro(llvm_singlesource)
   cmake_parse_arguments(_LSARG "" "PREFIX;TARGET_VAR" "" ${ARGN})
-  unset(_llvm_singlesource_extra_args)
-  if(_LSARG_PREFIX)
-    list(APPEND _llvm_singlesource_extra_args PREFIX ${_LSARG_PREFIX})
-  endif()
   if(DEFINED Source)
     set(sources ${Source})
   else()
@@ -179,10 +160,13 @@ macro(llvm_singlesource)
   endif()
   foreach(source ${sources})
     basename(name ${source})
-    llvm_test_executable(${name} TARGET_VAR _llvm_single_source_target
-      ${_llvm_singlesource_extra_args} ${source})
-    if(_LSARG_TARGET_VAR AND _llvm_single_source_target)
-      list(APPEND ${_LSARG_TARGET_VAR} ${_llvm_single_source_target})
+    if(NOT TESTSCRIPT)
+      llvm_test_traditional(${name})
+    endif()
+    set(_target ${_LSARG_PREFIX}${name})
+    llvm_test_executable(${_target} ${source})
+    if(_LSARG_TARGET_VAR)
+      list(APPEND ${_LSARG_TARGET_VAR} ${_target}})
     endif()
   endforeach()
 endmacro()
@@ -200,16 +184,15 @@ macro(llvm_multisource)
   list(LENGTH sources sources_len)
 
   if(sources_len GREATER 0 AND PROG)
-    set(executable ${PROG})
-    llvm_test_executable(${executable} ${sources}
-      PREFIX ${_LMARG_PREFIX}
-      TARGET_VAR _llvm_multisource_target)
-    if(_llvm_multisource_target)
-      target_include_directories(${_llvm_multisource_target}
-        PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
+    if(NOT TESTSCRIPT)
+      llvm_test_traditional(${PROG})
     endif()
-    if(_LMARG_TARGET_VAR AND _llvm_multisource_target)
-      set(${_LMARG_TARGET_VAR} ${_llvm_multisource_target})
+    set(_target ${_LMARG_PREFIX}${PROG})
+    llvm_test_executable(${_target} ${sources})
+    target_include_directories(${_target}
+      PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
+    if(_LMARG_TARGET_VAR)
+      set(${_LMARG_TARGET_VAR} ${_target})
     endif()
   endif()
 endmacro()




More information about the llvm-commits mailing list