mirror of
https://github.com/ScrelliCopter/tmx2gba.git
synced 2025-02-21 03:29:25 +11:00
first crack at making bundled dependencies optional
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
project(tmxlite VERSION 1.3.1)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
|
||||
|
||||
set(USE_RTTI TRUE CACHE BOOL "Use run time type information?")
|
||||
|
||||
set(USE_EXTLIBS FALSE CACHE BOOL "Use external zlib, zstd and pugixml libraries instead of the included source?")
|
||||
set(USE_ZSTD FALSE CACHE BOOL "Enable zstd compression? (Already set to true if USE_EXTLIBS is true)")
|
||||
|
||||
# includes the list of source files in the src directory
|
||||
set(PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
file(GLOB PROJECT_SRC ${PROJECT_DIR}/*.cpp)
|
||||
file(GLOB PROJECT_SRC ${PROJECT_DIR}/*.cpp)
|
||||
file(GLOB PROJECT_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp)
|
||||
file(GLOB PROJECT_HEADERS_INL ${CMAKE_CURRENT_SOURCE_DIR}/include/*.inl)
|
||||
file(GLOB PROJECT_HEADERS_DETAIL ${CMAKE_CURRENT_SOURCE_DIR}/include/detail/*.hpp)
|
||||
set(PROJECT_SRC ${PROJECT_SRC} ${PROJECT_HEADERS} ${PROJECT_HEADERS_INL} ${PROJECT_HEADERS_DETAIL})
|
||||
|
||||
add_library(tmxlite STATIC ${PROJECT_SRC})
|
||||
|
||||
@@ -28,23 +27,26 @@ if (MSVC)
|
||||
target_compile_definitions(tmxlite PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
# if we want external zip and xml libs find them and tell the compiler
|
||||
if (USE_EXTLIBS)
|
||||
find_package(ZLIB REQUIRED)
|
||||
find_package(PUGIXML REQUIRED)
|
||||
find_package(Zstd REQUIRED)
|
||||
|
||||
target_compile_definitions(tmxlite PRIVATE USE_EXTLIBS USE_ZSTD)
|
||||
target_include_directories(tmxlite PRIVATE ${ZLIB_INCLUDE_DIRS} ${PUGIXML_INCLUDE_DIR} ${ZSTD_INCLUDE_DIR})
|
||||
target_link_libraries(tmxlite ${ZLIB_LIBRARIES} ${PUGIXML_LIBRARY} ${ZSTD_LIBRARY})
|
||||
if (USE_BUNDLED_PUGIXML)
|
||||
target_link_libraries(tmxlite pugixml::static)
|
||||
else()
|
||||
# add miniz and pugixml from source
|
||||
target_link_libraries(tmxlite pugixml::static miniz::miniz)
|
||||
target_include_directories(tmxlite PRIVATE ${PUGIXML_INCLUDE_DIR})
|
||||
target_link_libraries(tmxlite ZLIB::ZLIB ${PUGIXML_LIBRARY})
|
||||
endif()
|
||||
|
||||
if (USE_ZSTD)
|
||||
target_compile_definitions(tmxlite PRIVATE USE_ZSTD)
|
||||
target_link_libraries(tmxlite zstd::static)
|
||||
endif()
|
||||
if (USE_ZLIB)
|
||||
target_compile_definitions(tmxlite PRIVATE USE_ZLIB)
|
||||
target_link_libraries(tmxlite ZLIB::ZLIB)
|
||||
else()
|
||||
target_link_libraries(tmxlite miniz::miniz)
|
||||
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_include_directories(tmxlite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
find_path(PUGIXML_INCLUDE_DIR NAMES pugixml.hpp)
|
||||
find_library(PUGIXML_LIBRARY NAMES pugixml)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(PUGIXML DEFAULT_MSG
|
||||
PUGIXML_LIBRARY PUGIXML_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(PUGIXML_INCLUDE_DIR
|
||||
PUGIXML_LIBRARY)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
# Search for the header file
|
||||
find_path(TMXLITE_INCLUDE_DIR NAMES tmxlite/Config.hpp PATH_SUFFIXES include)
|
||||
|
||||
# Search for the library
|
||||
find_library(TMXLITE_LIBRARIES NAMES tmxlite PATH_SUFFIXES lib)
|
||||
|
||||
# Did we find everything we need?
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(tmxlite DEFAULT_MSG TMXLITE_LIBRARIES TMXLITE_INCLUDE_DIR)
|
||||
@@ -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)
|
||||
@@ -25,7 +25,7 @@ and must not be misrepresented as being the original software.
|
||||
source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
#ifndef USE_EXTLIBS
|
||||
#ifndef USE_ZLIB
|
||||
#include "miniz.h"
|
||||
#else
|
||||
#include <zlib.h>
|
||||
@@ -63,7 +63,7 @@ bool tmx::decompress(const char* source, std::vector<unsigned char>& dest, std::
|
||||
//to be incorrect in miniz. This is fine for zlib
|
||||
//compressed data, but gzip compressed streams
|
||||
//will fail to inflate.
|
||||
#ifdef USE_EXTLIBS
|
||||
#ifdef USE_ZLIB
|
||||
if (inflateInit2(&stream, 15 + 32) != Z_OK)
|
||||
#else
|
||||
if (inflateInit(&stream) != Z_OK)
|
||||
|
||||
@@ -25,11 +25,7 @@ and must not be misrepresented as being the original software.
|
||||
source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef USE_EXTLIBS
|
||||
#include <pugixml.hpp>
|
||||
#else
|
||||
#include "detail/pugixml.hpp"
|
||||
#endif
|
||||
#include <tmxlite/ImageLayer.hpp>
|
||||
#include <tmxlite/FreeFuncs.hpp>
|
||||
#include <tmxlite/detail/Log.hpp>
|
||||
|
||||
@@ -25,11 +25,7 @@ and must not be misrepresented as being the original software.
|
||||
source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef USE_EXTLIBS
|
||||
#include <pugixml.hpp>
|
||||
#else
|
||||
#include "detail/pugixml.hpp"
|
||||
#endif
|
||||
#include <tmxlite/LayerGroup.hpp>
|
||||
#include <tmxlite/FreeFuncs.hpp>
|
||||
#include <tmxlite/ObjectGroup.hpp>
|
||||
|
||||
@@ -25,11 +25,7 @@ and must not be misrepresented as being the original software.
|
||||
source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef USE_EXTLIBS
|
||||
#include <pugixml.hpp>
|
||||
#else
|
||||
#include "detail/pugixml.hpp"
|
||||
#endif
|
||||
#include <tmxlite/Map.hpp>
|
||||
#include <tmxlite/FreeFuncs.hpp>
|
||||
#include <tmxlite/ObjectGroup.hpp>
|
||||
|
||||
@@ -25,11 +25,7 @@ and must not be misrepresented as being the original software.
|
||||
source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef USE_EXTLIBS
|
||||
#include <pugixml.hpp>
|
||||
#else
|
||||
#include "detail/pugixml.hpp"
|
||||
#endif
|
||||
#include <tmxlite/Object.hpp>
|
||||
#include <tmxlite/FreeFuncs.hpp>
|
||||
#include <tmxlite/Map.hpp>
|
||||
|
||||
@@ -25,11 +25,7 @@ and must not be misrepresented as being the original software.
|
||||
source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef USE_EXTLIBS
|
||||
#include <pugixml.hpp>
|
||||
#else
|
||||
#include "detail/pugixml.hpp"
|
||||
#endif
|
||||
#include <tmxlite/FreeFuncs.hpp>
|
||||
#include <tmxlite/ObjectGroup.hpp>
|
||||
#include <tmxlite/detail/Log.hpp>
|
||||
|
||||
@@ -24,11 +24,7 @@ and must not be misrepresented as being the original software.
|
||||
source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef USE_EXTLIBS
|
||||
#include <pugixml.hpp>
|
||||
#else
|
||||
#include "detail/pugixml.hpp"
|
||||
#endif
|
||||
#include <tmxlite/FreeFuncs.hpp>
|
||||
#include <tmxlite/ObjectTypes.hpp>
|
||||
#include <tmxlite/detail/Log.hpp>
|
||||
|
||||
@@ -25,11 +25,7 @@ and must not be misrepresented as being the original software.
|
||||
source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef USE_EXTLIBS
|
||||
#include <pugixml.hpp>
|
||||
#else
|
||||
#include "detail/pugixml.hpp"
|
||||
#endif
|
||||
#include <tmxlite/Property.hpp>
|
||||
#include <tmxlite/detail/Log.hpp>
|
||||
#include <tmxlite/FreeFuncs.hpp>
|
||||
|
||||
@@ -25,12 +25,7 @@ and must not be misrepresented as being the original software.
|
||||
source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef USE_EXTLIBS
|
||||
#include <pugixml.hpp>
|
||||
#include <zstd.h>
|
||||
#else
|
||||
#include "detail/pugixml.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef USE_ZSTD
|
||||
#include <zstd.h>
|
||||
@@ -135,7 +130,7 @@ void TileLayer::parseBase64(const pugi::xml_node& node)
|
||||
byteData.insert(byteData.end(), dataString.begin(), dataString.end());
|
||||
break;
|
||||
case CompressionType::Zstd:
|
||||
#if defined USE_ZSTD || defined USE_EXTLIBS
|
||||
#if defined USE_ZSTD
|
||||
{
|
||||
std::size_t dataSize = dataString.length() * sizeof(unsigned char);
|
||||
std::size_t result = ZSTD_decompress(byteData.data(), expectedSize, &dataString[0], dataSize);
|
||||
@@ -148,12 +143,12 @@ void TileLayer::parseBase64(const pugi::xml_node& node)
|
||||
}
|
||||
break;
|
||||
#else
|
||||
Logger::log("Library must be built with USE_EXTLIBS or USE_ZSTD for Zstd compression", Logger::Type::Error);
|
||||
Logger::log("Library must be built with USE_ZSTD for Zstd compression", Logger::Type::Error);
|
||||
return {};
|
||||
#endif
|
||||
case CompressionType::GZip:
|
||||
#ifndef USE_EXTLIBS
|
||||
Logger::log("Library must be built with USE_EXTLIBS for GZip compression", Logger::Type::Error);
|
||||
#ifndef USE_ZLIB
|
||||
Logger::log("Library must be built with USE_ZLIB for GZip compression", Logger::Type::Error);
|
||||
return {};
|
||||
#endif
|
||||
//[[fallthrough]];
|
||||
|
||||
@@ -25,11 +25,7 @@ and must not be misrepresented as being the original software.
|
||||
source distribution.
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef USE_EXTLIBS
|
||||
#include <pugixml.hpp>
|
||||
#else
|
||||
#include "detail/pugixml.hpp"
|
||||
#endif
|
||||
#include <tmxlite/Tileset.hpp>
|
||||
#include <tmxlite/FreeFuncs.hpp>
|
||||
#include <tmxlite/detail/Log.hpp>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#include <pugixml.hpp>
|
||||
Reference in New Issue
Block a user