Skip to content

build: Always define HAVE_SYSTEM - #36023

Open
Sjors wants to merge 1 commit into
bitcoin:masterfrom
Sjors:2026/08/have-system
Open

Sjors wants to merge 1 commit into
bitcoin:masterfrom
Sjors:2026/08/have-system

Conversation

@Sjors

@Sjors Sjors commented Aug 19, 2026 •

Copy link
Copy Markdown
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.

@DrahtBot

DrahtBot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

Reviews

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

@fanquake

Copy link
Copy Markdown
Member

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

Please don't make random changes for no reason.

@hebasto

hebasto commented Aug 19, 2026

Copy link
Copy Markdown
Member

Maybe simply revert 976b034?

@maflcko

maflcko commented Aug 19, 2026

Copy link
Copy Markdown
Member

Ref: #16419

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

@Sjors

Sjors commented Aug 19, 2026 •

Copy link
Copy Markdown
Member Author

@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.

When this feature is unavailable, #cmakedefine leaves its macro
undefined, triggering -Wundef. Use #cmakedefine01 to always generate 0
or 1.
@Sjors
Sjors force-pushed the 2026/08/have-system branch from 34a3159 to 013fffe Compare August 19, 2026 14:06
@Sjors Sjors changed the title build: Always define HAVE_SYSTEM and HAVE_FDATASYNC build: Always define HAVE_SYSTEM Aug 19, 2026
@sedited
sedited requested a review from hebasto October 2, 2026 12:53
@sedited

sedited commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

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

@hebasto

hebasto commented Nov 15, 2026

Copy link
Copy Markdown
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.

@Sjors

Sjors commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Is this concern aesthetic or technical?

Aesthetics, but in the sense that it's more clear: #if HAVE_SYSTEM reads as "if HAVE_SYSTEM is true", whereas #if defined(...) raises the question of what value it has, and whether that matters.

This only works if we consistently use cmakedefine01, ideally linter enforced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants