Handle gracefully the scenario where 'git' is missing on the host system
lemire opened this issue · comments
As far as I can tell, CPM has currently 'git' as a hard dependency but it does not warn the user if git is missing. Currently, if git is missing, it may fail with could not find git for clone of
.
When the dependencies are on github, you can side-step the issue with a backup...
find_package(Git QUIET)
if(Git_FOUND)
# do whatever you do right now
else()
# try an alternative
set(zip_url "https://github.com/${GITHUB_REPO}/archive/${COMMIT}.zip")
set(archive "${dep_root}/archive.zip")
set(dest "${dep_root}/_extract")
file(DOWNLOAD "${zip_url}" "${archive}")
file(MAKE_DIRECTORY "${dest}")
execute_process(
WORKING_DIRECTORY "${dest}"
COMMAND "${CMAKE_COMMAND}" -E tar xf "${archive}")
file(REMOVE "${archive}")
endif()
This was covered in issue #191 but was proposed as a way to save bandwidth. I am recommending to allow zip downloads to make CPM more robust (more likely to succeed).
If you don't want to offer this option, then, I recommend warning the user:
find_package(Git QUIET)
if(NOT(Git_FOUND))
message(STATUS "CPM could not find git, it may not work.")
endif()
I am trying to integrate CPM into ada-url/ada and the handling the case where git is not present is not pretty. It would be better if CPM handled it for us.