Index: llvm/cmake/modules/AddLLVM.cmake =================================================================== --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -1120,6 +1120,24 @@ endif () endfunction() +function(add_llvm_unittest_inputs test_name inputs) + add_custom_command( + TARGET ${test_name} + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Inputs + COMMENT "Making Inputs directory" + ) + + foreach (INPUT ${inputs}) + add_custom_command( + TARGET ${test_name} + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Inputs/${INPUT} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Inputs + COMMENT "Copying ${INPUT} to binary directory.") + endforeach() +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; +}