At my day job, I maintain a few custom toolchain files for cross-compiling. One of the problems I ran into when trying to add another one, is that the compiler requires several variables to be set. I’ve struggled to find any resources about setting environment variables at build time (only during the configuration step).
I can’t simply just add a custom target to modify the environment at build time, since the Ninja generator (which is one of the ones that I support) runs all of its commands in subshells.
The two workarounds I’ve come up with are:
Create a script to configure the environment variables that a user can run pre-build. (I don’t like this since it would be easy for a user to forget to run it, and our build procedures can get pretty complicated for those unfamiliar with it)
Create a wrapper script/program to use as the compiler. This would look something like:
REM compiler-wrapper.bat SET VAR1=value SET VAR2=other_value %PATH_TO_COMPILER% %*
This doesn’t quite feel right as a solution.
I understand that not all build systems support setting environment variables out of the box, but it would definitely simplify this situation if CMake was able to handle this for me.
This text will be hidden