Initial Switch support (Needs testing)

This commit is contained in:
Phillip Stephens 2018-09-20 10:47:48 -07:00
parent 488acc8675
commit 5306525029
15 changed files with 320 additions and 9 deletions

View File

@ -29,9 +29,9 @@ list(APPEND CORE_EXTRA src/win32_largefilewrapper.c include/win32_largefilewrapp
src/athena/FileWriterWin32.cpp src/athena/FileReaderWin32.cpp)
else()
list(APPEND CORE_EXTRA src/athena/FileWriterNix.cpp src/athena/FileReader.cpp)
if(APPLE OR GEKKO OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
if(APPLE OR GEKKO OR NX OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
list(APPEND CORE_EXTRA src/osx_largefilewrapper.c include/osx_largefilewrapper.h)
if(GEKKO)
if(GEKKO OR NX)
list(APPEND CORE_EXTRA src/gekko_support.c include/gekko_support.h)
endif()
endif()
@ -130,7 +130,7 @@ add_library(athena-wiisave EXCLUDE_FROM_ALL
include/md5.h
include/sha1.h
)
if(NOT MSVC AND NOT GEKKO)
if(NOT MSVC AND NOT GEKKO AND NOT NX)
set_source_files_properties(src/aes.cpp PROPERTIES COMPILE_FLAGS -maes)
endif()
@ -243,7 +243,7 @@ install(EXPORT AthenaTargets DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT athena)
# atdna import #
################
if(NOT GEKKO)
if(NOT GEKKO AND NOT NX)
add_subdirectory(atdna)
# Test target
atdna(atdna_test.cpp atdna/test.hpp)

View File

@ -0,0 +1,3 @@
set(CMAKE_EXECUTABLE_SUFFIX ".nro.so")
SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "/usr/bin/llvm-mc ${AS_FLAGS} <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")

174
cmake/SwitchTools_nx.cmake Normal file
View File

@ -0,0 +1,174 @@
get_filename_component(__tools_switch_sdir ${CMAKE_CURRENT_LIST_FILE} PATH) # Used to locate files to be used with configure_file
#############
## ELF2NRO ##
#############
if (NOT ELF2NRO)
# message(STATUS "Looking for makerom...")
find_program(ELF2NRO elf2nro ${DEVKITPRO}/tools/bin)
if (ELF2NRO)
message(STATUS "elf2nro: ${ELF2NRO} - found")
else ()
message(WARNING "elf2nro - not found")
endif ()
endif ()
#############
## ELF2KIP ##
#############
if (NOT ELF2KIP)
# message(STATUS "Looking for makerom...")
find_program(ELF2KIP elf2kip ${DEVKITPRO}/tools/bin)
if (ELF2KIP)
message(STATUS "elf2kip: ${ELF2KIP} - found")
else ()
message(WARNING "elf2kip - not found")
endif ()
endif ()
#############
## ELF2NSO ##
#############
if (NOT ELF2NSO)
# message(STATUS "Looking for makerom...")
find_program(ELF2NSO elf2nso ${DEVKITPRO}/tools/bin)
if (ELF2NSO)
message(STATUS "elf2nso: ${ELF2NSO} - found")
else ()
message(WARNING "elf2nso - not found")
endif ()
endif ()
#############
## BIN2S ##
#############
if (NOT BIN2S)
# message(STATUS "Looking for bin2s...")
find_program(BIN2S bin2s ${DEVKITPRO}/tools/bin)
if (BIN2S)
message(STATUS "bin2s: ${BIN2S} - found")
else ()
message(WARNING "bin2s - not found")
endif ()
endif ()
#############
## RAW2C ##
#############
if (NOT RAW2C)
# message(STATUS "Looking for bin2s...")
find_program(RAW2C raw2c ${DEVKITPRO}/tools/bin)
if (RAW2C)
message(STATUS "raw2c: ${RAW2C} - found")
else ()
message(WARNING "raw2c - not found")
endif ()
endif ()
##################
## BUILD_PFS0 ##
##################
if (NOT BUILD_PFS0)
# message(STATUS "Looking for bin2s...")
find_program(BUILD_PFS0 build_pfs0 ${DEVKITPRO}/tools/bin)
if (BUILD_PFS0)
message(STATUS "build_pfs0: ${BUILD_PFS0} - found")
else ()
message(WARNING "build_pfs0 - not found")
endif ()
endif ()
################
## NACPTOOL ##
################
if (NOT NACPTOOL)
# message(STATUS "Looking for bin2s...")
find_program(NACPTOOL nacptool ${DEVKITPRO}/tools/bin)
if (NACPTOOL)
message(STATUS "nacptool: ${NACPTOOL} - found")
else ()
message(WARNING "nacptool - not found")
endif ()
endif ()
function(__add_nacp target APP_TITLE APP_AUTHOR APP_VERSION)
set(__NACP_COMMAND ${NACPTOOL} --create ${APP_TITLE} ${APP_AUTHOR} ${APP_VERSION} ${CMAKE_CURRENT_BINARY_DIR}/${target})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}
COMMAND ${__NACP_COMMAND}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
VERBATIM
)
endfunction()
function(add_nro_target target)
get_filename_component(target_we ${target} NAME_WE)
if ((NOT (${ARGC} GREATER 1 AND "${ARGV1}" STREQUAL "NO_NACP")) OR (${ARGC} GREATER 3))
if (${ARGC} GREATER 3)
set(APP_TITLE ${ARGV1})
set(APP_AUTHOR ${ARGV2})
set(APP_VERSION ${ARGV3})
endif ()
if (${ARGC} EQUAL 5)
set(APP_ICON ${ARGV4})
endif ()
if (NOT APP_TITLE)
set(APP_TITLE ${target})
endif ()
if (NOT APP_AUTHOR)
set(APP_AUTHOR "Unspecified Author")
endif ()
if (NOT APP_VERSION)
set(APP_VERSION "1.0")
endif ()
if (NOT APP_ICON)
if (EXISTS ${target}.png)
set(APP_ICON ${target}.png)
elseif (EXISTS icon.png)
set(APP_ICON icon.png)
elseif (NX)
set(APP_ICON ${DEVKITPRO}/libnx/default_icon.png)
else ()
message(FATAL_ERROR "No icon found ! Please use NO_SMDH or provide some icon.")
endif ()
endif ()
if (NOT ${target_we}.nacp)
__add_nacp(${target_we}.nacp ${APP_TITLE} ${APP_AUTHOR} ${APP_VERSION})
endif ()
if (CMAKE_RUNTIME_OUTPUT_DIRECTORY)
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target_we}.nro
COMMAND ${ELF2NRO} $<TARGET_FILE:${target}> --icon=${APP_ICON} --nacp=${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nacp ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target_we}.nro
DEPENDS ${target} ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nacp
VERBATIM
)
else ()
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nro
COMMAND ${ELF2NRO} $<TARGET_FILE:${target}> --icon=${APP_ICON} --nacp=${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nacp ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nro
DEPENDS ${target} ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nacp
VERBATIM
)
endif ()
else ()
message(STATUS "No nacp file will be generated")
if (CMAKE_RUNTIME_OUTPUT_DIRECTORY)
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target_we}.nro
COMMAND ${ELF2NRO} $<TARGET_FILE:${target}> ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target_we}.nro
DEPENDS ${target}
VERBATIM
)
else ()
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nro
COMMAND ${ELF2NRO} $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nro
DEPENDS ${target}
VERBATIM
)
endif ()
endif ()
if (CMAKE_RUNTIME_OUTPUT_DIRECTORY)
add_custom_target(${target_we}_nro ALL SOURCES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target_we}.nro)
else ()
add_custom_target(${target_we}_nro ALL SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nro)
endif ()
endfunction()

View File

@ -0,0 +1,71 @@
set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6)
find_package(PythonInterp 3 REQUIRED)
set(CONVERTER "${LIBTRN}/tools/elf2nxo.py")
function(add_nro_target target)
get_filename_component(target_we ${target} NAME_WE)
if ((NOT (${ARGC} GREATER 1 AND "${ARGV1}" STREQUAL "NO_HDR")) OR (${ARGC} GREATER 3))
if (${ARGC} GREATER 3)
set(APP_TITLE ${ARGV1})
set(APP_AUTHOR ${ARGV2})
set(APP_VERSION ${ARGV3})
endif ()
if (${ARGC} EQUAL 5)
set(APP_ICON ${ARGV4})
endif ()
if (NOT APP_TITLE)
set(APP_TITLE ${target})
endif ()
if (NOT APP_AUTHOR)
set(APP_AUTHOR "Unspecified Author")
endif ()
if (NOT APP_VERSION)
set(APP_VERSION "1.0")
endif ()
if (NOT APP_ICON)
if (EXISTS ${target}.png)
set(APP_ICON ${target}.png)
elseif (EXISTS icon.png)
set(APP_ICON icon.png)
else ()
message(FATAL_ERROR "No icon found ! Please use NO_SMDH or provide some icon.")
endif ()
endif ()
if (CMAKE_RUNTIME_OUTPUT_DIRECTORY)
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target_we}.nro
COMMAND ${PYTHON_EXECUTABLE} ${CONVERTER} -n ${APP_TITLE} -d ${APP_AUTHOR} -v ${APP_VERSION} -i ${APP_ICON} $<TARGET_FILE:${target}> ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target_we}.nro nro
DEPENDS ${target} ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nacp
VERBATIM
)
else ()
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nro
COMMAND ${PYTHON_EXECUTABLE} ${CONVERTER} -n ${APP_TITLE} -d ${APP_AUTHOR} -v ${APP_VERSION} -i ${APP_ICON} $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nro nro
DEPENDS ${target} ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nacp
VERBATIM
)
endif ()
else ()
message(STATUS "No header will be generated")
if (CMAKE_RUNTIME_OUTPUT_DIRECTORY)
add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target_we}.nro
COMMAND ${PYTHON_EXECUTABLE} ${CONVERTER} $<TARGET_FILE:${target}> ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target_we}.nro nro
DEPENDS ${target}
VERBATIM
)
else ()
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nro
COMMAND ${PYTHON_EXECUTABLE} ${CONVERTER} $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nro nro
DEPENDS ${target}
VERBATIM
)
endif ()
endif ()
if (CMAKE_RUNTIME_OUTPUT_DIRECTORY)
add_custom_target(${target_we}_nro ALL SOURCES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target_we}.nro)
else ()
add_custom_target(${target_we}_nro ALL SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${target_we}.nro)
endif ()
endfunction()

View File

@ -52,7 +52,7 @@
#endif
// clang-format on
#ifdef GEKKO
#if defined(GEKKO) || defined(__SWITCH__)
#include "gekko_support.h"
typedef struct stat atStat64_t;
#define atStat64 stat

View File

@ -8,6 +8,8 @@ namespace athena::Sakura
class SpriteFile;
} // Sakura
namespace athena
{
namespace io
{
@ -19,6 +21,7 @@ public:
Sakura::SpriteFile* readFile();
};
}
} // zelda

View File

@ -3,6 +3,7 @@
#include <string>
#include <map>
#include <vector>
#include "athena/Global.hpp"
namespace athena

View File

@ -3,6 +3,7 @@
#include <unordered_map>
#include <string>
#include <vector>
#include "athena/Global.hpp"
namespace athena

View File

@ -1,7 +1,7 @@
#ifndef GEKKO_SUPPORT_H
#define GEKKO_SUPPORT_H
#ifdef GEKKO
#if defined(GEKKO) || defined(__SWITCH__)
#include <stdarg.h>
#include <stddef.h>
#include <sys/cdefs.h>
@ -11,6 +11,11 @@
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __SWITCH__
#define ftello64 ftello
#define fseeko64 fseeko
#endif
char *
realpath(const char *path, char *resolved);
int

51
libnx.cmake Normal file
View File

@ -0,0 +1,51 @@
set(CMAKE_SYSTEM_NAME "Switch")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 11)
set(WITH_PORTLIBS ON CACHE BOOL "use portlibs ?")
macro(msys_to_cmake_path MsysPath ResultingPath)
if(WIN32)
string(REGEX REPLACE "^/([a-zA-Z])/" "\\1:/" ${ResultingPath} "${MsysPath}")
else()
set(${ResultingPath} "${MsysPath}")
endif()
endmacro()
msys_to_cmake_path("$ENV{DEVKITPRO}" DEVKITPRO)
set(NX 1)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(SwitchTools_nx)
if(WIN32)
set(CMAKE_C_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc.exe")
set(CMAKE_CXX_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-g++.exe")
set(CMAKE_AR "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc-ar.exe" CACHE STRING "")
set(CMAKE_RANLIB "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc-ranlib.exe" CACHE STRING "")
else()
set(CMAKE_C_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc")
set(CMAKE_CXX_COMPILER "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-g++")
set(CMAKE_AR "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc-ar" CACHE STRING "")
set(CMAKE_RANLIB "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-gcc-ranlib" CACHE STRING "")
endif()
set(PKG_CONFIG "${DEVKITPRO}/portlibs/bin/aarch64-none-elf-pkg-config" CACHE STRING "")
set(CPPFLAGS "-D__SWITCH__ -D__USE_LARGEFILE64=1 -D__USE_LARGEOFFSET64=1 -I${DEVKITPRO}/libnx/include -I${DEVKITPRO}/portlibs/switch/include")
set(CMAKE_C_FLAGS "${CPPFLAGS} -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIC -ffunction-sections" CACHE STRING "C flags")
set(CMAKE_CXX_FLAGS "${CPPFLAGS} ${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions -std=gnu++11" CACHE STRING "C++ flags")
if(WITH_PORTLIBS)
set(CMAKE_FIND_ROOT_PATH ${DEVKITPRO}/devkitA64 ${DEVKITPRO} ${DEVKITPRO}/libnx ${DEVKITPRO}/portlibs/switch)
else()
set(CMAKE_FIND_ROOT_PATH ${DEVKITPRO}/devkitA64 ${DEVKITPRO}/libnx ${DEVKITPRO})
endif()
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
#set(CMAKE_STATIC_LINKER_FLAGS_INIT "-march=armv8-a -mtune=cortex-a57 -mtp=soft -L${DEVKITPRO}/libnx/lib -L${DEVKITPRO}/portlibs/switch/lib")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-specs=${DEVKITPRO}/libnx/switch.specs -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -L${DEVKITPRO}/libnx/lib -L${DEVKITPRO}/portlibs/switch/lib")
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Shared libs not available")
set(CMAKE_INSTALL_PREFIX ${DEVKITPRO}/portlibs/switch)

View File

@ -3,7 +3,7 @@
#include <cstring>
#if _WIN32
#include <intrin.h>
#elif !GEKKO
#elif !defined(GEKKO) && !defined(__SWITCH__)
#include <cpuid.h>
#endif

View File

@ -2,7 +2,7 @@
#if __APPLE__ || __FreeBSD__
#include "osx_largefilewrapper.h"
#elif GEKKO
#elif GEKKO || __SWITCH__
#include "gekko_support.h"
#include "osx_largefilewrapper.h"
#endif

View File

@ -1,5 +1,6 @@
#include "athena/SkywardSwordQuest.hpp"
#include "athena/Checksums.hpp"
#include "athena/Utility.hpp"
#include "utf8proc.h"
#include <sstream>

View File

@ -1,4 +1,5 @@
#include "athena/WiiFile.hpp"
#include "athena/Utility.hpp"
#include <algorithm>
namespace athena

View File

@ -1,4 +1,4 @@
#if defined(GEKKO)
#if defined(GEKKO) || defined(__SWITCH__)
#include "gekko_support.h"
#define SYMLOOP_MAX 8
#include <sys/stat.h>