1

I run cmake to generate a VS2019 project:

> cmake -B Debug  -S . --log-level=TRACE -G "Visual Studio 16 2019" -A Win32

I build it with:

> cmake --build Debug
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  Checking Build System
  <snip>

I'd like to see the exact command line CMake is executing to actually start the build engine.

using cmake --build Debug -v outputs more information but still doesn't show how the Build Engine was launched.

I have also tried this, which failed:

>cmake --debug-output --trace --build Debug
Running with debug output on.
Running with trace output on.
CMake Error: Unknown argument --build
CMake Error: Run 'cmake --help' for all supported options.

putting --debug-output and --trace after --build also fails:

>cmake --build Debug  --debug-output --trace
Unknown argument --debug-output
Usage: cmake --build <dir>             [options] [-- [native-options]]
       cmake --build --preset <preset> [options] [-- [native-options]]
Options:
<snip>

How can I get cmake --build to output the exact command (exe & arguments) that is being used for building? And how do I affect it?

1 Answer 1

5

For Visual Studio generator CMake uses MSBuild (or whatever the generator is configured for, actually, i think it's kind of "implementation-defined" feature, which is not supposed to be exposed to the users).

You can find full list of MSBuild command-line options here. In order to provide the build tool with the said options use <build-tool-options> of CMake's --build command. E.g. here is (quite verbose) logging:

cmake --build Debug -- -v:d

How can I get cmake --build to output the exact command (exe & arguments) that is using for building?

As I proposed originally you better just live with the abstractions provided by CMake, but one trick that you may find handy (and it kind of works independently from the build tool) is to try to specify some garbarge options for the tool, so it triggers error and exposes some details:

cmake --build Debug -- garbarge

In this case MSBuild actually prints exactly the command which failed (with original + garbarge arguments):

MSBUILD : error MSB1008: Only one project can be specified.
    Full command line: '"C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe" ALL_BUILD.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:m garbarge'
5
  • better just live with the abstractions provided by CMake - :( unfortunately that's not very helpful for debugging. Still, I appreciate the workaround. I knew about -- but raises the possibility of conflicting options between what is specified on the command line and what is specified by cmake and isn't as flexible as I hoped. If there is no better answer forthcoming I will accept this answer after a while, thanks.
    – Brad
    Commented May 20, 2022 at 23:08
  • Seems the older versions of MSBuild don't actually output their command line as shown here. (E.g. VS2019 the output reads: MSBUILD : error MSB1008: Only one project can be specified. Switch: fooy
    – Brad
    Commented May 20, 2022 at 23:11
  • @Brad hmmm... that gets complicated :) I don't have an idea so far for VS2019, but one thing i have in mind is to make MSBuild print linker and compiler options instead (which anyway indirectly reflect the MSBuild options). That's far from perfect but please take a look at: cmake --build Debug -- -t:rebuild -clp:ShowCommandLine. The -t:rebuild part is required to avoid using cached data Commented May 20, 2022 at 23:36
  • You can actually change the make program by using CMAKE_MAKE_PROGRAM but for the MSVS generator there is no alternative but msbuild, so setting this variable makes no sense.
    – ixSci
    Commented May 21, 2022 at 5:40
  • @Brad if the hack doesn't work you can always check the sources to assess what the command would look like.
    – ixSci
    Commented May 21, 2022 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.