I want to achieve this workflow:
And I would like to have this workflow on most platforms. I don't want to have to download dependencies manually.
How to do this without storing dependencies in repository?
In CMake you can use file(DOWNLOAD URL PATH)
to download a file, combine this with custom commands to download and unpack:
set(MY_URL "http://...")
set(MY_DOWNLOAD_PATH "path/to/download/to")
set(MY_EXTRACTED_FILE "path/to/extracted/file")
if (NOT EXISTS "${MY_DOWNLOAD_PATH}")
file(DOWNLOAD "${MY_URL}" "${MY_DOWNLOAD_PATH}")
endif()
add_custom_command(
OUTPUT "${MY_EXTRACTED_FILE}"
COMMAND command to unpack
DEPENDS "${MY_DOWNLOAD_PATH}")
Your target should depend on the output from the custom command, then when you run CMake the file will be downloaded, and when you build, extracted and used.
This could all be wrapped up in a macro to make it easier to use.
You could also look at using the CMake module ExternalProject which may do what you want.