4

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:

Florian Wolters
  • 3,820
  • 5
  • 35
  • 55
  • Your question really has nothing whatsoever to do with [[tag:batch-file]], so you really shouldn't be using its tag. All you have inside your `.cmd` file is a command, (to run an executable file with an argument), and that command could easily be run from any command line interface, and with a whole host of consoles/terminals. Now as you're clearly using Windows, specify the terminal/console in your question body and also replace your [[tag:batch-file]] tag with [[tag:cmd]], [[tag:powershell]] or whatever matches the console/terminal your question relates to. Thank you. – Compo Apr 30 '20 at 14:01
  • @Compo You're right, I've used the wrong tag. Fixed. – Florian Wolters Apr 30 '20 at 15:16

1 Answers1

1

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

RoBo
  • 43
  • 7