By downloading it with file(DOWNLOAD …):
set(SOME_FILE "some.tgz")
message(STATUS "Downloading the file...")
file(DOWNLOAD "https://your.domain/data/${SOME_FILE}"
"${CMAKE_CURRENT_SOURCE_DIR}/external/${SOME_FILE}"
#SHOW_PROGRESS
EXPECTED_HASH SHA1=b28c4cdfd737c41d1252945224aaddf97e45dc27 # should be the actual hash
STATUS DOWNLOAD_DATASETS_RESULTS
)
list(GET DOWNLOAD_DATASETS_RESULTS 0 DOWNLOAD_STATUS_CODE)
list(GET DOWNLOAD_DATASETS_RESULTS 1 DOWNLOAD_ERROR_MESSAGE)
if(${DOWNLOAD_STATUS_CODE} EQUAL 0)
message(STATUS "...successfully downloaded the file")
else()
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/external/${SOME_FILE}")
message(WARNING "...failed to download the file. ${DOWNLOAD_ERROR_MESSAGE}") # might want to use FATAL_ERROR instead of WARNING
endif()
But since it’s a .tgz
archive, you’ll also need to unpack it, perhaps with a cmake -E. And then, as many have already mentioned, ideally you’d need to have a CMake config for your package (which is auto-generated if you have a proper installation procedure), otherwise you’d need to manually add its headers and binaries to your project.
I’d recommend you to use a package manager (such as vcpkg) for all this. Higher entry level, for sure, but then such tasks will get much more simpler for you going forward.