microsoft / vscode-cmake-tools

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

CMake Tools does not detect when CMAKE_TOOLCHAIN_FILE is set within a CMakeLists.txt #3328

Open thejtshow opened 1 year ago

thejtshow commented 1 year ago

Brief Issue Summary

I am attempting to develop against the raspberry pi pico SDK in conjunction with CPM within vscode. This SDK comes with toolchains files and sets the CMAKE_TOOLCHAIN_FILE variable during part of its bootup. My simplified CMakeLists.txt looks like:

cmake_minimum_required(VERSION 3.25)

project(MyProject C CXX ASM)

# set up CPM - you may have to create the below directory
set(CPM_SOURCE_CACHE "/tmp/.cache")
include(cmake/get_cpm.cmake)

# download the sdk
CPMAddPackage(
    NAME pico-sdk
    GITHUB_REPOSITORY raspberrypi/pico-sdk
    GIT_TAG 1.5.1
    DOWNLOAD_ONLY TRUE
)

# download the sdk extras
CPMAddPackage(
    NAME pico-extras
    GITHUB_REPOSITORY raspberrypi/pico-extras
    GIT_TAG sdk-1.5.1
    DOWNLOAD_ONLY TRUE
)

# sdk configuration variables
set(PICO_BOARD pico_w CACHE STRING "" FORCE)
set(PICO_SDK_PATH ${CPM_PACKAGE_pico-sdk_SOURCE_DIR} CACHE PATH "")
set(PICO_EXTRAS_PATH ${CPM_PACKAGE_pico-extras_SOURCE_DIR} CACHE PATH "")

include(${PICO_SDK_PATH}/external/pico_sdk_import.cmake)
include(${PICO_EXTRAS_PATH}/external/pico_extras_import.cmake)

# Initialize the SDK
pico_sdk_init()

add_subdirectory(my_code)

This configures just fine, but I am unable to compile as it has selected the wrong toolchain. I also cannot manually select the arm compilers, as I get "cannot compile a simple test program".

I have resorted for the moment in adding the following code to my root file:

file(WRITE "${CMAKE_CURRENT_LIST_DIR}/.vscode/cmake-kits.json" 
"[
    {
        \"name\": \"PICO\",
        \"toolchainFile\": \"${PICO_SDK_PATH}/cmake/preload/toolchains/pico_arm_gcc.cmake\"
    }
]"
)

However, this is not ideal. I would expect the cmake tools extension to detect when CMAKE_TOOLCHAINS_FILE is set and react accordingly.

Thank you guys for an awesome extension!!

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

gcampbell-msft commented 1 year ago

@thejtshow Thanks for this feature request! I am marking it as such and tagging it appropriately.