Skip to content

[CMake] Properly remove raudio.c and rmodels.c if they're disabled modules#5878

Merged
raysan5 merged 3 commits into
raysan5:masterfrom
NighthowlerStudios:fix-disable-raudio-cmake
May 29, 2026
Merged

[CMake] Properly remove raudio.c and rmodels.c if they're disabled modules#5878
raysan5 merged 3 commits into
raysan5:masterfrom
NighthowlerStudios:fix-disable-raudio-cmake

Conversation

@NighthowlerStudios

@NighthowlerStudios NighthowlerStudios commented May 21, 2026

Copy link
Copy Markdown
Contributor

raudio.c and rmodels.c C 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:

ifeq ($(RAYLIB_MODULE_MODELS),TRUE)
    OBJS += rmodels.o
endif

Because of those omissions of the .o tasks, these C files aren't compiled when RAYLIB_MODULE_MODELS or RAYLIB_MODULE_AUDIO are set to FALSE. This means CMake's behaviour doesn't line up with Make.

rmodels.o : rmodels.c raylib.h rlgl.h raymath.h

Now, if a developer were to attempt to use the CMake version of these omissions (SUPPORT_MODULE_RAUDIO and SUPPORT_MODULE_RMODELS) and set them to 0 (OFF), the C files still get included. This is because the CMake is still putting them on the project by force.

# Sources to be compiled
set(raylib_sources
    raudio.c                    <<< different from Makefile
    rcore.c
    rmodels.c                 <<< different from Makefile
    rshapes.c
    rtext.c
    rtextures.c
    )

This PR adds logic to omit those C files if the SUPPORT_MODULE_RAUDIO or SUPPORT_MODULE_RMODELS flags 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

Comment thread src/CMakeLists.txt
@raysan5
raysan5 merged commit 186d3ce into raysan5:master May 29, 2026
16 checks passed
@raysan5

raysan5 commented May 29, 2026

Copy link
Copy Markdown
Owner

@NighthowlerStudios thanks for the improvement and @RobLoach thanks for the review!

@NighthowlerStudios
NighthowlerStudios deleted the fix-disable-raudio-cmake branch June 18, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants