How can I make CLion automatically copy my compiled executable to a specified directory after each build?
Since CLion uses CMake, I guess this should be possible with some CMake command in the CMakeLists.txt file. But I don't know how to do it.
I don't know about CLion but generally you can add this as a post-build step to an executable target in CMake with:
add_executable(MyExe ...)
add_custom_command(TARGET MyExe
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:MyExe> SomeOtherDir)
See e.g. Copy target file to another location in a post build step in CMake
My favorite option is to generate the executable in the right folder directly as explained here:
the secret is to use the target property RUNTIME_OUTPUT_DIRECTORY
. This has per-configuration options (e.g. RUNTIME_OUTPUT_DIRECTORY_DEBUG).
set_target_properties(mylibrary PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG <debug path>
RUNTIME_OUTPUT_DIRECTORY_RELEASE <release path>
)
See this link for more information.
However you can run on your terminal also:
cmake --help-property "RUNTIME_OUTPUT_DIRECTORY"
cmake --help-property "RUNTIME_OUTPUT_DIRECTORY_<CONFIG>"
To copy the executable after the compilation is a good working solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With