CMake FetchContent with HTTP redirection

Viewed 119

Trying to download a public file from SharePoint via CMake's FetchContent. My URL is like the following:

https://myorg.sharepoint.com/:u:/s/myfolder/EdajXJq3IV5HrSs9bKhEFoYByaMZHBYHyftA9GKLAGZ5wA?e=QPdu1N&Download=1

Note I added &Download=1 to the path given by SharePoint to access the file directly. However, my link gets redirect every time I use it. I'm able to download the file using wget & curl:

  1. curl -v -L --cookie tmp.cookie 'https://link.from.above' --output myfile.txt
  2. wget 'https://link.from.above'

Now trying do the same using CMake:

FetchContent_Declare(${MY_TARGET}
    URL ${FILE_URL}
)

But that doesn't work. I guess it has something to do with redirection / cookies.

1 Answers

Same problem here. We are currently using the following workaround (which is far from perfect):

  1. Check if the file exists in a specific location in the source directory
  2. If it does not exist, download the file using curl
  3. Pass the path to the downloaded file to FetchContent_Declare

If anyone has better ideas, I would like to hear them!

Related