My executable needs a text file to run (with configuration and similar stuff), it is a simple text file, not generated and it is together in the source directory. I tried using configure_file
and it works fine if I use any generator that is not Visual Studio or XCode. As soon as I try to do it using any of those two generators (in Windows and macOS respectively) the file is not copied in the Debug/Release directory but in the ${CMAKE_CURRENT_BINARY_DIR}
, I understand this happens because configure_file
runs at configure time and not at build time, so I guess I cannot use things like ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG}
to manually copy the file to that directory.
This is my CMakeLists.txt file, the hello.cpp
is a simple hello world application and the file sample.txt
is a simple file with a line of text:
cmake_minimum_required(VERSION 3.10)
project(hello)
configure_file(sample.txt sample.txt COPYONLY)
add_executable(hello hello.cc)
Is there any way to add that sample.txt
file as a direct dependency or something so it is copied at build time to the same directory where the output binary target?
Thanks a lot, I had been looking around the whole CMake documentation and questions without finding something relevant to my question.