I\'ve a custom command in my CMake script which generates a lot of output. I\'d like to take advantage of CMAKE_VERBOSE_MAKEFILE so I can decide if I want to see this output or
As SirDarius pointed out, execute_process()
has an option to silence tool output, while add_custom_command()
/ add_custom_target()
do not.
But there is a way to work around this: By putting the actual call to your tool in a separate CMake script wrapper, using execute_process()
with OUTPUT_QUIET
enabled or disabled depending on a switch:
# mycustom_command.cmake
if ( OUTPUT )
execute_process( COMMAND mycustom_command )
else()
execute_process( COMMAND mycustom_command OUTPUT_QUIET )
endif()
Then, use add_custom_command()
and the CMake script processing mode (-P
) to call that script from your main CMakeLists.txt, with the script switch enabled / disabled by whatever variable you use for that purpose in your CMakeLists.txt file.
add_custom_command( OUTPUT outfile
COMMAND ${CMAKE_COMMAND} -P mycustom_command.cmake -DOUTPUT=${OUTPUT_DESIRED}
)
This is fully portable. If your mycustom_command
is build from within your project as a target, just add it as DEPENDENCY
to your add_custom_command()
to have it build in time for the script call.