Skip to content

Commit

Permalink
add PLATFORM_NX
Browse files Browse the repository at this point in the history
  • Loading branch information
savaughn committed Dec 21, 2024
1 parent 0212ed0 commit 34de408
Show file tree
Hide file tree
Showing 11 changed files with 1,758 additions and 3 deletions.
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;SDL" "Platform to build for.")
enum_option(PLATFORM "Desktop;Web;Android;Raspberry Pi;DRM;SDL;NX" "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
19 changes: 19 additions & 0 deletions cmake/LibraryConfigurations.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ elseif ("${PLATFORM}" MATCHES "SDL")
set(PLATFORM_CPP "PLATFORM_DESKTOP_SDL")
set(LIBS_PRIVATE SDL2::SDL2)

elseif ("${PLATFORM}" MATCHES "NX")
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(PLATFORM_CPP "PLATFORM_NX")
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")

add_definitions(-DEGL_NO_X11)
add_definitions(-DPLATFORM_NX)

find_library(GLESV2 GLESv2)
find_library(EGL EGL)
find_library(DRM drm_nouveau)
find_library(GLAPI glapi)
find_library(LIBNX nx)

include_directories(${DEVKITPRO}/libnx/include/ ${DEVKITPRO}/portlibs/switch/include/)

set(LIBS_PRIVATE ${EGL} ${GLESV2} ${GLAPI} ${DRM} ${LIBNX} pthread m stdc++)
link_libraries("${LIBS_PRIVATE}")

endif ()

if (NOT ${OPENGL_VERSION} MATCHES "OFF")
Expand Down
53 changes: 52 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ ifeq ($(TARGET_PLATFORM),PLATFORM_DRM)
PLATFORM_OS = LINUX
endif
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
UNAMEOS = $(shell uname)
ifeq ($(UNAMEOS),Linux)
PLATFORM_OS = LINUX
endif
RAYLIB_LIBTYPE = STATIC
USE_EXTERNAL_GLFW = TRUE
endif

# RAYLIB_PATH adjustment for LINUX platform
# TODO: Do we really need this?
Expand Down Expand Up @@ -172,6 +180,11 @@ ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_R
endif
endif

ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
RAYLIB_PREFIX ?= ..
RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX))
endif

# Define default C compiler: CC
#------------------------------------------------------------------------------------------------
CC = gcc
Expand All @@ -192,6 +205,12 @@ ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_R
# to use emscripten.h and emscripten_set_main_loop()
CC = emcc
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
include $(DEVKITPRO)/libnx/switch_rules
endif

# Define default make program: MAKE
#------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -275,6 +294,12 @@ endif
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external $(EXTRA_INCLUDE_PATHS)
# Define additional directories containing required header files

# Define additional directories containing required header files
ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
LIBDIRS := $(PORTLIBS) $(LIBNX)
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
CFLAGS += -ffunction-sections $(ARCH) $(foreach dir,$(LIBDIRS),-I$(dir)/include) -D__SWITCH__
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
ifeq ($(PLATFORM_OS),BSD)
INCLUDE_PATHS += -I$(RAYLIB_INCLUDE_PATH) -I/usr/pkg/include -I/usr/X11R7/include
Expand Down Expand Up @@ -376,6 +401,10 @@ ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_R

endif

ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
LDFLAGS += -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$*.map $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
endif

# Define libraries required on linking: LDLIBS
# NOTE: To link libraries (lib<name>.so or lib<name>.a), use -l<name>
#------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -491,6 +520,9 @@ ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_R
# Libraries for web (HTML5) compiling
LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.web.a
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
LDLIBS = -lraylib -lEGL -lGLESv2 -lglapi -ldrm_nouveau -lnx -lm
endif

# Define source code object files required
#------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -655,12 +687,14 @@ AUDIO = \
audio/audio_sound_multi \
audio/audio_stream_effects

ifneq ($(TARGET_PLATFORM),PLATFORM_NX)
OTHERS = \
others/easings_testbed \
others/embedded_files_loading \
others/raylib_opengl_interop \
others/raymath_vector_angle \
others/rlgl_compute_shader
endif

ifeq ($(TARGET_PLATFORM), PLATFORM_DESKTOP_GFLW)
OTHERS += others/rlgl_standalone
Expand Down Expand Up @@ -690,6 +724,12 @@ ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
$(MAKE) -f Makefile.Android PROJECT_NAME=$@ PROJECT_SOURCE_FILES=$<
else ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_RGFW))
$(MAKE) -f Makefile.Web $@
else ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
$(CC) -MMD -MP -MF [email protected] -o [email protected] -c $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(TARGET_PLATFORM)
$(CXX) [email protected] $(LDFLAGS) $(LDLIBS) -o [email protected] -D$(TARGET_PLATFORM)
$(NM) -CSn [email protected] > [email protected]
nacptool --create "$(notdir $@)" "Raylib Example" "1.0.0" [email protected]
elf2nro [email protected] [email protected] --icon=textures/resources/raylib_logo.jpg [email protected]
else
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -D$(TARGET_PLATFORM)
endif
Expand Down Expand Up @@ -724,4 +764,15 @@ ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_R
rm -f */*.wasm */*.html */*.js */*.data
endif
endif
@echo Cleaning done
ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
find . -type f \( \
-name "*.o" -o \
-name "*.d" -o \
-name "*.elf" -o \
-name "*.lst" -o \
-name "*.map" -o \
-name "*.nacp" -o \
-name "*.nro" \) -delete
rm -fv *.o
endif
@echo Cleaning done
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ if (NOT ${PLATFORM} MATCHES "Web")
include(GlfwImport)
endif ()

if(${PLATFORM} MATCHES "NX")
include_directories(BEFORE SYSTEM switch-nx)
endif()

# Sets additional platform options and link libraries for each platform
# also selects the proper graphics API and version for that platform
# Produces a variable LIBS_PRIVATE that will be used later
Expand Down
39 changes: 38 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
# - Linux DRM subsystem (KMS mode)
# > PLATFORM_ANDROID:
# - Android (ARM, ARM64)
# > PLATFORM_NX:
# - Switch (LibNX)
#
# Many thanks to Milan Nikolic (@gen2brain) for implementing Android platform pipeline.
# Many thanks to Emanuele Petriglia for his contribution on GNU/Linux pipeline.
Expand Down Expand Up @@ -177,6 +179,13 @@ ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_R
ifndef PLATFORM_SHELL
PLATFORM_SHELL = sh
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
UNAMEOS = $(shell uname)
ifeq ($(UNAMEOS),Linux)
PLATFORM_OS = LINUX
endif
RAYLIB_LIBTYPE = STATIC
endif
endif
endif

Expand Down Expand Up @@ -263,6 +272,9 @@ ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
# By default use OpenGL ES 2.0 on Android
GRAPHICS = GRAPHICS_API_OPENGL_ES2
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
GRAPHICS = GRAPHICS_API_OPENGL_ES2
endif

# Define default C compiler and archiver to pack library: CC, AR
#------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -310,6 +322,12 @@ ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
# It seems from Android NDK r22 onwards we need to use llvm-ar
AR = $(ANDROID_TOOLCHAIN)/bin/llvm-ar
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
include $(DEVKITPRO)/libnx/switch_rules
endif

# Define compiler flags: CFLAGS
#------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -356,6 +374,9 @@ ifeq ($(RAYLIB_BUILD_MODE),RELEASE)
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
CFLAGS += -O2
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
CFLAGS += -O2
endif
endif

# Additional flags for compiler (if desired)
Expand Down Expand Up @@ -465,6 +486,11 @@ CFLAGS += $(CUSTOM_CFLAGS)
INCLUDE_PATHS = -I. $(EXTRA_INCLUDE_PATHS)

# Define additional directories containing required header files
ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
LIBDIRS := $(PORTLIBS) $(LIBNX)
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec
CFLAGS += -ffunction-sections -fdata-sections $(ARCH) $(foreach dir,$(LIBDIRS),-I$(dir)/include) -D__SWITCH__
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
INCLUDE_PATHS += -Iexternal/glfw/include
ifeq ($(PLATFORM_OS),BSD)
Expand Down Expand Up @@ -647,6 +673,9 @@ ifeq ($(RAYLIB_MODULE_RAYGUI),TRUE)
OBJS += raygui.o
endif

ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
OBJS += nxusb.o
endif
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
OBJS += android_native_app_glue.o
endif
Expand Down Expand Up @@ -757,6 +786,10 @@ rmodels.o : rmodels.c raylib.h rlgl.h raymath.h
raudio.o : raudio.c raylib.h
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS)

# Compile switch usb module
nxusb.o : nxusb.c nxusb.h raylib.h
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(TARGET_PLATFORM)

# Compile raygui module
# NOTE: raygui header should be distributed with raylib.h
raygui.o : raygui.c
Expand Down Expand Up @@ -785,6 +818,10 @@ android_native_app_glue.o : $(NATIVE_APP_GLUE)/android_native_app_glue.c
# HINT: Add -L$(RAYLIB_INSTALL_PATH) -I$(RAYLIB_H_INSTALL_PATH) to your own makefiles.
# See below and ../examples/Makefile for more information.

ifeq ($(TARGET_PLATFORM),PLATFORM_NX)
DESTDIR ?= $(PORTLIBS)
endif

# RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths.
DESTDIR ?= /usr/local
RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib
Expand Down Expand Up @@ -870,4 +907,4 @@ clean_shell_cmd:
del lib$(RAYLIB_LIB_NAME).a /s & \
del lib$(RAYLIB_LIB_NAME)dll.a /s & \
del $(RAYLIB_LIB_NAME).dll /s & \
del raygui.c /s & \
del raygui.c /s & \
Loading

0 comments on commit 34de408

Please sign in to comment.