title: How-to have colored console output if using CMake script mode with the execute_process command?
body: <p>I'm currently rewriting a CMake-based build system and got rid of all platform-dependent script files (e.g. Windows Batch).</p>
  
  <p>There is only one <code>.cmd</code> file that calls CMake as follows (a bit more complex, but the idea is that an user never has to invoke <code>cmake</code> directly).</p>
  
  <pre><code>cmake -P foo.cmake
  </code></pre>
  
  <p>In the <code>foo.cmake</code> script the actual configure (or <code>--build</code>) call with <code>cmake</code> is executed, e.g.</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.17)
  
  execute_process(
    COMMAND ${CMAKE_COMMAND} --build .
    ENCODING AUTO
    )
  </code></pre>
  
  <p>Now, when <code>cmake -P foo.cmake</code> is invoked, the output written to the console is <strong>not</strong> colored. If <code>cmake --build .</code> is executed in a terminal, the output is colored.</p>
  
  <p>I'm using Microsoft Windows v6.1.7601, CMake 3.17.2 and MSBuild 15.5.180.51428.</p>
  
  <ol>
  <li>How-to have colored console output if using CMake script mode with the <a href="https://cmake.org/cmake/help/latest/command/execute_process.html" rel="nofollow noreferrer"><code>execute_process</code></a> command?</li>
  <li>If it is not possible with <code>execute_process</code>: Does any alternative exist?</li>
  </ol>
  
  <p>Related:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/18968979/how-to-get-colorized-output-with-cmake">How to get colorized output with cmake?</a></li>
  <li><a href="http://cmake.3232098.n2.nabble.com/quot-cmake-build-quot-and-colors-td7584342.html" rel="nofollow noreferrer">http://cmake.3232098.n2.nabble.com/quot-cmake-build-quot-and-colors-td7584342.html</a></li>
  <li><a href="http://cmake.3232098.n2.nabble.com/Coloured-output-for-cmake-on-windows-td4279033.html" rel="nofollow noreferrer">http://cmake.3232098.n2.nabble.com/Coloured-output-for-cmake-on-windows-td4279033.html</a></li>
  <li><a href="https://github.com/microsoft/vscode-cmake-tools/issues/478" rel="nofollow noreferrer">https://github.com/microsoft/vscode-cmake-tools/issues/478</a></li>
  </ul>