file(DOWNLOAD ....) Error message question.

In our project we generate CMake code such as the following:

file(DOWNLOAD https://www.dream3d.io/Data_Archive/7_0_abaqus_hexahedron_writer_test.tar.gz
              "/Users/mjackson/Workspace1/DREAM3DNX/../DREAM3D_Data/TestFiles/7_0_abaqus_hexahedron_writer_test.tar.gz"
              EXPECTED_HASH SHA512=e28ec04784186a3d1d13d65d9df57ceb5dfc8d673b1815ce487244bbac6dea52ddfe27c980650de1ebc0eabad6cc6a40f9cc8ce025fca4d1d471b6920ade7825
              # SHOW_PROGRESS
              STATUS result
              )

The issue is that if the file cannot be downloaded from the server we this error message:

CMake Error at simplnx_fetch_remote_files.cmake:147 (file):
  file DOWNLOAD cannot compute hash on failed download

    status: [22;"HTTP response code said error"]

I have looked around in the CMake documentation but found nothing that would allow us to actually print which file was not found or downloaded. I cannot catch the error in the “STATUS” variable because CMake will return immediately on the “file(DOWNLOAD…” line so there is no chance for us to attempt to print anything. For a while we just used a message command to print each file url before the file(DOWNLOAD...) command was used. We have about 120 files to download which just fills up compile logs.

I would like to be able to do something like the following:

if("${status}" STREQUAL ....)
    message(FATAL_ERROR "The file ${URL} did not download correctly")
endif()

Maybe there is a way to get this figured out with “Modern” CMake that I am missing? We are currently using CMake 3.26 as our minimum.

Thanks to any for a bit of help.