CMake with stdin or pseudo-file

In Unix-like shells, a pseudo-file can be used as input of script for CMake. CMake can read from a pseudo-file or stdin on the command line, allowing one to run CMake script cmake -P ... commands without creating temporary files. This method by design is only for CMake script role; it does not work with other CMake roles like PROJECT.

Pseudo-file example for Unix-like shells and CMake ≥ 4.2:

cmake -P <(printf '%s\n' 'message("${CMAKE_VERSION}")')

stdin standard input example for Unix-like shells across all versions of CMake:

cmake -P /dev/stdin <<< "message('\${CMAKE_VERSION}')"

That’s useful to print the CMake version without parsing the output of cmake --version or creating a temporary file with the CMake script.

On Windows in PowerShell or Windows ComSpec, there isn’t a direct equivalent method to use stdin / CONIN$ or a pseudo-file. Use a temporary file instead, or use WSL to run the above Unix-like shell examples. There was a previous attempt to add cmake -P - support for stdin but as of this writing it was closed without merging.