microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.47k stars 454 forks source link

Allow setting environment variables per variant #248

Closed zjturner closed 6 years ago

zjturner commented 7 years ago

CMake relies on various environment variables to find certain things, like a host compiler, or visual studio detection. Right now there is some logic to use vswhere, but as you are aware this is only available on recent versions of Visual Studio, and it doesn't even apply to non-Windows environments, where you sometimes still need to specify environment variables.

What is needed is a way to specify environment variables in the configuration of a variant. For example:

        "debug": {
            "oneWordSummary$": "Debug",
            "description$": "Emit debug information without performing optimizations",
            "buildType": "Debug",
            "env": [
               "INCLUDE": "/usr/include"
               // etc
            ]
        },

In some cases, this is literally the only solution that will work, and no other amount of options can get around this. For example, imagine your compiler is clang, cross compiling for a Windows target on a Linux host. Here, clang actually finds the Windows SDK (on your Linux machine) by assuming you've set INCLUDE and LIB. There's no (practical) way around this. Why this is important for CMake is because even just generating CMake has to run the compiler against various test programs, and if the environment isn't set up properly, this will just fail.

vector-of-bool commented 6 years ago

@zjturner, sorry for the long turnaround here. The beta5 should have this implemented. Would you mind giving it a test drive and reporting back?

I'll close this issue for now, but you can re-open if you don't find it working to your satisfaction.