raysan5 / raylib

A simple and easy-to-use library to enjoy videogames programming
http://www.raylib.com
zlib License
22.51k stars 2.26k forks source link

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

Open planetis-m opened 2 weeks ago

planetis-m commented 2 weeks ago

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 commented 1 week ago

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 commented 1 week ago

@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 commented 1 week ago

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.