cmake: fix Nintendo Switch support

This commit is contained in:
Anonymous Maarten 2021-06-22 19:47:36 +02:00
parent 829cf6b700
commit 83ba0bd615
13 changed files with 56 additions and 44 deletions

View File

@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: "Build files" - name: "Build files"
run: | run: |
/opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -S. -Bbuild .. -DLIBRW_PLATFORM=GL3 -DLIBRW_GL3_GFXLIB=GLFW -DLIBRW_INSTALL=True /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 cmake --build build --parallel
- name: "Create binary package (cpack)" - name: "Create binary package (cpack)"
working-directory: ./build working-directory: ./build

View File

@ -14,7 +14,7 @@ elseif(NINTENDO_SWITCH)
set(LIBRW_PLATFORMS "NULL" "GL3") set(LIBRW_PLATFORMS "NULL" "GL3")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF) set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/nxtoolchain") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/nxtoolchain")
include(CheckNXFunctions) include(NXFunctions)
else() else()
set(LIBRW_PLATFORMS "NULL" "GL3" "PS2") set(LIBRW_PLATFORMS "NULL" "GL3" "PS2")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON) set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
@ -41,6 +41,11 @@ if(LIBRW_PLATFORM_PS2)
enable_language(DSM) enable_language(DSM)
endif() endif()
if(NOT COMMAND librw_platform_target)
function(librw_platform_target)
endfunction()
endif()
option(LIBRW_TOOLS "Build librw tools" ON) option(LIBRW_TOOLS "Build librw tools" ON)
option(LIBRW_INSTALL "Install librw files" OFF) option(LIBRW_INSTALL "Install librw files" OFF)

View File

@ -1,7 +0,0 @@
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()

View File

@ -0,0 +1,32 @@
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()
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
function(librw_platform_target TARGET)
cmake_parse_arguments(LPT "INSTALL" "" "" ${ARGN})
get_target_property(TARGET_TYPE "${TARGET}" TYPE)
if(TARGET_TYPE STREQUAL "EXECUTABLE")
nx_generate_nacp(${TARGET}.nacp
NAME "${TARGET}"
AUTHOR "${librw_AUTHOR}"
VERSION "${librw_VERSION}"
)
nx_create_nro(${TARGET}
NACP ${TARGET}.nacp
)
if(LIBRW_INSTALL AND LPT_INSTALL)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.nro"
DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()
endif()
endfunction()

View File

@ -11,3 +11,5 @@ add_custom_command(
TARGET camera POST_BUILD TARGET camera POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$<TARGET_FILE_DIR:camera>/files" COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$<TARGET_FILE_DIR:camera>/files"
) )
librw_platform_target(camera)

View File

@ -13,20 +13,4 @@ if(LIBRW_INSTALL)
) )
endif() endif()
if(NINTENDO_SWITCH) librw_platform_target(dumprwtree INSTALL)
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()

View File

@ -11,3 +11,5 @@ add_custom_command(
TARGET im2d POST_BUILD TARGET im2d POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$<TARGET_FILE_DIR:im2d>/files" COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$<TARGET_FILE_DIR:im2d>/files"
) )
librw_platform_target(im2d)

View File

@ -11,3 +11,5 @@ add_custom_command(
TARGET im3d POST_BUILD TARGET im3d POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$<TARGET_FILE_DIR:im3d>/files" COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$<TARGET_FILE_DIR:im3d>/files"
) )
librw_platform_target(im3d)

View File

@ -14,20 +14,4 @@ if(LIBRW_INSTALL)
) )
endif() endif()
if(NINTENDO_SWITCH) librw_platform_target(imguitest INSTALL)
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()

View File

@ -11,3 +11,5 @@ add_custom_command(
TARGET lights POST_BUILD TARGET lights POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/checker.dff" "$<TARGET_FILE_DIR:lights>" COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/checker.dff" "$<TARGET_FILE_DIR:lights>"
) )
librw_platform_target(lights)

View File

@ -4,10 +4,12 @@ add_executable(playground WIN32
target_link_libraries(playground target_link_libraries(playground
PUBLIC PUBLIC
librw librw_skeleton librw librw_skeleton_imgui
) )
add_custom_command( add_custom_command(
TARGET playground POST_BUILD TARGET playground POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/teapot.dff" "${CMAKE_CURRENT_SOURCE_DIR}/maze.tga" "${CMAKE_CURRENT_SOURCE_DIR}/Bm437_IBM_VGA8.FON" "${CMAKE_CURRENT_SOURCE_DIR}/Bm437_IBM_BIOS.FON" "$<TARGET_FILE_DIR:playground>" COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/teapot.dff" "${CMAKE_CURRENT_SOURCE_DIR}/maze.tga" "${CMAKE_CURRENT_SOURCE_DIR}/Bm437_IBM_VGA8.FON" "${CMAKE_CURRENT_SOURCE_DIR}/Bm437_IBM_BIOS.FON" "$<TARGET_FILE_DIR:playground>"
) )
librw_platform_target(playground)

View File

@ -6,3 +6,5 @@ target_link_libraries(ska2anm
PUBLIC PUBLIC
librw librw
) )
librw_platform_target(ska2anm)

View File

@ -6,3 +6,5 @@ target_link_libraries(subrast
PUBLIC PUBLIC
librw librw_skeleton librw_skeleton_imgui librw librw_skeleton librw_skeleton_imgui
) )
librw_platform_target(subrast)