CMake generated clean target not working properly
When using the the make clean target generated by CMake an incomplete specification of the outputs of the MICROPY_QSTRDEFS_COLLECTED custom target in py/mkrules.cmake leads to issues.
When this custom command is executed:
add_custom_command(
OUTPUT ${MICROPY_QSTRDEFS_COLLECTED}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py cat qstr _ ${MICROPY_GENHDR_DIR}/qstr ${MICROPY_QSTRDEFS_COLLECTED}
DEPENDS ${MICROPY_QSTRDEFS_SPLIT}
VERBATIM
COMMAND_EXPAND_LISTS
)
Two files are generated:
- qstrdefs.collected.h
- qstrdefs.collected.h.hash
But only qstrdefs.collected.h is specified as an OUTPUT. Hence when executing the make cleantarget qstrdefs.collected.h.hashis not removed (since CMake does not know of its existence). This leads to incomplete generation of qstrdefs.generated.h and in turn to a failing build.
This can be easily fixed by adding the hash file as an output like so:
...
set(MICROPY_QSTRDEFS_COLLECTED_HASH "${MICROPY_GENHDR_DIR}/qstrdefs.collected.h.hash")
...
add_custom_command(
OUTPUT ${MICROPY_QSTRDEFS_COLLECTED} ${MICROPY_QSTRDEFS_COLLECTED_HASH}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py cat qstr _ ${MICROPY_GENHDR_DIR}/qstr ${MICROPY_QSTRDEFS_COLLECTED}
DEPENDS ${MICROPY_QSTRDEFS_SPLIT}
VERBATIM
COMMAND_EXPAND_LISTS
)
Fixes for makeqstrdefs.py getting broken by "clean" on cmake
Using "clean" with the cmake build leaves the build directory in a broken state, due to stale makeqstrdefs.py hash files.
This fixes the cmake issue that the hash files are not deleted on a clean when they should be.
makeqstrdefs.py is also updated so that stale hash files left behind with the output is deleted will not prevent generation of the output. While cmake + clean will not do this anymore, it could still happen for other reasons. I've found a good goal for a robust build system is that any generated file can be deleted and it will correctly cope with this.