Ci ho pensato per un po 'e non farò finta di poter simulare uno make dist
senza che questo sia supportato direttamente da CMake stesso.
Il problema è che è possibile aggiungere un sacco di dipendenze di file con CMake da un lato (ad es. Per pre-compilare le librerie) e dall'altro lato CMake non conosce le dipendenze controllate direttamente dall'ambiente di generazione generato stesso (es. eventuali dipendenze dell'intestazione).
Così qui è un codice che solo raccoglie tutti CMakeList.txt
e source file specificati con qualsiasi target di compilazione:
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)
Nota: Il BUILDSYSTEM_TARGETS
proprietà utilizzata ha bisogno almeno la versione CMake 3,7
vedo il codice sopra come punto di partenza e prova del concetto. Potresti aggiungere librerie, intestazioni, ecc. In base alle necessità, ma probabilmente dovresti modificare solo lo cpack per fare le tue offerte.
Come punto di partenza, vedere ad es. the link @ usr1234567 fornito nei commenti.
Riferimenti
Non una risposta, ma si potrebbe usare il tuo VCS di farlo, per esempio [ 'git archive'] (http://schacon.github.com /git/git-archive.html) se stai usando git. – Simon
grazie per un suggerimento – marcin
C'è un post sul blog dal 2009, ma ancora un po 'goffo: http://agateau.com/2009/cmake-and-make-dist/ – usr1234567