From 83ba0bd615b8685c256d31af54852eff1ea68449 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 22 Jun 2021 19:47:36 +0200 Subject: [PATCH] cmake: fix Nintendo Switch support --- .github/workflows/build-switch.yml | 2 +- CMakeLists.txt | 7 +++++- cmake/nxtoolchain/CheckNXFunctions.cmake | 7 ------ cmake/nxtoolchain/NXFunctions.cmake | 32 ++++++++++++++++++++++++ tools/camera/CMakeLists.txt | 2 ++ tools/dumprwtree/CMakeLists.txt | 18 +------------ tools/im2d/CMakeLists.txt | 2 ++ tools/im3d/CMakeLists.txt | 2 ++ tools/imguitest/CMakeLists.txt | 18 +------------ tools/lights/CMakeLists.txt | 2 ++ tools/playground/CMakeLists.txt | 4 ++- tools/ska2anm/CMakeLists.txt | 2 ++ tools/subrast/CMakeLists.txt | 2 ++ 13 files changed, 56 insertions(+), 44 deletions(-) delete mode 100644 cmake/nxtoolchain/CheckNXFunctions.cmake create mode 100644 cmake/nxtoolchain/NXFunctions.cmake diff --git a/.github/workflows/build-switch.yml b/.github/workflows/build-switch.yml index faa5865..a532b15 100644 --- a/.github/workflows/build-switch.yml +++ b/.github/workflows/build-switch.yml @@ -12,7 +12,7 @@ jobs: - 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 + /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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 417c77a..3a663bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ 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) + include(NXFunctions) else() set(LIBRW_PLATFORMS "NULL" "GL3" "PS2") set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON) @@ -41,6 +41,11 @@ if(LIBRW_PLATFORM_PS2) enable_language(DSM) endif() +if(NOT COMMAND librw_platform_target) + function(librw_platform_target) + endfunction() +endif() + option(LIBRW_TOOLS "Build librw tools" ON) option(LIBRW_INSTALL "Install librw files" OFF) diff --git a/cmake/nxtoolchain/CheckNXFunctions.cmake b/cmake/nxtoolchain/CheckNXFunctions.cmake deleted file mode 100644 index 8fa23fa..0000000 --- a/cmake/nxtoolchain/CheckNXFunctions.cmake +++ /dev/null @@ -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() diff --git a/cmake/nxtoolchain/NXFunctions.cmake b/cmake/nxtoolchain/NXFunctions.cmake new file mode 100644 index 0000000..ce8637e --- /dev/null +++ b/cmake/nxtoolchain/NXFunctions.cmake @@ -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() diff --git a/tools/camera/CMakeLists.txt b/tools/camera/CMakeLists.txt index 4901e1d..2c7fcd4 100644 --- a/tools/camera/CMakeLists.txt +++ b/tools/camera/CMakeLists.txt @@ -11,3 +11,5 @@ add_custom_command( TARGET camera POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$/files" ) + +librw_platform_target(camera) diff --git a/tools/dumprwtree/CMakeLists.txt b/tools/dumprwtree/CMakeLists.txt index 96b05e7..71c2738 100644 --- a/tools/dumprwtree/CMakeLists.txt +++ b/tools/dumprwtree/CMakeLists.txt @@ -13,20 +13,4 @@ if(LIBRW_INSTALL) ) 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() +librw_platform_target(dumprwtree INSTALL) diff --git a/tools/im2d/CMakeLists.txt b/tools/im2d/CMakeLists.txt index 69b6fee..367df76 100644 --- a/tools/im2d/CMakeLists.txt +++ b/tools/im2d/CMakeLists.txt @@ -11,3 +11,5 @@ add_custom_command( TARGET im2d POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$/files" ) + +librw_platform_target(im2d) diff --git a/tools/im3d/CMakeLists.txt b/tools/im3d/CMakeLists.txt index 87c15a1..d01a4e5 100644 --- a/tools/im3d/CMakeLists.txt +++ b/tools/im3d/CMakeLists.txt @@ -11,3 +11,5 @@ add_custom_command( TARGET im3d POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/files" "$/files" ) + +librw_platform_target(im3d) diff --git a/tools/imguitest/CMakeLists.txt b/tools/imguitest/CMakeLists.txt index 293a4f1..d0af911 100644 --- a/tools/imguitest/CMakeLists.txt +++ b/tools/imguitest/CMakeLists.txt @@ -14,20 +14,4 @@ if(LIBRW_INSTALL) ) 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() +librw_platform_target(imguitest INSTALL) diff --git a/tools/lights/CMakeLists.txt b/tools/lights/CMakeLists.txt index a612b22..283c74a 100644 --- a/tools/lights/CMakeLists.txt +++ b/tools/lights/CMakeLists.txt @@ -11,3 +11,5 @@ add_custom_command( TARGET lights POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/checker.dff" "$" ) + +librw_platform_target(lights) diff --git a/tools/playground/CMakeLists.txt b/tools/playground/CMakeLists.txt index cc84d11..298f0e4 100644 --- a/tools/playground/CMakeLists.txt +++ b/tools/playground/CMakeLists.txt @@ -4,10 +4,12 @@ add_executable(playground WIN32 target_link_libraries(playground PUBLIC - librw librw_skeleton + librw librw_skeleton_imgui ) add_custom_command( 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" "$" ) + +librw_platform_target(playground) diff --git a/tools/ska2anm/CMakeLists.txt b/tools/ska2anm/CMakeLists.txt index b51751b..9dfbb2a 100644 --- a/tools/ska2anm/CMakeLists.txt +++ b/tools/ska2anm/CMakeLists.txt @@ -6,3 +6,5 @@ target_link_libraries(ska2anm PUBLIC librw ) + +librw_platform_target(ska2anm) diff --git a/tools/subrast/CMakeLists.txt b/tools/subrast/CMakeLists.txt index e0472b4..cb4d197 100644 --- a/tools/subrast/CMakeLists.txt +++ b/tools/subrast/CMakeLists.txt @@ -6,3 +6,5 @@ target_link_libraries(subrast PUBLIC librw librw_skeleton librw_skeleton_imgui ) + +librw_platform_target(subrast)