microsoft / vscode-cmake-tools

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

doc: cmake.environment is not applied to launch/debug #3926

Closed Ashark closed 4 months ago

Ashark commented 4 months ago

The documentation is currently misleading. cmake.environment is not actually applied to the debug configuaration.

I used the following code to print environment in binary launch:

#include <stdio.h>

int main(int argc, char **argv, char **envp)
{
    for (char **env = envp; *env != 0; env++)
    {
        char* thisEnv = *env;
        printf("%s\n", thisEnv);
    }
    return 0;
}

and this code in CMakeLists.txt to print env vars in cmake process:

message("Environment Variables:")
execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment"
    OUTPUT_VARIABLE env_output)
message("${env_output}")

I see that environment from cmake.environment is applied in cmake, but not when debugging binary.

I also did ensure that I launch for debugging from the configuration in launch.json, and not configurationless (because it can have weirdness in applying environment, see here).

To make it clear, I actually want the current behavior, i.e. it is ok that the cmake environment is not applied when binary debugging. This mr just fixes documentation so it is correct.