Use of file(COPY) to copy scripts to build directory

We have a CMake project that builds a C++ app on Windows and Linux. Currently, at runtime, the developer/user needs to run some scripts from the source tree before running the app from the build directory. It has been suggested that I copy the scripts to the build directory using CMake so that the relative path of the source tree is unimportant to the user. I assume this is good practice?

Should I use file(COPY) for this purpose or is there a preferred method?

Are the files only copied at configuration time or will they be updated, if changed, at build time too?

You should use configure_file("${src}" "${dest}" COPYONLY) for this purpose. This will only update the file if need be while also ensuring that the latest version is up-to-date after a build.

1 Like

@ben.boeckel Thanks for your answer.