Index: llvm/cmake/modules/AddLLVM.cmake =================================================================== --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -1112,7 +1112,7 @@ # executable must be linked with it in order to provide consistent # API for all shared libaries loaded by this executable. target_link_libraries(${test_name} PRIVATE gtest_main gtest ${LLVM_PTHREAD_LIB}) - + add_dependencies(${test_suite} ${test_name}) get_target_property(test_suite_folder ${test_suite} FOLDER) if (NOT ${test_suite_folder} STREQUAL "NOTFOUND") @@ -1120,6 +1120,35 @@ endif () endfunction() +function(add_llvm_unittest_inputs test_name inputs) + set(target_name copy_inputs_${test_name}) + + set(input_paths "") + set(output_paths "") + foreach (INPUT ${inputs}) + list(APPEND input_paths ${CMAKE_CURRENT_SOURCE_DIR}/Inputs/${INPUT}) + list(APPEND output_paths ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Inputs/${INPUT}) + endforeach() + + add_custom_target( + ${target_name} + DEPENDS ${output_paths} + COMMENT "Copying input files for ${test_name}.") + + foreach (INPUT ${inputs}) + set(input_path ${CMAKE_CURRENT_SOURCE_DIR}/Inputs/${INPUT}) + set(output_path ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Inputs/${INPUT}) + + add_custom_command( + TARGET "copy_inputs_${test_name}" + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${input_path} ${output_path} + COMMENT "Copying ${INPUT} to binary directory.") + endforeach() + add_dependencies(${test_name} "copy_inputs_${test_name}") +endfunction() + + # Generic support for adding a benchmark. function(add_benchmark benchmark_name) if( NOT LLVM_BUILD_BENCHMARKS ) Index: llvm/include/llvm/Testing/Support/SupportHelpers.h =================================================================== --- llvm/include/llvm/Testing/Support/SupportHelpers.h +++ llvm/include/llvm/Testing/Support/SupportHelpers.h @@ -10,10 +10,12 @@ #ifndef LLVM_TESTING_SUPPORT_SUPPORTHELPERS_H #define LLVM_TESTING_SUPPORT_SUPPORTHELPERS_H -#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Support/Error.h" #include "gtest/gtest-printers.h" +#include + namespace llvm { namespace detail { struct ErrorHolder { @@ -52,6 +54,10 @@ } } } // namespace detail + +namespace unittest { +SmallString<128> getInputFileDirectory(); +} } // namespace llvm #endif Index: llvm/lib/Testing/Support/CMakeLists.txt =================================================================== --- llvm/lib/Testing/Support/CMakeLists.txt +++ llvm/lib/Testing/Support/CMakeLists.txt @@ -3,6 +3,7 @@ add_llvm_library(LLVMTestingSupport Error.cpp + SupportHelpers.cpp BUILDTREE_ONLY Index: llvm/lib/Testing/Support/SupportHelpers.cpp =================================================================== --- /dev/null +++ llvm/lib/Testing/Support/SupportHelpers.cpp @@ -0,0 +1,19 @@ + +#include "llvm/Testing/Support/SupportHelpers.h" + +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" + +using namespace llvm; +using namespace llvm::unittest; + +extern const char *TestMainArgv0; + +SmallString<128> llvm::unittest::getInputFileDirectory() { + llvm::SmallString<128> Result = llvm::sys::path::parent_path(TestMainArgv0); + llvm::sys::fs::make_absolute(Result); + llvm::sys::path::append(Result, "Inputs"); + return Result; +}