Skip to content

GNUToMS: Tolerate existence of a %USERPROFILE%/source directory

Albert Ziegenhagel requested to merge alzi/cmake:fix-gnu-to-ms into master

The file C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\vsdevcmd\core\vsdevcmd_end.bat that is executed when you start the VS command environment via vcvarsall.bat has the following code in it:

@REM Set the current directory that users will be set after the script completes
@REM in the following order:
@REM 1. [VSCMD_START_DIR] will be used if specified in the user environment
@REM 2. [USERPROFILE]\source if it exists
@REM 3. current directory
if "%VSCMD_START_DIR%" NEQ "" (
    cd /d "%VSCMD_START_DIR%"
) else (
    if EXIST "%USERPROFILE%\Source" (
        cd /d "%USERPROFILE%\Source"
    )
)

This sets the current working directory to %USERPROFILE%/source if it exists or %VSCMD_START_DIR% if it is defined.

Because the current implementation of the GNUtoMS feature relies on relative paths, it does not work if one of those conditions is met.

This merge request forces %VSCMD_START_DIR% to be set to the correct directory, and fixes those problems.

Edited by Brad King

Merge request reports