Skip to content
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

[config.h] Consider changing how defines are used in raylib to support configuration from build systems #4411

Open
planetis-m opened this issue Oct 21, 2024 · 5 comments
Labels
enhancement This is an improvement of some feature

Comments

@planetis-m
Copy link
Contributor

planetis-m commented Oct 21, 2024

Description:
Currently, raylib uses #if defined(SUPPORT_X) to conditionally enable/disable certain features like file format support. However, setting a define to 0 from the build system (e.g., -DSUPPORT_FILEFORMAT_PNG=0) doesn't actually disable the feature because the macro is still considered "defined."

This limitation makes it difficult to selectively disable certain features without manually editing config.h, especially when working with different build systems or when trying to configure raylib via command-line flags alone.

Proposed Change:
Switch the current #if defined(SUPPORT_X) checks to something like #if SUPPORT_X == 1. This would allow features to be properly toggled off by defining them as 0 from the build system.

Example:

#ifndef SUPPORT_FILEFORMAT_PNG
#define SUPPORT_FILEFORMAT_PNG 1
#endif

#if SUPPORT_FILEFORMAT_PNG
    // PNG support code
#endif

This would enable features to be turned off using -DSUPPORT_FILEFORMAT_PNG=0 in the build system, without requiring edits to the default configuration file.

Discussion Summary:
This topic was discussed on the raylib Discord server. The current method was found to be limiting for build systems that rely on command-line defines. While the change is agreed to be useful, it was also acknowledged that it's better suited for a future release after the current planned version has been completed.

@znichola
Copy link

znichola commented Oct 27, 2024

I think this could be achieved by passing the define with the -U flag to undefine it, at least this is available with gcc. Not sure how easy this would be to make portable, but it does seem like a lower impact solution.

@planetis-m
Copy link
Contributor Author

planetis-m commented Oct 27, 2024

@znichola no that won't work, we have already tried it. Here's a test you can try:

#include <stdio.h>

#ifndef EXAMPLE_OPTION
#define EXAMPLE_OPTION  1
#endif

int main(void)
{
#if EXAMPLE_OPTION == 1
    puts("option enabled");
#endif
}

@znichola
Copy link

znichola commented Oct 27, 2024

Ah yes of course I see, that's dumb of me, I was thinking from the angle of disabling flags that were added with -D (if for instance using a raylib wrapper and not wanting to modify its build script), but that is not the case with the config.h.

@sagehane
Copy link
Contributor

In regards to the current Zig build system, there's currently no way to undefine a macro so it's currently impossible to disable something like SUPPORT_FILEFORMAT_PNG.

I was thinking if it would make sense to make it so if the value of a SUPPORT macro is set to 0, it should be equivalent to not setting the value.

@Peter0x44
Copy link
Contributor

@sagehane that's exactly what this issue is about, changing all the #if defined (...) to #if will do that
There is no point to do the == 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an improvement of some feature
Projects
None yet
Development

No branches or pull requests

5 participants