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)
project(example)
add_executable(example main.cpp a.cpp)
include(ExternalProject)
ExternalProject_Add(gtest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
INSTALL_COMMAND ""
)
CMake and ninja versions:
# cmake --version
cmake version 3.16.3
ninja --version
1.10.0
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/gtest-all.cc.o
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/gtest-all.cc.o -c /test/build/gtest-prefix/src/gtest/googletest/src/gtest-all.cc
...
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/gtest_main.cc.o
[2/8] Building CXX object googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[3/8] Building CXX object googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
[4/8] Building CXX object googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[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/gtest_main.cc.o -MF googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o.d -o googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o -c /test/build/gtest-prefix/src/gtest/googletest/src/gtest_main.cc
[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/gmock_main.cc.o -MF googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o.d -o googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o -c /test/build/gtest-prefix/src/gtest/googlemock/src/gmock_main.cc
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.