Brad
Brad

Reputation: 3510

CMake --build verbosity

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?

Upvotes: 1

Views: 3819

Answers (1)

Aleksandr Medvedev
Aleksandr Medvedev

Reputation: 8968

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'

Upvotes: 5

Related Questions