If we look at the minimal example below,
cmake_minimum_required(VERSION 3.20)
project(example)
add_executable(${PROJECT_NAME} main.cpp test.txt)
Once the executable target is built, it will only rebuild if main.cpp
is modified. If test.txt
is modified, it wouldn't rebuild because eventhough test.txt
is included as a source for the executable target, it isn't used to compile the executable. Is there any way that we can configure cmake so that when test.txt
is modified, it will trigger a rebuild?
The real use case for my application is I have a metal file that is associated with an executable target (e.g. add_executable(${PROJECT_NAME} main.cpp mylib.metal)
) and I want to generate mylib.metallib
along with the example
executable when the target is build. I have something like
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND "the command to compile .metal into .metallib")
but this add_custom_command
will only be invoked during the first compilation of the executable target, or whenever main.cpp
is modified, I want this add_custom_command
to be invoked also when mylib.metal
is modified. How can this be done?