Search code examples
cmakemsbuilddevenv

Can cmake --build use msbuild instead of devenv


I'm using CMake 3.23 with Visual Studio 2022. From everything I found about cmake --build command it should be running msbuild, but evidently it's running devenv instead. Is there some setting I'm not aware of? How do I get it to run msbuild so I can pass options to it?

This is my generator command:

cmake -G "Visual Studio 17" -A x64 -T v143 ..

And then cmake --build is running devenv instead of msbuild:

cmake --build . --config Release -- /verbosity:detailed

Microsoft Visual Studio 2022 Version 17.2.3.
Copyright (C) Microsoft Corp. All rights reserved.

Invalid Command Line. Unknown Switch : verbosity:detailed.

Use:
devenv  [solutionfile | projectfile | folder | anyfile.ext]  [switches]

Solution

  • CMake by default is using MSBuild and falls back to devenv if you either requested it deliberately (with CMAKE_MAKE_PROGRAM) or you have an Intel Fortran project in which case it has to use devenv.

    You can check if it found MSBuild by checking the CMAKE_VS_MSBUILD_COMMAND variable. And you can force CMake to use MSBuild by setting CMAKE_MAKE_PROGRAM to the MSBuild path (although I don't know how it will behave if you have a Fortran project).