cmake: Check user-defined APPEND_*FLAGS variables early #32367

pull hebasto wants to merge 3 commits into bitcoin:master from hebasto:250428-enable-lang changing 4 files +56 −20
  1. hebasto commented at 4:35 pm on April 28, 2025: member

    For the purpose of checks performed by the build system, we strive to handle user-defined APPEND_*FLAGS in the same way as flags provided by other standard means. In particular, they are considered when the try_compile() command is used.

    However, these flags are not considered during enable_language() command invocation due to design limitations, which might cause issues, such as #32323.

    This PR addresses the issue by introducing an additional compiler check that does consider the user-defined APPEND_*FLAGS.

    Fixes #32323:

     0$ cmake -B build -DAPPEND_CXXFLAGS="-ftrivial-auto-var-init"
     1-- The CXX compiler identification is GNU 14.2.0
     2-- Detecting CXX compiler ABI info
     3-- Detecting CXX compiler ABI info - done
     4-- Check for working CXX compiler: /usr/bin/c++ - skipped
     5-- Detecting CXX compile features
     6-- Detecting CXX compile features - done
     7-- Performing Test CXX_COMPILER_WORKS
     8-- Performing Test CXX_COMPILER_WORKS - Failed
     9CMake Error at cmake/module/EnableLanguage.cmake:42 (message):
    10  The CXX compiler is not able to compile a simple test program.
    11
    12  Check that the "APPEND_*FLAGS" variables are set correctly.
    13
    14
    15
    16Call Stack (most recent call first):
    17  CMakeLists.txt:71 (bitcoincore_enable_language)
    18
    19
    20-- Configuring incomplete, errors occurred!
    21hebasto@TS-P340:~/dev/bitcoin$ cmake -B build -DAPPEND_CXXFLAGS="-ftrivial-auto-var-init=zero"
    22-- Performing Test CXX_COMPILER_WORKS
    23-- Performing Test CXX_COMPILER_WORKS - Success
    24...
    
  2. cmake: Wrap `enable_language()` command in macro
    This change introduces the `bitcoincore_enable_language()` macro to wrap
    CMake’s `enable_language()` command, applying Bitcoin Core-specific
    settings and checks.
    6d55894a02
  3. cmake: Move `APPEND_*` variables logic to `bitcoincore_enable_language`
    This change is required for the following commit.
    8287a7670b
  4. hebasto added the label Build system on Apr 28, 2025
  5. DrahtBot commented at 4:35 pm on April 28, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32367.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK janb84

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #32865 (cmake: Use AUTHOR_WARNING for warnings by fanquake)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  6. hebasto marked this as a draft on Apr 28, 2025
  7. hebasto force-pushed on Apr 28, 2025
  8. hebasto marked this as ready for review on Apr 28, 2025
  9. cmake: Check user-defined `APPEND_*` variables early
    This change improves usability in cases where the user provides
    `APPEND_*` variables that are incompatible with the compiler for some
    reason.
    eb2a943504
  10. hebasto force-pushed on Apr 28, 2025
  11. janb84 commented at 9:16 am on April 29, 2025: contributor

    ACK eb2a943

    • PR fixes #32323 (reproduced on main, checked it was solved by this PR) ✅
    • Code review looks good to me. Adds a new macro with additional checks and some optimisations.✅ (There is one reference to enable_languages() in secp256k1 but that is separate and not relevant to this PR )

    Main:

    Configure with faulty flag: cmake -B build -DAPPEND_CXXFLAGS="-ftrivial-auto-var-init"

    expected config BREAK

    Configure with correct flag: cmake -B build -DAPPEND_CXXFLAGS="-ftrivial-auto-var-init=zero" not expected: STILL BREAKS

    This PR:

    Configure with faulty flag cmake -B build -DAPPEND_CXXFLAGS="-ftrivial-auto-var-init" expected BREAK

    Configure with correct flag cmake -B build -DAPPEND_CXXFLAGS="-ftrivial-auto-var-init=zero" config WORKS


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-07-06 21:13 UTC

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