mirror of
https://github.com/ScrelliCopter/tmx2gba.git
synced 2025-02-21 03:29:25 +11:00
revamp zstd find behaviour
This commit is contained in:
@@ -19,7 +19,7 @@ if (ENABLE_ASAN)
|
|||||||
add_link_options(-fsanitize=address -shared-libasan)
|
add_link_options(-fsanitize=address -shared-libasan)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
|
||||||
|
|
||||||
# Libraries
|
# Libraries
|
||||||
if (USE_BUNDLED_PUGIXML)
|
if (USE_BUNDLED_PUGIXML)
|
||||||
@@ -37,7 +37,7 @@ endif()
|
|||||||
if (USE_BUNDLED_ZSTD)
|
if (USE_BUNDLED_ZSTD)
|
||||||
add_subdirectory(ext/zstd)
|
add_subdirectory(ext/zstd)
|
||||||
else()
|
else()
|
||||||
find_package(ZSTD REQUIRED)
|
find_package(Zstd REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(ext/base64)
|
add_subdirectory(ext/base64)
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
#
|
|
||||||
# - Try to find Facebook zstd library
|
|
||||||
# This will define
|
|
||||||
# ZSTD_FOUND
|
|
||||||
# ZSTD_INCLUDE_DIR
|
|
||||||
# ZSTD_LIBRARY
|
|
||||||
#
|
|
||||||
|
|
||||||
find_path(ZSTD_INCLUDE_DIR NAMES zstd.h)
|
|
||||||
|
|
||||||
find_library(ZSTD_LIBRARY_DEBUG NAMES zstdd zstd_staticd)
|
|
||||||
find_library(ZSTD_LIBRARY_RELEASE NAMES zstd zstd_static)
|
|
||||||
|
|
||||||
include(SelectLibraryConfigurations)
|
|
||||||
SELECT_LIBRARY_CONFIGURATIONS(ZSTD)
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
|
|
||||||
ZSTD DEFAULT_MSG
|
|
||||||
ZSTD_LIBRARY ZSTD_INCLUDE_DIR
|
|
||||||
)
|
|
||||||
|
|
||||||
if (ZSTD_FOUND)
|
|
||||||
message(STATUS "Found Zstd: ${ZSTD_LIBRARY}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY)
|
|
||||||
171
cmake/modules/FindZstd.cmake
Normal file
171
cmake/modules/FindZstd.cmake
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
# SPDX-License-Identifier: Zlib
|
||||||
|
# SPDX-FileCopyrightText: 2024 a dinosaur
|
||||||
|
|
||||||
|
#[=======================================================================[.rst:
|
||||||
|
FindZstd
|
||||||
|
--------
|
||||||
|
|
||||||
|
Find the Facebook Zstd library.
|
||||||
|
|
||||||
|
Imported Targets
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
.. variable:: Zstd::Zstd
|
||||||
|
|
||||||
|
:prop_tgt:`IMPORTED` target for using Zstd, if Zstd is found.
|
||||||
|
|
||||||
|
Result Variables
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
This module defines the following variables:
|
||||||
|
.. variable:: Zstd_FOUND
|
||||||
|
|
||||||
|
True if Zstd was found.
|
||||||
|
|
||||||
|
.. variable:: Zstd_INCLUDE_DIRS
|
||||||
|
|
||||||
|
Path to the directory containing the Zstd headers (zstd.h, etc.)
|
||||||
|
|
||||||
|
.. variable:: Zstd_LIBRARIES
|
||||||
|
|
||||||
|
Location of the Zstd library.
|
||||||
|
|
||||||
|
.. variable:: Zstd_VERSION
|
||||||
|
|
||||||
|
The version of Zstd found.
|
||||||
|
|
||||||
|
Legacy Variables
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
The following variables are defined by the official Zstd CMakeLists.txt:
|
||||||
|
|
||||||
|
.. variable:: zstd_VERSION_MAJOR
|
||||||
|
|
||||||
|
The major version of Zstd.
|
||||||
|
|
||||||
|
.. variable:: zstd_VERSION_MINOR
|
||||||
|
|
||||||
|
The minor version of Zstd.
|
||||||
|
|
||||||
|
.. variable:: zstd_VERSION_PATCH
|
||||||
|
|
||||||
|
The patch/release version of Zstd.
|
||||||
|
|
||||||
|
The following variables are provided for compatibility with old find modules:
|
||||||
|
|
||||||
|
.. variable:: ZSTD_INCLUDE_DIR
|
||||||
|
|
||||||
|
Directory containing the Zstd header. (use ``Zstd_INCLUDE_DIRS`` instead)
|
||||||
|
|
||||||
|
.. variable:: ZSTD_LIBRARY
|
||||||
|
|
||||||
|
The Zstd library. (use ``Zstd_LIBRARIES`` instead)
|
||||||
|
|
||||||
|
Hints
|
||||||
|
^^^^^
|
||||||
|
|
||||||
|
.. variable:: Zstd_PREFER_STATIC_LIBS
|
||||||
|
|
||||||
|
Set to ``ON`` to prefer static libraries. Defaults to ``OFF``
|
||||||
|
|
||||||
|
Cache Variables
|
||||||
|
^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
The following cache variables may also be set,
|
||||||
|
these are transitory and should not be relied upon:
|
||||||
|
|
||||||
|
.. variable:: Zstd_INCLUDE_DIR
|
||||||
|
|
||||||
|
Directory containing the Zstd header.
|
||||||
|
|
||||||
|
.. variable:: Zstd_LIBRARY_DEBUG
|
||||||
|
|
||||||
|
The Zstd debug library if found.
|
||||||
|
|
||||||
|
.. variable:: Zstd_LIBRARY_RELEASE
|
||||||
|
|
||||||
|
The Zstd release library if found.
|
||||||
|
|
||||||
|
.. variable:: Zstd_LIBRARY
|
||||||
|
|
||||||
|
The Zstd library.
|
||||||
|
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
#TODO: define Zstd::static & Zstd::shared and alias Zstd::Zstd based on preference
|
||||||
|
|
||||||
|
find_path(Zstd_INCLUDE_DIR NAMES zstd.h)
|
||||||
|
|
||||||
|
mark_as_advanced(Zstd_INCLUDE_DIR)
|
||||||
|
|
||||||
|
if (Zstd_PREFER_STATIC_LIBS)
|
||||||
|
find_library(Zstd_LIBRARY_DEBUG NAMES zstd_staticd zstdd)
|
||||||
|
find_library(Zstd_LIBRARY_RELEASE NAMES zstd_static zstd)
|
||||||
|
else()
|
||||||
|
find_library(Zstd_LIBRARY_DEBUG NAMES zstdd zstd_staticd)
|
||||||
|
find_library(Zstd_LIBRARY_RELEASE NAMES zstd zstd_static)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(SelectLibraryConfigurations)
|
||||||
|
select_library_configurations(Zstd)
|
||||||
|
|
||||||
|
mark_as_advanced(Zstd_LIBRARY Zstd_LIBRARY_DEBUG Zstd_LIBRARY_RELEASE)
|
||||||
|
|
||||||
|
if (Zstd_INCLUDE_DIR AND EXISTS "${Zstd_INCLUDE_DIR}/zstd.h")
|
||||||
|
function (_zstd_read_define _variable _define)
|
||||||
|
set(_file "${Zstd_INCLUDE_DIR}/zstd.h")
|
||||||
|
set(_regex "#define[ \t]+${_define}[ \t]+([0-9]+)")
|
||||||
|
file(STRINGS "${_file}" _line LIMIT_COUNT 1 REGEX "${_regex}")
|
||||||
|
if (CMAKE_VERSION VERSION_LESS "3.29")
|
||||||
|
string(REGEX MATCH "${_regex}" _line "${_line}")
|
||||||
|
endif()
|
||||||
|
set(${_variable} ${CMAKE_MATCH_1} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
_zstd_read_define(zstd_VERSION_MAJOR "ZSTD_VERSION_MAJOR")
|
||||||
|
_zstd_read_define(zstd_VERSION_MINOR "ZSTD_VERSION_MINOR")
|
||||||
|
_zstd_read_define(zstd_VERSION_PATCH "ZSTD_VERSION_RELEASE")
|
||||||
|
set(Zstd_VERSION "${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}")
|
||||||
|
|
||||||
|
mark_as_advanced(zstd_VERSION_MAJOR zstd_VERSION_MINOR zstd_VERSION_PATCH Zstd_VERSION)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(Zstd
|
||||||
|
REQUIRED_VARS Zstd_LIBRARY Zstd_INCLUDE_DIR
|
||||||
|
VERSION_VAR Zstd_VERSION)
|
||||||
|
|
||||||
|
mark_as_advanced(Zstd_FOUND)
|
||||||
|
|
||||||
|
if (Zstd_FOUND)
|
||||||
|
set(Zstd_INCLUDE_DIRS ${Zstd_INCLUDE_DIR})
|
||||||
|
set(Zstd_LIBRARIES ${Zstd_LIBRARY})
|
||||||
|
|
||||||
|
# Legacy variables
|
||||||
|
set(ZSTD_INCLUDE_DIR ${Zstd_INCLUDE_DIR})
|
||||||
|
set(ZSTD_LIBRARY ${Zstd_LIBRARY})
|
||||||
|
mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY)
|
||||||
|
|
||||||
|
if (NOT TARGET Zstd::Zstd)
|
||||||
|
add_library(Zstd::Zstd UNKNOWN IMPORTED)
|
||||||
|
set_property(TARGET Zstd::Zstd PROPERTY
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${Zstd_INCLUDE_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT Zstd_LIBRARY_DEBUG AND NOT Zstd_LIBRARY_RELEASE)
|
||||||
|
set_property(TARGET Zstd::Zstd PROPERTY
|
||||||
|
IMPORTED_LOCATION "${Zstd_LIBRARY}")
|
||||||
|
endif()
|
||||||
|
if (Zstd_LIBRARY_DEBUG)
|
||||||
|
set_property(TARGET Zstd::Zstd APPEND PROPERTY
|
||||||
|
IMPORTED_CONFIGURATIONS DEBUG)
|
||||||
|
set_property(TARGET Zstd::Zstd PROPERTY
|
||||||
|
IMPORTED_LOCATION_DEBUG "${Zstd_LIBRARY_DEBUG}")
|
||||||
|
endif()
|
||||||
|
if (Zstd_LIBRARY_RELEASE)
|
||||||
|
set_property(TARGET Zstd::Zstd APPEND PROPERTY
|
||||||
|
IMPORTED_CONFIGURATIONS RELEASE)
|
||||||
|
set_property(TARGET Zstd::Zstd PROPERTY
|
||||||
|
IMPORTED_LOCATION_RELEASE "${Zstd_LIBRARY_RELEASE}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
@@ -44,11 +44,6 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_compile_definitions(tmxlite PRIVATE USE_ZSTD)
|
target_compile_definitions(tmxlite PRIVATE USE_ZSTD)
|
||||||
if (USE_BUNDLED_ZSTD)
|
target_link_libraries(tmxlite Zstd::Zstd)
|
||||||
target_link_libraries(tmxlite zstd::static)
|
|
||||||
else()
|
|
||||||
target_include_directories(tmxlite PRIVATE ${ZSTD_INCLUDE_DIR})
|
|
||||||
target_link_libraries(tmxlite ZLIB::ZLIB ${ZSTD_LIBRARY})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_include_directories(tmxlite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
target_include_directories(tmxlite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
|||||||
@@ -108,7 +108,8 @@ endif()
|
|||||||
set_source_files_properties(${Sources} PROPERTIES LANGUAGE C)
|
set_source_files_properties(${Sources} PROPERTIES LANGUAGE C)
|
||||||
|
|
||||||
add_library(zstd STATIC ${Sources} ${Headers})
|
add_library(zstd STATIC ${Sources} ${Headers})
|
||||||
add_library(zstd::static ALIAS zstd)
|
add_library(Zstd::static ALIAS zstd)
|
||||||
|
add_library(Zstd::Zstd ALIAS zstd)
|
||||||
|
|
||||||
add_zstd_compilation_flags(zstd)
|
add_zstd_compilation_flags(zstd)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user