I am attempting to supply some "source" files with some executables. I was wondering if there was a way to copy these source files to the build directory (From the source directory) then to the install directory using CMake.
My more specific goal here is to include OpenCL kernels that I write in their own *.cl files.
Example:
mkdir build
cd build
cmake ..
make
Now my directory should have an executable (standard CMake) and some_opencl_kernel.cl
which I open in my executable.
You can copy the file to your build tree using
add_custom_command
by adding something like the following:This adds a post-build event to your target (I've called it
MyExe
) which copies the filesrc/some_opencl_kernel.cl
to the same directory in your build tree as your executable.There are various other ways of copying a file into the build tree, but I like this one since it uses the "generator expression"
$<TARGET_FILE_DIR:MyExe>
to identify the location of the executable's directory in the build tree. This can vary depending on e.g. build-type or platform, so the generator expression is about the most reliable, cross-platform way of specifying this location I feel.As for installing, you can just use the
install(FILES ...)
command. Assuming for your executable you have something like:you can just add:
which will install it to
${CMAKE_INSTALL_PREFIX}/bin/some_opencl_kernel.cl
alongside the executable.If you want to copy a folder's tree with some type of files:
If you want to copy all files in folders, just remove the FILES_MATCHING patterns.