GTest output has no colors when building with cmake + ninja and runs automatically

I am trying to configure CMake and the ninja as a build system for my project. Except for the application itself, I have an additional executable for unit tests running on gtest. I thought it would be great if they were executed automatically when they were built. Here is how I did it:

β”œβ”€β”€ build └── source β”œβ”€β”€ CMakeLists.txt β”œβ”€β”€ main.cc └── ut β”œβ”€β”€ CMakeLists.txt β”œβ”€β”€ gtest β”‚  β”œβ”€β”€ ... └── ut.cc 

source / CMakeLists.txt ...

 cmake_minimum_required (VERSION 2.6) project (trial) add_subdirectory(ut) add_executable(trial main.cc) 

... and source / ut / CMakeLists.txt:

 add_subdirectory(gtest) include_directories ("gtest/include") add_executable(ut ut.cc) target_link_libraries(ut LINK_PUBLIC gtest_main) add_custom_target(run_uts COMMAND ut DEPENDS ut WORKING_DIRECTORY ${CMAKE_PROJECT_DIR} ) 

Now that I will build it, that is:

 cd build cmake -GNinja ../source ninja run_uts 

It works great, except that the output is colorless. When I run the ut binary, i.e. build/ut/ut , I get beautiful green and red colors. Colors are also present when I use Unix Makefiles as a generator for CMake.

Since I'm only learning CMake, is there something I missed or is it a ninja problem?

+5
source share
1 answer

I assume that your automatic code runs the gtest executable and directs the output to a file. By default, gtest only adds color sequences when sending output to the terminal. To force it to add color sequences for output sent to a file or channel, run the test executable using the --gtest_color=yes ./p> parameter

+7
source

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


All Articles