CMake (CMD) doesn't detect VS 2022

Exactly what it says in the title. Initially, I kept getting this error:

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
   No CMAKE_C_COMPILER could be found.
   Tell CMake where to find the compiler by setting either the environment
   variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
   the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:3 (project):
   No CMAKE_CXX_COMPILER could be found.
   Tell CMake where to find the compiler by setting either the environment
   variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
   to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!

I used cmake --help to see the list of generators and VS 2022 is nowhere to be found.

Generators

The following generators are available on this platform (* marks default):
* Unix Makefiles               = Generates standard UNIX makefiles.
  Ninja                        = Generates build.ninja files.
  Ninja Multi-Config           = Generates build-<Config>.ninja files.
  CodeBlocks - Ninja           = Generates CodeBlocks project files.
  CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.
  CodeLite - Ninja             = Generates CodeLite project files.
  CodeLite - Unix Makefiles    = Generates CodeLite project files.
  Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
  Kate - Ninja                 = Generates Kate project files.
  Kate - Unix Makefiles        = Generates Kate project files.
  Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.
  Sublime Text 2 - Unix Makefiles
                               = Generates Sublime Text 2 project files.

Then I try forcing CMake to use VS 2022 but I get this error:
"CMake Error: CMAKE_GENERATOR was set but the specified generator doesn't exist. Using CMake default."

What’s really frustrating is that this only happens when using CMD. When I run CMake-GUI, it actually does detect VS 2022. So what’s going on?

As the VS generator is missing, I guess you’re not using the normal Windows build of CMake. This may be some CYGWIN or MSYS build.
Download the official Windows build and try that instead.

1 Like

The MSYS build? You mean this?

If this is what’s causing it, then what should I do so I can use the command line correctly?

Yes, that CMake is meant for building inside MSYS usually targeting MSYS, with a compiler installed there.
Install a CMake from the official site instead.

As an alternative you can use the one installed with VS2022 (if you have it installed). If you open a VS2022 developer command prompt, it should be in the PATH. Further details and possibilities are mentioned in the documentation.

No see, I already have the official CMake installed, and I’m still getting this issue. I’m asking if the MSYS version is somehow creating conflict.

Depending on the installation order, one might in front of the other.
Check with where cmake which executable is found. Fix your PATH to be in the desired order.

I renamed the MSYS version to something else and now it targets the Windows build instead. And now everything works. Thanks.