If we alter cstir.h
, we need to run gmi_xstir
(and similar for other packages).
It would be good if CMake detected changes to the relevant files (cstir.h
, cgadgetron.h
, creg.h
, etc.) and run the relevant executably (gmi_xstir
, gmi_xgadgetron
, gmi_xreg
, etc.).
I'm alsmot 100% sure this is possible in CMake, I just can't remember how to do it.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
You'll have to create a custom target depending on gmi_xstir
and cstir.h
which will run the specific command you need.
# Re-run gmi_xreg if cReg.h has changed
ADD_CUSTOM_COMMAND(
OUTPUT ""
COMMAND "gmi_xreg"
DEPENDS "../../cReg/cReg.h"
)
I tried this, but it's not correct. Any ideas?
What do you mean "is not correct"?
I normally set the OUTPUT
but it may be that the relative path to cReg.h
is not resolved properly.
ADD_CUSTOM_COMMAND( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp" COMMAND "gmi_xreg" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../../cReg/cReg.h" )
Using your example everything compiles, but when I change cReg.h
, mReg.c
isn't updated accordingly. (which is what I meant by "not correct").
Is the command gmi_xreg
issued at any time if you update cReg.h
? Or the change of cReg.h
is not picked by CMake?
I'm not sure whether the change of cReg.h
isn't being detected (seems unlikely), or if I'm not using the command properly (more likely). At any rate, gmi_xreg
isn't being run during the make
stage.
I tried on a simplified example. Adding a target works
add_custom_target( run_gmi COMMAND gmi_xreg DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/head.h" )
but you'll run it with make run_gmi
There are 2 signatures of the add_custom_command
.
You are trying to use the first and the documentation is less than clear here. In practice the add_custom_command
is not run at all unless you attach it to a target
. Therefore one has to add a target. In the following I have created a hello
target which is a hello-world program.
The custom
target depends on the OUTPUT
of the custom
command and it will output a file named timestamp
in the ${CMAKE_CURRENT_BINARY_DIR}
with the content of the output of command hello
I hope this clarifies.
set(OUTPUT timestamp) add_custom_command( OUTPUT ${OUTPUT} COMMAND hello > ${OUTPUT} DEPENDS hello WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) add_custom_target(custom DEPENDS ${OUTPUT})
Additionally be careful as
Do not list the output in more than one independent target that may build in parallel or the two instances of the rule may conflict (instead use the add_custom_target() command to drive the command and make the other targets depend on that one).
The second signature
adds a custom command to a target such as a library or executable. This defines a new command that will be associated with building the specified
<target>
.
Sorry, I can't follow your example. What's head.h
and what's the custom target custom
?
From my side, this is as I've got: rijobro@3ab7954
It's not great because:
gmi_xreg
is run every time cmake is run.test1
.If this is easy for you (because I'm struggling!), feel free to commit directly to my branch.
I think you did right. The custom command is only run if you specifically attach to a target, which is what you did by create_custom_target
. Now, this target must depend on the source you want to monitor.
The additional problem would be that you need to make your new target become a dependency of install, probably.
there's some target/dependency stuff in UCL/STIR#280 (where I resolved it for doxygen)
Some doc on this is at https://crascit.com/2017/04/18/generated-sources-in-cmake-builds/
As gmi_xreg
creates both mreg.h
, mreg.c
, it seems to me that you need to say
add_executable(gmi_xreg gmi_xreg.cpp)
# Re-run gmi_xreg if cReg.h has changed ADD_CUSTOM_COMMAND
( OUTPUT mreg.h mreg.c COMMAND "gmi_xreg" DEPENDS "../../cReg/cReg.h" "gmi_xreg" ) add_executable(mreg ${CMAKE_CURRENT_BINARY_DIR}/mreg.c ${CMAKE_CURRENT_BINARY_DIR}/mreg.h) INSTALL(TARGETS mreg DESTINATION ${MATLAB_DEST})
A problem then is that gmi_xreg
relies on the SIRF_PATH
env variable
https://github.com/CCPPETMR/SIRF/blob/51d131ef1b945560e131f5585df108ba744f6c2f/src/Registration/mReg/gmi/gmi_xreg.cpp#L56
I'm not 100% sure why this is as I haven't checked the output. Presumably, this path could/should be passed as an argument to gmi_xreg
. @evgueni-ovtchinnikov could help with that.