diff --git a/CMakeLists.txt b/CMakeLists.txt index 1956e8a..e0e3aee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ if (ENABLE_ASAN) add_link_options(-fsanitize=address -shared-libasan) endif() -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") # Libraries if (USE_BUNDLED_PUGIXML) @@ -37,7 +37,7 @@ endif() if (USE_BUNDLED_ZSTD) add_subdirectory(ext/zstd) else() - find_package(ZSTD REQUIRED) + find_package(Zstd REQUIRED) endif() add_subdirectory(ext/base64) diff --git a/cmake/modules/FindZSTD.cmake b/cmake/modules/FindZSTD.cmake deleted file mode 100644 index 42c5dd9..0000000 --- a/cmake/modules/FindZSTD.cmake +++ /dev/null @@ -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) diff --git a/cmake/modules/FindZstd.cmake b/cmake/modules/FindZstd.cmake new file mode 100644 index 0000000..132737c --- /dev/null +++ b/cmake/modules/FindZstd.cmake @@ -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() diff --git a/ext/tmxlite/CMakeLists.txt b/ext/tmxlite/CMakeLists.txt index b65b0af..cf96564 100644 --- a/ext/tmxlite/CMakeLists.txt +++ b/ext/tmxlite/CMakeLists.txt @@ -44,11 +44,6 @@ else() endif() target_compile_definitions(tmxlite PRIVATE USE_ZSTD) -if (USE_BUNDLED_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_link_libraries(tmxlite Zstd::Zstd) target_include_directories(tmxlite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/ext/zstd/CMakeLists.txt b/ext/zstd/CMakeLists.txt index 2e1b219..e0fe53c 100644 --- a/ext/zstd/CMakeLists.txt +++ b/ext/zstd/CMakeLists.txt @@ -108,7 +108,8 @@ endif() set_source_files_properties(${Sources} PROPERTIES LANGUAGE C) 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)