如何在CMake中将文件列表传递给add_custom_command?

时间:2018-12-20 08:12:05

标签: cmake

我为我运行的每个构建都在CMake中创建一个zip文件。我列出了我需要复制到构建目录并添加到zip文件中的每个文件。我还没有弄清楚如何在不手动重新列出add_custom_command中的所有文件的情况下将列表传递给add_custom_command。

# Copy needed files to build directory
set (ADDITIONAL_FILES
    "${SOME_LIBRARY_DIR}/some_library.dll"
    "${PROJECT_SOURCE_DIR}/readme.txt"
)
foreach (file ${ADDITIONAL_FILES})
    get_filename_component(file_name ${file} NAME)
    configure_file(
        ${file}
        "${PROJECT_BINARY_DIR}/${file_name}" COPYONLY)
endforeach()

# Create release zip file
add_custom_command(OUTPUT
   "${PROJECT_NAME}_v${${PROJECT_NAME}_VERSION}.zip"
   DEPENDS ${PROJECT_NAME}
   COMMAND ${CMAKE_COMMAND} -E tar "cfv"
   "${PROJECT_BINARY_DIR}/${PROJECT_NAME}_v${${PROJECT_NAME}_VERSION}.zip"
   --format=zip
   "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.exe"
   "${PROJECT_BINARY_DIR}/some_library.dll"
   "${PROJECT_BINARY_DIR}/readme.txt"
   COMMAND ${CMAKE_COMMAND} -E echo "creating zip")
add_custom_target(run ALL
  DEPENDS "${PROJECT_NAME}_v${${PROJECT_NAME}_VERSION}.zip"
)

如何将文件列表传递给add_custom_command?

0 个答案:

没有答案