How to execute custom command in CMake with "unpolluted" environment?

by Dan M.   Last Updated October 09, 2019 15:26 PM

Problem: I have an add_custom_command which calls an external tool that does a build of some external lib via gmake. The gmake output is logged into a log file.

CMake uses Unix Makefiles as a generator target and it sets $(VERBOSE).SILENT. This option somehow gets inherited by gmake (probably via MAKEFLAGS) called from the tool which was executed in the top level make file generated from add_custom_command. As a result, the log file doesn't contain any useful info.

This is not ideal - used CMake generator and its internal options are inadvertently leaked into my external tool. Is there some way to prevent this?

Here is the code:

...
add_custom_command(OUTPUT "<some target name>"
                   COMMAND ${BUILDTOOL_COMMAND} # i.e. buildtool <buildtool args>
                   VERBATIM)
...

For which CMake generates build.make file with the following:

...
# Suppress display of executed commands.
$(VERBOSE).SILENT:

...

<some target name>: 
    buildtool <buildtool args>
...


Related Questions


Makefiles: subdirectories and similar filenames

Updated January 05, 2018 18:26 PM

cmake for embedded: remove Linux POSIX headers

Updated December 01, 2018 02:26 AM

second expansion of make variables

Updated August 24, 2018 05:26 AM

Makefiles: How do they determine build targets?

Updated February 08, 2019 20:26 PM

What these lines in receipe do?

Updated July 29, 2015 13:11 PM