Cmake: How to Suppress "Entering Directory" Messages

cmake: How to suppress Entering directory messages?

You can use

MAKEFLAGS += --no-print-directory

Described in the GNU make manual

Suppress all make output except for errors and warnings

Depending on how "errors and warnings" are reported ...

make > /dev/null

That will redirect all STDOUT (Standard Output) from the make command (and thus all sub-processes it spawns) to the endless bit-bucket of nothingness. This may be too greedy though, as some programs use STDOUT (and not STDERR) to report warnings.

I do not know of a way globally change STDOUT of all sub-processes from within the context of the Makefile itself.

Happy coding.

How can I get make to be verbose but with only meaningful lines when building with cmake?

You can discover for yourself that there is no way to do what you want.

Since cmake is just generating makefiles, and it's make that is actually running the recipes and printing the output, you need to look at the makefile and see how the rules are constructed. If you find a sample rule for a link line for example you will see it looks like this:

myexecutable: ...
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/mydir/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking CXX executable myexecutable"
cd /mydir && $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/myexecutable.dir/link.txt --verbose=$(VERBOSE)

Note that there is no special variable, or token, or anything appearing in this recipe before the cd /mydir ... text.

So, there is absolutely no way to control how this particular recipe is printed, separately from how all the other recipes are printed. You either get them all, or you get none of them.

Alternative to CMake POST_BUILD command when target is in subdirectory

Just use common combination of add_custom_command and add_custom_target, when the first one produces file for the second one:

# Because OUTPUT option may not use generator expressions,
# extract name of file from target's properties.
get_target_property(mytarget_basename mytarget OUTPUT_NAME)
get_target_property(mytarget_suffix mytarget SUFFIX)
set(mytarget_filename ${mytarget_basename}${mytarget_suffix})
# make copied file be dependent from one which is build.
# Note, that DEPENDS here creates dependencies both from the target
# and from the file it creates.
add_custom_command(OUTPUT
${CMAKE_BINARY_DIR}/final_destination/${mytarget_filename}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:mytarget>
${CMAKE_BINARY_DIR}/final_destination
DEPENDS mytarget
)
# Create target which consume the command via DEPENDS.
add_custom_target(copy_files ALL
DEPENDS ${CMAKE_BINARY_DIR}/final_destination/${mytarget_filename}
)

Comparing with POST_BUILD using, this code uses additional target. But you have no other choice: add_custom_command cannot be attached to the target created in other directory.


Usually, instead of copiing executable/library into other binary directory it is simpler to specify this directory via CMAKE_<TYPE>_OUTPUT_DIRECTORY variable.

Using CMake with GNU Make: How can I see the exact commands?

When you run make, add VERBOSE=1 to see the full command output. For example:

cmake .
make VERBOSE=1

Or you can add -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON to the cmake command for permanent verbose command output from the generated Makefiles.

cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .
make

To reduce some possibly less-interesting output you might like to use the following options. The option CMAKE_RULE_MESSAGES=OFF removes lines like [ 33%] Building C object..., while --no-print-directory tells make to not print out the current directory filtering out lines like make[1]: Entering directory and make[1]: Leaving directory.

cmake -DCMAKE_RULE_MESSAGES:BOOL=OFF -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .
make --no-print-directory


Related Topics



Leave a reply



Submit