问题描述
我试图配置CMake和忍者作为我的项目的构建系统。除了应用程序本身,我有一个额外的可执行程序由gtest供电的单元测试。我认为这将是很好,让他们自动执行时,他们建立。
I'm trying to configure CMake and ninja as a build system for my project. Except the app itself I have an extra executable for unit tests powered by gtest. I thought it would be nice to have them executed automatically whenever they are built. Here's how I made it:
├── build
└── source
├── CMakeLists.txt
├── main.cc
└── ut
├── CMakeLists.txt
├── gtest
│ ├── ...
└── ut.cc
source / CMakeLists.txt ...
source/CMakeLists.txt...
cmake_minimum_required (VERSION 2.6)
project (trial)
add_subdirectory(ut)
add_executable(trial main.cc)
... and source / ut / CMakeLists.txt:
...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}
)
现在当我构建它,即:
cd build
cmake -GNinja ../source
ninja run_uts
$ b b
它工作正常,除了输出是无色的。当我用手运行ut二进制,即 build / ut / ut
我得到好的绿色和红色的颜色。
It works fine except that the output is colorless. When I run the ut binary by hand, i.e. build/ut/ut
I get nice green and red colors. The colors are also there when I use Unix Makefiles as a genrator for CMake.
因为我只学习CMake,有一些我错过了或是一个问题, Ninja?
Since I'm only learning CMake, is there something I missed or is it an issue with Ninja?
推荐答案
我假设您的自动化代码运行一个gtest可执行文件,并将输出定向到一个文件。默认情况下,gtest仅在将输出发送到终端时才添加颜色序列。为了强制它添加颜色序列到输出发送到文件或管道,运行测试可执行文件与 - gtest_color = yes
。
I assume your automated code runs a gtest executable and directs the output to a file. By default, gtest adds color sequences only when sending output to a terminal. In order to force it to add color sequences to output sent to a file or a pipe, run your test executable with the --gtest_color=yes
option.
这篇关于当使用cmake + ninja构建时,GTest的输出没有颜色,并自动执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!