Cmake zip folder but remove leading path

拥有回忆 提交于 2021-02-19 07:30:26

问题


I would like to zip folder in my project from CMake. For that I use following code snippet:

ADD_CUSTOM_COMMAND (
    TARGET ${PROJECT_NAME}
    PRE_BUILD
    COMMAND ${CMAKE_COMMAND}
    ARGS -E tar cvf ${ZIP_OUT_DIR}/my_archive.zip --format=zip -- ${FOLDER_TO_ZIP}/another_folder/
)

The problem with this code is that the files after unzipping contain path component (../../my_file.txt in my case). I tried to use tar cvf -C ${FOLDER_TO_ZIP}/another_folder but unfortunatelly CMake doesn't accept this option.

How can I get rid of leading path from zip archive when using CMake ?


回答1:


The paths are relative to the working directory. So you just need to specify the WORKING_DIRECTORY:

ADD_CUSTOM_COMMAND(
    TARGET ${PROJECT_NAME}
    PRE_BUILD
    COMMAND ${CMAKE_COMMAND} -E tar cvf ${ZIP_OUT_DIR}/my_archive.zip --format=zip -- .
    WORKING_DIRECTORY ${FOLDER_TO_ZIP}/another_folder
)


来源:https://stackoverflow.com/questions/44796465/cmake-zip-folder-but-remove-leading-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!