Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cmake build support #22

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
/libntfs-3g/pkg
/liblwext4/src
/liblwext4/pkg

build
.cache
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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."
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()
25 changes: 25 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
59 changes: 59 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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)
find_path(ntfs-3g_inc ntfs-3g)

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})

target_compile_definitions(libusbhsfs PRIVATE GPL_BUILD)
endif()