Search code examples
c++cmakecmakelists-optionscmake-language

CMake's CMakeLists.txt cant find Visual Studio 17 2022


[image of my CMake showing the error:CMake Error at CMakeLists.txt:3 (project): Generator

Visual Studio 17 2022

could not find any instance of Visual Studio.

](https://i.sstatic.net/kZH0j.png)

Even after trying various settings in the "configure" window my CMake keeps struggling to find my VS code. It seems to be telling me that there's a problem with line 3 of my CMakeLists.txt but I don't know how to change it so that it can recognize my vs code. How CMakeLists.txt shows up in my notes app text editor Here's what that section of my CMake.txt looks like

I'd just like it to be able to find my current version of VS code (which is the most recent one) so that I can start using CMake for the first time.


Solution

  • Cmake is trying to generate visual studio projects for which it needs a copy of visual studio, not visual studio code (which is an entirely unrelated product).

    Visual studio code is just a text editor and doesn't come with a c++ compiler or a build system.

    You'll either need to install visual studio (which has both a compiler and a build system) or you'll need to install a compiler (e.g. visual studio build tools, GCC from mingw or clang) along with another build system (e.g. make or ninja).

    I'd also recommend installing the vscode cmake plugin which will automate configuration and building of cmake projects