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

Cmake tools selects on 1.19.49 a different compiler than on 1.18.44 when reconfiguring #4032

Closed the-programmer closed 2 months ago

the-programmer commented 2 months ago

Brief Issue Summary

This is a follow-up of https://github.com/microsoft/vscode-cmake-tools/issues/4018. In my CMakeLists.txt I have the following line set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/arm_none_eabi_gcc.cmake). This is done so CMake selects the correct compiler for cross-compiling.

However it seems that a change in 1.19.49 breaks the cross compile. In version 1.19.49 CMake Tools selects the Visual studio 17 C compiler instead of my toolchain.

My toolchain is attached. (The tool "arm-none-eabi-dump" is something internal) arm_none_eabi_gcc.cmake

My CMakeLists.txt is also attached. CMakeLists.txt

CMake Tools Diagnostics

Diagnostics of 1.19.49

{
  "os": "win32",
  "vscodeVersion": "1.92.2",
  "cmtVersion": "1.19.49",
  "configurations": [
    {
      "folder": "c:\\Development\\[...]\\[...]",
      "cmakeVersion": "3.30.2",
      "configured": true,
      "generator": "Visual Studio 17 2022",
      "usesPresets": false,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug",
      "Release",
      "MinSizeRel",
      "RelWithDebInfo"
    ],
    "requests": [
      "file:///c%3A/Development/[...].c",
      "file:///c%3A/Development/[...].c",
      "file:///c%3A/Development/[...].c"
    ],
    "responses": [
      {
        "uri": "file:///c%3A/Development/[...].c",
        "configuration": {
          "includePath": [],
          "defines": [],
          "compilerPath": "c:/program files/microsoft visual studio/2022/professional/vc/tools/msvc/14.40.33807/bin/hostx64/x64/cl.exe",
          "compilerArgs": [],
          "compilerFragments": [
            "-w -ggdb -std=gnu99 -mcpu=cortex-m3 -march=armv7-m -ABI=eabi -mthumb -MD -mapcs-frame -fno-common -fpermissive -fsigned-char -fomit-frame-pointer -Os -g"
          ]
        }
      },
      {
        "uri": "file:///c%3A/Development/[...].c",
        "configuration": {
          "includePath": [],
          "defines": [],
          "compilerPath": "c:/program files/microsoft visual studio/2022/professional/vc/tools/msvc/14.40.33807/bin/hostx64/x64/cl.exe",
          "compilerArgs": [],
          "compilerFragments": [
            "-w -ggdb -std=gnu99 -mcpu=cortex-m3 -march=armv7-m -ABI=eabi -mthumb -MD -mapcs-frame -fno-common -fpermissive -fsigned-char -fomit-frame-pointer -Os -g"
          ]
        }
      },
      {
        "uri": "file:///c%3A/Development/[...].c",
        "configuration": {
          "includePath": [],
          "defines": [],
          "compilerPath": "c:/program files/microsoft visual studio/2022/professional/vc/tools/msvc/14.40.33807/bin/hostx64/x64/cl.exe",
          "compilerArgs": [],
          "compilerFragments": [
            "-w -ggdb -std=gnu99 -mcpu=cortex-m3 -march=armv7-m -ABI=eabi -mthumb -MD -mapcs-frame -fno-common -fpermissive -fsigned-char -fomit-frame-pointer -Os -g"
          ]
        }
      }
    ],
    "partialMatches": [],
    "targetCount": 13,
    "executablesCount": 1,
    "librariesCount": 10,
    "targets": [...]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": true
    }
  ]
}
{
  "os": "win32",
  "vscodeVersion": "1.92.2",
  "cmtVersion": "1.19.49",
  "configurations": [
    {
      "folder": "c:\\Development\\[...]\\[...]",
      "cmakeVersion": "3.30.2",
      "configured": true,
      "generator": "Visual Studio 17 2022",
      "usesPresets": false,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug",
      "Release",
      "MinSizeRel",
      "RelWithDebInfo"
    ],
    "requests": [
      "file:///c%3A/Development/[...].c",
      "file:///c%3A/Development/[...].c",
      "file:///c%3A/Development/[...].c"
    ],
    "responses": [
      {
        "uri": "file:///c%3A/Development/[...].c",
        "configuration": {
          "includePath": [],
          "defines": [],
          "compilerPath": "c:/program files/microsoft visual studio/2022/professional/vc/tools/msvc/14.40.33807/bin/hostx64/x64/cl.exe",
          "compilerArgs": [],
          "compilerFragments": [
            "-w -ggdb -std=gnu99 -mcpu=cortex-m3 -march=armv7-m -ABI=eabi -mthumb -MD -mapcs-frame -fno-common -fpermissive -fsigned-char -fomit-frame-pointer -Os -g"
          ]
        }
      },
      {
        "uri": "file:///c%3A/Development/[...].c",
        "configuration": {
          "includePath": [],
          "defines": [],
          "compilerPath": "c:/program files/microsoft visual studio/2022/professional/vc/tools/msvc/14.40.33807/bin/hostx64/x64/cl.exe",
          "compilerArgs": [],
          "compilerFragments": [
            "-w -ggdb -std=gnu99 -mcpu=cortex-m3 -march=armv7-m -ABI=eabi -mthumb -MD -mapcs-frame -fno-common -fpermissive -fsigned-char -fomit-frame-pointer -Os -g"
          ]
        }
      },
      {
        "uri": "file:///c%3A/Development/[...].c",
        "configuration": {
          "includePath": [],
          "defines": [],
          "compilerPath": "c:/program files/microsoft visual studio/2022/professional/vc/tools/msvc/14.40.33807/bin/hostx64/x64/cl.exe",
          "compilerArgs": [],
          "compilerFragments": [
            "-w -ggdb -std=gnu99 -mcpu=cortex-m3 -march=armv7-m -ABI=eabi -mthumb -MD -mapcs-frame -fno-common -fpermissive -fsigned-char -fomit-frame-pointer -Os -g"
          ]
        }
      }
    ],
    "partialMatches": [],
    "targetCount": 13,
    "executablesCount": 1,
    "librariesCount": 10,
    "targets": [...]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": true
    }
  ]
}

Diagnostics of 1.18.44

{
  "os": "win32",
  "vscodeVersion": "1.92.2",
  "cmtVersion": "1.18.44",
  "configurations": [
    {
      "folder": "c:\\Development\\[...]\\[...]",
      "cmakeVersion": "3.30.2",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [
      "file:///c%3A/Development/[...]/.c",
      "file:///c%3A/Development/[...]/.c",
      "file:///c%3A/Development/[...]/.c"
    ],
    "responses": [
      {
        "uri": "file:///c%3A/Development/[...].c",
        "configuration": {
          "includePath": [],
          "defines": [],
          "compilerPath": "c:/program files (x86)/arm gnu toolchain arm-none-eabi/12.3 rel1/bin/arm-none-eabi-gcc.exe",
          "compilerArgs": [],
          "compilerFragments": [
            "-w -ggdb -std=gnu99 -mcpu=cortex-m3 -march=armv7-m -ABI=eabi -mthumb -MD -mapcs-frame -fno-common -fpermissive -fsigned-char -fomit-frame-pointer -Os -g"
          ]
        }
      },
      {
        "uri": "file:///c%3A/Development/[...].c",
        "configuration": {
          "includePath": [],
          "defines": [],
          "compilerPath": "c:/program files (x86)/arm gnu toolchain arm-none-eabi/12.3 rel1/bin/arm-none-eabi-gcc.exe",
          "compilerArgs": [],
          "compilerFragments": [
            "-w -ggdb -std=gnu99 -mcpu=cortex-m3 -march=armv7-m -ABI=eabi -mthumb -MD -mapcs-frame -fno-common -fpermissive -fsigned-char -fomit-frame-pointer -Os -g"
          ]
        }
      },
      {
        "uri": "file:///c%3A/Development/[...].c",
        "configuration": {
          "includePath": [],
          "defines": [],
          "compilerPath": "c:/program files (x86)/arm gnu toolchain arm-none-eabi/12.3 rel1/bin/arm-none-eabi-gcc.exe",
          "compilerArgs": [],
          "compilerFragments": [
            "-w -ggdb -std=gnu99 -mcpu=cortex-m3 -march=armv7-m -ABI=eabi -mthumb -MD -mapcs-frame -fno-common -fpermissive -fsigned-char -fomit-frame-pointer -Os -g"
          ]
        }
      }
    ],
    "partialMatches": [],
    "targetCount": 11,
    "executablesCount": 1,
    "librariesCount": 10,
    "targets": [...]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": true
    }
  ]
}

Debug Log

The Trace rebuild log from 1.19.49

[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" --version
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" -E capabilities
[main] Safe constructing new CMakeProject instance
[variant] Constructing VariantManager
[main] Constructing new CMakeProject instance
[main] Starting CMake Tools second-phase init
[kit] Not reading non-existent kits file: C:\Users\[...]\AppData\Local\CMakeTools\cmake-tools-kits.json
[kit] Not reading non-existent kits file: c:\Development\[...]\[...]\.vscode\cmake-kits.json
[main] Injecting new Kit into CMake driver
[variant] Loaded new set of variants
[main] CMakeProject instance initialization complete.
[extension] Configuring workspace on open c:\Development\[...]\[...]
[main] Starting new CMake driver
[main] Starting CMake driver
[cmakefileapi-driver] Creating instance of CMakeFileApiDriver
[driver] Initializing base driver using kit
[driver] CMakeDriver Kit set to __unspec__
[kit] The environment for kit '__unspec__': {...}
[driver] Trying to detect generator supported by system
[expand] expanded ${workspaceFolder}/build
[cache] Reading CMake cache file c:/Development/[...]/[...]/build/CMakeCache.txt
[cache] Parsing CMake cache string
[cmakefileapi-driver] Removing c:/Development/[...]/[...]/build/CMakeCache.txt
[driver] Setting new variant Debug
[expand] expanded ${workspaceFolder}/build
[main] Configuring project: [...] 
[main] Saving open files before configure/build
[expand] expanded ${workspaceFolder}/build
[driver] Start configure 
[driver] Running pre-configure checks and steps
[expand] expanded ${workspaceFolder}/build
[cmakefileapi-driver] Configuring using kit
[cmakefileapi-driver] Invoking CMake C:\Program Files\CMake\bin\cmake.exe with arguments ["-DCMAKE_BUILD_TYPE:STRING=Debug","-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE","-Wno-dev","-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON","--no-warn-unused-cli","-SC:/Development/[...]/[...]","-Bc:/Development/[...]/[...]/build"]
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -Wno-dev -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON --no-warn-unused-cli -SC:/Development/[...]/[...] -Bc:/Development/[...]/[...]/build
[proc]   with environment: [...]
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Building for: Visual Studio 17 2022
[cmake] -- The C compiler identification is MSVC 19.40.33813.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Configuring done (7.2s)
[cmake] -- Generating done (0.2s)
[cmake] -- Build files have been written to: C:/Development/[...]/[...]/build
[cmakefileapi-parser] Read reply folder: c:\Development\[...]\[...]\build\.cmake\api\v1\reply
[cmakefileapi-parser] Found index files: [...]
[cache] Reading CMake cache file c:/Development/[...]/[...]/build/CMakeCache.txt
[cache] Parsing CMake cache string

And from 1.18.44

[main] Configuring project: [...] 
[main] Saving open files before configure/build
[driver] Removing c:/Development/[...]/[...]/build/CMakeCache.txt
[driver] Removing c:\Development\[...]\[...]\build\CMakeFiles
[expand] expanded ${workspaceFolder}/build
[driver] Start configure 
[driver] Running pre-configure checks and steps
[expand] expanded ${workspaceFolder}/build
[cmakefileapi-driver] Configuring using kit
[cmakefileapi-driver] Invoking CMake C:\Program Files\CMake\bin\cmake.exe with arguments ["-DCMAKE_BUILD_TYPE:STRING=Debug","-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE","-Wno-dev","-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON","--no-warn-unused-cli","-SC:/Development/[...]/[...]","-Bc:/Development/[...]/[...]/build","-G","Ninja"]
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -Wno-dev -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON --no-warn-unused-cli -SC:/Development/[...]/[...] -Bc:/Development/[...]/[...]/build -G Ninja
[proc]   with environment: [...]
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 12.3.1
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files (x86)/Arm GNU Toolchain arm-none-eabi/12.3 rel1/bin/arm-none-eabi-gcc.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Configuring done (1.1s)
[cmake] -- Generating done (0.2s)
[cmake] -- Build files have been written to: C:/Development/[...]/[...]/build
[cmakefileapi-parser] Read reply folder: c:\Development\[...]\[...]\build\.cmake\api\v1\reply
[cmakefileapi-parser] Found index files: [[...]
[cache] Reading CMake cache file c:/Development/[...]/[...]/build/CMakeCache.txt
[cache] Parsing CMake cache string
[extension] [7409] cmake.cleanConfigureAll finished (returned {"result":0,"resultType":0})

Additional Information

The only thing is that I currently don't have the time to make a full demo project that can show the issue. If required, I'll try to create it but I hope that this is sufficiënt.

gcampbell-msft commented 2 months ago

@the-programmer What generator are you intending to use for your project?

What do you have set in cmake.generator and cmake.preferredGenerators?

gcampbell-msft commented 2 months ago

Looking at your diagnostics log, I feel pretty confident that the issue is from the same issue as #4005. We are aware of the issue and are actively trying to get a fix out.

the-programmer commented 2 months ago

In both cases, the generator is "empty". Both in the Workspace and User settings.

gcampbell-msft commented 2 months ago

@the-programmer Oh interesting, presuming you are using kits, what is the definition of the kit you are using?

gcampbell-msft commented 2 months ago

Ah, I think I know what the issue is, it's not the same scenario as #4005, but it does come from the same changes over the last release.

Context for people investigating this, I believe it's because we're adding defaults to the preferredGenerators list but then we don't find them on PATH and so we "can't find it". We are investigating a fix.

the-programmer commented 2 months ago

I am not (intentionally) using kits for this. I (did) have a kit file at C:\Users\[...]\AppData\Local\CMakeTools\cmake-tools-kits.json but I renamed that to cmake-tools-kits.json.old so CMake/CMake Tools doesn't detect the contents.

gcampbell-msft commented 2 months ago

@the-programmer Could you test with this vsix and let me know if it resolves your issue?

cmake-tools.zip

gcampbell-msft commented 2 months ago

The fix for this issue will be released in the next hour or so in v1.20.2.

the-programmer commented 2 months ago

Thanks. I'll try it on Monday.

the-programmer commented 2 months ago

So, I just tried the pre-release versions 1.20.2 and 1.20.3. However, both of them still select Visual Studio as the compiler. Any ideas what could be causing this? or do you need more information?

the-programmer commented 2 months ago

@gcampbell-msft, Since your response times are usually fast. I was wondering if you noted my last comment. (The issue isn't fixed in 1.20.3)

gcampbell-msft commented 2 months ago

@the-programmer Thanks for following up. The most recent official version release should solve your issue.

The fixes in #4033 should resolve your issue. However, if they do not, please open a new issue so that we can properly track it. Thanks.