diff --git a/Fortran/UnitTests/fcvs21_f95/CMakeLists.txt b/Fortran/UnitTests/fcvs21_f95/CMakeLists.txt --- a/Fortran/UnitTests/fcvs21_f95/CMakeLists.txt +++ b/Fortran/UnitTests/fcvs21_f95/CMakeLists.txt @@ -33,13 +33,19 @@ # clean-up fort.* files otherwise one of the tests will fail llvm_test_prepare(rm -f %S/fort.*) -# Test 509 requires this flag in more recent versions of GCC +file(GLOB Source CONFIGURE_DEPENDS *.f) + +# Test 509 requires this flag in more recent versions of GCC. +# If this flag is not supported, the test should be excluded. check_fortran_compiler_flag("-std=legacy" SUPPORTS_LEGACY) if (SUPPORTS_LEGACY) add_compile_options(-std=legacy) -endif () +else() + # Regex because the GLOB returns the full path to each file + list(FILTER Source EXCLUDE REGEX "FM509\.f$") +endif() set(FP_TOLERANCE 1.0e-11) # set by the most sensitive numerical test -llvm_singlesource() +llvm_singlesource(${Source}) file(COPY lit.local.cfg DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/cmake/modules/SingleMultiSource.cmake b/cmake/modules/SingleMultiSource.cmake --- a/cmake/modules/SingleMultiSource.cmake +++ b/cmake/modules/SingleMultiSource.cmake @@ -7,16 +7,16 @@ # # Defines helpers to add executables and tests. The entry points to this # file are: -# `llvm_singlesource([PREFIX p])`, and +# `llvm_singlesource([PREFIX p] [sources...])`, and # `llvm_multisource()` # # Following convenience functions provide shortcuts for common test cases: # -# llvm_singlesource([PREFIX p]) +# llvm_singlesource([PREFIX p] [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. +# Invokes llvm_test_executable() for each C/C++/Fortran source file. +# If sources is empty, creates test executables for all C/C++/Fortran +# files in current directory. # Passes optional PREFIX parameter to llvm_test_executable(). # # llvm_multisource(target) @@ -27,14 +27,22 @@ include(TestSuite) # Configure the current directory as a SingleSource subdirectory - i.e. every -# file in *.{c,cpp,cc} is treated as its own test. +# C/C++/Fortran file is treated as its own test. function(llvm_singlesource) + # PREFIX is optional so it cannot be a named argument. cmake_parse_arguments(_LSARG "" "PREFIX" "" ${ARGN}) - if(DEFINED Source) - set(sources ${Source}) - else() + if(DEFINED _LSARG_PREFIX) + # Remove "PREFIX" and the associated value from ARGN so that it only + # contains sources. + list(REMOVE_AT ARGN 0) + list(REMOVE_AT ARGN 0) + endif() + + set(sources ${ARGN}) + if(NOT sources) file(GLOB sources *.c *.cpp *.cc *.f *.F *.f90 *.F90) endif() + foreach(source ${sources}) basename(name ${source}) set(_target ${_LSARG_PREFIX}${name})