[CMake] How to trigger a build when a dependent file changes?

Glenn Ramsey gr at componic.co.nz
Mon Sep 9 20:30:07 EDT 2013


Hi All,

I would like to set up CMake to build qresource files when the contents of files 
referenced in the .qrc file change. For example I have some qml files that are 
packaged into a qrc file and the qrc needs to be recompiled if the qml files are 
changed.

I have the following macro to run the resource compiler which will only rebuild 
it if the resource file itself changes.

MACRO(PYQT5_WRAP_RC outfiles)
   FOREACH(it ${ARGN})
     GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
     GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
     SET(outfile ${CMAKE_CURRENT_SOURCE_DIR}/${outfile}_rc.py)
     ADD_CUSTOM_TARGET(${it} ALL
       DEPENDS ${outfile}
     )
     ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
       COMMAND ${PYRCC5BINARY} ${infile} -o ${outfile}
       MAIN_DEPENDENCY ${infile}
     )
     SET(${outfiles} ${${outfiles}} ${outfile})
   ENDFOREACH(it)
ENDMACRO (PYQT5_WRAP_RC)

The macro is used like this.

PYQT5_WRAP_RC(rc_gen file1.qml file2.qml ...)

I have tried a few things with custom targets but nothing I have tried seems to 
work.

How can I do this?

Glenn


More information about the CMake mailing list