[test-suite] r340298 - cmake: Use functions instead of macros where possible; NFC

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 21 09:39:32 PDT 2018


Author: matze
Date: Tue Aug 21 09:39:32 2018
New Revision: 340298

URL: http://llvm.org/viewvc/llvm-project?rev=340298&view=rev
Log:
cmake: Use functions instead of macros where possible; NFC

Modified:
    test-suite/trunk/cmake/modules/CopyDir.cmake
    test-suite/trunk/cmake/modules/DetectArchitecture.cmake
    test-suite/trunk/cmake/modules/External.cmake
    test-suite/trunk/cmake/modules/Host.cmake
    test-suite/trunk/cmake/modules/SingleMultiSource.cmake
    test-suite/trunk/cmake/modules/TestSuite.cmake

Modified: test-suite/trunk/cmake/modules/CopyDir.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/CopyDir.cmake?rev=340298&r1=340297&r2=340298&view=diff
==============================================================================
--- test-suite/trunk/cmake/modules/CopyDir.cmake (original)
+++ test-suite/trunk/cmake/modules/CopyDir.cmake Tue Aug 21 09:39:32 2018
@@ -1,4 +1,4 @@
-macro(llvm_copy_dir target to) # args: dir0 dir1 ...
+function(llvm_copy_dir target to) # args: dir0 dir1 ...
   set(COPY_COMMAND "")
   foreach(dir ${ARGN})
     set(COPY_COMMAND ${COPY_COMMAND} COMMAND ${CMAKE_COMMAND} -E copy_directory "${dir}" "${to}")
@@ -7,11 +7,11 @@ macro(llvm_copy_dir target to) # args: d
     TARGET ${target} POST_BUILD
     ${COPY_COMMAND}
   )
-endmacro()
+endfunction()
 
-macro(llvm_copy target to from)
+function(llvm_copy target to from)
   add_custom_command(
     TARGET ${target} POST_BUILD
     COMMAND ${CMAKE_COMMAND} -E copy ${from} ${to}
   )
-endmacro()
+endfunction()

Modified: test-suite/trunk/cmake/modules/DetectArchitecture.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/DetectArchitecture.cmake?rev=340298&r1=340297&r2=340298&view=diff
==============================================================================
--- test-suite/trunk/cmake/modules/DetectArchitecture.cmake (original)
+++ test-suite/trunk/cmake/modules/DetectArchitecture.cmake Tue Aug 21 09:39:32 2018
@@ -4,7 +4,7 @@
 #
 ##===----------------------------------------------------------------------===##
 
-macro(detect_architecture variable)
+function(detect_architecture variable)
   try_compile(HAVE_${variable}
     ${CMAKE_BINARY_DIR}
     ${CMAKE_SOURCE_DIR}/cmake/modules/DetectArchitecture.c
@@ -18,7 +18,7 @@ macro(detect_architecture variable)
       string(REGEX MATCH "[^ ]*$" DETECT_ARCH_MATCH ${DETECT_ARCH_STRING})
       if(DETECT_ARCH_MATCH)
         message(STATUS "Check target system architecture: ${DETECT_ARCH_MATCH}")
-        set(${variable} ${DETECT_ARCH_MATCH})
+        set(${variable} ${DETECT_ARCH_MATCH} PARENT_SCOPE)
       else()
         message(SEND_ERROR "Could not detect target system architecture!")
       endif()
@@ -29,16 +29,16 @@ macro(detect_architecture variable)
     message(STATUS "Determine the system architecture - failed")
     file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
       "Determining the system architecture failed with the following output:\n${OUTPUT}")
-    set(${variable})
+    set(${variable} PARENT_SCOPE)
   endif()
   
-endmacro(detect_architecture)
+endfunction(detect_architecture)
 
 #
 # Performs a try_run to determine the cpu architecture of target
 #
 
-macro(detect_x86_cpu_architecture variable)
+function(detect_x86_cpu_architecture variable)
   try_run(HAVE_RUN_${variable} HAVE_COMPILE_${variable}
     ${CMAKE_BINARY_DIR}
     ${CMAKE_SOURCE_DIR}/cmake/modules/DetectX86CPUArchitecture.c
@@ -48,7 +48,7 @@ macro(detect_x86_cpu_architecture variab
   if(HAVE_COMPILE_${variable} AND NOT (HAVE_RUN_${variable} STREQUAL  FAILED_TO_RUN))
     if(RUN_OUTPUT)
       message(STATUS "Check target system architecture: ${RUN_OUTPUT}")
-      set(${variable} ${RUN_OUTPUT})
+      set(${variable} ${RUN_OUTPUT} PARENT_SCOPE)
     else()
       message(SEND_ERROR "Could not detect target system cpu architecture!")
     endif()
@@ -56,8 +56,7 @@ macro(detect_x86_cpu_architecture variab
     message(STATUS "Determine the system cpu architecture - failed")
     file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
       "Determining the system cpu architecture failed with the following output:\n${COMP_OUTPUT}\n${RUN_OUTPUT}")
-    set(${variable})
+    set(${variable} PARENT_SCOPE)
   endif()
 
-endmacro(detect_x86_cpu_architecture)
-
+endfunction(detect_x86_cpu_architecture)

Modified: test-suite/trunk/cmake/modules/External.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/External.cmake?rev=340298&r1=340297&r2=340298&view=diff
==============================================================================
--- test-suite/trunk/cmake/modules/External.cmake (original)
+++ test-suite/trunk/cmake/modules/External.cmake Tue Aug 21 09:39:32 2018
@@ -7,20 +7,21 @@ set(TEST_SUITE_EXTERNALS_DIR "" CACHE PA
 # - If PATHVAR is unset set it to the first existing directory in this list:
 #   - ${TEST_SUITE_EXTERNALS_DIR}/${NAME}
 #   - ${CMAKE_SOURCE_DIR}/test-suite-externals/${NAME}
-macro(llvm_externals_find PATHVAR NAME DESCRIPTION)
+function(llvm_externals_find PATHVAR NAME DESCRIPTION)
   set(${PATHVAR} "" CACHE PATH "Directory containing ${DESCRIPTION} sourcecode")
   if(NOT ${PATHVAR})
     if(TEST_SUITE_EXTERNALS_DIR)
       if (IS_DIRECTORY "${TEST_SUITE_EXTERNALS_DIR}/${NAME}")
-        set(${PATHVAR} "${TEST_SUITE_EXTERNALS_DIR}/${NAME}")
+        set(${PATHVAR} "${TEST_SUITE_EXTERNALS_DIR}/${NAME}" PARENT_SCOPE)
       endif()
     else()
       if(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/test-suite-externals/${NAME}")
-        set(${PATHVAR} "${CMAKE_SOURCE_DIR}/test-suite-externals/${NAME}")
+        set(${PATHVAR} "${CMAKE_SOURCE_DIR}/test-suite-externals/${NAME}"
+            PARENT_SCOPE)
       endif()
     endif()
     if(${PATHVAR})
       message(STATUS "Found ${DESCRIPTION}: ${${PATHVAR}}")
     endif()
   endif()
-endmacro()
+endfunction()

Modified: test-suite/trunk/cmake/modules/Host.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/Host.cmake?rev=340298&r1=340297&r2=340298&view=diff
==============================================================================
--- test-suite/trunk/cmake/modules/Host.cmake (original)
+++ test-suite/trunk/cmake/modules/Host.cmake Tue Aug 21 09:39:32 2018
@@ -1,7 +1,7 @@
 set(TEST_SUITE_HOST_CC "cc" CACHE STRING "C compiler targetting the host")
 mark_as_advanced(TEST_SUITE_HOST_CC)
 
-macro(llvm_add_host_executable targetname exename)
+function(llvm_add_host_executable targetname exename)
   cmake_parse_arguments(_arg "" "" "LDFLAGS;CPPFLAGS" ${ARGN})
 
   set(_objs)
@@ -31,4 +31,4 @@ macro(llvm_add_host_executable targetnam
   )
   add_custom_target(${targetname}
     DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${exename}")
-endmacro()
+endfunction()

Modified: test-suite/trunk/cmake/modules/SingleMultiSource.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/SingleMultiSource.cmake?rev=340298&r1=340297&r2=340298&view=diff
==============================================================================
--- test-suite/trunk/cmake/modules/SingleMultiSource.cmake (original)
+++ test-suite/trunk/cmake/modules/SingleMultiSource.cmake Tue Aug 21 09:39:32 2018
@@ -1,8 +1,8 @@
 ##===- SingleMultiSource.cmake --------------------------------------------===##
 #
-# This defines macros to be used by the SingleSource and MultiSource
+# This defines functions 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
+# and it is recommended to only use the functions in TestSuite.cmake and
 # TestFile.cmake instead.
 #
 # Defines helpers to add executables and tests. The entry points to this
@@ -10,7 +10,7 @@
 #   `llvm_singlesource([PREFIX p])`, and
 #   `llvm_multisource()`
 #
-# Following convenience macros provide shortcuts for common test cases:
+# Following convenience functions provide shortcuts for common test cases:
 #
 # llvm_singlesource([PREFIX p])
 #
@@ -28,7 +28,7 @@ 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)
+function(llvm_singlesource)
   cmake_parse_arguments(_LSARG "" "PREFIX" "" ${ARGN})
   if(DEFINED Source)
     set(sources ${Source})
@@ -41,7 +41,7 @@ macro(llvm_singlesource)
     set(_target ${_LSARG_PREFIX}${name})
     llvm_test_executable(${_target} ${source})
   endforeach()
-endmacro()
+endfunction()
 
 # 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,

Modified: test-suite/trunk/cmake/modules/TestSuite.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/TestSuite.cmake?rev=340298&r1=340297&r2=340298&view=diff
==============================================================================
--- test-suite/trunk/cmake/modules/TestSuite.cmake (original)
+++ test-suite/trunk/cmake/modules/TestSuite.cmake Tue Aug 21 09:39:32 2018
@@ -10,7 +10,7 @@ include(TestFile)
 # necessary, registers the target with the TEST_SUITE_TARGETS list and makes
 # sure we build the required dependencies for compiletime measurements
 # and support the TEST_SUITE_PROFILE_USE mode.
-macro(llvm_test_executable target)
+function(llvm_test_executable target)
   add_executable(${target} ${ARGN})
   append_target_flags(COMPILE_FLAGS ${target} ${CFLAGS})
   append_target_flags(COMPILE_FLAGS ${target} ${CPPFLAGS})
@@ -27,12 +27,13 @@ macro(llvm_test_executable target)
   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()
+  set(TESTSCRIPT "" PARENT_SCOPE)
+endfunction()
 
 # Creates a new library build target. Use this instead of `add_library`.
 # Behaves like `llvm_test_executable`, just produces a library instead of an
 # executable.
-macro(llvm_test_library target)
+function(llvm_test_library target)
   add_library(${target} ${ARGN})
 
   append_target_flags(COMPILE_FLAGS ${target} ${CFLAGS})
@@ -45,21 +46,21 @@ macro(llvm_test_library target)
   # TODO: How to support TEST_SUITE_PROFILE_USE properly?
 
   test_suite_add_build_dependencies(${target})
-endmacro()
+endfunction()
 
 # Add dependencies required for compiletime measurements to a target. You
 # usually do not need to call this directly when using `llvm_test_executable`
 # or `llvm_test_library`.
-macro(test_suite_add_build_dependencies target)
+function(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()
+endfunction()
 
 # 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)
+function(append_target_flags propertyname target)
   if(NOT "${ARGN}" STREQUAL "")
     get_target_property(old_flags ${target} ${propertyname})
     if(${old_flags} STREQUAL "old_flags-NOTFOUND")
@@ -77,4 +78,4 @@ macro(append_target_flags propertyname t
     string(STRIP "${old_flags} ${quoted}" new_flags)
     set_target_properties(${target} PROPERTIES ${propertyname} "${new_flags}")
   endif()
-endmacro()
+endfunction()




More information about the llvm-commits mailing list