cmakebuild-automationhttp-proxy

Give http proxy to cmake without using environment variables


In a cmake project, I download an external project with FetchContent. I am behind a proxy, but this is no problem locally, where I can set the environment variables HTTP_PROXY and HTTPS_PROXY.

However, I want to use an automation server for testing and deployment. On this automation server for some reason, I can set environment variables for the build step, but not for the configure step where FetchContent tries to download the external project.

All I can do is give command-line arguments to cmake.

Solutions that work, but I do not want:

Solutions that do not work:

Is there any way to give the http proxy to cmake via a command-line option?


Solution

  • All I can do is give command-line arguments to cmake.

    Then I believe CMAKE_PROJECT_INCLUDE or any of the other script injection variables could work.

    IE create a CMake file proxy.cmake:

    set(ENV{HTTP_PROXY} "...")
    

    Then pass this to the configure step:

    cmake -DCMAKE_PROJECT_INCLUDE=proxy.cmake
    

    Now that CMake script will run during the configuration step setting up your desired environment.