Skip to content

Commit

Permalink
Merge branch 'integrate_libs'
Browse files Browse the repository at this point in the history
  • Loading branch information
pivotiiii committed Apr 28, 2024
2 parents da2c9fa + 18c5f56 commit 36a5fec
Show file tree
Hide file tree
Showing 14 changed files with 1,196 additions and 93 deletions.
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ project(
nsui_banner_fixer
VERSION 2.0.0
DESCRIPTION "Fixes banners for GBA forwarders generated with NSUIv28 on non-US consoles."
LANGUAGES CXX)
LANGUAGES C CXX)

option(BUILD_TESTS "Build tests." ON)
option(DYNAMIC_LINKING "Link CURL and OPENSSL dynamic instead of static. (Linux only)" OFF)
option(STATIC_STD_LIBS "Link libstdc++ and libgcc static instead of dynamic. (Linux only)" OFF)

include(dependencies.cmake)
add_subdirectory(src)

enable_testing()
add_subdirectory(test)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()



#----------------------------------------------------------------------------------------

Expand Down
198 changes: 172 additions & 26 deletions dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,185 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(tclap)

#----------------------------------------------------------------------------------------
# Windows
#----------------------------------------------------------------------------------------

FetchContent_Declare(
Boost
URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz
URL_MD5 893b5203b862eb9bbd08553e24ff146a
DOWNLOAD_EXTRACT_TIMESTAMP ON
EXCLUDE_FROM_ALL
)
set(BOOST_INCLUDE_LIBRARIES process)
FetchContent_MakeAvailable(Boost)
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
FetchContent_Declare(
Boost
URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz
URL_MD5 893b5203b862eb9bbd08553e24ff146a
DOWNLOAD_EXTRACT_TIMESTAMP ON
EXCLUDE_FROM_ALL
)
set(BOOST_INCLUDE_LIBRARIES process)
FetchContent_MakeAvailable(Boost)

#----------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------

FetchContent_Declare(
3dstool
URL https://github.com/dnasdw/3dstool/releases/download/v1.0.9/3dstool.zip
)
FetchContent_Declare(
3dstool
URL https://github.com/dnasdw/3dstool/releases/download/v1.0.9/3dstool.zip
)

FetchContent_Declare(
ctrtool
URL https://github.com/3DSGuy/Project_CTR/releases/download/ctrtool-v0.5/ctrtool-win_x86_64-v0.5.zip
)
FetchContent_Declare(
ctrtool
URL https://github.com/3DSGuy/Project_CTR/releases/download/ctrtool-v0.5/ctrtool-win_x86_64-v0.5.zip
)

FetchContent_Declare(
makerom
URL https://github.com/3DSGuy/Project_CTR/releases/download/makerom-v0.15/makerom-win_x86_64-v0.15.zip
)
FetchContent_Declare(
makerom
URL https://github.com/3DSGuy/Project_CTR/releases/download/makerom-v0.15/makerom-win_x86_64-v0.15.zip
)

FetchContent_MakeAvailable(3dstool ctrtool makerom)

#----------------------------------------------------------------------------------------

FetchContent_MakeAvailable(3dstool ctrtool makerom)
install(FILES ${3dstool_SOURCE_DIR}/3dstool.exe DESTINATION tools)
install(FILES ${ctrtool_SOURCE_DIR}/ctrtool.exe DESTINATION tools)
install(FILES ${makerom_SOURCE_DIR}/makerom.exe DESTINATION tools)
endif()

#----------------------------------------------------------------------------------------
# Linux
#----------------------------------------------------------------------------------------

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
FetchContent_Declare(
stdcapture
GIT_REPOSITORY https://github.com/dmikushin/stdcapture.git
GIT_TAG 25ea65ba7933c4ce7baa48dcc90063476d539586 #
)
FetchContent_MakeAvailable(stdcapture)

#----------------------------------------------------------------------------------------

FetchContent_Declare(
3dstool_download
GIT_REPOSITORY https://github.com/dnasdw/3dstool.git
GIT_TAG 9c4336bca8898f3860b41241b8a7d9d4a6772e79
GIT_PROGRESS TRUE
PATCH_COMMAND git apply "${CMAKE_CURRENT_SOURCE_DIR}/patches/3dstool.patch"
UPDATE_DISCONNECTED 1
)
FetchContent_Populate(3dstool_download)
file(GLOB 3dstool_sources ${3dstool_download_SOURCE_DIR}/src/*.cpp)

file(GLOB capstone_sources
${3dstool_download_SOURCE_DIR}/dep/src/capstone-3.0.5/include/*.h
${3dstool_download_SOURCE_DIR}/dep/src/capstone-3.0.5/*.h
${3dstool_download_SOURCE_DIR}/dep/src/capstone-3.0.5/*.c
${3dstool_download_SOURCE_DIR}/dep/src/capstone-3.0.5/arch/ARM/*.c
${3dstool_download_SOURCE_DIR}/dep/src/capstone-3.0.5/arch/ARM/*.h
${3dstool_download_SOURCE_DIR}/dep/src/capstone-3.0.5/arch/ARM/*.inc)

if(DYNAMIC_LINKING)
find_package(CURL REQUIRED)
find_package(OpenSSL REQUIRED)
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BUILD64 1)
endif()
include(${3dstool_download_SOURCE_DIR}/cmake/AddDep.cmake)
ADD_DEP_INCLUDE_DIR("${3dstool_download_SOURCE_DIR}/dep")
ADD_DEP_LIBRARY_DIR("${3dstool_download_SOURCE_DIR}/dep")
set(3dstool_deps libcurl libssl libcrypto)
foreach(LIB IN LISTS 3dstool_deps)
add_library(${LIB} STATIC IMPORTED)
add_dependencies(${LIB} 3dstool_check)
target_include_directories(${LIB} INTERFACE ${DEP_INCLUDE_DIR})
set_target_properties(${LIB} PROPERTIES IMPORTED_LOCATION ${DEP_LIBRARY_DIR}/${LIB}.a)
endforeach()
target_link_libraries(libcrypto INTERFACE libssl libcurl)
target_link_libraries(libcurl INTERFACE libssl libcrypto)
target_link_libraries(libssl INTERFACE libcrypto libcurl)
target_link_libraries(libcrypto INTERFACE dl)
endif()

#----------------------------------------------------------------------------------------

FetchContent_Declare(
project_ctr_download
GIT_REPOSITORY https://github.com/3DSGuy/Project_CTR.git
GIT_TAG master
GIT_PROGRESS TRUE
PATCH_COMMAND git apply "${CMAKE_CURRENT_SOURCE_DIR}/patches/ctr.patch"
UPDATE_DISCONNECTED 1
)
FetchContent_MakeAvailable(project_ctr_download)

#----------------------------------------------------------------------------------------

FILE(
COPY ${project_ctr_download_SOURCE_DIR}/ctrtool/src/
DESTINATION ${project_ctr_download_SOURCE_DIR}/include/ctrtool
FILES_MATCHING PATTERN "*.h")

add_custom_command(
OUTPUT ${project_ctr_download_SOURCE_DIR}/ctrtool/bin/ctrtool.a
${project_ctr_download_SOURCE_DIR}/ctrtool/deps/libbroadon-es/bin/libbroadon-es.a
${project_ctr_download_SOURCE_DIR}/ctrtool/deps/libfmt/bin/libfmt.a
${project_ctr_download_SOURCE_DIR}/ctrtool/deps/libmbedtls/bin/libmbedtls.a
${project_ctr_download_SOURCE_DIR}/ctrtool/deps/libnintendo-n3ds/bin/libnintendo-n3ds.a
${project_ctr_download_SOURCE_DIR}/ctrtool/deps/libtoolchain/bin/libtoolchain.a
COMMAND make -C ${project_ctr_download_SOURCE_DIR}/ctrtool deps static_lib
COMMENT "=================== running make on project_ctr/ctrtool ..."
)
add_custom_target(ctrtool_make ALL DEPENDS ${project_ctr_download_SOURCE_DIR}/ctrtool/bin/ctrtool.a)

add_library(ctrtool_lib STATIC IMPORTED)
add_dependencies(ctrtool_lib ctrtool_make)
target_include_directories(ctrtool_lib INTERFACE ${project_ctr_download_SOURCE_DIR}/include)
set_target_properties(ctrtool_lib PROPERTIES IMPORTED_LOCATION ${project_ctr_download_SOURCE_DIR}/ctrtool/bin/ctrtool.a)

set(ctrtool_deps libbroadon-es libfmt libmbedtls libnintendo-n3ds libtoolchain)
foreach(LIB IN LISTS ctrtool_deps)
add_library(${LIB} STATIC IMPORTED)
add_dependencies(${LIB} ctrtool_make)
target_include_directories(${LIB} INTERFACE ${project_ctr_download_SOURCE_DIR}/ctrtool/deps/${LIB}/include)
set_target_properties(${LIB} PROPERTIES IMPORTED_LOCATION ${project_ctr_download_SOURCE_DIR}/ctrtool/deps/${LIB}/bin/${LIB}.a)
target_link_libraries(ctrtool_lib INTERFACE ${LIB})
endforeach()
target_link_libraries(libtoolchain INTERFACE libmbedtls)

#----------------------------------------------------------------------------------------

FILE(
COPY ${project_ctr_download_SOURCE_DIR}/makerom/src/
DESTINATION ${project_ctr_download_SOURCE_DIR}/include/makerom
FILES_MATCHING PATTERN "*.h")

add_custom_command(
OUTPUT ${project_ctr_download_SOURCE_DIR}/makerom/bin/makerom.a
${project_ctr_download_SOURCE_DIR}/makerom/deps/libblz/bin/libblz.a
${project_ctr_download_SOURCE_DIR}/makerom/deps/libyaml/bin/libyaml.a
${project_ctr_download_SOURCE_DIR}/makerom/deps/libmbedtls/bin/libmbedtls.a
COMMAND make -C ${project_ctr_download_SOURCE_DIR}/makerom deps static_lib
COMMENT "=================== running make on project_ctr/makerom ..."
)
add_custom_target(makerom_make ALL DEPENDS ${project_ctr_download_SOURCE_DIR}/makerom/bin/makerom.a)

add_library(makerom_lib STATIC IMPORTED)
add_dependencies(makerom_lib makerom_make)
target_include_directories(makerom_lib INTERFACE ${project_ctr_download_SOURCE_DIR}/include)
set_target_properties(makerom_lib PROPERTIES IMPORTED_LOCATION ${project_ctr_download_SOURCE_DIR}/makerom/bin/makerom.a)

set(makerom_deps libblz libyaml)
foreach(LIB IN LISTS makerom_deps)
add_library(${LIB} STATIC IMPORTED)
add_dependencies(${LIB} makerom_make)
target_include_directories(${LIB} INTERFACE ${project_ctr_download_SOURCE_DIR}/makerom/deps/${LIB}/include)
set_target_properties(${LIB} PROPERTIES IMPORTED_LOCATION ${project_ctr_download_SOURCE_DIR}/makerom/deps/${LIB}/bin/${LIB}.a)
target_link_libraries(makerom_lib INTERFACE ${LIB})
endforeach()

add_library(libmbedtls2 STATIC IMPORTED)
add_dependencies(libmbedtls2 makerom_make)
target_include_directories(libmbedtls2 INTERFACE ${project_ctr_download_SOURCE_DIR}/makerom/deps/libmbedtls/include)
set_target_properties(libmbedtls2 PROPERTIES IMPORTED_LOCATION ${project_ctr_download_SOURCE_DIR}/makerom/deps/libmbedtls/bin/libmbedtls.a)
target_link_libraries(makerom_lib INTERFACE libmbedtls2)
endif()


install(FILES ${3dstool_SOURCE_DIR}/3dstool.exe DESTINATION tools)
install(FILES ${ctrtool_SOURCE_DIR}/ctrtool.exe DESTINATION tools)
install(FILES ${makerom_SOURCE_DIR}/makerom.exe DESTINATION tools)
150 changes: 150 additions & 0 deletions patches/3dstool.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644
index 963d2714..00000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,79 +0,0 @@
-cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
-project(3dstool)
-if(MSVC_VERSION EQUAL 1700 AND MSVC_IDE)
- set(CMAKE_GENERATOR_TOOLSET "v110_xp" CACHE STRING "Name of generator toolset." FORCE)
-endif()
-if(MSVC_VERSION EQUAL 1800 AND MSVC_IDE)
- set(CMAKE_GENERATOR_TOOLSET "v120_xp" CACHE STRING "Name of generator toolset." FORCE)
-endif()
-if(MSVC_VERSION EQUAL 1900 AND MSVC_IDE)
- set(CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "Name of generator toolset." FORCE)
-endif()
-if(MSVC_VERSION GREATER 1909 AND MSVC_VERSION LESS 1920 AND MSVC_IDE)
- set(CMAKE_GENERATOR_TOOLSET "v141_xp" CACHE STRING "Name of generator toolset." FORCE)
-endif()
-if(MSVC_VERSION GREATER 1600 AND NOT MSVC_IDE)
- if(CMAKE_SIZEOF_VOID_P EQUAL 8)
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE,5.02")
- else()
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE,5.01")
- endif()
-endif()
-if(APPLE)
- set(CMAKE_MACOSX_RPATH 1)
-endif()
-set(_3DSTOOL_MAJOR 1)
-set(_3DSTOOL_MINOR 2)
-set(_3DSTOOL_PATCHLEVEL 6)
-if(NOT MSVC_IDE AND NOT XCODE_VERSION AND NOT CMAKE_BUILD_TYPE)
- set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
-endif()
-option(BUILD64 "Build x86_64(unix only)" ON)
-if(MSVC OR APPLE OR (NOT CYGWIN AND NOT MINGW))
- option(USE_DEP "Use prebuilt dep" ON)
-endif()
-set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}")
-set(ROOT_SOURCE_DIR "${PROJECT_SOURCE_DIR}")
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${ROOT_SOURCE_DIR}/cmake")
-include(AddCompilationFlags)
-include(AddDep)
-include(AddTarget)
-include(AutoFiles)
-ADD_COMPILATION_FLAGS()
-if(USE_DEP)
- ADD_DEP_INCLUDE_DIR("${ROOT_SOURCE_DIR}/dep")
- ADD_DEP_LIBRARY_DIR("${ROOT_SOURCE_DIR}/dep")
-endif()
-if(UNIX OR MINGW)
- if(CYGWIN)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
- else()
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
- if(NOT APPLE)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
- endif()
- endif()
- if((UNIX AND BUILD64) OR (MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 8))
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
- else()
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
- endif()
-endif()
-if(MSVC_IDE OR XCODE_VERSION)
- set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin")
-else()
- set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}")
-endif()
-add_definitions(-D_3DSTOOL_VERSION="${_3DSTOOL_MAJOR}.${_3DSTOOL_MINOR}.${_3DSTOOL_PATCHLEVEL}")
-if(WIN32)
- add_definitions(-D_CRT_SECURE_NO_WARNINGS)
-endif()
-if(UNIX OR MINGW)
- add_definitions(-D_FILE_OFFSET_BITS=64)
- add_definitions(-Wno-multichar -Wno-shift-overflow -Wno-unused-result)
- set(CMAKE_INSTALL_RPATH .)
- set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
-endif()
-add_subdirectory(src)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
deleted file mode 100644
index 23a33253..00000000
--- a/src/CMakeLists.txt
+++ /dev/null
@@ -1,46 +0,0 @@
-AUTO_FILES("." "src" "\\.(cpp|h)$")
-if(MSVC_VERSION LESS 1600)
- AUTO_FILES("${ROOT_SOURCE_DIR}/dep/src/capstone/msvc" "src" "\\.h$")
-endif()
-AUTO_FILES("${ROOT_SOURCE_DIR}/dep/src/capstone-3.0.5/include" "src" "\\.h$")
-AUTO_FILES("${ROOT_SOURCE_DIR}/dep/src/capstone-3.0.5" "src" "capstone-3.0.5/[^/]+\\.(c|h)$")
-AUTO_FILES("${ROOT_SOURCE_DIR}/dep/src/capstone-3.0.5/arch/ARM" "src" "\\.(c|h|inc)$")
-include_directories(${DEP_INCLUDE_DIR} "${ROOT_SOURCE_DIR}/dep/src/capstone-3.0.5/include")
-if(MSVC_VERSION LESS 1600)
- include_directories("${ROOT_SOURCE_DIR}/dep/src/capstone/msvc")
-endif()
-link_directories(${DEP_LIBRARY_DIR})
-add_definitions(-DSDW_MAIN -DCURL_STATICLIB -DCAPSTONE_USE_SYS_DYN_MEM -DCAPSTONE_HAS_ARM)
-if(APPLE)
- add_definitions(-DSDW_XCONVERT)
-endif()
-ADD_EXE(3dstool "${src}")
-if(WIN32)
- if(MSVC)
- if(MSVC_VERSION LESS 1800)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4005")
- endif()
- target_link_libraries(3dstool libcurl libcrypto WS2_32 Wldap32 Crypt32)
- set(3dstool_LINK_FLAGS_DEBUG "${3dstool_LINK_FLAGS_DEBUG} /NODEFAULTLIB:LIBCMT")
- if(MSVC_VERSION GREATER 1700)
- set(3dstool_LINK_FLAGS_DEBUG "${3dstool_LINK_FLAGS_DEBUG} /IGNORE:4099")
- set(3dstool_LINK_FLAGS_RELWITHDEBINFO "${3dstool_LINK_FLAGS_RELWITHDEBINFO} /IGNORE:4099")
- endif()
- set_target_properties(3dstool PROPERTIES
- LINK_FLAGS_DEBUG "${3dstool_LINK_FLAGS_DEBUG}"
- LINK_FLAGS_RELWITHDEBINFO "${3dstool_LINK_FLAGS_RELWITHDEBINFO}")
- else()
- target_link_libraries(3dstool curl crypto)
- endif()
-else()
- target_link_libraries(3dstool curl ssl crypto)
- if(APPLE)
- target_link_libraries(3dstool ldap)
- else()
- target_link_libraries(3dstool pthread dl)
- endif()
- if(APPLE OR CYGWIN)
- target_link_libraries(3dstool iconv)
- endif()
-endif()
-install(TARGETS 3dstool DESTINATION bin)
diff --git a/src/utility.cpp b/src/utility.cpp
index 7e341c06..ec84ca10 100644
--- a/src/utility.cpp
+++ b/src/utility.cpp
@@ -113,7 +113,7 @@ void PadFile(FILE* a_fpFile, n64 a_nPadSize, u8 a_uPadData)
#if defined(SDW_MAIN)
extern int UMain(int argc, UChar* argv[]);

-int main(int argc, char* argv[])
+int main_3dstool(int argc, char* argv[])
{
SetLocale();
int nArgc = 0;
Loading

0 comments on commit 36a5fec

Please sign in to comment.