A build wrapper may let you add CMake arguments while hiding the environment used to launch CMake. An early project hook gives you one place to supply the configure process’s proxy values.

Save a small file at a stable, absolute path, for example /home/alex/cmake/proxy-env.cmake:

set(ENV{http_proxy} "http://proxy.example:8080")
set(ENV{https_proxy} "http://proxy.example:8080")

Pass that file to configuration:

cmake -S . -B build -DCMAKE_PROJECT_INCLUDE_BEFORE=/home/alex/cmake/proxy-env.cmake

CMAKE_PROJECT_INCLUDE_BEFORE includes the file at the beginning of each project() call. It therefore runs earlier than CMAKE_PROJECT_INCLUDE, which runs at the end of that call. This distinction matters when language setup or a nested project needs the route.

For configure-time public downloads allowed through a public intermediary, choose the HTTP URL values from the HTTP proxy list. The hook still cannot affect work that ran before it, including a download before the first project() call. It also does not write a persistent operating-system environment setting.

Processes started afterward by this CMake process can inherit the values, provided their network clients support them. A later, separately launched build has its own environment. A download deferred to that build stage must receive its proxy there too.

Keep the hook file outside a public source tree when it contains private connection details. The -D argument stores the hook path as a CMake variable; set(ENV{...}) changes the running process environment rather than turning a cache variable into a proxy setting.

Tënë sô zo