handle custom platform
This commit is contained in:
parent
0748dc2d1e
commit
30ccc969de
13 changed files with 3514 additions and 10 deletions
26
external/README.md
vendored
Normal file
26
external/README.md
vendored
Normal file
|
|
@ -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
|
||||
```
|
||||
5
external/custom_platforms/custom_platform_1/cmake/raylibPlatformCustomLibraryConfig.cmake
vendored
Normal file
5
external/custom_platforms/custom_platform_1/cmake/raylibPlatformCustomLibraryConfig.cmake
vendored
Normal file
|
|
@ -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")
|
||||
3
external/custom_platforms/custom_platform_1/cmake/raylibPlatformCustomTargetConfig.cmake
vendored
Normal file
3
external/custom_platforms/custom_platform_1/cmake/raylibPlatformCustomTargetConfig.cmake
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
message(STATUS "From raylibPlatformCustomTargetConfig (Custom platform 1 (Web)")
|
||||
|
||||
target_link_options(raylib PRIVATE "-sUSE_GLFW=3")
|
||||
1319
external/custom_platforms/custom_platform_1/src/raylib_platform_custom.c
vendored
Normal file
1319
external/custom_platforms/custom_platform_1/src/raylib_platform_custom.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
36
external/custom_platforms/custom_platform_1/src/raylib_platform_custom.h
vendored
Normal file
36
external/custom_platforms/custom_platform_1/src/raylib_platform_custom.h
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*******************************************************************************************
|
||||
* raylib_platform_custom.h
|
||||
*
|
||||
* Custom Platform definition file
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2023 Yan Pujante
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
* as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#ifndef RAYLIB_PLATFORM_CUSTOM_H
|
||||
#define RAYLIB_PLATFORM_CUSTOM_H
|
||||
|
||||
#define PLATFORM_CUSTOM_ID "platform_custom_1"
|
||||
#define PLATFORM_CUSTOM_BACKEND "Platform backend: Custom Platform 1 (Web clone)"
|
||||
#define PLATFORM_CUSTOM_CLOCK_MONOTONIC
|
||||
// #define PLATFORM_CUSTOM_DISABLE_HI_RES_TIMER
|
||||
// #define PLATFORM_CUSTOM_ENABLE_OPENGL_ES2
|
||||
|
||||
#endif //RAYLIB_PLATFORM_CUSTOM_H
|
||||
70
external/custom_platforms/custom_platform_2/cmake/raylibPlatformCustomLibraryConfig.cmake
vendored
Normal file
70
external/custom_platforms/custom_platform_2/cmake/raylibPlatformCustomLibraryConfig.cmake
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
message(STATUS "From aylibPlatformCustomLibraryConfig (Custom platform 2 (Desktop)")
|
||||
|
||||
if (APPLE)
|
||||
# Need to force OpenGL 3.3 on OS X
|
||||
# See: https://github.com/raysan5/raylib/issues/341
|
||||
set(GRAPHICS "GRAPHICS_API_OPENGL_33")
|
||||
find_library(OPENGL_LIBRARY OpenGL)
|
||||
set(LIBS_PRIVATE ${OPENGL_LIBRARY})
|
||||
link_libraries("${LIBS_PRIVATE}")
|
||||
if (NOT CMAKE_SYSTEM STRLESS "Darwin-18.0.0")
|
||||
add_definitions(-DGL_SILENCE_DEPRECATION)
|
||||
MESSAGE(AUTHOR_WARNING "OpenGL is deprecated starting with macOS 10.14 (Mojave)!")
|
||||
endif ()
|
||||
elseif (WIN32)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
find_package(OpenGL QUIET)
|
||||
set(LIBS_PRIVATE ${OPENGL_LIBRARIES} winmm)
|
||||
elseif (UNIX)
|
||||
find_library(pthread NAMES pthread)
|
||||
find_package(OpenGL QUIET)
|
||||
if ("${OPENGL_LIBRARIES}" STREQUAL "")
|
||||
set(OPENGL_LIBRARIES "GL")
|
||||
endif ()
|
||||
|
||||
if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD")
|
||||
find_library(OSS_LIBRARY ossaudio)
|
||||
endif ()
|
||||
|
||||
set(LIBS_PRIVATE m pthread ${OPENGL_LIBRARIES} ${OSS_LIBRARY})
|
||||
else ()
|
||||
find_library(pthread NAMES pthread)
|
||||
find_package(OpenGL QUIET)
|
||||
if ("${OPENGL_LIBRARIES}" STREQUAL "")
|
||||
set(OPENGL_LIBRARIES "GL")
|
||||
endif ()
|
||||
|
||||
set(LIBS_PRIVATE m atomic pthread ${OPENGL_LIBRARIES} ${OSS_LIBRARY})
|
||||
|
||||
if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD")
|
||||
find_library(OSS_LIBRARY ossaudio)
|
||||
set(LIBS_PRIVATE m pthread ${OPENGL_LIBRARIES} ${OSS_LIBRARY})
|
||||
endif ()
|
||||
|
||||
if (NOT "${CMAKE_SYSTEM_NAME}" MATCHES "(Net|Open)BSD" AND USE_AUDIO)
|
||||
set(LIBS_PRIVATE ${LIBS_PRIVATE} dl)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if("${GLFW_ROOT_DIR}" STREQUAL "")
|
||||
message(FATAL_ERROR "This platform requires glfw. Provide its location via GLFW_ROOT_DIR")
|
||||
endif()
|
||||
|
||||
message(STATUS "Using glfw from ${GLFW_ROOT_DIR}")
|
||||
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_USE_WAYLAND ${USE_WAYLAND} CACHE BOOL "" FORCE)
|
||||
set(GLFW_LIBRARY_TYPE "STATIC" CACHE STRING "" FORCE)
|
||||
|
||||
add_subdirectory("${GLFW_ROOT_DIR}")
|
||||
|
||||
# Hide glfw's symbols when building a shared lib
|
||||
if (BUILD_SHARED_LIBS)
|
||||
set_property(TARGET glfw PROPERTY C_VISIBILITY_PRESET hidden)
|
||||
endif()
|
||||
|
||||
include_directories(BEFORE SYSTEM "${GLFW_ROOT_DIR}/include")
|
||||
|
||||
set(LIBS_PRIVATE ${LIBS_PRIVATE} glfw)
|
||||
12
external/custom_platforms/custom_platform_2/cmake/raylibPlatformCustomProjectConfig.cmake
vendored
Normal file
12
external/custom_platforms/custom_platform_2/cmake/raylibPlatformCustomProjectConfig.cmake
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
message(STATUS "From raylibPlatformCustomProjectConfig (Custom platform 2 (Desktop)")
|
||||
|
||||
# Note that changing CMAKE_OSX_ARCHITECTURES should be done BEFORE project()
|
||||
if(APPLE)
|
||||
if(MACOS_FATLIB)
|
||||
if (CMAKE_OSX_ARCHITECTURES)
|
||||
message(FATAL_ERROR "User supplied -DCMAKE_OSX_ARCHITECTURES overrides -DMACOS_FATLIB=ON")
|
||||
else()
|
||||
set(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
1830
external/custom_platforms/custom_platform_2/src/raylib_platform_custom.c
vendored
Normal file
1830
external/custom_platforms/custom_platform_2/src/raylib_platform_custom.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
36
external/custom_platforms/custom_platform_2/src/raylib_platform_custom.h
vendored
Normal file
36
external/custom_platforms/custom_platform_2/src/raylib_platform_custom.h
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*******************************************************************************************
|
||||
* raylib_platform_custom.h
|
||||
*
|
||||
* Custom Platform definition file
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2023 Yan Pujante
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
* as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#ifndef RAYLIB_PLATFORM_CUSTOM_H
|
||||
#define RAYLIB_PLATFORM_CUSTOM_H
|
||||
|
||||
#define PLATFORM_CUSTOM_ID "platform_custom_2"
|
||||
#define PLATFORM_CUSTOM_BACKEND "Platform backend: Custom Platform 2 (Desktop clone)"
|
||||
// #define PLATFORM_CUSTOM_CLOCK_MONOTONIC
|
||||
// #define PLATFORM_CUSTOM_DISABLE_HI_RES_TIMER
|
||||
#define PLATFORM_CUSTOM_ENABLE_OPENGL_ES2
|
||||
|
||||
#endif //RAYLIB_PLATFORM_CUSTOM_H
|
||||
38
external/examples/example_for_custom_platform_1/CMakeLists.txt
vendored
Normal file
38
external/examples/example_for_custom_platform_1/CMakeLists.txt
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
# This should be absolute to where raylib lives
|
||||
set(RAYLIB_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../../..")
|
||||
|
||||
if(PLATFORM STREQUAL "Custom")
|
||||
set(PLATFORM_CUSTOM_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../../custom_platforms/custom_platform_1")
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --profiling-funcs -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY -s SAFE_HEAP=1")
|
||||
endif()
|
||||
|
||||
project(example_for_custom_platform_1 LANGUAGES CXX)
|
||||
|
||||
set(target "example_for_custom_platform_1")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
#######################################################
|
||||
# adding raylib
|
||||
# Note: raylib is bundled in this project but could
|
||||
# easily be fetched instead
|
||||
#######################################################
|
||||
add_subdirectory("${RAYLIB_ROOT_DIR}" raylib EXCLUDE_FROM_ALL)
|
||||
|
||||
#######################################################
|
||||
# Main executable
|
||||
#######################################################
|
||||
add_executable(${target} main.cpp)
|
||||
target_link_libraries(${target} PUBLIC raylib)
|
||||
|
||||
if(PLATFORM STREQUAL "Custom")
|
||||
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||
set(EMSDK "$ENV{EMSDK}" CACHE PATH "Location of the emscript sdk")
|
||||
if("${EMSDK}" STREQUAL "")
|
||||
message(FATAL_ERROR "Make sure you define the variable EMSDK (either as an environment variable or as a CMake -DEMSDK=... option).")
|
||||
endif()
|
||||
target_include_directories(${target} PUBLIC "${EMSDK}/emscripten/main/cache/sysroot/include")
|
||||
endif()
|
||||
28
external/examples/example_for_custom_platform_1/main.cpp
vendored
Normal file
28
external/examples/example_for_custom_platform_1/main.cpp
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "raylib.h"
|
||||
|
||||
static char BUF[1024];
|
||||
|
||||
int main()
|
||||
{
|
||||
double width = 850;
|
||||
double height = 450;
|
||||
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
InitWindow((int) width, (int) height, "raylib custom platform 1 (web)");
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawText("Congrats! You created your first window!", 10, 40, 20, LIGHTGRAY);
|
||||
DrawLine(0, 0, GetScreenWidth(), GetScreenHeight(), RED);
|
||||
DrawFPS(10, 70);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
}
|
||||
30
external/examples/example_for_custom_platform_2/CMakeLists.txt
vendored
Normal file
30
external/examples/example_for_custom_platform_2/CMakeLists.txt
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
# This should be absolute to where raylib lives
|
||||
set(RAYLIB_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../../..")
|
||||
|
||||
if(PLATFORM STREQUAL "Custom")
|
||||
# custom_platform_2 requires GLFW_ROOT_DIR to be set
|
||||
set(GLFW_ROOT_DIR "${RAYLIB_ROOT_DIR}/src/external/glfw")
|
||||
set(PLATFORM_CUSTOM_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../../custom_platforms/custom_platform_2")
|
||||
endif()
|
||||
|
||||
project(example_for_custom_platform_2 LANGUAGES CXX)
|
||||
|
||||
set(target "example_for_custom_platform_2")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
#######################################################
|
||||
# adding raylib
|
||||
# Note: raylib is bundled in this project but could
|
||||
# easily be fetched instead
|
||||
#######################################################
|
||||
add_subdirectory("${RAYLIB_ROOT_DIR}" raylib EXCLUDE_FROM_ALL)
|
||||
|
||||
#######################################################
|
||||
# Main executable
|
||||
#######################################################
|
||||
add_executable(${target} main.cpp)
|
||||
target_link_libraries(${target} PUBLIC raylib)
|
||||
|
||||
28
external/examples/example_for_custom_platform_2/main.cpp
vendored
Normal file
28
external/examples/example_for_custom_platform_2/main.cpp
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "raylib.h"
|
||||
|
||||
static char BUF[1024];
|
||||
|
||||
int main()
|
||||
{
|
||||
double width = 850;
|
||||
double height = 450;
|
||||
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
InitWindow((int) width, (int) height, "raylib custom platform 1 (web)");
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawText("Congrats! You created your first window!", 10, 40, 20, LIGHTGRAY);
|
||||
DrawLine(0, 0, GetScreenWidth(), GetScreenHeight(), RED);
|
||||
DrawFPS(10, 70);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in a new issue