Extra HTTP headers for `file(UPLOAD|DOWNLOAD)`


Sometimes doing HTTP operations it’s required to provide some extra headers. For example, talking to JFrog Artifactory requires the X-JFrog-Art-Api header w/ API key.

I propose to add EXTRA_HEADERS <string>... named parameter to the file(UPLOAD|DOWNLOAD ...) signature.

P.S. I’m ready to make an MR for this.

P.S.S. The other thing that will be nice to have is a configurable HTTP method to be able to talk to various REST APIs. For example, upload could be done via POST, PUT, CREATE, or even PATCH methods. There is HTTP DELETE method which is also nice to have (e.g. to delete files from Artifactory repos), but currently I’ve got no clear idea how to extend file signature for this.

file(DOWNLOAD) and file(UPLOAD) support the HTTPHEADER keyword since CMake 3.7 (see https://cmake.org/cmake/help/latest/release/3.7.html#commands).


OMG! How can I miss it!? %)
Great "news@ 2 me :slight_smile:

Ugh :frowning:
Unfortunately nor file(DOWNLOAD)neither UPLOAD can’t be used to talk to REST API of JFrog Artifactory :frowning:

I need to send some content and receive JSON response.

@brad.king, @craig.scott

I’d like to add a http() command for that purpose. What do you think?

   [CONTENT <string>] 
   [HTTPHEADERS <header>...]
   [TIMEOUT <seconds>]
   [ERROR_VARIABLE <name>]

where the first parameter is a HTTP method (i.e., GET, POST, PUT, CREATE & etc).

@zaufi you’ve been proposing many CMake language features that imply you’re using it as a general-purpose scripting language. Why? It’s meant for configuring project build trees and simple glue scripts. Interacting with REST APIs is well outside that scope. I don’t think we should grow the language that much.

One can use find_program()/find_package(...) and execute_process do arbitrary things in a true general-purpose language like Python.

My case:
I’ve added a custom target to build ABI dumps. The result dumps I want to store in JFrog Artifactory at the release build step. The master builds gonna check the ABI changes against the latest release.

Having “external” scripts in Python, means I have to start at lease one repo and full featured Python project which includes: tests, setup.py, building package, add CI builds, add a private pypi repo and deploy built packages to it, manage to preinstall of this CLI tool into my docker images used to build my projects, use find_program in my CMake project, add custom target or output…

All that pain in the ass could be done w/ couple REST API requests to Artifactory… :frowning:

That is why I strongly believe http() command is a better way.

May be a tool like curl will match your needs… with a largely less complex infrastructure than python.

No sure why you say that.
You can perfectly use a prebuilt python docker image (or any other prebuilt image that contains the tools you need to do REST request) and use it to run a python script which would be stored in your current repo as an helper script just as CMakeLists.txt or other xxx.cmake may be.
I don’t get why you would need a full-blown python module for that?
You may pass anything coming from a CMake build (CI) step as build artifact to the one that needs it.

I don’t know which CI you use but I bet any CI could use various docker images for various step/jobs?

Or may be I missed something in your points?