mirror of
https://github.com/aap/librw.git
synced 2024-11-25 13:15:43 +00:00
Merge pull request #73 from AGraber/nx-new
Add Nintendo Switch support through CMake
This commit is contained in:
commit
6f5e6fe4e8
2
.github/workflows/build-cmake-conan.yml
vendored
2
.github/workflows/build-cmake-conan.yml
vendored
@ -62,7 +62,7 @@ jobs:
|
||||
conan export cmake/ps2toolchain ps2dev-cmaketoolchain/master@
|
||||
- name: "Download/build dependencies (conan install)"
|
||||
run: |
|
||||
conan install ${{ github.workspace }} librw/master@ -if build -o platform=${{ matrix.platform }} -o gl3_gfxlib=${{ matrix.gl3_gfxlib}} --build missing -pr:h ./host_profile -pr:b default
|
||||
conan install ${{ github.workspace }} librw/master@ -if build -o librw:platform=${{ matrix.platform }} -o librw:gl3_gfxlib=${{ matrix.gl3_gfxlib}} --build missing -pr:h ./host_profile -pr:b default
|
||||
env:
|
||||
CONAN_SYSREQUIRES_MODE: enabled
|
||||
- name: "Build librw (conan build)"
|
||||
|
26
.github/workflows/build-switch.yml
vendored
Normal file
26
.github/workflows/build-switch.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
name: Build for Nintendo Switch using CMake provided by devkitPro
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
release:
|
||||
types: published
|
||||
jobs:
|
||||
build-nintendo-switch:
|
||||
runs-on: ubuntu-latest
|
||||
container: devkitpro/devkita64:latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: "Build files"
|
||||
run: |
|
||||
/opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -S. -Bbuild .. -DLIBRW_PLATFORM=GL3 -DLIBRW_GL3_GFXLIB=GLFW -DLIBRW_INSTALL=True
|
||||
cmake --build build --parallel
|
||||
- name: "Create binary package (cpack)"
|
||||
working-directory: ./build
|
||||
run: |
|
||||
cpack
|
||||
- name: "Archive binary package (github artifacts)"
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: "switch-gl3"
|
||||
path: build/*.tar.xz
|
||||
if-no-files-found: error
|
@ -1,12 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(librw C CXX)
|
||||
project(librw
|
||||
VERSION 0.0.1
|
||||
LANGUAGES C CXX
|
||||
)
|
||||
set(librw_AUTHOR aap)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||
|
||||
if(WIN32)
|
||||
set(LIBRW_PLATFORMS "NULL" "GL3" "D3D9")
|
||||
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
|
||||
elseif(NINTENDO_SWITCH)
|
||||
set(LIBRW_PLATFORMS "NULL" "GL3")
|
||||
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/nxtoolchain")
|
||||
include(CheckNXFunctions)
|
||||
else()
|
||||
set(LIBRW_PLATFORMS "NULL" "GL3" "PS2")
|
||||
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
|
||||
endif()
|
||||
set(LIBRW_PLATFORM "NULL" CACHE STRING "Platform")
|
||||
set_property(CACHE LIBRW_PLATFORM PROPERTY STRINGS ${LIBRW_PLATFORMS})
|
||||
@ -60,6 +71,19 @@ if(LIBRW_INSTALL)
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
||||
)
|
||||
|
||||
if(LIBRW_GL3_GFXLIB STREQUAL "SDL2")
|
||||
install(
|
||||
FILES "${CMAKE_CURRENT_LIST_DIR}/cmake/FindSDL2.cmake"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
|
||||
)
|
||||
endif()
|
||||
if(NINTENDO_SWITCH)
|
||||
install(
|
||||
FILES "${CMAKE_CURRENT_LIST_DIR}/cmake/nxtoolchain/FindNXGL.cmake"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
|
||||
)
|
||||
endif()
|
||||
|
||||
string(REPLACE "." ";" cmake_c_compiler_version_list "${CMAKE_C_COMPILER_VERSION}")
|
||||
list(GET cmake_c_compiler_version_list 0 cmake_c_compiler_version_major)
|
||||
|
||||
@ -100,6 +124,8 @@ if(LIBRW_INSTALL)
|
||||
set(os "-apple")
|
||||
elseif(UNIX)
|
||||
set(os "-linux")
|
||||
elseif(NINTENDO_SWITCH)
|
||||
set(os "-switch")
|
||||
else()
|
||||
set(compiler "-UNK")
|
||||
message(WARNING "Unknown os. Created cpack package will be wrong. (override using cpack -P)")
|
||||
|
@ -3,13 +3,19 @@ include("${CMAKE_CURRENT_LIST_DIR}/librw-targets.cmake")
|
||||
set(LIBRW_PLATFORM "@LIBRW_PLATFORM@")
|
||||
set(LIBRW_PLATFORMS "@LIBRW_PLATFORMS@")
|
||||
set(LIBRW_PLATFORM_@LIBRW_PLATFORM@ ON)
|
||||
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL @LIBRW_PLATFORM_GL3_REQUIRES_OPENGL@)
|
||||
|
||||
if(LIBRW_PLATFORM_GL3)
|
||||
set(LIBRW_GL3_GFXLIB "@LIBRW_GL3_GFXLIB@")
|
||||
set(LIBRW_GL3_GFXLIBS "@LIBRW_GL3_GFXLIBS@")
|
||||
|
||||
set(OpenGL_GL_PREFERENCE GLVND)
|
||||
find_package(OpenGL REQUIRED)
|
||||
if(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL)
|
||||
set(OpenGL_GL_PREFERENCE GLVND)
|
||||
find_package(OpenGL REQUIRED)
|
||||
endif()
|
||||
if(NINTENDO_SWITCH)
|
||||
find_package(NXGL REQUIRED)
|
||||
endif()
|
||||
if(LIBRW_GL3_GFXLIB STREQUAL "GLFW")
|
||||
find_package(glfw3 REQUIRED)
|
||||
elseif(LIBRW_GL3_GFXLIB STREQUAL "SDL2")
|
||||
|
7
cmake/nxtoolchain/CheckNXFunctions.cmake
Normal file
7
cmake/nxtoolchain/CheckNXFunctions.cmake
Normal file
@ -0,0 +1,7 @@
|
||||
if(NOT COMMAND nx_generate_nacp)
|
||||
message(FATAL_ERROR "The `nx_generate_nacp` cmake command is not available. Please use an appropriate Nintendo Switch toolchain.")
|
||||
endif()
|
||||
|
||||
if(NOT COMMAND nx_create_nro)
|
||||
message(FATAL_ERROR "The `nx_create_nro` cmake command is not available. Please use an appropriate Nintendo Switch toolchain.")
|
||||
endif()
|
38
cmake/nxtoolchain/FindNXGL.cmake
Normal file
38
cmake/nxtoolchain/FindNXGL.cmake
Normal file
@ -0,0 +1,38 @@
|
||||
find_library(NXGL_EGL_LIBRARY EGL)
|
||||
find_library(NXGL_GLAPI_LIBRARY glapi)
|
||||
find_library(NXGL_DRM_NOUVEAU_LIBRARY drm_nouveau)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(NXGL
|
||||
REQUIRED_VARS NXGL_EGL_LIBRARY NXGL_GLAPI_LIBRARY NXGL_DRM_NOUVEAU_LIBRARY
|
||||
)
|
||||
|
||||
if(NXGL_FOUND)
|
||||
if(NOT TARGET NXGL::EGL)
|
||||
add_library(NXGL::EGL UNKNOWN IMPORTED)
|
||||
set_target_properties(NXGL::EGL PROPERTIES
|
||||
IMPORTED_LOCATION "${NXGL_EGL_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT TARGET NXGL::glapi)
|
||||
add_library(NXGL::glapi UNKNOWN IMPORTED)
|
||||
set_target_properties(NXGL::glapi PROPERTIES
|
||||
IMPORTED_LOCATION "${NXGL_GLAPI_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT TARGET NXGL::drm_nouveau)
|
||||
add_library(NXGL::drm_nouveau UNKNOWN IMPORTED)
|
||||
set_target_properties(NXGL::drm_nouveau PROPERTIES
|
||||
IMPORTED_LOCATION "${NXGL_DRM_NOUVEAU_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT TARGET NXGL::OpenGL)
|
||||
add_library(NXGL::OpenGL INTERFACE IMPORTED)
|
||||
set_target_properties(NXGL::OpenGL PROPERTIES
|
||||
INTERFACE_LINK_LIBRARIES "NXGL::EGL;NXGL::glapi;NXGL::drm_nouveau"
|
||||
)
|
||||
endif()
|
||||
endif()
|
@ -148,13 +148,16 @@ set_target_properties(librw
|
||||
)
|
||||
|
||||
if(LIBRW_PLATFORM_GL3)
|
||||
set(OpenGL_GL_PREFERENCE GLVND)
|
||||
find_package(OpenGL REQUIRED)
|
||||
if(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL)
|
||||
set(OpenGL_GL_PREFERENCE GLVND)
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
target_link_libraries(librw
|
||||
PUBLIC
|
||||
OpenGL::GL
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(librw
|
||||
PUBLIC
|
||||
OpenGL::GL
|
||||
)
|
||||
if (LIBRW_GL3_GFXLIB STREQUAL "GLFW")
|
||||
find_package(glfw3 REQUIRED)
|
||||
target_link_libraries(librw
|
||||
@ -175,6 +178,14 @@ if(LIBRW_PLATFORM_GL3)
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NINTENDO_SWITCH)
|
||||
find_package(NXGL REQUIRED)
|
||||
target_link_libraries(librw
|
||||
PUBLIC
|
||||
NXGL::OpenGL
|
||||
)
|
||||
endif()
|
||||
elseif(LIBRW_PLATFORM_D3D9)
|
||||
target_link_libraries(librw
|
||||
PUBLIC
|
||||
|
@ -12,3 +12,21 @@ if(LIBRW_INSTALL)
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NINTENDO_SWITCH)
|
||||
nx_generate_nacp(dumprwtree.nacp
|
||||
NAME "dumprwtree"
|
||||
AUTHOR "${librw_AUTHOR}"
|
||||
VERSION "${librw_VERSION}"
|
||||
)
|
||||
|
||||
nx_create_nro(dumprwtree
|
||||
NACP dumprwtree.nacp
|
||||
)
|
||||
|
||||
if(LIBRW_INSTALL)
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/dumprwtree.nro"
|
||||
DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
@ -13,3 +13,21 @@ if(LIBRW_INSTALL)
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NINTENDO_SWITCH)
|
||||
nx_generate_nacp(imguitest.nacp
|
||||
NAME "librw imguitest"
|
||||
AUTHOR "${librw_AUTHOR}"
|
||||
VERSION "${librw_VERSION}"
|
||||
)
|
||||
|
||||
nx_create_nro(imguitest
|
||||
NACP imguitest.nacp
|
||||
)
|
||||
|
||||
if(LIBRW_INSTALL)
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/imguitest.nro"
|
||||
DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user