ExternalProject's CONFIGURE_COMMAND - can I "extend" instead of replacing it?

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?

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 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 part of the project() command docs for ideas.

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 :confused: . It also needs some adaptation to support things like:

  • etc.