CMake, do not print the directory when compiling the process

I recently upgraded my project to CMake, one thing is annoying. When creating the source files, it prints the directory in which the 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 do it as follows

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

I can not find anything about this.

+6
source share
1 answer

As @Hugues Moreau commented , these texts are directly encoded in CMake and cannot be changed.

You can - without using another script to parse your command line or output - just suppress the output by setting the global RULE_MESSAGESproperty on OFFand add your own call echo.

Note:

  • It also skips percent and color information.
  • Makefiles

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)

+2

Source: https://habr.com/ru/post/1017152/


All Articles