microsoft / microsoft/vscode-cmake-tools
Feature Request: Better compiler detection for custom kits
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.7k
- Forks
- 546
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 32
Description
### Description
I would love for this tool to auto-detect compiler details for a kit using only a toolchain file. My build directory is configured as
```
"cmake.buildDirectory": "${workspaceFolder}/build/${buildKitVendor}_${buildKitTargetArch}/${buildType}"
```
and I am trying to use a kit that uses a toolchain to define everything; `arm-toolchain.cmake` is a file I wrote which defines all the rules for using my toolchain. Notably, it sets `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER`, which are the important ones.
```json
{
"name": "ARM Toolchain",
"toolchainFile": "/home/myuser/cmake/arm-toolchain.cmake",
}
```
When I select this kit, it's possible to build a project using this toolchain, but the output directory is
```
${workspaceFolder}/build/__unknow_vendor___unknow/Debug
```
Poking through the source for this plugin, I saw that the build kit vendor is based on both the start of the kit name and the C compiler defined in the kit configuration, so if I modify my kit to be this, then the output directory suddenly becomes what I expect - `build/GCC-arm/Debug`
```json
{
"name": "GCC ARM Toolchain",
"toolchainFile": "/home/myuser/cmake/arm-toolchain.cmake",
"compilers": {
"C": "/path/to/toolchain/sysroot/usr/bin/arm-dey-linux-gnueabi/arm-dey-linux-gnueabi-gcc"
}
},
```
But this is redundant because the compiler should be determinable from the contents of `CMAKE_C_COMPILER` alone as defined in the toolchain file and I just had to copy the exact same path from there to here.
I suspect that this is due largely to the order that events happen and what is parsed when - determining the build
directory is probably done before cmake is ever invoked, so if this plugin were to do what I'm asking, it'd have to manually parse the toolchain
file, or invoke cmake to generate CMakeCache.txt and then read the compiler out of that file.
The "more correct" solution would be to not try to parse the file manually and let cmake figure it out, but then it's a bit of a chicken-and-egg problem - you have to invoke cmake to figure out where to invoke cmake. However, it seems like that would be a reasonable approach to, when a kit is selected, try to use it to generate for some trivial project built into this plugin, and then get the compiler details from the generated CMakeCache file.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at kit selection and the build-directory vendor detection described in the issue, then trace how a kit's toolchainFile and compiler settings are read. Compare parsing the toolchain file with generating a trivial project and reading CMakeCache.txt; done means a toolchain-only kit derives compiler details and no longer produces an __unknown vendor directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, typescript
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100