Index: SingleSource/Benchmarks/Shootout-C++/CMakeLists.txt =================================================================== --- SingleSource/Benchmarks/Shootout-C++/CMakeLists.txt +++ 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: SingleSource/Benchmarks/Shootout/CMakeLists.txt =================================================================== --- SingleSource/Benchmarks/Shootout/CMakeLists.txt +++ 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: SingleSource/Regression/C++/CMakeLists.txt =================================================================== --- SingleSource/Regression/C++/CMakeLists.txt +++ 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: SingleSource/Regression/C/CMakeLists.txt =================================================================== --- SingleSource/Regression/C/CMakeLists.txt +++ 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: SingleSource/UnitTests/Vector/CMakeLists.txt =================================================================== --- SingleSource/UnitTests/Vector/CMakeLists.txt +++ 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: SingleSource/UnitTests/Vector/NEON/CMakeLists.txt =================================================================== --- SingleSource/UnitTests/Vector/NEON/CMakeLists.txt +++ 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: cmake/modules/SingleMultiSource.cmake =================================================================== --- cmake/modules/SingleMultiSource.cmake +++ cmake/modules/SingleMultiSource.cmake @@ -2,36 +2,45 @@ # # Defines helpers to add executables and tests. The entry points to this # file are: -# `llvm_singlesource()` and +# `llvm_test_executable(executable [PREFIX p] [TARGETS 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] [TARGETS Var] sources...) +# Main macro for test creation. +# name -- base name for the test target to create +# PREFIX p - executable name prefix +# TARGETS VarName - append target name to ${VarName} +# source.. -- list of files to compile. +# +# Following convenience macros provide shortcuts for common test cases: +# +# llvm_singlesource([PREFIX p] [TARGETS Var] [sources...]) +# +# Invokes llvm_test_executable() for each c/c++ source file. If +# sources is empty, creates test executables for all C/C++ files in +# current directory, except for those listed in PROGRAMS_TO_SKIP. +# Passes optional PREFIX and TARGETS parameters through to +# llvm_test_executable(). +# +# 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 +134,21 @@ add_dependencies(${executable} timeit-host fpcmp-host) endmacro() -macro(test_suite_add_executable name mainsource) +macro(llvm_test_executable name) + cmake_parse_arguments(_ARG "" "PREFIX;TARGETS" "" ${ARGN}) + if (_ARG_PREFIX) + set(executable "${_ARG_PREFIX}-${name}") + else() + set(executable ${name}) + endif() + 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} ${_ARG_UNPARSED_ARGUMENTS}) + if (_ARG_TARGETS) + list(APPEND ${_ARG_TARGETS} ${executable}) + endif() append_compile_flags(${executable} ${CFLAGS}) append_compile_flags(${executable} ${CPPFLAGS}) append_compile_flags(${executable} ${CXXFLAGS}) @@ -159,13 +177,18 @@ # 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(_ARG "" "PREFIX;TARGETS" "" ${ARGN}) + set(_extra_args) + if (_ARG_PREFIX) + list(APPEND _extra_args PREFIX ${_ARG_PREFIX}) + endif() + if (_ARG_TARGETS) + list(APPEND _extra_args TARGETS ${_ARG_TARGETS}) + 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} ${_extra_args} ${source}) endforeach() endmacro() @@ -181,8 +204,12 @@ 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}) + set(_TARGET) + llvm_test_executable(${executable} ${sources} TARGETS _TARGET) + if(_TARGET) + target_include_directories(${_TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + target_include_directories(${_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + endif() endif() endmacro()