From 90b6106fb41330f852bcccf201dafb6c8fbf328b Mon Sep 17 00:00:00 2001 From: tarsin Date: Sun, 26 Feb 2023 17:31:59 +0800 Subject: [PATCH] Convert libarchive build to FetchContent --- .gitmodules | 3 -- .../cpp/0001-Don-t-build-shared-lib.patch | 38 +++++++++++++++++++ app/src/main/cpp/0002-Insert-link-libs.patch | 25 ++++++++++++ app/src/main/cpp/CMakeLists.txt | 13 ++++--- app/src/main/cpp/libarchive | 1 - 5 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 app/src/main/cpp/0001-Don-t-build-shared-lib.patch create mode 100644 app/src/main/cpp/0002-Insert-link-libs.patch delete mode 160000 app/src/main/cpp/libarchive diff --git a/.gitmodules b/.gitmodules index d36e57913..14a2bece7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "app/src/main/cpp/libarchive"] - path = app/src/main/cpp/libarchive - url = https://github.com/Ehviewer-Overhauled/libarchive [submodule "app/src/main/cpp/nettle/nettle"] path = app/src/main/cpp/nettle/nettle url = https://github.com/Ehviewer-Overhauled/nettle diff --git a/app/src/main/cpp/0001-Don-t-build-shared-lib.patch b/app/src/main/cpp/0001-Don-t-build-shared-lib.patch new file mode 100644 index 000000000..e16abcf5d --- /dev/null +++ b/app/src/main/cpp/0001-Don-t-build-shared-lib.patch @@ -0,0 +1,38 @@ +From 2a67861e6f06794f3671c4988bac12330d8422e3 Mon Sep 17 00:00:00 2001 +From: tarsin +Date: Fri, 27 May 2022 23:21:20 +0800 +Subject: [PATCH 1/2] Don't build shared lib + +--- + libarchive/CMakeLists.txt | 8 +------- + 1 file changed, 1 insertion(+), 7 deletions(-) + +diff --git a/libarchive/CMakeLists.txt b/libarchive/CMakeLists.txt +index ff7ade00..00c2e170 100644 +--- a/libarchive/CMakeLists.txt ++++ b/libarchive/CMakeLists.txt +@@ -242,12 +242,6 @@ ELSEIF(ARCHIVE_ACL_SUNOS) + LIST(APPEND libarchive_SOURCES archive_disk_acl_sunos.c) + ENDIF() + +-# Libarchive is a shared library +-ADD_LIBRARY(archive SHARED ${libarchive_SOURCES} ${include_HEADERS}) +-TARGET_INCLUDE_DIRECTORIES(archive PUBLIC .) +-TARGET_LINK_LIBRARIES(archive ${ADDITIONAL_LIBS}) +-SET_TARGET_PROPERTIES(archive PROPERTIES SOVERSION ${SOVERSION}) +- + # archive_static is a static library + ADD_LIBRARY(archive_static STATIC ${libarchive_SOURCES} ${include_HEADERS}) + TARGET_LINK_LIBRARIES(archive_static ${ADDITIONAL_LIBS}) +@@ -260,7 +254,7 @@ ENDIF(NOT WIN32 OR CYGWIN) + + IF(ENABLE_INSTALL) + # How to install the libraries +- INSTALL(TARGETS archive archive_static ++ INSTALL(TARGETS archive_static + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) +-- +2.39.2 + diff --git a/app/src/main/cpp/0002-Insert-link-libs.patch b/app/src/main/cpp/0002-Insert-link-libs.patch new file mode 100644 index 000000000..c4cf952a4 --- /dev/null +++ b/app/src/main/cpp/0002-Insert-link-libs.patch @@ -0,0 +1,25 @@ +From c9298fd6dc0a8b04dd4b2247118b9cb895c46e58 Mon Sep 17 00:00:00 2001 +From: tarsin +Date: Sat, 23 Jul 2022 16:05:36 +0800 +Subject: [PATCH 2/2] Insert link libs + +--- + CMakeLists.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 713e3bc5..7247640d 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -415,7 +415,7 @@ IF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}") + # # endif + ENDIF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}") + +-SET(ADDITIONAL_LIBS "") ++SET(ADDITIONAL_LIBS ${LIBARCHIVE_CUSTOM_LIBS}) + # + # Find ZLIB + # +-- +2.39.2 + diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 969af477b..ac456b85d 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -24,8 +24,6 @@ FetchContent_Declare(liblzma GIT_REPOSITORY https://git.tukaani.org/xz.git GIT_TAG v5.4.1 PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/0001-Don-t-build-other-binarys.patch || true - BINARY_DIR build - SUBBUILD_DIR subbuild ) FetchContent_MakeAvailable(liblzma) @@ -55,10 +53,15 @@ SET(HAVE_LIBLZMADEC 1) # Configure libarchive link's static lib SET(LIBARCHIVE_CUSTOM_LIBS "nettle" "liblzma") -# Build libarchive -add_subdirectory(libarchive) +FetchContent_Declare(libarchive + GIT_REPOSITORY https://github.com/libarchive/libarchive + GIT_TAG v3.6.2 + PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/0001-Don-t-build-shared-lib.patch ${CMAKE_CURRENT_LIST_DIR}/0002-Insert-link-libs.patch || true + ) + +FetchContent_MakeAvailable(libarchive) +include_directories(${libarchive_SOURCE_DIR}/libarchive) # Build and link our app's native lib add_library(${PROJECT_NAME} SHARED archive.c fdutils.c gifutils.c natsort/strnatcmp.c) -target_include_directories(${PROJECT_NAME} PUBLIC libarchive/libarchive) target_link_libraries(${PROJECT_NAME} archive_static log) diff --git a/app/src/main/cpp/libarchive b/app/src/main/cpp/libarchive deleted file mode 160000 index c9298fd6d..000000000 --- a/app/src/main/cpp/libarchive +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c9298fd6dc0a8b04dd4b2247118b9cb895c46e58