Add Custom Command
Kent - September 26, 2023
Add custom command in CMake can be used to copy assets and runtime dependencies into the build folder for easier debugging.
The one thing to remember when you’re about to copy assets/dependencies into the build folder, is that it should be done at the BUILD stage, and not the CONFIGURE stage of CMake.
If you find your self doing generator expressions during the configure stage of CMake, you’re doing something wrong.
# Wrong
configure_file(
${CMAKE_SOURCE_DIR}/bin/runtime-lib.dll
${CMAKE_BINARY_DIR}/$<CONFIG>/
# error ^^^^^^^^^
COPYONLY)
This generator expression will not be executed, since this is evaluated during configure. Generator expressions are only evaluated during build.
Use add_custom_command
to copy over runtime dependencies to the build folder.
Given the following CMakeLists.txt
;
|
|
Build with:
cmake -S. -Bbuild
See Also
- Vcpkg and Cmake
- Why do programmers need private offices with doors?
- F22a Raptor Part Names
- Languishing
- Malapropism
Comments
Any comments? Create a new discussion on GitHub.There used to be an inline comment form here, but it was removed.