[CMake] Properly remove raudio.c and rmodels.c if they're disabled modules#5878
Merged
raysan5 merged 3 commits intoMay 29, 2026
Merged
Conversation
RobLoach
suggested changes
May 26, 2026
RobLoach
approved these changes
May 29, 2026
Owner
|
@NighthowlerStudios thanks for the improvement and @RobLoach thanks for the review! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
raudio.candrmodels.cC files are still being built by raylib's CMake even if the module is disabled.After further investigation I discovered that the Makefile (using make), already takes these removals into account. Line 756 of src/Makefile:
Because of those omissions of the
.otasks, these C files aren't compiled whenRAYLIB_MODULE_MODELSorRAYLIB_MODULE_AUDIOare set toFALSE. This means CMake's behaviour doesn't line up with Make.raylib/src/Makefile
Line 867 in 0d78f10
Now, if a developer were to attempt to use the CMake version of these omissions (
SUPPORT_MODULE_RAUDIOandSUPPORT_MODULE_RMODELS) and set them to0(OFF), the C files still get included. This is because the CMake is still putting them on the project by force.This PR adds logic to omit those C files if the
SUPPORT_MODULE_RAUDIOorSUPPORT_MODULE_RMODELSflags on CMake configure were disabled. This makes the logic inline with what the other Makefiles are doing.This makes it easier on devs who want to use Raylib's CMake directly instead of writing their own CMake from scratch that rips apart C files, if it makes sense for them on their platform.
Whilst this is not useful for debloating the libraylib.a output (gcc already strips away enough that the compile size difference is a mere few hundred bytes)...
What it is useful for is getting rid of compiler errors thrown by rmodels.c or raudio.c if you don't include certain libraries (file system related) on your platform target (such as embedded pico or esp32), even though you told CMake to not use those two files in the first place via
SUPPORT_MODULE_XXX