build: Always define HAVE_SYSTEM #36023

pull Sjors wants to merge 1 commits into bitcoin:master from Sjors:2026/08/have-system changing 1 files +1 −1
  1. Sjors commented at 1:26 PM on August 19, 2026: member

    When this feature is unavailable, #cmakedefine leaves its macro undefined, triggering -Wundef. I noticed this while building the kernel for iOs.

    Use #cmakedefine01 to always generate 0 or 1.

  2. DrahtBot added the label Build system on Aug 19, 2026
  3. DrahtBot commented at 1:26 PM on August 19, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. fanquake commented at 1:35 PM on August 19, 2026: member

    I haven't observed HAVE_FDATASYNC myself, but applied the same change anyway.

    Please don't make random changes for no reason.

  5. hebasto commented at 1:36 PM on August 19, 2026: member

    Maybe simply revert 976b034b13d28877aee641833d5ee28a8cc5d83f?

  6. maflcko commented at 1:46 PM on August 19, 2026: member

    Ref: #16419

    Can we not use a single style and enforce it with a linter, similar to the lint_includes_build_config one?

  7. Sjors force-pushed on Aug 19, 2026
  8. DrahtBot added the label CI failed on Aug 19, 2026
  9. Sjors commented at 2:04 PM on August 19, 2026: member

    @fanquake I dropped HAVE_FDATASYNC. It was deliberately made this way in #19803 for some reason. @hebasto using #if defined(HAVE_SYSTEM) looks ugly imo, but it also risks someone using #if HAVE_SYSTEM accidentally.

  10. build: Always define HAVE_SYSTEM
    When this feature is unavailable, #cmakedefine leaves its macro
    undefined, triggering -Wundef. Use #cmakedefine01 to always generate 0
    or 1.
    013fffe371
  11. Sjors force-pushed on Aug 19, 2026
  12. Sjors renamed this:
    build: Always define HAVE_SYSTEM and HAVE_FDATASYNC
    build: Always define HAVE_SYSTEM
    on Aug 19, 2026
  13. DrahtBot removed the label CI failed on Aug 19, 2026
  14. sedited requested review from hebasto on Oct 2, 2026
  15. sedited commented at 8:03 PM on November 6, 2026: contributor

    The change seems fine to me, but it would be nice to be consistent across these definitions.

  16. hebasto commented at 4:03 PM on November 15, 2026: member

    using #if defined(HAVE_SYSTEM) looks ugly imo...

    Is this concern aesthetic or technical?

    However, I agree that using #if defined(...) poses a problem. We can't spot a typo in the macro name, for example #if defined(HAVE_SUSTEM). Also see #36874.

    ... but it also risks someone using #if HAVE_SYSTEM accidentally.

    In this case, it does not change behavior when bitcoin-build-config.h contains #define HAVE_SYSTEM 1. And it will trigger -Wundef when the macro is undefined.

    The problem of detecting misused directives in the source code remains for #cmakedefine01 as well. Perhaps this is a task for the linter.

    Can we not use a single style...

    ... it would be nice to be consistent across these definitions.

    The current usage is not uniform either. For example, here are the different patterns for configuration macro definitions:

    1. #define HAVE_FOO or undefined -- is not used.
    2. #define HAVE_FOO 1 or undefined:
    $ git grep '#cmakedefine ' -- cmake/bitcoin-build-config.h.in | wc -l
    18
    
    1. #define HAVE_FOO 1 or #define HAVE_FOO 0:
    $ git grep '#cmakedefine01' -- cmake/bitcoin-build-config.h.in | wc -l
    4
    

    Use #cmakedefine01 to always generate 0 or 1.

    This approach gives us free protection against a misspelled macro name, which will trigger the -Wundef compiler warning.

    Here are some useful external resources:


    Bottom line: I agree with this PR change. I'd really like to see here a new linter check that prevents accidental misuse of #ifdef, #ifndef or defined() for configuration macros set via #cmakedefine01.


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: 2026-11-21 11:51 UTC

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