6

I recently updated my project to CMake, one thing is annoying. When building source files it prints the directory where object files are saved.

[ 13%] Building CXX object a/CMakeFiles/a.dir/src/A.cpp.o
[ 14%] Building CXX object b/CMakeFiles/b.dir/src/B.cpp.o
[ 15%] Building CXX object c/CMakeFiles/c.dir/src/C.cpp.o

I want to make it like this

[ 13%] Building CXX object A.cpp.o
[ 14%] Building CXX object B.cpp.o
[ 15%] Building CXX object C.cpp.o

I can't find anything about this.

Ramy
  • 172
  • 1
  • 17
  • 1
    AFAIK the piece of code that prints this is [here](https://gitlab.kitware.com/cmake/cmake/blob/v3.8.1/Source/cmNinjaTargetGenerator.cxx#L666), line is `description << "Building " << lang << " object $out";` and it seems `$out` is the relative path for object, that is then passed to gcc unmodified. So I don't expect to find a config option for that. Are you looking after a sort of filter to apply (in your terminal) to cmake output? – Hugues M. May 15 '17 at 09:20
  • 1
    See http://stackoverflow.com/questions/9765547/how-to-customize-cmake-output – sakra May 15 '17 at 09:29

1 Answers1

2

As @Hugues Moreau commented those texts are directly coded into CMake and can't be modified.

You could - without utilizing another script parsing your command line or output - only suppress the output with setting global RULE_MESSAGES property to OFF and adding your own echo call.

NOTE:

  1. It omits the percentage and color information also
  2. It works only for Makefiles generators

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

project(HelloWorld)

if(CMAKE_GENERATOR MATCHES "Makefiles")
    set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
    set(
        CMAKE_CXX_COMPILE_OBJECT 
        "$(CMAKE_COMMAND) -E echo Building <LANGUAGE> object $(@F)" 
        "${CMAKE_CXX_COMPILE_OBJECT}"
    )
endif()    

add_executable(HelloWorld main.cpp)

References

Florian
  • 39,996
  • 9
  • 133
  • 149
  • This replaces the output with 'Building C object A.cpp.o'. However it doesn't keep the `[ %14]` progress at the start. – jyn Aug 03 '20 at 17:45
  • Oh whoops, you mentioned that in your answer. – jyn Aug 03 '20 at 17:47