[test-suite] r295337 - cmake/modules: Restructuring, add rule for libraries

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 16 09:08:33 PST 2017


Author: matze
Date: Thu Feb 16 11:08:33 2017
New Revision: 295337

URL: http://llvm.org/viewvc/llvm-project?rev=295337&view=rev
Log:
cmake/modules: Restructuring, add rule for libraries

Restructure the SingleMultiSource.cmake file: The macro in remaining in
the file are considered deprecated and should only be used by the
benchmarks in the SingleSource and MultiSource directories. The macros
in the TestFile.cmake and TestSuite.cmake files should be useful for any
sub-suites that are added.

Added:
    test-suite/trunk/cmake/modules/TestSuite.cmake
Modified:
    test-suite/trunk/CMakeLists.txt
    test-suite/trunk/cmake/modules/SingleMultiSource.cmake
    test-suite/trunk/cmake/modules/TestFile.cmake

Modified: test-suite/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/CMakeLists.txt?rev=295337&r1=295336&r2=295337&view=diff
==============================================================================
--- test-suite/trunk/CMakeLists.txt (original)
+++ test-suite/trunk/CMakeLists.txt Thu Feb 16 11:08:33 2017
@@ -106,6 +106,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}
 set(CMAKE_EXE_LINKER_FLAGS
     "${CMAKE_EXE_LINKER_FLAGS} ${TEST_SUITE_DIAGNOSE_LINKER_FLAGS}")
 
+include(TestSuite)
 include(SingleMultiSource)
 find_package(TCL)
 

Modified: test-suite/trunk/cmake/modules/SingleMultiSource.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/SingleMultiSource.cmake?rev=295337&r1=295336&r2=295337&view=diff
==============================================================================
--- test-suite/trunk/cmake/modules/SingleMultiSource.cmake (original)
+++ test-suite/trunk/cmake/modules/SingleMultiSource.cmake Thu Feb 16 11:08:33 2017
@@ -1,16 +1,15 @@
 ##===- SingleMultiSource.cmake --------------------------------------------===##
 #
+# This defines macros to be used by the SingleSource and MultiSource
+# directories. This style of defining benchmarks is considered obsolete now
+# and it is recommended to only use the macros in TestSuite.cmake and
+# TestFile.cmake instead.
+#
 # Defines helpers to add executables and tests. The entry points to this
 # file are:
-#   `llvm_test_executable(executable sources...)`,
 #   `llvm_singlesource([PREFIX p] [TARGET_VAR VarName])`, and
 #   `llvm_multisource([PREFIX p] [TARGET_VAR VarName])`
 #
-# llvm_test_executable(name sources...)
-#   Main macro for test creation.
-#   name -- base name for the test target to create
-#   sources... -- list of files to compile.
-#
 # Following convenience macros provide shortcuts for common test cases:
 #
 # llvm_singlesource([PREFIX p] [TARGET_VAR VarName])
@@ -27,8 +26,55 @@
 #
 ##===----------------------------------------------------------------------===##
 
-include(TestFile)
+include(TestSuite)
+
+# Configure the current directory as a SingleSource subdirectory - i.e. every
+# file in *.{c,cpp,cc} is treated as its own test.
+macro(llvm_singlesource)
+  cmake_parse_arguments(_LSARG "" "PREFIX;TARGET_VAR" "" ${ARGN})
+  if(DEFINED Source)
+    set(sources ${Source})
+  else()
+    file(GLOB sources *.c *.cpp *.cc)
+  endif()
+  foreach(source ${sources})
+    basename(name ${source})
+    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()
+
+# Configure the current directory as a MultiSource subdirectory - i.e. there is
+# one test and it consists of all sources in the directory (or a curated list,
+# if Source is defined).
+macro(llvm_multisource)
+  cmake_parse_arguments(_LMARG "" "PREFIX;TARGET_VAR" "" ${ARGN})
+  if(DEFINED Source)
+    set(sources ${Source})
+  else()
+    file(GLOB sources *.c *.cpp *.cc)
+  endif()
+  list(LENGTH sources sources_len)
 
+  if(sources_len GREATER 0 AND PROG)
+    if(NOT TESTSCRIPT)
+      llvm_test_traditional(${PROG})
+    endif()
+    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()
 
 # Sets Var to ${name} with directory and shortest extension removed.
 macro(basename Var name)
@@ -38,35 +84,6 @@ macro(basename Var name)
   string(REGEX REPLACE "\\.[^.]*$" "" ${Var} ${_filename})
 endmacro()
 
-# Add flags to a cmake target property.
-macro(append_target_flags propertyname target)
-  if(NOT "${ARGN}" STREQUAL "")
-    get_target_property(old_flags ${target} ${propertyname})
-    if(${old_flags} STREQUAL "old_flags-NOTFOUND")
-      set(old_flags)
-    endif()
-    # Transform ${ARGN} which is a cmake list into a series of commandline
-    # arguments. This requires some shell quoting (the approach here isn't
-    # perfect)
-    string(REPLACE " " "\\ " quoted "${ARGN}")
-    string(REPLACE "\"" "\\\"" quoted "${quoted}")
-    string(REPLACE ";" " " quoted "${quoted}")
-    # Ensure that there is no leading or trailing whitespace
-    # This is especially important if old_flags is empty and the property
-    # is LINK_LIBRARIES, as extra whitespace violates CMP0004
-    string(STRIP "${old_flags} ${quoted}" new_flags)
-    set_target_properties(${target} PROPERTIES ${propertyname} "${new_flags}")
-  endif()
-endmacro()
-
-macro(append_compile_flags target)
-  append_target_flags(COMPILE_FLAGS ${target} ${ARGN})
-endmacro()
-
-macro(append_link_flags target)
-  append_target_flags(LINK_LIBRARIES ${target} ${ARGN})
-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.
@@ -123,76 +140,4 @@ function(llvm_test_traditional name)
   set(TESTSCRIPT "${TESTSCRIPT}" PARENT_SCOPE)
 endfunction()
 
-macro (test_suite_add_build_dependencies executable)
-  if(NOT TEST_SUITE_USE_PERF)
-    add_dependencies(${executable} timeit-target)
-  endif()
-  add_dependencies(${executable} timeit-host fpcmp-host)
-endmacro()
 
-macro(llvm_test_executable executable)
-  add_executable(${executable} ${ARGN})
-  append_compile_flags(${executable} ${CFLAGS})
-  append_compile_flags(${executable} ${CPPFLAGS})
-  append_compile_flags(${executable} ${CXXFLAGS})
-  # Note that we cannot use target_link_libraries() here because that one
-  # only interprets inputs starting with '-' as flags.
-  append_link_flags(${executable} ${LDFLAGS})
-  set(executable_path ${CMAKE_CURRENT_BINARY_DIR}/${executable})
-  if(TEST_SUITE_PROFILE_USE)
-    append_compile_flags(${executable} -fprofile-instr-use=${executable_path}.profdata)
-    append_link_flags(${executable} -fprofile-instr-use=${executable_path}.profdata)
-  endif()
-
-  set_property(GLOBAL APPEND PROPERTY TEST_SUITE_TARGETS ${executable})
-  llvm_add_test(${executable_path}.test ${executable_path})
-  test_suite_add_build_dependencies(${executable})
-endmacro()
-
-# Configure the current directory as a SingleSource subdirectory - i.e. every
-# file in *.{c,cpp,cc} is treated as its own test.
-macro(llvm_singlesource)
-  cmake_parse_arguments(_LSARG "" "PREFIX;TARGET_VAR" "" ${ARGN})
-  if(DEFINED Source)
-    set(sources ${Source})
-  else()
-    file(GLOB sources *.c *.cpp *.cc)
-  endif()
-  foreach(source ${sources})
-    basename(name ${source})
-    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()
-
-# Configure the current directory as a MultiSource subdirectory - i.e. there is
-# one test and it consists of all sources in the directory (or a curated list,
-# if Source is defined).
-macro(llvm_multisource)
-  cmake_parse_arguments(_LMARG "" "PREFIX;TARGET_VAR" "" ${ARGN})
-  if(DEFINED Source)
-    set(sources ${Source})
-  else()
-    file(GLOB sources *.c *.cpp *.cc)
-  endif()
-  list(LENGTH sources sources_len)
-
-  if(sources_len GREATER 0 AND PROG)
-    if(NOT TESTSCRIPT)
-      llvm_test_traditional(${PROG})
-    endif()
-    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()

Modified: test-suite/trunk/cmake/modules/TestFile.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/TestFile.cmake?rev=295337&r1=295336&r2=295337&view=diff
==============================================================================
--- test-suite/trunk/cmake/modules/TestFile.cmake (original)
+++ test-suite/trunk/cmake/modules/TestFile.cmake Thu Feb 16 11:08:33 2017
@@ -1,3 +1,11 @@
+##===- TestSuite.cmake ----------------------------------------------------===##
+#
+# Defines helper functions to create .test files that describe how to run a
+# benchmark and optionally how to prepare before running, how to verify the
+# results and how to extract metrics from the output.
+#
+##===----------------------------------------------------------------------===##
+
 # Specify a "RUN: " line to be put in a .test file. See also llvm_add_test().
 macro(llvm_test_run)
   CMAKE_PARSE_ARGUMENTS(ARGS "" "RUN_TYPE;EXECUTABLE;WORKDIR" "" ${ARGN})

Added: test-suite/trunk/cmake/modules/TestSuite.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/TestSuite.cmake?rev=295337&view=auto
==============================================================================
--- test-suite/trunk/cmake/modules/TestSuite.cmake (added)
+++ test-suite/trunk/cmake/modules/TestSuite.cmake Thu Feb 16 11:08:33 2017
@@ -0,0 +1,76 @@
+##===- TestSuite.cmake ----------------------------------------------------===##
+#
+# Defines helper functions to build benchmarks and the corresponding .test files
+#
+##===----------------------------------------------------------------------===##
+include(TestFile)
+
+# Creates a new executable build target, applies CFLAGS, CPPFLAGS, CXXFLAGS
+# and LDFLAGS. Creates a .test file if possible and registers the target
+# with the TEST_SUITE_TARGETS list.
+macro(llvm_test_executable target)
+  add_executable(${target} ${ARGN})
+  append_target_flags(COMPILE_FLAGS ${target} ${CFLAGS})
+  append_target_flags(COMPILE_FLAGS ${target} ${CPPFLAGS})
+  append_target_flags(COMPILE_FLAGS ${target} ${CXXFLAGS})
+  # Note that we cannot use target_link_libraries() here because that one
+  # only interprets inputs starting with '-' as flags.
+  append_target_flags(LINK_LIBRARIES ${target} ${LDFLAGS})
+  set(target_path ${CMAKE_CURRENT_BINARY_DIR}/${target})
+  if(TEST_SUITE_PROFILE_USE)
+    append_target_flags(COMPILE_FLAGS ${target} -fprofile-instr-use=${target_path}.profdata)
+    append_target_flags(LINK_LIBRARIES ${target} -fprofile-instr-use=${target_path}.profdata)
+  endif()
+
+  set_property(GLOBAL APPEND PROPERTY TEST_SUITE_TARGETS ${target})
+  llvm_add_test(${CMAKE_CURRENT_BINARY_DIR}/${target}.test ${target_path})
+  test_suite_add_build_dependencies(${target})
+endmacro()
+
+# Creates a new library build target, applies CFLAGS, CPPFLAGS, CXXFLAGS
+# and LDFLAGS.
+macro(llvm_test_library target)
+  add_library(${target} ${ARGN})
+
+  append_target_flags(COMPILE_FLAGS ${target} ${CFLAGS})
+  append_target_flags(COMPILE_FLAGS ${target} ${CPPFLAGS})
+  append_target_flags(COMPILE_FLAGS ${target} ${CXXFLAGS})
+  # Note that we cannot use target_link_libraries() here because that one
+  # only interprets inputs starting with '-' as flags.
+  append_target_flags(LINK_LIBRARIES ${target} ${LDFLAGS})
+
+  # TODO: How to support TEST_SUITE_PROFILE_USE properly?
+
+  test_suite_add_build_dependencies(${target})
+endmacro()
+
+# Internal function that transforms a list of flags to a string and appends
+# it to a given property of a target.
+macro(append_target_flags propertyname target)
+  if(NOT "${ARGN}" STREQUAL "")
+    get_target_property(old_flags ${target} ${propertyname})
+    if(${old_flags} STREQUAL "old_flags-NOTFOUND")
+      set(old_flags)
+    endif()
+    # Transform ${ARGN} which is a cmake list into a series of commandline
+    # arguments. This requires some shell quoting (the approach here isn't
+    # perfect)
+    string(REPLACE " " "\\ " quoted "${ARGN}")
+    string(REPLACE "\"" "\\\"" quoted "${quoted}")
+    string(REPLACE ";" " " quoted "${quoted}")
+    # Ensure that there is no leading or trailing whitespace
+    # This is especially important if old_flags is empty and the property
+    # is LINK_LIBRARIES, as extra whitespace violates CMP0004
+    string(STRIP "${old_flags} ${quoted}" new_flags)
+    set_target_properties(${target} PROPERTIES ${propertyname} "${new_flags}")
+  endif()
+endmacro()
+
+# Internal function that adds the tools used for compiletime measurement as a
+# target.
+macro(test_suite_add_build_dependencies target)
+  if(NOT TEST_SUITE_USE_PERF)
+    add_dependencies(${target} timeit-target)
+  endif()
+  add_dependencies(${target} timeit-host fpcmp-host)
+endmacro()




More information about the llvm-commits mailing list