Hi,
I am writing a test case for which I need several input files. All of these files are fairly trivial, they just need to be there so that CMake actually generates something; so I think checking them in would not be a great idea.
Currently I am doing this in RunCMakeTest.cmake
:
set(test_bindir ${RunCMake_BINARY_DIR}/MyTestName-build)
file(WRITE ${test_bindir}/foo.cpp "int foo(int a) { return a*a; }")
file(WRITE ${test_bindir}/samplefile.txt.in "1")
file(WRITE ${test_bindir}/CMakeLists.txt
"cmake_minimum_required(VERSION 3.18)\n"
"project(MyTestName)\n"
"add_library(foo ${test_bindir}/foo.cpp)\n"
"configure_file(${test_bindir}/samplefile.txt.in ${test_bindir}/samplefile.txt.tmp)\n"
"file(GENERATE OUTPUT ${test_bindir}/samplefile.txt INPUT ${test_bindir}/samplefile.txt.tmp)\n")
...
<snip>
@brad.king suggested to use the file-GENERATE.cmake
facility for this, but I cannot find any documentation or examples. I read Tests/RunCMake/README.rst
but didn’t find anything in that regard.
What is the clean way to generate input files for a test case using the CMake test infrastructure?