No verbose output when building an external project with ninja

This is my example project:

CMakeLists.txt a.cpp main.cpp

And this is CMakeLists.txt file. It contains two local source files and an external project GTest from a git repository:

cmake_minimum_required(VERSION 3.16)
add_executable(example main.cpp a.cpp)
   GIT_TAG        release-1.10.0

CMake and ninja versions:

# cmake --version
cmake version 3.16.3
ninja --version

When there is used the Unix Makefiles generator and the project is being built with verbose output set, then all compilations commands for the external project (GTest) are being presented:

# cmake -G "Unix Makefiles" -S.. -B.
# make VERBOSE=1
[ 18%] Performing download step (git clone) for 'gtest'
cd /test/build/gtest-prefix/src && /usr/bin/cmake -P /test/build/gtest-prefix/tmp/gtest-gitclone.cmake
Cloning into 'gtest'...
[ 12%] Building CXX object googletest/CMakeFiles/gtest.dir/src/
cd /test/build/gtest-prefix/src/gtest-build/googletest && /usr/bin/c++   -I/test/build/gtest-prefix/src/gtest/googletest/include -I/test/build/gtest-prefix/src/gtest/googletest  -Wall -Wshadow -Werror -Wno-error=dangling-else -DGTEST_HAS_PTHREAD=1 -fexceptions -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -std=c++11 -o CMakeFiles/gtest.dir/src/ -c /test/build/gtest-prefix/src/gtest/googletest/src/

However the same is not true for ninja. I can see that the compilation output is being shown for the files which are not in external project, but for the files inside the external project, the verbose output (compilation options) is not shown, just an information about the progress:

# cmake -GNinja -S.. -B.
# ninja -v
[1/11] /usr/bin/c++     -MD -MT CMakeFiles/example.dir/a.cpp.o -MF CMakeFiles/example.dir/a.cpp.o.d -o CMakeFiles/example.dir/a.cpp.o -c ../a.cpp
[9/11] cd /test/build/gtest-prefix/src/gtest-build && /usr/bin/cmake --build . && /usr/bin/cmake -E touch /test/build/gtest-prefix/src/gtest-stamp/gtest-build
[1/8] Building CXX object googletest/CMakeFiles/gtest_main.dir/src/
[2/8] Building CXX object googlemock/CMakeFiles/gmock_main.dir/src/
[3/8] Building CXX object googlemock/CMakeFiles/gmock.dir/src/
[4/8] Building CXX object googletest/CMakeFiles/gtest.dir/src/
[5/8] Linking CXX static library lib/libgtest.a
[6/8] Linking CXX static library lib/libgtest_main.a
[7/8] Linking CXX static library lib/libgmock.a
[8/8] Linking CXX static library lib/libgmock_main.a

However when I go inside the GTest directory and invoke ninja there, then I can see verbose output:

build/gtest-prefix/src/gtest-build# ninja clean
build/gtest-prefix/src/gtest-build# ninja -v
[1/8] /usr/bin/c++   -isystem /test/build/gtest-prefix/src/gtest/googletest/include -isystem /test/build/gtest-prefix/src/gtest/googletest -Wall -Wshadow -Werror -Wno-error=dangling-else -DGTEST_HAS_PTHREAD=1 -fexceptions -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -std=c++11 -MD -MT googletest/CMakeFiles/gtest_main.dir/src/ -MF googletest/CMakeFiles/gtest_main.dir/src/ -o googletest/CMakeFiles/gtest_main.dir/src/ -c /test/build/gtest-prefix/src/gtest/googletest/src/
[2/8] /usr/bin/c++   -isystem /test/build/gtest-prefix/src/gtest/googlemock/include -isystem /test/build/gtest-prefix/src/gtest/googlemock -isystem /test/build/gtest-prefix/src/gtest/googletest/include -isystem /test/build/gtest-prefix/src/gtest/googletest -Wall -Wshadow -Werror -Wno-error=dangling-else -DGTEST_HAS_PTHREAD=1 -fexceptions -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -std=c++11 -MD -MT googlemock/CMakeFiles/gmock_main.dir/src/ -MF googlemock/CMakeFiles/gmock_main.dir/src/ -o googlemock/CMakeFiles/gmock_main.dir/src/ -c /test/build/gtest-prefix/src/gtest/googlemock/src/

Is there any way to enable verbose output for an external project when using ninja, so the compilation options can be shown? This works for make.

You’ll have to pass CMAKE_VERBOSE_BUILD during configure to the subprojects or use the flag needed manually.

This is because $(MAKE) passes the VERBOSE=1 through for you. Ninja has no equivalent feature.