Skip to content

[cmake] Honor CMAKE_VERBOSE_MAKEFILE when building external projects #75749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2023

Conversation

DimitryAndric
Copy link
Collaborator

When the top-level CMake invocation has CMAKE_VERBOSE_MAKEFILE=ON, indicating the user wants to have verbose builds (i.e. all executed commands explicitly echoed), some of the subprojects and runtimes (such as compiler-rt, libcxx, etc) do not build in verbose mode. For example, with Ninja:

[ 99% 6252/6308] cd /build/runtimes/builtins-bins && /usr/local/bin/cmake --build .
[  0% 6/308] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvti2.c.o
[  0% 7/308] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvdi2.c.o
[  0% 8/308] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvsi2.c.o
...

This is because llvm_ExternalProject_Add() and add_custom_libcxx() use CMake's ExternalProject_Add() function to configure such subproject builds, and do not pass through the CMAKE_VERBOSE_MAKEFILE setting.

Similar to what is done in clang/CMakeLists.txt, add -DCMAKE_VERBOSE_MAKEFILE=ON to the ExternalProject_Add() invocations in llvm_ExternalProject_Add() and add_custom_libcxx(), whenever the top-level CMake invocation had CMAKE_VERBOSE_MAKEFILE turned on.

When the top-level CMake invocation has `CMAKE_VERBOSE_MAKEFILE=ON`, indicating the user wants to have verbose builds
(i.e. all executed commands explicitly echoed), some of the subprojects and runtimes (such as compiler-rt, libcxx, etc)
do not build in verbose mode. For example, with Ninja:

```
[ 99% 6252/6308] cd /build/runtimes/builtins-bins && /usr/local/bin/cmake --build .
[  0% 6/308] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvti2.c.o
[  0% 7/308] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvdi2.c.o
[  0% 8/308] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvsi2.c.o
...
```

This is because `llvm_ExternalProject_Add()` and `add_custom_libcxx()` use CMake's `ExternalProject_Add()` function to
configure such subproject builds, and do not pass through the `CMAKE_VERBOSE_MAKEFILE` setting.

Similar to what is done in `clang/CMakeLists.txt`, add `-DCMAKE_VERBOSE_MAKEFILE=ON` to the `ExternalProject_Add()`
invocations in `llvm_ExternalProject_Add()` and `add_custom_libcxx()`, whenever the top-level CMake invocation had
`CMAKE_VERBOSE_MAKEFILE` turned on.
@llvmbot llvmbot added cmake Build system in general and CMake in particular compiler-rt labels Dec 17, 2023
Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked that CMAKE_VERBOSE_MAKEFILE does not affect Ninja, so perhaps most people will not observe anything.

@DimitryAndric
Copy link
Collaborator Author

I got this suggestion from https://discourse.cmake.org/t/no-verbose-output-when-building-an-external-project-with-ninja/1113, where they recommend using CMAKE_VERBOSE_BUILD with Ninja. For GNU make it is not necessary since you can pass VERBOSE=1 as a variable on the command line, and it will automatically be passed down to all sub-makes.

As an example, when I do a top-level configure with CMake -G Ninja -D CMAKE_VERBOSE_BUILD:BOOL=ON with this patch, I now get (for the builtins lib, for example):

-- Build files have been written to: /build/runtimes/builtins-bins
[ 30% 4/10] cd /build/runtimes/builtins-bins && /usr/local/bin/cmake --build .
Change Dir: '/build/runtimes/builtins-bins'

Run Build Command(s): /usr/local/bin/ninja -v
[  3% 6/29] /build/./bin/clang --target=x86_64-unknown-freebsd15.0 -DVISIBILITY_HIDDEN  -O3 -DNDEBUG -m32 -fno-lto -std=c11 -fPIC -fno-builtin -fvisibility=hidden -fomit-frame-pointer -MD -MT CMakeFiles/clang_rt.builtins-i386.dir/mulosi4.c.o -MF CMakeFiles/clang_rt.builtins-i386.dir/mulosi4.c.o.d -o CMakeFiles/clang_rt.builtins-i386.dir/mulosi4.c.o -c /share/dim/src/llvm/llvm-project/compiler-rt/lib/builtins/mulosi4.c
[  6% 7/29] /build/./bin/clang --target=x86_64-unknown-freebsd15.0 -DVISIBILITY_HIDDEN  -O3 -DNDEBUG -m32 -fno-lto -std=c11 -fPIC -fno-builtin -fvisibility=hidden -fomit-frame-pointer -MD -MT CMakeFiles/clang_rt.builtins-i386.dir/muldc3.c.o -MF CMakeFiles/clang_rt.builtins-i386.dir/muldc3.c.o.d -o CMakeFiles/clang_rt.builtins-i386.dir/muldc3.c.o -c /share/dim/src/llvm/llvm-project/compiler-rt/lib/builtins/muldc3.c
...

@DimitryAndric DimitryAndric merged commit aad5c2f into main Dec 17, 2023
@DimitryAndric DimitryAndric deleted the users/DimitryAndric/honor-cmake-verbose branch December 17, 2023 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular compiler-rt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants