Closed roblabla closed 3 years ago
Thanks! Could this be done for most other env var accesses as well? Additionally, like cc-rs
, could this print out the results of what env vars are inspected (sometimes very helpful for debugging failures)
Could this be done for most other env var accesses as well?
Right, so here are the two other environment variables where I think it'd make sense to make them per-target:
CMAKE_GENERATOR
: Makes sense, you may want to use mingw makefiles or msbuild depending on the target for instance.CMAKE_INSTALL_PREFIX
: This is used by find_package and company.The other two, I'm not so sure:
DEP_{dep}_ROOT
: I'm not sure what this does.CMAKE
: This just points to the cmake binary. I don't think it makes sense to make it per-target, as I believe the same cmake binary is used when cross-compiling (at least that's what I do!).For DEP_*
those are cargo-specific things so they should avoid this function (although it might be nice to print out that they're being accessed like cc-rs
does), but for CMAKE
I'd just throw it into the same function for consistency, but I agree that it's pretty doubtful anyone will use a target-specific variable for that.
How does this look? It should now get the per-target environment variable for CMAKE
, CMAKE_GENERATOR
, CMAKE_PREFIX_PATH
and CMAKE_TOOLCHAIN_FILE
, and print on access. The same env_cache logic found in cc-rs was used here to make sure we only print once per env variable.
Thanks!
This would help cross-compilation a bit, allowing the user to have some global environment variables set up for each of their cross-compilation toolchain.
The
get_target_env_var
function is taken fromcc-rs::get_var
function.