From cf8b5805335f15a3b6b6cbb221b90ec490489a4e Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Wed, 18 May 2022 23:38:17 +0100 Subject: [PATCH 1/3] add cmake build support --- .gitignore | 3 +++ CMakeLists.txt | 17 ++++++++++++++ example/CMakeLists.txt | 25 +++++++++++++++++++++ source/CMakeLists.txt | 51 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 example/CMakeLists.txt create mode 100644 source/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 457ec0d..76f93d1 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ /libntfs-3g/pkg /liblwext4/src /liblwext4/pkg + +build +.cache diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..af366b5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.12) + +project(libusbhsfs + VERSION 0.2.6 + DESCRIPTION "USB Mass Storage Class Host + Filesystem Mounter static library for Nintendo Switch homebrew applications." + HOMEPAGE_URL "https://github.com/DarkMatterCore/libusbhsfs" + LANGUAGES C +) + +option(USBHSFS_GPL "ext4 and ntfs support" OFF) +option(USBHSFS_EXAMPLE "build example" OFF) + +add_subdirectory(source) + +if (USBHSFS_EXAMPLE) + add_subdirectory(example) +endif() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 0000000..6abc228 --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.12) + +project(libusbhsfs-example + LANGUAGES C +) + +string(TIMESTAMP BUILD_TIMESTAMP "%Y-%m-%d %H:%M:%S" UTC) + +add_executable(libusbhsfs-example source/main.c) + +target_link_libraries(libusbhsfs-example PRIVATE libusbhsfs) +target_compile_definitions(libusbhsfs-example PRIVATE + APP_TITLE="libusbhsfs-example" + BUILD_TIMESTAMP="${BUILD_TIMESTAMP}" +) + +nx_generate_nacp(libusbhsfs-example.nacp + NAME "libusbhsfs-example" + AUTHOR "DarkMatterCore, XorTroll, Rhys Koedijk" + VERSION 0.0.1 +) + +nx_create_nro(libusbhsfs-example + NACP libusbhsfs-example.nacp +) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt new file mode 100644 index 0000000..45f62a1 --- /dev/null +++ b/source/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.12) + +add_library(libusbhsfs + usbhsfs_drive.c + usbhsfs_log.c + usbhsfs_manager.c + usbhsfs_mount.c + usbhsfs_request.c + usbhsfs_scsi.c + usbhsfs_utils.c +) + +target_include_directories(libusbhsfs PUBLIC ${CMAKE_SOURCE_DIR}/include) + +# fatfs stuff +target_sources(libusbhsfs PRIVATE + fatfs/diskio.c + fatfs/ff_dev.c + fatfs/ff.c + fatfs/ffsystem.c + fatfs/ffunicode.c +) + +# sxos stuff +target_sources(libusbhsfs PRIVATE + sxos/usbfs_dev.c + sxos/usbfs.c +) + +if (USBHSFS_GPL) + target_sources(libusbhsfs PRIVATE + lwext4/ext_dev.c + lwext4/ext_disk_io.c + lwext4/ext.c + + ntfs-3g/ntfs_dev.c + ntfs-3g/ntfs_disk_io.c + ntfs-3g/ntfs.c + ) + + find_library(ntfs-3g_lib ntfs-3g REQUIRED) + find_path(ntfs-3g_inc ntfs-3g REUIRED) + + find_library(lwext4_lib lwext4 REUIRED) + find_path(lwext4_inc lwext4 REUIRED) + + target_link_libraries(libusbhsfs PRIVATE ${ntfs-3g_lib} ${lwext4_lib}) + target_include_directories(libusbhsfs PRIVATE ${ntfs-3g_inc} ${lwext4_inc}) + + target_compile_definitions(libusbhsfs PRIVATE GPL_BUILD) +endif() From f444c63cebce6c85ba65ec473aa9a66ce56bade8 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Wed, 18 May 2022 23:56:33 +0100 Subject: [PATCH 2/3] auto set CMAKE_TOOLCHAIN_FILE if the user doesn't set the var themselves --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index af366b5..6673ed6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,11 @@ cmake_minimum_required(VERSION 3.12) +# this may stop working if dkp decides to change the location +# of the cmake files, in which case, pass -DCMAKE_TOOLCHAIN_FILE="the/new/path" +if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE "$ENV{DEVKITPRO}/cmake/Switch.cmake") +endif() + project(libusbhsfs VERSION 0.2.6 DESCRIPTION "USB Mass Storage Class Host + Filesystem Mounter static library for Nintendo Switch homebrew applications." From c13742ac4557c78956dae25737304142046e6c12 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Thu, 19 May 2022 00:48:15 +0100 Subject: [PATCH 3/3] removed "required" from find_xxx() as it was added in cmake 3.18 3.18 is too new of a version imo. --- source/CMakeLists.txt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 45f62a1..3727bfc 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -38,11 +38,19 @@ if (USBHSFS_GPL) ntfs-3g/ntfs.c ) - find_library(ntfs-3g_lib ntfs-3g REQUIRED) - find_path(ntfs-3g_inc ntfs-3g REUIRED) + find_library(ntfs-3g_lib ntfs-3g) + find_path(ntfs-3g_inc ntfs-3g) - find_library(lwext4_lib lwext4 REUIRED) - find_path(lwext4_inc lwext4 REUIRED) + find_library(lwext4_lib lwext4) + find_path(lwext4_inc lwext4) + + if (NOT ntfs-3g_lib OR NOT ntfs-3g_inc) + message(FATAL_ERROR "ntfs-3g is not installed!") + endif() + + if (NOT lwext4_lib OR NOT lwext4_inc) + message(FATAL_ERROR "lwext4 is not installed!") + endif() target_link_libraries(libusbhsfs PRIVATE ${ntfs-3g_lib} ${lwext4_lib}) target_include_directories(libusbhsfs PRIVATE ${ntfs-3g_inc} ${lwext4_inc})