[CMake] Add CXX dependency generation to custom command for Ninja?
Chris Green
greenc at fnal.gov
Tue Jan 10 18:30:15 EST 2017
Hi,
We have a custom command for a third-party utility (genreflex, from the
ROOT system) which has a directive:
IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/classes.h
How would I, either as an extra COMMAND or as a separate custom command,
manually invoke the configured CXX compiler with all the
correctly-configured include directories and other pre-processor and
compiler flags with the expected option (-MMD for GCC, I think) on the
above-mentioned classes.h file so that the resulting file can be used in
a DEPFILE directive for the Ninja generator? I would like to model as
closely as possible exactly what CMake would specify to invoke the
compiler to (e.g.) compile an object with only the necessary changes,
but I'm not sure whence to obtain this information. I'm assuming it's
some combination of automatic variables and properties via generator
expressions, but I'm at a loss, I'm afraid. I also don't know whether I
would need to specify the .d file as an OUTPUT or a BYPRODUCTS if I do
this as a COMMAND, or in DEPENDS in addition to DEPFILE if a separate
custom command, and which choice would be better (assuming both of them
work). The resulting CMake code would need to conditionally support both
Makefile and Ninja generators.
Any advice gratefully accepted.
Current custom command definition:
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${dictname}_dict.cpp
${SOURCE_OUTPUT} ${GD_ROOTMAP_OUTPUT} ${PCM_OUTPUT}
COMMAND ${ROOT_GENREFLEX} ${CMAKE_CURRENT_SOURCE_DIR}/classes.h
-s ${CMAKE_CURRENT_SOURCE_DIR}/classes_def.xml
-I${CMAKE_SOURCE_DIR}
${GENREFLEX_INCLUDES} ${GENREFLEX_FLAGS}
-o ${dictname}_dict.cpp
${CLEANUP_COMMAND}
IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/classes.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/classes_def.xml
COMMENT "Generating dictionary files for target ${dictname}"
)
Many thanks,
Chris.
--
Chris Green <greenc at fnal.gov>, FNAL CS/SCD/ADSS/SSI/TAC;
'phone (630) 840-2167; Skype: chris.h.green;
IM: greenc at jabber.fnal.gov, chissgreen (AIM),
chris.h.green (Google Talk).
More information about the CMake
mailing list