Reputation: 9835
I have a cmake script that tries to resolve a path by reading an environment variable. When running that script (I print out the value of the environment variable), the message is empty (meaning the env var wasn't read successfully). However for other env vars (like PATH
, CUDA_PATH
, WINDIR
, ...), this works. But some (like OpenCV_DIR
, GOROOT
, VCPKG_ROOT
, ...) simply don't resolve. They are all machine wide environment variables.
The line that print the env var is
message("ENV VAR: " $ENV{SOME_VAR})
Why are some env vars resolved correctly while others aren't?
Edit: I'm on Windows 10 using cmake 3.11.1
Edit2: To clarify some things: cmake is invoked from vcpkg package manager and all environment variables are system wide and persistent (verified; they were set at some point in the past and setting those vars is not part of the build process).
Upvotes: 1
Views: 1226
Reputation: 556
In vcpkg, in order to improve robustness and avoid machine contamination, builds are executed in a special "clean" environment. You can get a virtualenv into this environment via the command vcpkg env --triplet <target triplet>
.
If you want to explicitly enable certain environment variables in the clean environment, you can set them in the triplet file (triplets\foo.cmake
).
There may also be a better way to achieve what you're looking for (open an issue on the GitHub page).
Upvotes: 1