Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake , don't print directory when compiling process

Tags:

cmake

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.

like image 744
Ramy Avatar asked May 10 '17 21:05

Ramy


1 Answers

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

  • GNU Make - Automatic Variables
like image 163
Florian Avatar answered Oct 15 '22 13:10

Florian