mirror of
https://github.com/stenzek/duckstation.git
synced 2026-07-11 01:24:11 +02:00
CI: Use prebuilt dependencies
Decouple from the repository. Less CI time, and faster building of older commits.
This commit is contained in:
@@ -1,9 +1,40 @@
|
||||
# Set prefix path to look for our bundled dependencies first on Windows.
|
||||
if(WIN32 AND CPU_ARCH_X64)
|
||||
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/dep/msvc/deps-x64")
|
||||
elseif(WIN32 AND CPU_ARCH_ARM64)
|
||||
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/dep/msvc/deps-arm64")
|
||||
# SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin <stenzek@gmail.com>
|
||||
# SPDX-License-Identifier: CC-BY-NC-ND-4.0 + Packaging Restriction
|
||||
|
||||
# Get prebuilt dependencies for the current platform and architecture.
|
||||
if(WIN32)
|
||||
if (CPU_ARCH_X64)
|
||||
set(DEPS_PATH "${CMAKE_SOURCE_DIR}/dep/prebuilt/windows-x64")
|
||||
elseif(CPU_ARCH_ARM64)
|
||||
set(DEPS_PATH "${CMAKE_SOURCE_DIR}/dep/prebuilt/windows-arm64")
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported architecture")
|
||||
endif()
|
||||
elseif(APPLE)
|
||||
set(DEPS_PATH "${CMAKE_SOURCE_DIR}/dep/prebuilt/macos-universal")
|
||||
elseif(LINUX)
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
set(DEPS_CROSS_PREFIX "-cross")
|
||||
else()
|
||||
set(DEPS_CROSS_PREFIX "")
|
||||
endif()
|
||||
|
||||
if (CPU_ARCH_X64)
|
||||
set(DEPS_PATH "${CMAKE_SOURCE_DIR}/dep/prebuilt/linux-x64")
|
||||
elseif(CPU_ARCH_ARM32)
|
||||
set(DEPS_PATH "${CMAKE_SOURCE_DIR}/dep/prebuilt/linux${DEPS_CROSS_PREFIX}-armhf")
|
||||
elseif(CPU_ARCH_ARM64)
|
||||
set(DEPS_PATH "${CMAKE_SOURCE_DIR}/dep/prebuilt/linux${DEPS_CROSS_PREFIX}-arm64")
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported architecture")
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported platform")
|
||||
endif()
|
||||
if(NOT EXISTS "${DEPS_PATH}")
|
||||
message(FATAL_ERROR "Prebuilt dependencies not found for the current platform and architecture.")
|
||||
endif()
|
||||
set(CMAKE_PREFIX_PATH "${DEPS_PATH}")
|
||||
|
||||
# Enable threads everywhere.
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
@@ -12,78 +43,73 @@ find_package(Threads REQUIRED)
|
||||
# pkg-config gets pulled transitively on some platforms.
|
||||
if(NOT WIN32 AND NOT APPLE)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Libbacktrace REQUIRED)
|
||||
endif()
|
||||
|
||||
# libpng relies on zlib, which we need the system version for on Mac.
|
||||
if(APPLE OR CPU_ARCH_ARM32 OR CPU_ARCH_ARM64)
|
||||
find_package(ZLIB REQUIRED)
|
||||
else()
|
||||
find_package(ZLIB 1.3.1 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/ZLIB")
|
||||
endif()
|
||||
|
||||
# Enforce use of bundled dependencies to avoid conflicts with system libraries.
|
||||
set(FIND_ROOT_PATH_BACKUP ${CMAKE_FIND_ROOT_PATH})
|
||||
set(FIND_ROOT_PATH_MODE_INCLUDE_BACKUP ${CMAKE_FIND_ROOT_PATH_MODE_INCLUDE})
|
||||
set(FIND_ROOT_PATH_MODE_LIBRARY_BACKUP ${CMAKE_FIND_ROOT_PATH_MODE_LIBRARY})
|
||||
set(FIND_ROOT_PATH_MODE_PACKAGE_BACKUP ${CMAKE_FIND_ROOT_PATH_MODE_PACKAGE})
|
||||
set(FIND_ROOT_PATH_MODE_PROGRAM_BACKUP ${CMAKE_FIND_ROOT_PATH_MODE_PROGRAM})
|
||||
set(CMAKE_FIND_ROOT_PATH ${CMAKE_PREFIX_PATH})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
|
||||
find_package(zstd 1.5.7 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/zstd")
|
||||
find_package(WebP 1.6.0 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/share/WebP/cmake")
|
||||
find_package(PNG 1.6.55 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/PNG")
|
||||
find_package(libjpeg-turbo 3.1.3 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/libjpeg-turbo")
|
||||
find_package(freetype 2.14.1 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/freetype")
|
||||
find_package(harfbuzz REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/harfbuzz")
|
||||
find_package(plutosvg 0.0.7 REQUIRED
|
||||
PATHS "${DEPS_PATH}/lib/cmake/plutosvg")
|
||||
find_package(cpuinfo REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/cpuinfo")
|
||||
find_package(DiscordRPC 3.4.0 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/DiscordRPC")
|
||||
find_package(SoundTouch 2.3.3 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/SoundTouch")
|
||||
find_package(libzip 1.11.4 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/libzip")
|
||||
find_package(Shaderc 2026.1 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/Shaderc")
|
||||
find_package(spirv_cross_c_shared REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/share/spirv_cross_c_shared/cmake")
|
||||
find_package(SDL3 3.4.2 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/SDL3")
|
||||
|
||||
# Search for local zlib version outside of Mac.
|
||||
if(NOT APPLE AND NOT CPU_ARCH_ARM32 AND NOT CPU_ARCH_ARM64)
|
||||
find_package(ZLIB 1.3.1 REQUIRED)
|
||||
endif()
|
||||
# Verify dependency paths.
|
||||
foreach(dep zstd WebP PNG libjpeg-turbo freetype harfbuzz plutosvg cpuinfo
|
||||
DiscordRPC SoundTouch libzip Shaderc spirv_cross_c_shared SDL3)
|
||||
if((${dep}_LIBRARY AND NOT "${${dep}_LIBRARY}" MATCHES "^${DEPS_PATH}") OR
|
||||
(${dep}_DIR AND NOT "${${dep}_DIR}" MATCHES "^${DEPS_PATH}"))
|
||||
message(FATAL_ERROR "Using incorrect ${dep} library. Check your dependencies.")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Bundled dependencies.
|
||||
find_package(zstd 1.5.7 REQUIRED)
|
||||
find_package(WebP REQUIRED) # v1.4.0, spews an error on Linux because no pkg-config.
|
||||
find_package(PNG 1.6.54 REQUIRED)
|
||||
find_package(JPEG REQUIRED)
|
||||
find_package(SDL3 3.4.0 REQUIRED)
|
||||
find_package(Freetype 2.14.1 REQUIRED)
|
||||
find_package(harfbuzz REQUIRED)
|
||||
find_package(plutosvg 0.0.6 REQUIRED)
|
||||
find_package(cpuinfo REQUIRED)
|
||||
find_package(DiscordRPC 3.4.0 REQUIRED)
|
||||
find_package(SoundTouch 2.3.3 REQUIRED)
|
||||
find_package(libzip 1.11.4 REQUIRED)
|
||||
find_package(Shaderc REQUIRED)
|
||||
find_package(spirv_cross_c_shared REQUIRED)
|
||||
|
||||
if(NOT WIN32 AND NOT APPLE)
|
||||
find_package(Libbacktrace REQUIRED)
|
||||
|
||||
# We need to add the rpath for shaderc to the executable.
|
||||
get_target_property(SHADERC_LIBRARY Shaderc::shaderc_shared IMPORTED_LOCATION)
|
||||
get_filename_component(SHADERC_LIBRARY_DIRECTORY ${SHADERC_LIBRARY} DIRECTORY)
|
||||
list(APPEND CMAKE_BUILD_RPATH ${SHADERC_LIBRARY_DIRECTORY})
|
||||
get_target_property(SPIRV_CROSS_LIBRARY spirv-cross-c-shared IMPORTED_LOCATION)
|
||||
get_filename_component(SPIRV_CROSS_LIBRARY_DIRECTORY ${SPIRV_CROSS_LIBRARY} DIRECTORY)
|
||||
list(APPEND CMAKE_BUILD_RPATH ${SPIRV_CROSS_LIBRARY_DIRECTORY})
|
||||
endif()
|
||||
|
||||
# Restore system package search path.
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${FIND_ROOT_PATH_MODE_INCLUDE_BACKUP})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ${FIND_ROOT_PATH_MODE_LIBRARY_BACKUP})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ${FIND_ROOT_PATH_MODE_PACKAGE_BACKUP})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${FIND_ROOT_PATH_MODE_PROGRAM_BACKUP})
|
||||
set(CMAKE_FIND_ROOT_PATH ${FIND_ROOT_PATH_BACKUP})
|
||||
|
||||
# Qt has transitive dependencies on system libs, so do it afterwards.
|
||||
if(BUILD_QT_FRONTEND)
|
||||
# All our builds include Qt, so this is not a problem.
|
||||
set(QT_NO_PRIVATE_MODULE_WARNING ON)
|
||||
|
||||
# Should be prebuilt.
|
||||
if(LINUX)
|
||||
find_package(Qt6 6.10.2 COMPONENTS Core Gui GuiPrivate Widgets LinguistTools DBus REQUIRED)
|
||||
find_package(Qt6 6.10.2 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/Qt6"
|
||||
COMPONENTS Core Gui GuiPrivate Widgets LinguistTools DBus)
|
||||
else()
|
||||
find_package(Qt6 6.10.2 COMPONENTS Core Gui GuiPrivate Widgets LinguistTools REQUIRED)
|
||||
find_package(Qt6 6.10.2 REQUIRED
|
||||
NO_DEFAULT_PATH PATHS "${DEPS_PATH}/lib/cmake/Qt6"
|
||||
COMPONENTS Core Gui GuiPrivate Widgets LinguistTools)
|
||||
endif()
|
||||
|
||||
# Have to verify it down here, don't want users using unpatched Qt.
|
||||
if(NOT Qt6_DIR MATCHES "^${CMAKE_PREFIX_PATH}")
|
||||
if(NOT Qt6_DIR MATCHES "^${DEPS_PATH}")
|
||||
message(FATAL_ERROR "Using incorrect Qt library. Check your dependencies.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -8,12 +8,14 @@ FIND_PATH(
|
||||
LIBBACKTRACE_INCLUDE_DIR backtrace.h
|
||||
HINTS "${CMAKE_PREFIX_PATH}/include" /usr/include /usr/local/include
|
||||
${LIBBACKTRACE_PATH_INCLUDES}
|
||||
NO_CMAKE_FIND_ROOT_PATH
|
||||
)
|
||||
|
||||
FIND_LIBRARY(
|
||||
LIBBACKTRACE_LIBRARY
|
||||
NAMES backtrace
|
||||
PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64" ${ADDITIONAL_LIBRARY_PATHS} ${LIBBACKTRACE_PATH_LIB}
|
||||
NO_CMAKE_FIND_ROOT_PATH
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
# Copyright (C) 2020 Sony Interactive Entertainment Inc.
|
||||
# Copyright (C) 2012 Raphael Kubo da Costa <rakuco@webkit.org>
|
||||
# Copyright (C) 2013 Igalia S.L.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
|
||||
# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#[=======================================================================[.rst:
|
||||
FindWebP
|
||||
--------------
|
||||
|
||||
Find WebP headers and libraries.
|
||||
|
||||
Imported Targets
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
``WebP::libwebp``
|
||||
The WebP library, if found.
|
||||
|
||||
``WebP::demux``
|
||||
The WebP demux library, if found.
|
||||
|
||||
Result Variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This will define the following variables in your project:
|
||||
|
||||
``WebP_FOUND``
|
||||
true if (the requested version of) WebP is available.
|
||||
``WebP_VERSION``
|
||||
the version of WebP.
|
||||
``WebP_LIBRARIES``
|
||||
the libraries to link against to use WebP.
|
||||
``WebP_INCLUDE_DIRS``
|
||||
where to find the WebP headers.
|
||||
``WebP_COMPILE_OPTIONS``
|
||||
this should be passed to target_compile_options(), if the
|
||||
target is not used for linking
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(PC_WEBP QUIET libwebp)
|
||||
set(WebP_COMPILE_OPTIONS ${PC_WEBP_CFLAGS_OTHER})
|
||||
set(WebP_VERSION ${PC_WEBP_CFLAGS_VERSION})
|
||||
|
||||
find_path(WebP_INCLUDE_DIR
|
||||
NAMES webp/decode.h
|
||||
HINTS ${PC_WEBP_INCLUDEDIR} ${PC_WEBP_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
find_library(WebP_LIBRARY
|
||||
NAMES ${WebP_NAMES} webp libwebp
|
||||
HINTS ${PC_WEBP_LIBDIR} ${PC_WEBP_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
# There's nothing in the WebP headers that could be used to detect the exact
|
||||
# WebP version being used so don't attempt to do so. A version can only be found
|
||||
# through pkg-config
|
||||
if ("${WebP_FIND_VERSION}" VERSION_GREATER "${WebP_VERSION}")
|
||||
if (WebP_VERSION)
|
||||
message(FATAL_ERROR "Required version (" ${WebP_FIND_VERSION} ") is higher than found version (" ${WebP_VERSION} ")")
|
||||
else ()
|
||||
message(WARNING "Cannot determine WebP version without pkg-config")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# Find components
|
||||
if (WebP_INCLUDE_DIR AND WebP_LIBRARY)
|
||||
set(_WebP_REQUIRED_LIBS_FOUND ON)
|
||||
set(WebP_LIBS_FOUND "WebP (required): ${WebP_LIBRARY}")
|
||||
else ()
|
||||
set(_WebP_REQUIRED_LIBS_FOUND OFF)
|
||||
set(WebP_LIBS_NOT_FOUND "WebP (required)")
|
||||
endif ()
|
||||
|
||||
if ("demux" IN_LIST WebP_FIND_COMPONENTS)
|
||||
find_library(WebP_DEMUX_LIBRARY
|
||||
NAMES ${WebP_DEMUX_NAMES} webpdemux libwebpdemux
|
||||
HINTS ${PC_WEBP_LIBDIR} ${PC_WEBP_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
if (WebP_DEMUX_LIBRARY)
|
||||
if (WebP_FIND_REQUIRED_demux)
|
||||
list(APPEND WebP_LIBS_FOUND "demux (required): ${WebP_DEMUX_LIBRARY}")
|
||||
else ()
|
||||
list(APPEND WebP_LIBS_FOUND "demux (optional): ${WebP_DEMUX_LIBRARY}")
|
||||
endif ()
|
||||
else ()
|
||||
if (WebP_FIND_REQUIRED_demux)
|
||||
set(_WebP_REQUIRED_LIBS_FOUND OFF)
|
||||
list(APPEND WebP_LIBS_NOT_FOUND "demux (required)")
|
||||
else ()
|
||||
list(APPEND WebP_LIBS_NOT_FOUND "demux (optional)")
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (NOT WebP_FIND_QUIETLY)
|
||||
if (WebP_LIBS_FOUND)
|
||||
message(STATUS "Found the following WebP libraries:")
|
||||
foreach (found ${WebP_LIBS_FOUND})
|
||||
message(STATUS " ${found}")
|
||||
endforeach ()
|
||||
endif ()
|
||||
if (WebP_LIBS_NOT_FOUND)
|
||||
message(STATUS "The following WebP libraries were not found:")
|
||||
foreach (found ${WebP_LIBS_NOT_FOUND})
|
||||
message(STATUS " ${found}")
|
||||
endforeach ()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(WebP
|
||||
FOUND_VAR WebP_FOUND
|
||||
REQUIRED_VARS WebP_INCLUDE_DIR WebP_LIBRARY _WebP_REQUIRED_LIBS_FOUND
|
||||
VERSION_VAR WebP_VERSION
|
||||
)
|
||||
|
||||
if (WebP_LIBRARY AND NOT TARGET WebP::libwebp)
|
||||
add_library(WebP::libwebp UNKNOWN IMPORTED GLOBAL)
|
||||
set_target_properties(WebP::libwebp PROPERTIES
|
||||
IMPORTED_LOCATION "${WebP_LIBRARY}"
|
||||
INTERFACE_COMPILE_OPTIONS "${WebP_COMPILE_OPTIONS}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${WebP_INCLUDE_DIR}"
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (WebP_DEMUX_LIBRARY AND NOT TARGET WebP::demux)
|
||||
add_library(WebP::demux UNKNOWN IMPORTED GLOBAL)
|
||||
set_target_properties(WebP::demux PROPERTIES
|
||||
IMPORTED_LOCATION "${WebP_DEMUX_LIBRARY}"
|
||||
INTERFACE_COMPILE_OPTIONS "${WebP_COMPILE_OPTIONS}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${WebP_INCLUDE_DIR}"
|
||||
)
|
||||
endif ()
|
||||
|
||||
mark_as_advanced(
|
||||
WebP_INCLUDE_DIR
|
||||
WebP_LIBRARY
|
||||
WebP_DEMUX_LIBRARY
|
||||
)
|
||||
|
||||
if (WebP_FOUND)
|
||||
set(WebP_LIBRARIES ${WebP_LIBRARY} ${WebP_DEMUX_LIBRARY})
|
||||
set(WebP_INCLUDE_DIRS ${WebP_INCLUDE_DIR})
|
||||
endif ()
|
||||
@@ -1,186 +0,0 @@
|
||||
# Copyright (C) 2020 Dieter Baron and Thomas Klausner
|
||||
#
|
||||
# The authors can be contacted at <info@libzip.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# 3. The names of the authors may not be used to endorse or promote
|
||||
# products derived from this software without specific prior
|
||||
# written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
||||
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#[=======================================================================[.rst:
|
||||
Findzstd
|
||||
-------
|
||||
|
||||
Finds the Zstandard (zstd) library.
|
||||
|
||||
Imported Targets
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module provides the following imported targets, if found:
|
||||
|
||||
``zstd::libzstd_shared``
|
||||
The shared Zstandard library
|
||||
``zstd::libzstd_static``
|
||||
The shared Zstandard library
|
||||
|
||||
Result Variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This will define the following variables:
|
||||
|
||||
``zstd_FOUND``
|
||||
True if the system has the Zstandard library.
|
||||
``zstd_VERSION``
|
||||
The version of the Zstandard library which was found.
|
||||
|
||||
Cache Variables
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
The following cache variables may also be set:
|
||||
|
||||
``zstd_INCLUDE_DIR``
|
||||
The directory containing ``zstd.h``.
|
||||
``zstd_STATIC_LIBRARY``
|
||||
The path to the Zstandard static library.
|
||||
``zstd_SHARED_LIBRARY``
|
||||
The path to the Zstandard shared library.
|
||||
``zstd_DLL``
|
||||
The path to the Zstandard DLL.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(PC_zstd QUIET libzstd)
|
||||
|
||||
find_path(zstd_INCLUDE_DIR
|
||||
NAMES zstd.h
|
||||
HINTS ${PC_zstd_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
find_file(zstd_DLL
|
||||
NAMES libzstd.dll zstd.dll
|
||||
PATH_SUFFIXES bin
|
||||
HINTS ${PC_zstd_PREFIX}
|
||||
)
|
||||
|
||||
# On Windows, we manually define the library names to avoid mistaking the
|
||||
# implib for the static library
|
||||
if(zstd_DLL)
|
||||
set(_zstd_win_static_name zstd-static)
|
||||
set(_zstd_win_shared_name zstd)
|
||||
else()
|
||||
# vcpkg removes the -static suffix in static builds
|
||||
set(_zstd_win_static_name zstd zstd_static)
|
||||
set(_zstd_win_shared_name)
|
||||
endif()
|
||||
|
||||
set(_previous_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".dylib" ".dll.a" ".lib")
|
||||
find_library(zstd_SHARED_LIBRARY
|
||||
NAMES zstd ${_zstd_win_shared_name}
|
||||
HINTS ${PC_zstd_LIBDIR}
|
||||
)
|
||||
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".lib")
|
||||
find_library(zstd_STATIC_LIBRARY
|
||||
NAMES zstd ${_zstd_win_static_name}
|
||||
HINTS ${PC_zstd_LIBDIR}
|
||||
)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_previous_suffixes})
|
||||
|
||||
# Set zstd_LIBRARY to the shared library or fall back to the static library
|
||||
if(zstd_SHARED_LIBRARY)
|
||||
set(_zstd_LIBRARY ${zstd_SHARED_LIBRARY})
|
||||
else()
|
||||
set(_zstd_LIBRARY ${zstd_STATIC_LIBRARY})
|
||||
endif()
|
||||
|
||||
# Extract version information from the header file
|
||||
if(zstd_INCLUDE_DIR)
|
||||
file(STRINGS ${zstd_INCLUDE_DIR}/zstd.h _ver_major_line
|
||||
REGEX "^#define ZSTD_VERSION_MAJOR *[0-9]+"
|
||||
LIMIT_COUNT 1)
|
||||
string(REGEX MATCH "[0-9]+"
|
||||
zstd_MAJOR_VERSION "${_ver_major_line}")
|
||||
file(STRINGS ${zstd_INCLUDE_DIR}/zstd.h _ver_minor_line
|
||||
REGEX "^#define ZSTD_VERSION_MINOR *[0-9]+"
|
||||
LIMIT_COUNT 1)
|
||||
string(REGEX MATCH "[0-9]+"
|
||||
zstd_MINOR_VERSION "${_ver_minor_line}")
|
||||
file(STRINGS ${zstd_INCLUDE_DIR}/zstd.h _ver_release_line
|
||||
REGEX "^#define ZSTD_VERSION_RELEASE *[0-9]+"
|
||||
LIMIT_COUNT 1)
|
||||
string(REGEX MATCH "[0-9]+"
|
||||
zstd_RELEASE_VERSION "${_ver_release_line}")
|
||||
set(Zstd_VERSION "${zstd_MAJOR_VERSION}.${zstd_MINOR_VERSION}.${zstd_RELEASE_VERSION}")
|
||||
unset(_ver_major_line)
|
||||
unset(_ver_minor_line)
|
||||
unset(_ver_release_line)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(zstd
|
||||
FOUND_VAR zstd_FOUND
|
||||
REQUIRED_VARS
|
||||
_zstd_LIBRARY
|
||||
zstd_INCLUDE_DIR
|
||||
VERSION_VAR zstd_VERSION
|
||||
)
|
||||
|
||||
if(zstd_FOUND AND zstd_SHARED_LIBRARY AND NOT TARGET zstd::libzstd_shared)
|
||||
add_library(zstd::libzstd_shared SHARED IMPORTED)
|
||||
if(WIN32)
|
||||
set_target_properties(zstd::libzstd_shared PROPERTIES
|
||||
IMPORTED_LOCATION "${zstd_DLL}"
|
||||
IMPORTED_IMPLIB "${zstd_SHARED_LIBRARY}"
|
||||
)
|
||||
else()
|
||||
set_target_properties(zstd::libzstd_shared PROPERTIES
|
||||
IMPORTED_LOCATION "${zstd_SHARED_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
set_target_properties(zstd::libzstd_shared PROPERTIES
|
||||
INTERFACE_COMPILE_OPTIONS "${PC_zstd_CFLAGS_OTHER}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(zstd_FOUND AND zstd_STATIC_LIBRARY AND NOT TARGET zstd::libzstd_static)
|
||||
add_library(zstd::libzstd_static STATIC IMPORTED)
|
||||
set_target_properties(zstd::libzstd_static PROPERTIES
|
||||
IMPORTED_LOCATION "${zstd_STATIC_LIBRARY}"
|
||||
INTERFACE_COMPILE_OPTIONS "${PC_zstd_CFLAGS_OTHER}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(
|
||||
zstd_INCLUDE_DIR
|
||||
zstd_DLL
|
||||
zstd_SHARED_LIBRARY
|
||||
zstd_STATIC_LIBRARY
|
||||
)
|
||||
Reference in New Issue
Block a user