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

Introduce a way to add a 100% external custom platform #3594

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
cmake_minimum_required(VERSION 3.0)

# Directory for easier includes
# Anywhere you see include(...) you can check <root>/cmake for that file
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

include(CustomPlatform)

custom_platform_include_if_exists("raylibPlatformCustomProjectConfig")

project(raylib)

# Avoid excessive expansion of variables in conditionals. In particular, if
Expand All @@ -18,9 +27,6 @@ cmake_policy(SET CMP0054 NEW)
# See https://cmake.org/cmake/help/latest/policy/CMP0063.html
cmake_policy(SET CMP0063 NEW)

# Directory for easier includes
# Anywhere you see include(...) you can check <root>/cmake for that file
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# RAYLIB_IS_MAIN determines whether the project is being used from root
# or if it is added as a dependency (through add_subdirectory for example).
Expand Down
2 changes: 1 addition & 1 deletion CMakeOptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
include(CMakeDependentOption)
include(EnumOption)

enum_option(PLATFORM "Desktop;Web;Android;Raspberry Pi;DRM" "Platform to build for.")
enum_option(PLATFORM "Desktop;Web;Android;Raspberry Pi;DRM;Custom" "Platform to build for.")

enum_option(OPENGL_VERSION "OFF;4.3;3.3;2.1;1.1;ES 2.0;ES 3.0" "Force a specific OpenGL Version?")

Expand Down
2 changes: 1 addition & 1 deletion cmake/BuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif()
# This helps support the case where emsdk toolchain file is used
# either by setting it with -DCMAKE_TOOLCHAIN_FILE=<path_to_emsdk>/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
# or by using "emcmake cmake -B build -S ." as described in https://emscripten.org/docs/compiling/Building-Projects.html
if(EMSCRIPTEN)
if(EMSCRIPTEN AND NOT ${PLATFORM} MATCHES "Custom")
SET(PLATFORM Web CACHE STRING "Forcing PLATFORM_WEB because EMSCRIPTEN was detected")
endif()

Expand Down
9 changes: 9 additions & 0 deletions cmake/CustomPlatform.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
macro(custom_platform_include_if_exists file)
if("${PLATFORM}" MATCHES "Custom")
if (EXISTS "${PLATFORM_CUSTOM_ROOT_DIR}/cmake/${file}.cmake")
include("${PLATFORM_CUSTOM_ROOT_DIR}/cmake/${file}.cmake")
else ()
message(STATUS "No file ${PLATFORM_CUSTOM_ROOT_DIR}/cmake/${file}.cmake detected... skipped")
endif ()
endif()
endmacro()
2 changes: 2 additions & 0 deletions cmake/LibraryConfigurations.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ elseif ("${PLATFORM}" MATCHES "DRM")
endif ()
set(LIBS_PRIVATE ${GLESV2} ${EGL} ${DRM} ${GBM} atomic pthread m dl)

elseif ("${PLATFORM}" MATCHES "Custom")
set(PLATFORM_CPP "PLATFORM_CUSTOM")
endif ()

if (NOT ${OPENGL_VERSION} MATCHES "OFF")
Expand Down
26 changes: 26 additions & 0 deletions external/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
For the sake of this PR, this folder was added to demonstrate what a custom platform look like as well
as how to use a custom platform

* `custom_platforms/custom_platform_1`: clone of the web platform
* `custom_platforms/custom_platform_2`: clone of the desktop platform


* `examples/example_for_custom_platform_1`: example using the custom_platform_1

How to build (use emscripten since it is a web platform: make sure you use the proper locations)
```text
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=/usr/local/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DEMSDK=/usr/local/emsdk -DPLATFORM=Custom -DCMAKE_BUILD_TYPE=Debug ..
cmake --build . --target example_for_custom_platform_1
```

* `examples/example_for_custom_platform_2`: example using the custom_platform_2

How to build:
```text
mkdir build
cd build
cmake -DPLATFORM=Custom -DCMAKE_BUILD_TYPE=Debug ..
cmake --build . --target example_for_custom_platform_2
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
message(STATUS "From raylibPlatformCustomLibraryConfig (Custom platform 1 (Web)")

set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 --profiling")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message(STATUS "From raylibPlatformCustomTargetConfig (Custom platform 1 (Web)")

target_link_options(raylib PRIVATE "-sUSE_GLFW=3")
Loading