From 6cd0b5a7143faa59bbfad5ee8910e29372fd3572 Mon Sep 17 00:00:00 2001 From: rw-r-r-0644 Date: Wed, 25 Sep 2019 15:36:49 +0200 Subject: [PATCH] Add cmake support --- share/romfs-wiiu.cmake | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 share/romfs-wiiu.cmake diff --git a/share/romfs-wiiu.cmake b/share/romfs-wiiu.cmake new file mode 100644 index 0000000..8eed09c --- /dev/null +++ b/share/romfs-wiiu.cmake @@ -0,0 +1,66 @@ + cmake_minimum_required(VERSION 3.2) + +# add romfs to project +macro(romfs_add target romfs_dir) + # find absolute romfs directory + set(ROMFS_INPUT_DIR ${romfs_dir}) + if(NOT IS_ABSOLUTE ${romfs_dir}) + set(ROMFS_INPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${romfs_dir}") + endif() + + # build tar object file from directory + add_custom_command( + OUTPUT app.romfs.o + COMMAND tar -H ustar -cvf romfs.tar -C "${ROMFS_INPUT_DIR}" . + COMMAND ${CMAKE_LINKER} --relocatable --format binary --output app.romfs.o romfs.tar + COMMAND rm -f romfs.tar + DEPENDS ${ROMFS_INPUT_DIR} + ) + + # build a static library from the object + add_library( + ROMFS + STATIC + app.romfs.o + ) + + set_source_files_properties( + app.romfs.o + PROPERTIES + EXTERNAL_OBJECT true + GENERATED true + ) + + set_target_properties( + ROMFS + PROPERTIES + LINKER_LANGUAGE C + ) + + # link the tar object static library to the final target + + + # find the libromfs-wiiu library and headers + find_path( + ROMFS_INCLUDE_DIR + romfs-wiiu.h + ) + + find_library( + ROMFS_LIBRARY + romfs-wiiu + ) + + # add the libromfs-wiiu library and headers to the final target + target_include_directories( + ${target} + PUBLIC + ${ROMFS_INCLUDE_DIR} + ) + + target_link_libraries( + ${target} + ${ROMFS_LIBRARY} + ROMFS + ) +endmacro()