Introduce a way to add a 100% external custom platform / CMake #3596
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.
Let me start with a few things (in order to avoid misunderstanding):
The purpose of this PR is to implement a way for raylib to support platforms that are NOT embedded in raylib and as a result not maintained by @raysan5.
Goals (that I believe I have achieved with this PR)
After looking at the source code, I believe there are 2 areas where there needs to be "hooks" for a platform to reside outside raylib:
The overall approach that I took is the following: use conventions as much as possible so that it is easy both from the user of the platform and the developer of the platform to integrate with raylib.
The "only" required pieces of information that raylib needs are:
PLATFORM_CUSTOM_ROOT_DIR
variable.The custom platform looks like this (by convention):
cmake/raylibPlatformCustomProjectConfig.cmake
: optional and contain cmake definitions that needs to happen beforeproject()
is invokedcmake/raylibPlatformCustomLibraryConfig.cmake
: optional and contain cmake definitions of libraries and generic option (like settingCMAKE_STATIC_LIBRARY_SUFFIX
)cmake/raylibPlatformCustomTargetConfig.cmake
: optional and contain cmake definitions that applies on theraylib
target (ex:target_link_options(raylib PRIVATE "-sUSE_GLFW=3")
)src/raylib_platform_custom.c
is the implementation of the platform that gets included inrcore.c
(similar toplatforms/rcore_desktop.c
)src/raylib_platform_custom.h
is a new header file containing several definitions that are used in the codeLet me give an example of the last one: in rlgl.h there is this code:
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL)
so I changed it to
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL) || defined(PLATFORM_CUSTOM_ENABLE_OPENGL_ES2)
and
PLATFORM_CUSTOM_ENABLE_OPENGL_ES2
is a define that needs to be defined (or not) in thesrc/raylib_platform_custom.h
The name
PLATFORM_CUSTOM_ENABLE_OPENGL_ES2
as well as the other entries in this file have been inferred by what the#if
is supposed to mean but not knowing the code, that was my best bet.I understand this is a lot (to explain, but in the end not a lot of changes!)
I have another branch that you can checkout/clone which demonstrates 2 custom platforms and 2 examples of how to use them under the external folder.
As you will see the 2 custom platforms are simply clones of 2 built-in ones, but they get used as a custom/external platform, NOT a built-in one.
The PR in its current state, is fully functional. But obviously I am open to feedback and proposed changes, especially when it comes to naming and conventions. As stated previously, it works with CMake only.