diff --git a/CMakeLists.txt b/CMakeLists.txt index 9619768c8..5c65fe381 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,13 @@ cmake_minimum_required(VERSION 3.0) + +# Directory for easier includes +# Anywhere you see include(...) you can check /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 @@ -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 /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). diff --git a/CMakeOptions.txt b/CMakeOptions.txt index db0a1a102..80fa96889 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -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?") diff --git a/cmake/BuildOptions.cmake b/cmake/BuildOptions.cmake index 0fce64292..75fac68a2 100644 --- a/cmake/BuildOptions.cmake +++ b/cmake/BuildOptions.cmake @@ -11,7 +11,7 @@ endif() # This helps support the case where emsdk toolchain file is used # either by setting it with -DCMAKE_TOOLCHAIN_FILE=/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() diff --git a/cmake/CustomPlatform.cmake b/cmake/CustomPlatform.cmake new file mode 100644 index 000000000..edfcb39db --- /dev/null +++ b/cmake/CustomPlatform.cmake @@ -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() diff --git a/cmake/LibraryConfigurations.cmake b/cmake/LibraryConfigurations.cmake index d4bf45a08..f04be6231 100644 --- a/cmake/LibraryConfigurations.cmake +++ b/cmake/LibraryConfigurations.cmake @@ -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") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4335bda5c..27acedf86 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,6 +5,7 @@ set(API_VERSION 450) include(GNUInstallDirs) include(JoinPaths) +include(CustomPlatform) # Sets build type if not set by now if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) @@ -38,7 +39,7 @@ set(raylib_sources ) # /cmake/GlfwImport.cmake handles the details around the inclusion of glfw -if (NOT ${PLATFORM} MATCHES "Web") +if (NOT ${PLATFORM} MATCHES "Web" AND NOT ${PLATFORM} MATCHES "Custom") include(GlfwImport) endif () @@ -47,6 +48,8 @@ endif () # Produces a variable LIBS_PRIVATE that will be used later include(LibraryConfigurations) +custom_platform_include_if_exists("raylibPlatformCustomLibraryConfig") + if (USE_AUDIO) MESSAGE(STATUS "Audio Backend: miniaudio") list(APPEND raylib_sources raudio.c) @@ -105,6 +108,12 @@ target_include_directories(raylib ${OPENAL_INCLUDE_DIR} ) +if("${PLATFORM}" MATCHES "Custom") + target_include_directories(raylib PUBLIC "${PLATFORM_CUSTOM_ROOT_DIR}/src") +endif() + +custom_platform_include_if_exists("raylibPlatformCustomTargetConfig") + # Copy the header files to the build directory for convenience file(COPY ${raylib_public_headers} DESTINATION "include") diff --git a/src/rcore.c b/src/rcore.c index a85b0971f..4efabda9a 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -235,7 +235,11 @@ __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigne #define FLAG_TOGGLE(n, f) ((n) ^= (f)) #define FLAG_CHECK(n, f) ((n) & (f)) -#if (defined(__linux__) || defined(PLATFORM_WEB)) && (_POSIX_C_SOURCE < 199309L) +#if defined(PLATFORM_CUSTOM) +#include "raylib_platform_custom.h" +#endif + +#if (defined(__linux__) || defined(PLATFORM_WEB) || defined(PLATFORM_CUSTOM_CLOCK_MONOTONIC)) && (_POSIX_C_SOURCE < 199309L) #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 199309L // Required for: CLOCK_MONOTONIC if compiled with c99 without gnu ext. #endif @@ -491,6 +495,8 @@ const char *TextFormat(const char *text, ...); // Formatting of tex #include "platforms/rcore_drm.c" #elif defined(PLATFORM_ANDROID) #include "platforms/rcore_android.c" +#elif defined(PLATFORM_CUSTOM) + #include "raylib_platform_custom.c" #else // TODO: Include your custom platform backend! // i.e software rendering backend or console backend! @@ -559,6 +565,8 @@ void InitWindow(int width, int height, const char *title) TRACELOG(LOG_INFO, "Platform backend: NATIVE DRM"); #elif defined(PLATFORM_ANDROID) TRACELOG(LOG_INFO, "Platform backend: ANDROID"); +#elif defined(PLATFORM_CUSTOM) + TRACELOG(LOG_INFO, PLATFORM_CUSTOM_BACKEND); #else // TODO: Include your custom platform backend! // i.e software rendering backend or console backend! @@ -3046,7 +3054,7 @@ void InitTimer(void) // However, it can also reduce overall system performance, because the thread scheduler switches tasks more often. // High resolutions can also prevent the CPU power management system from entering power-saving modes. // Setting a higher resolution does not improve the accuracy of the high-resolution performance counter. -#if defined(_WIN32) && defined(SUPPORT_WINMM_HIGHRES_TIMER) && !defined(SUPPORT_BUSY_WAIT_LOOP) && !defined(PLATFORM_DESKTOP_SDL) +#if defined(_WIN32) && defined(SUPPORT_WINMM_HIGHRES_TIMER) && !defined(SUPPORT_BUSY_WAIT_LOOP) && !defined(PLATFORM_DESKTOP_SDL) && !defined(PLATFORM_CUSTOM_DISABLE_HI_RES_TIMER) timeBeginPeriod(1); // Setup high-resolution timer to 1ms (granularity of 1-2 ms) #endif diff --git a/src/rlgl.h b/src/rlgl.h index 4b3184986..ef3f8e8ab 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -324,6 +324,10 @@ //---------------------------------------------------------------------------------- // Types and Structures Definition //---------------------------------------------------------------------------------- +#if defined(PLATFORM_CUSTOM) +#include "raylib_platform_custom.h" +#endif + #if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800) #include #elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE) @@ -818,7 +822,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad #elif defined(GRAPHICS_API_OPENGL_ES2) // NOTE: OpenGL ES 2.0 can be enabled on PLATFORM_DESKTOP, // in that case, functions are loaded from a custom glad for OpenGL ES 2.0 - #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL) + #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL) || defined(PLATFORM_CUSTOM_ENABLE_OPENGL_ES2) #define GLAD_GLES2_IMPLEMENTATION #include "external/glad_gles2.h" #else @@ -2281,7 +2285,7 @@ void rlLoadExtensions(void *loader) #elif defined(GRAPHICS_API_OPENGL_ES2) - #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL) + #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL) || defined(PLATFORM_CUSTOM_ENABLE_OPENGL_ES2) // TODO: Support GLAD loader for OpenGL ES 3.0 if (gladLoadGLES2((GLADloadfunc)loader) == 0) TRACELOG(RL_LOG_WARNING, "GLAD: Cannot load OpenGL ES2.0 functions"); else TRACELOG(RL_LOG_INFO, "GLAD: OpenGL ES 2.0 loaded successfully");