In CMake, I want to create a custom target with a dependency on a generated file.
It would be along the lines of:
configure_file(conf.py.in conf.py)
add_custom_target(doc
COMMAND ${SPHINX_EXECUTABLE} -b html ${SPHINX_SOURCE} ${SPHINX_BUILD}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating documentation with Sphinx"
DEPENDS conf.py)
I.e. I would like to avoid unconditionally generating conf.py; I would rather have a custom target with a dependency on it and thereby limit when conf.py is generated.
How can I do this?
I don't quite understand how I can "integrate" configure_file() into the add_custom_target() (presumably the COMMAND or argument?), or make the latter "depend on" the former.
configure_fileoccurs during configuration.add_custom_targetoccurs during the build step.CMake is roughly broken up into 3 steps:
configure_filewill run during this step.)add_custom_targetwill run during this step.)IE the file
configure_fileproduces will be ready beforeadd_custom_targetby definition.Then your work is already done. Configure file will only run when the input file changes.
From the CMake documentation:
If the input file is modified the build system will re-run CMake to re-configure the file and generate the build system again. The generated file is modified and its timestamp updated on subsequent cmake runs only if its content is changed.- configure_fileAs a result you don't need to
DEPENDon this file. It's guaranteed to exist before the build starts.