我已经考虑这个问题有一段时间了,我不会假装我可以在make dist没有 CMake 本身直接支持的情况下模拟 a。
问题是,一方面您可以使用 CMake 添加大量文件依赖项(例如预构建库),另一方面 CMake 不知道生成的构建环境本身直接检查的依赖项(例如任何标头依赖项) )。
因此,这里的代码仅收集CMakeList.txt任何构建目标给出的所有文件和源文件:
function(make_dist_creator _variable _access _value _current_list_file _stack)
if (_access STREQUAL "MODIFIED_ACCESS")
# Check if we are finished (end of main CMakeLists.txt)
if (NOT _current_list_file)
get_property(_subdirs GLOBAL PROPERTY MAKE_DIST_DIRECTORIES)
list(REMOVE_DUPLICATES _subdirs)
foreach(_subdir IN LISTS _subdirs)
list(APPEND _make_dist_sources "${_subdir}/CMakeLists.txt")
get_property(_targets DIRECTORY "${_subdir}" PROPERTY BUILDSYSTEM_TARGETS)
foreach(_target IN LISTS _targets)
get_property(_sources TARGET "${_target}" PROPERTY SOURCES)
foreach(_source IN LISTS _sources)
list(APPEND _make_dist_sources "${_subdir}/${_source}")
endforeach()
endforeach()
endforeach()
add_custom_target(
dist
COMMAND "${CMAKE_COMMAND}" -E tar zcvf "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.tar.gz" -- ${_make_dist_sources}
COMMENT "Make distribution ${PROJECT_NAME}.tar.gz"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
message("_make_dist_sources = ${_make_dist_sources}")
else()
# else collect subdirectories in my source dir
file(RELATIVE_PATH _dir_rel "${CMAKE_SOURCE_DIR}" "${_value}")
if (NOT _dir_rel MATCHES "\.\.")
set_property(GLOBAL APPEND PROPERTY MAKE_DIST_DIRECTORIES "${_value}")
endif()
endif()
endif()
endfunction()
variable_watch("CMAKE_CURRENT_LIST_DIR" make_dist_creator)
Run Code Online (Sandbox Code Playgroud)
注:所用BUILDSYSTEM_TARGETS属性至少需要 CMake 3.7 版本
我将上面的代码视为一个起点和概念证明。您可以根据需要添加库、标头等,但您可能应该调整cpack来执行您的命令。
作为起点,请参阅评论中提供的链接@usr1234567。
参考
| 归档时间: |
|
| 查看次数: |
1758 次 |
| 最近记录: |