diff --git a/components/core/CMakeLists.txt b/components/core/CMakeLists.txt index 6181cfd24f..6bc420b163 100644 --- a/components/core/CMakeLists.txt +++ b/components/core/CMakeLists.txt @@ -79,16 +79,6 @@ set(CLP_USE_STATIC_LIBS ON CACHE BOOL "Whether to link against static libraries" if (CLP_USE_STATIC_LIBS) if (APPLE) set(CLP_STATIC_LIBS_UNSUPPORTED_PLATFORM "macOS") - elseif (EXISTS "/etc/centos-release") - # NOTE: - # 1. We don't support static linking on any CentOS-based distro except manylinux_2_28 (which - # shows up as "AlmaLinux"). - # 2. A release called "AlmaLinux" doesn't guarantee we're running on a manylinux distro, but - # we can improve this check when someone reports an issue. - file(READ "/etc/centos-release" CENTOS_RELEASE_CONTENT) - if(NOT "${CENTOS_RELEASE_CONTENT}" MATCHES "AlmaLinux") - set(CLP_STATIC_LIBS_UNSUPPORTED_PLATFORM "CentOS") - endif() endif() if (DEFINED CLP_STATIC_LIBS_UNSUPPORTED_PLATFORM) @@ -222,12 +212,9 @@ if(CLP_NEED_LIBARCHIVE) if(CLP_USE_STATIC_LIBS) set(LibArchive_USE_STATIC_LIBS ON) endif() - find_package(LibArchive REQUIRED) - if(LibArchive_FOUND) - message(STATUS "Found LibArchive ${LibArchive_VERSION}") - else() - message(FATAL_ERROR "Could not find ${CLP_LIBS_STRING} libraries for LibArchive") - endif() + # TODO: Add why we need 3.8.1 + find_package(LibArchive 3.8.1 REQUIRED) + message(STATUS "Found LibArchive ${LibArchive_VERSION}") endif() # Find and setup libcurl diff --git a/components/core/cmake/Modules/FindLibArchive.cmake b/components/core/cmake/Modules/FindLibArchive.cmake index c257e88341..fcf57b8740 100644 --- a/components/core/cmake/Modules/FindLibArchive.cmake +++ b/components/core/cmake/Modules/FindLibArchive.cmake @@ -1,48 +1,51 @@ # Try to find LibArchive -# NOTE: The FindLibArchive.cmake included with CMake has no support for static libraries, so we use our own. +# NOTE: The FindLibArchive.cmake included with CMake has no support for static libraries, so we use +# our own. # # Set LibArchive_USE_STATIC_LIBS=ON to look for static libraries. # -# Once done this will define: -# LibArchive_FOUND - Whether LibArchive was found on the system -# LibArchive_INCLUDE_DIR - The LibArchive include directories -# LibArchive_VERSION - The version of LibArchive installed on the system +# Once done, this will define: +# LibArchive_FOUND - Whether the library was found on the system +# LibArchive_INCLUDE_DIR - The library include directories +# LibArchive_LIBRARY - The path to the library file +# +# And will define the following if the package configuration file provides relevant information: +# LibArchive_VERSION - The version of library installed on the system +# LibArchive_LIBRARY_DEPENDENCIES - Any additional modules required to link with the library # # Conventions: # - Variables only for use within the script are prefixed with "libarchive_" # - Variables that should be externally visible are prefixed with "LibArchive_" -set(libarchive_LIBNAME "archive") +include(FindPackageHandleStandardArgs) include(cmake/Modules/FindLibraryDependencies.cmake) -# On macOS, libarchive installed through brew is not linked into prefix by default. -# So it cannot be found by pkg-config and we need to manually find it. -# For more details, see https://github.com/Homebrew/homebrew-core/issues/117642 -# Find and setup libarchive -if(APPLE) - execute_process(COMMAND brew --prefix libarchive OUTPUT_VARIABLE libarchive_MACOS_PREFIX) - string(STRIP "${libarchive_MACOS_PREFIX}" libarchive_MACOS_PREFIX) - set(ENV{libarchive_PREV_CMAKE_PATH} "$ENV{CMAKE_PREFIX_PATH}") # save it so we can revert it later - set(ENV{CMAKE_PREFIX_PATH} "${libarchive_MACOS_PREFIX};$ENV{CMAKE_PREFIX_PATH}") +set(libarchive_HEADER "archive.h") +set(libarchive_LIBNAME "archive") +set(libarchive_LOCAL_PREFIX "libarchive") +set(libarchive_PKGCONFIG_NAME "libarchive") + +if(DEFINED LibArchive_ROOT) + set(libarchive_PKGCONFIG_DIR "${LibArchive_ROOT}/lib/pkgconfig") + set(ENV{libarchive_ORIG_PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}") + set(ENV{PKG_CONFIG_PATH} "${libarchive_PKGCONFIG_DIR};$ENV{PKG_CONFIG_PATH}") endif() # Run pkg-config find_package(PkgConfig) -pkg_check_modules(libarchive_PKGCONF QUIET "lib${libarchive_LIBNAME}") +pkg_check_modules(libarchive_PKGCONF QUIET "${libarchive_PKGCONFIG_NAME}") # Set include directory -find_path(LibArchive_INCLUDE_DIR archive.h +find_path(LibArchive_INCLUDE_DIR ${libarchive_HEADER} HINTS ${libarchive_PKGCONF_INCLUDEDIR} PATH_SUFFIXES include ) # Handle static libraries if(LibArchive_USE_STATIC_LIBS) - # Save current value of CMAKE_FIND_LIBRARY_SUFFIXES - set(libarchive_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - # Temporarily change CMAKE_FIND_LIBRARY_SUFFIXES to static library suffix + set(libarchive_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES .a) endif() @@ -52,13 +55,10 @@ find_library(LibArchive_LIBRARY HINTS ${libarchive_PKGCONF_LIBDIR} PATH_SUFFIXES lib ) -if (LibArchive_LIBRARY) - # NOTE: This must be set for find_package_handle_standard_args to work - set(LibArchive_FOUND ON) -endif() +# Find dependencies if(LibArchive_USE_STATIC_LIBS) - FindStaticLibraryDependencies(${libarchive_LIBNAME} libarchive + FindStaticLibraryDependencies(${libarchive_LIBNAME} ${libarchive_LOCAL_PREFIX} "${libarchive_PKGCONF_STATIC_LIBRARIES}") # Restore original value of CMAKE_FIND_LIBRARY_SUFFIXES @@ -68,25 +68,27 @@ endif() FindDynamicLibraryDependencies(libarchive "${libarchive_DYNAMIC_LIBS}") +message(STATUS "libarchive_PKGCONF_STATIC_LIBRARIES = ${libarchive_PKGCONF_STATIC_LIBRARIES}") +message(STATUS "libarchive_DYNAMIC_LIBS = ${libarchive_DYNAMIC_LIBS}") +message(STATUS "libarchive_LIBRARY_DEPENDENCIES = ${libarchive_LIBRARY_DEPENDENCIES}") + # Set version set(LibArchive_VERSION ${libarchive_PKGCONF_VERSION}) -include(FindPackageHandleStandardArgs) +# Set up find_package() call find_package_handle_standard_args(LibArchive - REQUIRED_VARS LibArchive_INCLUDE_DIR + REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR VERSION_VAR LibArchive_VERSION ) if(NOT TARGET LibArchive::LibArchive) # Add library to build - if (LibArchive_FOUND) - if (LibArchive_USE_STATIC_LIBS) - add_library(LibArchive::LibArchive STATIC IMPORTED) - else() - # NOTE: We use UNKNOWN so that if the user doesn't have the SHARED - # libraries installed, we can still use the STATIC libraries - add_library(LibArchive::LibArchive UNKNOWN IMPORTED) - endif() + if(LibArchive_USE_STATIC_LIBS) + add_library(LibArchive::LibArchive STATIC IMPORTED) + else() + # NOTE: We use UNKNOWN so that if the user doesn't have the SHARED + # libraries installed, we can still use the STATIC libraries + add_library(LibArchive::LibArchive UNKNOWN IMPORTED) endif() # Set include directories for library @@ -115,7 +117,8 @@ if(NOT TARGET LibArchive::LibArchive) endif() endif() -if(APPLE) - # remove LibArchive-specific path - set(ENV{CMAKE_PREFIX_PATH} "$ENV{libarchive_PREV_CMAKE_PATH}") -endif() \ No newline at end of file +# Restore original value of PKG_CONFIG_PATH +if(DEFINED ENV{libarchive_ORIG_PKG_CONFIG_PATH}) + set(ENV{PKG_CONFIG_PATH} "$ENV{libarchive_ORIG_PKG_CONFIG_PATH}") + unset(ENV{libarchive_ORIG_PKG_CONFIG_PATH}) +endif() diff --git a/components/core/tools/scripts/lib_install/centos-stream-9/install-prebuilt-packages.sh b/components/core/tools/scripts/lib_install/centos-stream-9/install-prebuilt-packages.sh index fa56074a58..96aa9702ac 100755 --- a/components/core/tools/scripts/lib_install/centos-stream-9/install-prebuilt-packages.sh +++ b/components/core/tools/scripts/lib_install/centos-stream-9/install-prebuilt-packages.sh @@ -17,8 +17,10 @@ dnf install -y \ make \ mariadb-connector-c-devel \ openssl-devel \ + python3-devel \ python3-pip \ - unzip + unzip \ + zlib-devel if ! command -v pipx >/dev/null 2>&1; then python3 -m pip install pipx diff --git a/taskfiles/deps/main.yaml b/taskfiles/deps/main.yaml index 308e3c119b..3078e2a48f 100644 --- a/taskfiles/deps/main.yaml +++ b/taskfiles/deps/main.yaml @@ -72,6 +72,7 @@ tasks: - task: "catch2" - task: "date" - task: "fmt" + - task: "libarchive" - task: "liblzma" - task: "log-surgeon" - task: "lz4" @@ -253,6 +254,24 @@ tasks: TARBALL_SHA256: "1250e4cc58bf06ee631567523f48848dc4596133e163f02615c97f78bab6c811" TARBALL_URL: "https://github.com/fmtlib/fmt/archive/refs/tags/10.2.1.tar.gz" + libarchive: + internal: true + run: "once" + cmds: + - task: "utils:install-remote-cmake-lib" + vars: + CMAKE_GEN_ARGS: + - "-DCMAKE_BUILD_TYPE=Release" + - "-DCMAKE_INSTALL_LIBDIR=lib" + - "-DCMAKE_INSTALL_MESSAGE=LAZY" + - "-DCMAKE_INSTALL_PREFIX={{.G_DEPS_CORE_DIR}}/LibArchive-install" + - "-DENABLE_EXPAT=OFF" + - "-DENABLE_OPENSSL=OFF" + LIB_NAME: "LibArchive" + TARBALL_SHA256: "bde832a5e3344dc723cfe9cc37f8e54bde04565bfe6f136bc1bd31ab352e9fab" + TARBALL_URL: "https://github.com/libarchive/libarchive/releases/download/v3.8.1\ + /libarchive-3.8.1.tar.gz" + liblzma: internal: true vars: