Index: test-suite/trunk/Bitcode/simd_ops/CMakeLists.txt =================================================================== --- test-suite/trunk/Bitcode/simd_ops/CMakeLists.txt +++ test-suite/trunk/Bitcode/simd_ops/CMakeLists.txt @@ -17,8 +17,6 @@ string(REPLACE "." "" namebc ${namebc}) set(Source ${CMAKE_CURRENT_SOURCE_DIR}/${ARCH}_halide_runtime.bc ${CMAKE_CURRENT_SOURCE_DIR}/${ARCH}_tests/${namebc}.bc ${CMAKE_CURRENT_SOURCE_DIR}/${ARCH}_scalar_tests/scalar_${namebc}.bc) set(PROG simd_ops_${namebc}) - llvm_multisource() - target_link_libraries(${PROG} simd_ops) + llvm_multisource(TARGET_VAR _target) + target_link_libraries(${_target} simd_ops) endforeach() - - Index: test-suite/trunk/SingleSource/Benchmarks/Shootout-C++/CMakeLists.txt =================================================================== --- test-suite/trunk/SingleSource/Benchmarks/Shootout-C++/CMakeLists.txt +++ test-suite/trunk/SingleSource/Benchmarks/Shootout-C++/CMakeLists.txt @@ -1,4 +1,3 @@ -llvm_target_prefix("shootout-cxx") list(APPEND CXXFLAGS -Wno-deprecated) list(APPEND CPPFLAGS -Wno-deprecated) set(FP_TOLERANCE 0.00000001) @@ -16,6 +15,6 @@ # Necessary for ackermann on iOS list(APPEND LDFLAGS -Xlinker -stack_size -Xlinker 0x800000) endif() -llvm_singlesource() +llvm_singlesource(PREFIX "shootout-cxx") llvm_add_subdirectories(EH) Index: test-suite/trunk/SingleSource/Benchmarks/Shootout-C++/EH/CMakeLists.txt =================================================================== --- test-suite/trunk/SingleSource/Benchmarks/Shootout-C++/EH/CMakeLists.txt +++ test-suite/trunk/SingleSource/Benchmarks/Shootout-C++/EH/CMakeLists.txt @@ -1,3 +1,3 @@ set(REQUIRES_EH_SUPPORT 1) list(APPEND LDFLAGS -lstdc++) -llvm_singlesource() +llvm_singlesource(PREFIX "shootout-cxx") Index: test-suite/trunk/SingleSource/Benchmarks/Shootout/CMakeLists.txt =================================================================== --- test-suite/trunk/SingleSource/Benchmarks/Shootout/CMakeLists.txt +++ test-suite/trunk/SingleSource/Benchmarks/Shootout/CMakeLists.txt @@ -1,4 +1,3 @@ -llvm_target_prefix("shootout") list(APPEND LDFLAGS -lm) if(ARCH STREQUAL "XCore") set(XCORE_TARGET_NEEDS_MEMORY 256) @@ -6,4 +5,4 @@ if(TEST_SUITE_BENCHMARKING_ONLY) list(APPEND PROGRAMS_TO_SKIP hello) endif() -llvm_singlesource() +llvm_singlesource(PREFIX "shootout") Index: test-suite/trunk/SingleSource/Regression/C++/CMakeLists.txt =================================================================== --- test-suite/trunk/SingleSource/Regression/C++/CMakeLists.txt +++ test-suite/trunk/SingleSource/Regression/C++/CMakeLists.txt @@ -1,5 +1,4 @@ -llvm_target_prefix("regression-cxx") list(APPEND LDFLAGS -lstdc++) -llvm_singlesource() +llvm_singlesource(PREFIX "regression-cxx") llvm_add_subdirectories(EH) Index: test-suite/trunk/SingleSource/Regression/C++/EH/CMakeLists.txt =================================================================== --- test-suite/trunk/SingleSource/Regression/C++/EH/CMakeLists.txt +++ test-suite/trunk/SingleSource/Regression/C++/EH/CMakeLists.txt @@ -1,3 +1,3 @@ set(REQUIRES_EH_SUPPORT 1) list(APPEND LDFLAGS -lstdc++) -llvm_singlesource() +llvm_singlesource(PREFIX "regression-cxx") Index: test-suite/trunk/SingleSource/Regression/C/CMakeLists.txt =================================================================== --- test-suite/trunk/SingleSource/Regression/C/CMakeLists.txt +++ test-suite/trunk/SingleSource/Regression/C/CMakeLists.txt @@ -1,8 +1,7 @@ -llvm_target_prefix("regression-c") if(ARCH STREQUAL "x86") if(DEFINED USE_REFERENCE_OUTPUT) set(EXEC_XFAILS casts) endif() endif() list(APPEND LDFLAGS -lm) -llvm_singlesource() +llvm_singlesource(PREFIX "regression-c") Index: test-suite/trunk/SingleSource/UnitTests/Vector/CMakeLists.txt =================================================================== --- test-suite/trunk/SingleSource/UnitTests/Vector/CMakeLists.txt +++ test-suite/trunk/SingleSource/UnitTests/Vector/CMakeLists.txt @@ -1,4 +1,3 @@ -llvm_target_prefix("Vector") if(ARCH STREQUAL "PowerPC") llvm_add_subdirectories(Altivec) endif() @@ -19,4 +18,4 @@ set(RUNTIMELIMIT 7200) endif() endif() -llvm_singlesource() +llvm_singlesource(PREFIX "Vector") Index: test-suite/trunk/SingleSource/UnitTests/Vector/NEON/CMakeLists.txt =================================================================== --- test-suite/trunk/SingleSource/UnitTests/Vector/NEON/CMakeLists.txt +++ test-suite/trunk/SingleSource/UnitTests/Vector/NEON/CMakeLists.txt @@ -1,3 +1,2 @@ -llvm_target_prefix("Vector-NEON") list(APPEND CFLAGS -std=c99) -llvm_singlesource() +llvm_singlesource(PREFIX "Vector-NEON") Index: test-suite/trunk/SingleSource/UnitTests/Vector/SSE/CMakeLists.txt =================================================================== --- test-suite/trunk/SingleSource/UnitTests/Vector/SSE/CMakeLists.txt +++ test-suite/trunk/SingleSource/UnitTests/Vector/SSE/CMakeLists.txt @@ -2,4 +2,4 @@ list(APPEND LDFLAGS -lm) list(APPEND TARGET_FLAGS -msse2) list(APPEND LCCFLAGS -msse2) -llvm_singlesource() +llvm_singlesource(PREFIX "Vector") Index: test-suite/trunk/cmake/modules/SingleMultiSource.cmake =================================================================== --- test-suite/trunk/cmake/modules/SingleMultiSource.cmake +++ test-suite/trunk/cmake/modules/SingleMultiSource.cmake @@ -2,36 +2,47 @@ # # Defines helpers to add executables and tests. The entry points to this # file are: -# `llvm_singlesource()` and +# `llvm_test_executable(executable [PREFIX p] [TARGET_VAR VarName] sources...)`, +# `llvm_singlesource([PREFIX p] [TARGETS VarName])`, and # `llvm_multisource()` # -# Each is a macro that uses the environment it was called in to determine -# what to build and how, and generates a test file that can be given to LIT. -# The test file is generated at configure time. +# llvm_test_executable(name [PREFIX p] [TARGET_VAR Var] 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. +# +# Following convenience macros provide shortcuts for common test cases: +# +# llvm_singlesource([PREFIX p] [TARGET_VAR Var] [sources...]) +# +# Invokes llvm_test_executable() for each c/c++ source file. If +# 'sources is emptyno sources are specified, creates test executables +# for all C/C++ files in current directory, except for those +# listed in PROGRAMS_TO_SKIP. +# Passes optional PREFIX parameter to llvm_test_executable(). +# 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...]) +# +# Variables that control target generation: +# PROGRAMS_TO_SKIP - list of base names of executalbes to skip. # ##===----------------------------------------------------------------------===## include(TestFile) -# Set unique target prefix within caller's scope. -function(llvm_target_prefix prefix) - if(prefix) - set(TARGET_PREFIX "${prefix}-" PARENT_SCOPE) - else() - set(TARGET_PREFIX "" PARENT_SCOPE) - endif() -endfunction() - -# Given a source file name after which a test should be named, create a unique -# name for the test. Usually this is just the source file with the suffix -# stripped, and ${TARGET_PREFIX} prepended. -function(get_unique_exe_name new_name main_src) - string(REGEX REPLACE ".[cp]+$" "" path ${main_src}) - get_filename_component(name ${path} NAME ) - - set(${new_name} "${TARGET_PREFIX}${name}" PARENT_SCOPE) -endfunction() +# Sets Var to ${name} with directory and shortest extension removed. +macro(basename Var name) + # strip directory name + get_filename_component(_filename ${name} NAME) + # remove shortest extension. + string(REGEX REPLACE "\\.[^.]*$" "" ${Var} ${_filename}) +endmacro() # Add flags to a cmake target property. macro(append_target_flags propertyname target) @@ -125,12 +136,22 @@ add_dependencies(${executable} timeit-host fpcmp-host) endmacro() -macro(test_suite_add_executable name mainsource) +macro(llvm_test_executable name) + cmake_parse_arguments(_LTARG "" "PREFIX;TARGET_VAR" "" ${ARGN}) + if (_LTARG_PREFIX) + set(executable "${_LTARG_PREFIX}-${name}") + else() + set(executable ${name}) + endif() + unset("${_LTARG_TARGET_VAR}") + list(FIND PROGRAMS_TO_SKIP ${executable} exe_idx) list(FIND PROGRAMS_TO_SKIP ${name} name_idx) # Should we skip this? - if(${name_idx} EQUAL -1) - get_unique_exe_name(executable ${mainsource}) - add_executable(${executable} ${ARGN}) + if(${name_idx} EQUAL -1 AND ${exe_idx} EQUAL -1) + add_executable(${executable} ${_LTARG_UNPARSED_ARGUMENTS}) + if (_LTARG_TARGET_VAR) + set(${_LTARG_TARGET_VAR} ${executable}) + endif() append_compile_flags(${executable} ${CFLAGS}) append_compile_flags(${executable} ${CPPFLAGS}) append_compile_flags(${executable} ${CXXFLAGS}) @@ -159,13 +180,19 @@ # 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}) + unset(_llvm_singlesource_extra_args) + if (_LSARG_PREFIX) + list(APPEND _llvm_singlesource_extra_args PREFIX ${_LSARG_PREFIX}) + endif() file(GLOB sources *.c *.cpp *.cc) foreach(source ${sources}) - # Find the pure name of the test - string(REGEX REPLACE ".[cp]+$" "" path ${source}) - string(REGEX REPLACE ".*/" "" name ${path}) - - test_suite_add_executable(${name} ${source} ${source}) + 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}) + endif() endforeach() endmacro() @@ -173,6 +200,7 @@ # 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() @@ -181,8 +209,16 @@ list(LENGTH sources sources_len) if(sources_len GREATER 0 AND DEFINED PROG) - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - include_directories(${CMAKE_CURRENT_BINARY_DIR}) - test_suite_add_executable(${PROG} "${PROG}.c" ${sources}) + 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}) + endif() + if (_LMARG_TARGET_VAR AND _llvm_multisource_target) + set(${_LMARG_TARGET_VAR} ${_llvm_multisource_target}) + endif() endif() endmacro()