Florian Wolters
Florian Wolters

Reputation: 4120

How-to have colored console output if using CMake script mode with the execute_process command?

I'm currently rewriting a CMake-based build system and got rid of all platform-dependent script files (e.g. Windows Batch).

There is only one .cmd file that calls CMake as follows (a bit more complex, but the idea is that an user never has to invoke cmake directly).

cmake -P foo.cmake

In the foo.cmake script the actual configure (or --build) call with cmake is executed, e.g.

cmake_minimum_required(VERSION 3.17)

execute_process(
  COMMAND ${CMAKE_COMMAND} --build .
  ENCODING AUTO
  )

Now, when cmake -P foo.cmake is invoked, the output written to the console is not colored. If cmake --build . is executed in a terminal, the output is colored.

I'm using Microsoft Windows v6.1.7601, CMake 3.17.2 and MSBuild 15.5.180.51428.

  1. How-to have colored console output if using CMake script mode with the execute_process command?
  2. If it is not possible with execute_process: Does any alternative exist?

Related:

Upvotes: 4

Views: 3645

Answers (1)

RoBo
RoBo

Reputation: 43

You might want to give Visual Studio Code and the Output Colorizer extension a try

Upvotes: 1

Related Questions