Can I tell CMake to pipe all stderr output from the compiler and/or linker through an external program and showing the output of that on the terminal instead?
For Makefile generators you can apply a filter to the compiler output by setting a custom launcher for compile rules. The following CMake list file sketches the necessary steps:
cmake_minimum_required(VERSION 2.8)
project (Main)
configure_file(
"${PROJECT_SOURCE_DIR}/gcc_filter.sh.in"
"${PROJECT_BINARY_DIR}/gcc_filter.sh"
@ONLY)
add_executable (Main Main.cpp)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${PROJECT_BINARY_DIR}/gcc_filter.sh")
In the project root directory add the following shell script template file gcc_filter.sh.in:
#!/bin/sh
# shell script invoked with the following arguments
# $(CXX) $(CXX_DEFINES) $(CXX_FLAGS) -o OBJECT_FILE -c SOURCE_FILE
# invoke compiler
exec "$@" 2>&1 | "@PROJECT_SOURCE_DIR@/myfilter.sh"
The actual shell script invoked by the custom launcher rule is first copied to the project binary directory with the configure_file call in the CMake list file. The executable bit of the file gcc_filter.sh.in must be set. The shell script forwards all arguments to the compiler and then pipes the compiler output to another shell script myfilter.sh in the project root directory:
#!/bin/sh
exec wc
The example myfilter.sh just invokes wc but more elaborate output filtering can be easily done using the above recipe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With