This video bring me an idea with POST_BUILD. I used POST_BUILD to delete zip folder after build proccess and worked! Since compiling from scratch or recompiling are working correctly because system are forced to re-zip all files.
Code: Select all
add_custom_command(
OUTPUT ${WEB_DIR}/zip/index.html.gz
OUTPUT ${WEB_DIR}/zip/style.css.gz
COMMAND ${CMAKE_COMMAND} -E remove_directory ${WEB_DIR}/zip
COMMAND ${CMAKE_COMMAND} -E make_directory ${WEB_DIR}/zip
COMMAND gzip -krf -9 ${WEB_DIR}/
COMMAND find ${WEB_DIR} -maxdepth 1 -name "*.gz" -exec mv -t ${WEB_DIR}/zip {} +
)
add_custom_command(TARGET ${COMPONENT_LIB} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove_directory ${WEB_DIR}/zip
)
add_custom_target(gzip_files DEPENDS ${WEB_DIR}/zip/index.html.gz)
add_dependencies(${COMPONENT_LIB} gzip_files)
target_add_binary_data(${COMPONENT_LIB} "${WEB_DIR}/zip/index.html.gz" BINARY)
target_add_binary_data(${COMPONENT_LIB} "${WEB_DIR}/zip/style.css.gz" BINARY)