CMake comments are not shown when building with ninja

292 views
Skip to first unread message

Goran Žauhar

unread,
Feb 22, 2018, 9:29:21 AM2/22/18
to ninja-build
Hi there,

when building following project using ninja, comment does not get shown in console. When building with make comment is shown.
Is this CMake or ninja issue? Or design decision?
I am using CMake-3.10.2 and ninja-1.8.2 on Ubuntu 16.04.

cmake_minimum_required(VERSION 3.10)
project(ninja-test)
file(WRITE test.c "#include <stdio.h> \n int main() { printf(\"Hello\\n\"); }")
add_executable(ninja-test test.c)
add_custom_command(
    TARGET ninja-test
    PRE_LINK
    COMMAND touch foo
    COMMENT "Does not get shown when using ninja!"
)

Kind regards,
Goran

Ben Boeckel

unread,
Feb 22, 2018, 9:40:10 AM2/22/18
to Goran Žauhar, ninja-build
On Thu, Feb 22, 2018 at 03:10:45 -0800, Goran Žauhar wrote:
> Is this CMake or ninja issue?

Depends :)

> Or design decision?

It should work, but I'm not as familiar with
`add_custom_command(TARGET)`.

> add_executable(ninja-test test.c)
> add_custom_command(
> TARGET ninja-test
> PRE_LINK
> COMMAND touch foo
> COMMENT "Does not get shown when using ninja!"

Does it show up in the build.ninja file? What's the stanza which does
(or should) have this command?

--Ben

Glenn Coombs

unread,
Apr 30, 2024, 6:04:28 AMApr 30
to ninja-build
Was this issue ever resolved ?  I think I have the same problem.  When my custom command gets run I can see a message "Running utility command for <target name>" instead of the string I gave using the COMMENT parameter to the add-custom_command.  This is the relevant CMake command:

add_custom_command(TARGET ${ARG_TARGET} POST_BUILD VERBATIM
    COMMENT "Signing file: ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.exe"
    COMMAND ${dti_certificate_tool} --add ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.exe)

I am using CMake 3.28.0-msvc1 and Ninja 1.11.0.

Ben Boeckel

unread,
Apr 30, 2024, 12:27:37 PMApr 30
to Glenn Coombs, ninja-build
On Tue, Apr 30, 2024 at 02:29:17 -0700, Glenn Coombs wrote:
> Was this issue ever resolved ? I think I have the same problem. When my
> custom command gets run I can see a message "Running utility command for
> <target name>" instead of the string I gave using the COMMENT parameter to
> the add-custom_command. This is the relevant CMake command:

Can you provide answers to my questions? Pre/post commands are
implemented via `&&` chaining with the relevant command and may have
`COMMENT` ignored for the main command's comment instead. I'm not sure
how to change the comment during command execution, but maybe merging
with the stock description in some way can be done?

--Ben

Glenn Coombs

unread,
Apr 30, 2024, 11:30:36 PMApr 30
to ninja-build
Hi Ben,

Yes, I'm happy to provide answers to your questions.  The COMMENT string is not present in the build.ninja file.  The corresponding lines in the build.ninja file for the add_custom_command look like this:

#############################################
# Utility command for applications_log_viewer

build Packaging\Applications\LogViewer\Generic\CMakeFiles\applications_log_viewer.util: CUSTOM_COMMAND Packaging\Applica
tions\LogViewer\Generic\CMakeFiles\applications_log_viewer Packaging\Applications\LogViewer\Generic\applications_log_vie
wer.exe Packaging\Applications\LogViewer\Generic\stage_applications_log_viewer
  COMMAND = C:\WINDOWS\system32\cmd.exe /C "cd /D D:\Code\github\applications-packaging\build\release-32-windows\Packaging\Applications\LogViewer\Generic && D:\Code\ArtifactRepo\artifacts\Windows\CertificateTool\v10.79.2.0\vc142\CertificateTool.exe --add D:/Code/github/applications-packaging/build/release-32-windows/Packaging/Applications/LogViewer/Generic/applications_log_viewer.exe"
  DESC = Running utility command for applications_log_viewer
  restat = 1

build Packaging\Applications\LogViewer\Generic\applications_log_viewer: phony Packaging\Applications\LogViewer\Generic\CMakeFiles\applications_log_viewer.util

If I edit the DESC line in the build.ninja file then it shows the message I want so it looks like the problem is that the COMMENT string from the CMake add-custom_command is not being transferred through to the DESC field in the build.ninja file.

--
Glenn

Ben Boeckel

unread,
May 1, 2024, 5:39:29 PMMay 1
to Glenn Coombs, ninja-build
On Tue, Apr 30, 2024 at 20:30:36 -0700, Glenn Coombs wrote:
> Yes, I'm happy to provide answers to your questions. The COMMENT string is
> not present in the build.ninja file. The corresponding lines in the
> build.ninja file for the add_custom_command look like this:

Can you test this MR:

https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9484

It will put the `COMMENT` strings for any commands with the stock one
separated by `; `.

--Ben

Glenn Coombs

unread,
May 3, 2024, 2:46:03 AMMay 3
to ninja-build
I have tested you MR and it works for the simple case with only one command and comment like my original example.  But then I tried this example:

add_custom_command(TARGET ${ARG_TARGET} POST_BUILD VERBATIM
    COMMENT "Signing file: ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.exe"
    COMMAND ${dti_certificate_tool} --add ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.exe
    COMMENT "Creating dummy file"
    COMMAND ${CMAKE_COMMAND} -E touch " ${CMAKE_CURRENT_BINARY_DIR}/dummy"
)

Glenn Coombs

unread,
May 3, 2024, 2:49:14 AMMay 3
to ninja-build
Oops, hit the wrong button and posted before I had finished the last message.

I have tested you MR and it works for the simple case with only one command and comment like my original example.  But then I tried this example:

add_custom_command(TARGET ${ARG_TARGET} POST_BUILD VERBATIM
    COMMENT "Signing file: ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.exe"
    COMMAND ${dti_certificate_tool} --add ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.exe
    COMMENT "Creating dummy file"
    COMMAND ${CMAKE_COMMAND} -E touch " ${CMAKE_CURRENT_BINARY_DIR}/dummy"
)

In this case I only see the second comment printed out.

Ben Boeckel

unread,
May 3, 2024, 8:00:25 AMMay 3
to Glenn Coombs, ninja-build
On Thu, May 02, 2024 at 23:49:14 -0700, Glenn Coombs wrote:
> Oops, hit the wrong button and posted before I had finished the last
> message.
>
> I have tested you MR and it works for the simple case with only one command
> and comment like my original example. But then I tried this example:
>
> add_custom_command(TARGET ${ARG_TARGET} POST_BUILD VERBATIM
> COMMENT "Signing file: ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.exe"
> COMMAND ${dti_certificate_tool} --add
> ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.exe
> COMMENT "Creating dummy file"
> COMMAND ${CMAKE_COMMAND} -E touch " ${CMAKE_CURRENT_BINARY_DIR}/dummy"
> )
>
> In this case I only see the second comment printed out.

Because only one `COMMENT` is allowed per `add_custom_command` call. The
second instance overwrites the first during argument parsing.

--Ben

Glenn Coombs

unread,
May 6, 2024, 5:12:49 AMMay 6
to ninja-build
Looks like I misread the CMake documentation for add_custom_command. I'd assumed it supported multiple COMMENT arguments, one for each of the COMMAND arguments.  You are correct and it only supports a single COMMENT argument.  I guess the COMMENT is supposed to describe what the sequence of commands is trying to achieve rather than listing a separate message for each command.

I think your patch is good, it works for me.
Reply all
Reply to author
Forward
0 new messages