cmake: Errors not actually errors? #33153

issue fanquake openend this issue on August 7, 2025
  1. fanquake commented at 12:29 pm on August 7, 2025: member

    Using current master (6a2bb0fd835977637e0f43db76121bbfd21565f6), if you configure with the following, CMake will “Error”:

     0# gcc --version
     1# gcc (Ubuntu 14.2.0-4ubuntu2~24.04) 14.2.0
     2
     3cmake -B build -DBUILD_KERNEL_LIB=ON -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
     4<snip>
     5Cross compiling ....................... FALSE
     6C++ compiler .......................... GNU 14.2.0, /usr/bin/c++
     7CMAKE_BUILD_TYPE ...................... RelWithDebInfo
     8Preprocessor defined macros ........... 
     9C++ compiler flags .................... -O2 -g -std=c++20 -fPIC -fno-extended-identifiers -fdebug-prefix-map=/root/ci_scratch/src=. -fmacro-prefix-map=/root/ci_scratch/src=. -fstack-reuse=none -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wformat -Wformat-security -Wvla -Wredundant-decls -Wdate-time -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wbidi-chars=any -Wundef -Wno-unused-parameter
    10Linker flags .......................... -O2 -g -fstack-reuse=none -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wl,-z,relro -Wl,-z,now -Wl,-z,separate-code -fPIE -pie
    11
    12NOTE: The summary above may not exactly match the final applied build flags
    13      if any additional CMAKE_* or environment variables have been modified.
    14      To see the exact flags applied, build with the --verbose option.
    15
    16Treat compiler warnings as errors ..... OFF
    17Use ccache for compiling .............. ON
    18
    19
    20-- Configuring done (23.3s)
    21CMake Error at src/kernel/CMakeLists.txt:11 (add_library):
    22  CMake doesn't support IPO for current compiler
    23
    24
    25-- Generating done (0.1s)
    26CMake Generate step failed.  Build files cannot be regenerated correctly.
    

    However you can just call cmake --build build, and compilation “works”:

     0cmake --build build -j14 --target bitcoinkernel
     1[  0%] Generating bitcoin-build-info.h
     2[  0%] Built target secp256k1_precomputed
     3[  0%] Built target crc32c
     4[ 14%] Built target bitcoin_crypto
     5[ 14%] Built target secp256k1
     6[ 42%] Built target leveldb
     7[ 42%] Built target generate_build_info
     8[ 42%] Built target bitcoin_clientversion
     9[100%] Built target bitcoinkernel
    10
    11# file build/lib/libbitcoinkernel.a 
    12build/lib/libbitcoinkernel.a: current ar archive
    

    It would be good if when CMake errors during configuration, it’s not actually possible to continue building, rather than silently ignoring errors.

    Note that the presence of -Werror=dev when configuring, makes no difference here.

    Also, the error string CMake is throwing, is also incorrect, as the compiler does support LTO.

  2. fanquake added the label Build system on Aug 7, 2025
  3. maflcko commented at 12:39 pm on August 7, 2025: member

    in the Guix build, errors will just be silently ignored.

    I think the guix build has set -e, so it should be fine and not proceed here.

  4. hebasto commented at 12:44 pm on August 7, 2025: member

    Using current master (6a2bb0f), if you configure with the following, CMake will “Error”

    What version of CMake are you using?

  5. fanquake commented at 1:08 pm on August 7, 2025: member

    What version of CMake are you using?

    Happens with 3.28.3 & 4.0.3.

  6. fanquake commented at 1:12 pm on August 7, 2025: member

    I think the guix build has set -e, so it should be fine and not proceed here.

    Looks like this is the case, and tested the build does fail. So I guess it will just (potentially) silently ignore errors everywhere else.

  7. hebasto commented at 3:22 pm on August 7, 2025: member

    Also, the error string CMake is throwing, is also incorrect, as the compiler does support LTO.

    CMake doesn’t blame the compiler, rather itself: “CMake doesn’t support IPO for current compiler”.

    For some reason, this occurs with the “Unix Makefiles” generator but not with the “Ninja” generator.

  8. hebasto commented at 3:22 pm on August 7, 2025: member
  9. hebasto commented at 3:34 pm on August 7, 2025: member

    It seems that the $<TARGET_OBJECTS:..> added to bitcoinkernel sources in #33077 are causing the issue.

    cc @theuni

  10. purpleKarrot commented at 2:19 pm on August 12, 2025: contributor

    It is why I am against using $<TARGET_OBJECTS:..>. CMake propagates a lot of information across the edges in the build dependency graph. Extracting only the objects from a target does not create an edge and therefore a lot of necessary information is not propagated properly. Manually forwarding each individual target property is not practical either. We simply don’t know the complete set of target properties, as some of them are internal.

    We should not use $<TARGET_OBJECTS:..>, at all. We may link libraries with target_link_libraries(), which creates a proper edge in the build dependency graph. In the case of a static library with a private dependency, it means that this dependency is not as private as you might intend: There will be a link-only edge in the dependency graph.

    But as I wrote in #33077 (comment), I would like to see a proof of concept example that linking against a prebuilt static library with a custom toolchain is even possible and safe. None of the internal symbols of the kernel library are ODR protected. What happens if a client statically links against both the kernel and secp? With the information in the dependency graph that secp is a link-only dependency, version conflicts can be detected at configure time. But without that information?

  11. fanquake added this to the milestone 30.0 on Sep 2, 2025
  12. fanquake commented at 3:36 pm on September 2, 2025: member
    Put this on v30.0, because we shouldn’t ship a build system that produces errors, and then just ignores them.
  13. purpleKarrot commented at 10:07 am on September 3, 2025: contributor

    I would suggest the following changes:

    • Revert fdbade6f8ded63519b637c8fa6f39914a400ab5e
    • Install the kernel library iff it is built as a shared library.
    • Export cmake package configuration iff the kernel is built as a shared library.
    • Don’t install a .pc file for the kernel at all.

    Rationale:

    .pc files are not relocatable and only work when all packages are installed to a common prefix, which is done by package managers. Since we want to distribute our own packages, we have no way to provide .pc files that are not broken. It is better to provide no .pc files at all. We may export CMake package configurations, which don’t have this problem. We might also export experimental CPS files for consumers that don’t (want to) use CMake.

    The problem with a static kernel library is even worse, as I have explained above.

  14. ryanofsky commented at 8:02 pm on September 3, 2025: contributor

    Since we want to distribute our own packages, we have no way to provide .pc files that are not broken.

    This seems like a reason not to distribute .pc files, but it doesn’t seem like a reason not to generate them in local builds and generate them for package managers. There are other build systems besides cmake, and it seems like it would be nice if you could build and install the kernel from source or use a package manager, and build against the library in a meson project, or rust/zig/python/go project with pkgconfig.

    Maybe I am misunderstanding “Since we want to distribute our own packages” though. I’m not sure what that means exactly. If the idea is to distribute precompiled binaries with relocatable cmake modules that seems like it could be a good approach, but probably less common as a distribution mechanism?

  15. hebasto commented at 10:37 pm on September 4, 2025: member

    I agree that this issue needs to be fixed.

    However, considering:

    • the limited time left before branching off,
    • the specific conditions (e.g., -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON) under which the issue manifests,
    • the lack of consensus on how to fix it, and
    • the absence of an open PR with a suggested fix,

    I propose bumping the milestone for this PR from 30.0 to 31.0.

  16. fanquake commented at 11:50 pm on September 4, 2025: member

    the limited time left before branching off,

    I don’t see how that’s relevant. Any fix merged into master over the next few weeks can be backported to 30.x.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-09-10 18:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me