1
0
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:
2024-03-26 01:41:18 +11:00
parent c5c5f7b804
commit 0db78a5b56
19 changed files with 99 additions and 133 deletions

View File

@@ -17,35 +17,31 @@ set(PUGIXML_PUBLIC_DEFINITIONS
$<$<BOOL:${PUGIXML_NO_STL}>:PUGIXML_NO_STL>
$<$<BOOL:${PUGIXML_NO_EXCEPTIONS}>:PUGIXML_NO_EXCEPTIONS>)
add_library(pugixml-static STATIC
${PROJECT_SOURCE_DIR}/src/pugixml.cpp)
add_library(pugixml::static ALIAS pugixml-static)
add_library(pugixml STATIC
src/pugiconfig.hpp
src/pugixml.hpp
src/pugixml.cpp)
add_library(pugixml::static ALIAS pugixml)
if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
set_property(TARGET pugixml-static PROPERTY CXX_STANDARD_REQUIRED ON)
endif()
set_target_properties(pugixml PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_STANDARD 11)
if (NOT DEFINED CMAKE_CXX_STANDARD)
set_property(TARGET pugixml-static PROPERTY CXX_STANDARD 11)
endif()
set_property(TARGET pugixml-static PROPERTY EXPORT_NAME static)
target_include_directories(pugixml-static PUBLIC
set_property(TARGET pugixml PROPERTY EXPORT_NAME static)
target_include_directories(pugixml PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
target_compile_definitions(pugixml-static PUBLIC
target_compile_definitions(pugixml PUBLIC
${PUGIXML_BUILD_DEFINES}
${PUGIXML_PUBLIC_DEFINITIONS})
add_library(pugixml INTERFACE)
target_link_libraries(pugixml INTERFACE pugixml-static)
add_library(pugixml::pugixml ALIAS pugixml)
set_target_properties(pugixml-static PROPERTIES
set_target_properties(pugixml PROPERTIES
EXCLUDE_FROM_ALL ON
POSITION_INDEPENDENT_CODE ON
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
OUTPUT_NAME pugixml)
set_target_properties(pugixml-static PROPERTIES
set_target_properties(pugixml PROPERTIES
EXCLUDE_FROM_ALL OFF)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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]];

View File

@@ -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>

View File

@@ -1 +0,0 @@
#include <pugixml.hpp>

View File

@@ -40,10 +40,6 @@ function (add_zstd_compilation_flags _target)
target_link_options(${_target} PRIVATE -z noexecstack) # LDFLAGS
target_compile_options(${_target} PRIVATE -Wunused-parameter -Wa,--noexecstack) # CFLAGS & CXXFLAGS
elseif (MSVC)
set(ACTIVATE_MULTITHREADED_COMPILATION "ON" CACHE BOOL "activate multi-threaded compilation (/MP flag)")
if (CMAKE_GENERATOR MATCHES "Visual Studio" AND ACTIVATE_MULTITHREADED_COMPILATION)
target_compile_options(${_target} PRIVATE "/MP")
endif ()
# UNICODE SUPPORT
target_compile_definitions(${_target} PRIVATE _UNICODE UNICODE)
# Enable asserts in Debug mode
@@ -97,26 +93,12 @@ set(Headers
${DictBuilderHeaders})
if (ZSTD_LEGACY_SUPPORT)
set(LIBRARY_LEGACY_DIR ${LIBRARY_DIR}/legacy)
set(Sources ${Sources}
${LIBRARY_LEGACY_DIR}/zstd_v01.c
${LIBRARY_LEGACY_DIR}/zstd_v02.c
${LIBRARY_LEGACY_DIR}/zstd_v03.c
${LIBRARY_LEGACY_DIR}/zstd_v04.c
${LIBRARY_LEGACY_DIR}/zstd_v05.c
${LIBRARY_LEGACY_DIR}/zstd_v06.c
${LIBRARY_LEGACY_DIR}/zstd_v07.c)
set(Headers ${Headers}
${LIBRARY_LEGACY_DIR}/zstd_legacy.h
${LIBRARY_LEGACY_DIR}/zstd_v01.h
${LIBRARY_LEGACY_DIR}/zstd_v02.h
${LIBRARY_LEGACY_DIR}/zstd_v03.h
${LIBRARY_LEGACY_DIR}/zstd_v04.h
${LIBRARY_LEGACY_DIR}/zstd_v05.h
${LIBRARY_LEGACY_DIR}/zstd_v06.h
${LIBRARY_LEGACY_DIR}/zstd_v07.h)
foreach (SOURCE zstd_v01.c zstd_v02.c zstd_v03.c zstd_v04.c zstd_v05.c zstd_v06.c zstd_v07.c)
list(APPEND Sources ${LIBRARY_DIR}/legacy/${SOURCE})
endforeach()
foreach (HEADER zstd_legacy.h zstd_v01.h zstd_v02.h zstd_v03.h zstd_v04.h zstd_v05.h zstd_v06.h zstd_v07.h)
list(APPEND Headers ${LIBRARY_DIR}/legacy/${HEADER})
endforeach()
endif()
# Explicitly set the language to C for all files, including ASM files.
@@ -125,28 +107,28 @@ endif()
# macros.
set_source_files_properties(${Sources} PROPERTIES LANGUAGE C)
add_library(libzstd_static STATIC ${Sources} ${Headers})
add_library(zstd::static ALIAS libzstd_static)
add_library(zstd STATIC ${Sources} ${Headers})
add_library(zstd::static ALIAS zstd)
add_zstd_compilation_flags(libzstd_static)
add_zstd_compilation_flags(zstd)
# Define library directory, where sources and header files are located
target_include_directories(libzstd_static PUBLIC ${LIBRARY_DIR})
target_include_directories(libzstd_static PRIVATE ${LIBRARY_DIR}/common)
target_include_directories(zstd PUBLIC ${LIBRARY_DIR})
target_include_directories(zstd PRIVATE ${LIBRARY_DIR}/common)
if (ZSTD_LEGACY_SUPPORT)
include_directories(${LIBRARY_LEGACY_DIR})
target_compile_definitions(libzstd_static PRIVATE ZSTD_LEGACY_SUPPORT=${ZSTD_LEGACY_LEVEL})
target_include_directories(zstd PRIVATE ${LIBRARY_DIR}/legacy)
target_compile_definitions(zstd PRIVATE ZSTD_LEGACY_SUPPORT=${ZSTD_LEGACY_LEVEL})
else()
target_compile_definitions(libzstd_static PRIVATE ZSTD_LEGACY_SUPPORT=0)
target_compile_definitions(zstd PRIVATE ZSTD_LEGACY_SUPPORT=0)
endif()
if (ZSTD_MULTITHREAD_SUPPORT)
target_compile_definitions(libzstd_static PRIVATE ZSTD_MULTITHREAD)
target_compile_definitions(zstd PRIVATE ZSTD_MULTITHREAD)
if (UNIX)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(libzstd_static Threads::Threads)
target_link_libraries(zstd Threads::Threads)
if (NOT CMAKE_USE_PTHREADS_INIT)
message(SEND_ERROR "ZSTD currently does not support thread libraries other than pthreads")
endif()
@@ -155,16 +137,8 @@ endif()
# Add specific compile definitions for MSVC project
if (MSVC)
set(COMMON_DEFINITIONS ZSTD_DISABLE_ASM _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(libzstd_static PRIVATE ZSTD_HEAPMODE=0 ${COMMON_DEFINITIONS})
target_compile_definitions(zstd PRIVATE ZSTD_HEAPMODE=0 ZSTD_DISABLE_ASM _CRT_SECURE_NO_WARNINGS)
endif()
# Define static library names
set_property(TARGET libzstd_static PROPERTY POSITION_INDEPENDENT_CODE ON)
# With MSVC static library needs to be renamed to avoid conflict with import library
if (MSVC OR (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT MINGW))
set_property(TARGET libzstd_static PROPERTY OUTPUT_NAME zstd_static)
else()
set_property(TARGET libzstd_static PROPERTY OUTPUT_NAME zstd)
endif()
set_property(TARGET zstd PROPERTY POSITION_INDEPENDENT_CODE ON)