# ExternalProject's CONFIGURE\_COMMAND - can I "extend" instead of replacing it?

**URL:** <https://discourse.cmake.org/t/externalprojects-configure-command-can-i-extend-instead-of-replacing-it/8765>\
**Category:** Code\
**Created:** [August 17, 2023, 8:15pm UTC](https://discourse.cmake.org/t/externalprojects-configure-command-can-i-extend-instead-of-replacing-it/8765 "2023-08-17T20:15:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaxEd](https://discourse.cmake.org/user_avatar/discourse.cmake.org/maxed/32/3561_2.png) [@MaxEd](https://discourse.cmake.org/u/MaxEd)\
**Post date:** [August 17, 2023, 8:15pm UTC](https://discourse.cmake.org/t/externalprojects-configure-command-can-i-extend-instead-of-replacing-it/8765/1 "2023-08-17T20:15:59Z")

</div>

I need to set some environment variables before running configuration step. The recommended way to do this is to modify CONFIGURE\_COMMAND and add `${CMAKE_COMMAND} -E env VAR=VALUE` to it. However, I still need to call CMake after that. If I simply write `${CMAKE_COMMAND} .`, I get errors, because this setup ignores CMAKE\_ARGS and the rest of ExternalProject\_Add arguments. What I want is to run “default” configure command in addition to command that sets the environment. Is there a way to do this, or does the need for setting environment variables break everything in ExternalProject\_Add, and I need to pass all arguments (generator, platform, args) to CONFIGURE\_COMMAND by hand?

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [August 17, 2023, 9:31pm UTC](https://discourse.cmake.org/t/externalprojects-configure-command-can-i-extend-instead-of-replacing-it/8765/2 "2023-08-17T21:31:09Z")

</div>

There’s currently no mechanism to modify rather than replace the default configure command. But depending on what effects you expect your environment variables to have, there may be other ways to inject them. For example, if you’re using CMake 3.24 or later, you could add a setup file using the [CMAKE\_PROJECT\_TOP\_LEVEL\_INCLUDES](https://cmake.org/cmake/help/latest/variable/CMAKE_PROJECT_TOP_LEVEL_INCLUDES.html) variable, which you could define using `CMAKE_ARGS`. This setup file could use `set(ENV{sometime} ...)` commands to set environment variables. Note that this would only get executed after the toolchain has been set up, so if you need the environment variables set before then, you’d need a different mechanism. You could try setting one of the other variables like `CMAKE_PROJECT_INCLUDE_BEFORE`. Take a look at the [Code Injection](https://cmake.org/cmake/help/latest/command/project.html#code-injection) part of the `project()` command docs for ideas.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [August 18, 2023, 12:48pm UTC](https://discourse.cmake.org/t/externalprojects-configure-command-can-i-extend-instead-of-replacing-it/8765/3 "2023-08-18T12:48:59Z")

</div>

> [@MaxEd](#):
>
> The recommended way to do this is to modify CONFIGURE\_COMMAND and add `${CMAKE_COMMAND} -E env VAR=VALUE` to it

That’s probably the easiest, yes. Our superbuild has a patchset layer on top of `ExternalProject` to handle a `PROCESS_ENVIRONMENT` that handles such things on top of the configure, build, and install commands. It’s something I’ve wanted to clean up and actually get in `ExternalProject` proper, but I’ve not had the time 😕 . It also needs some adaptation to support things like:

- `CONFIGURE_ENV`
- `BUILD_ENV`
- etc.
