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

@@ -3,6 +3,7 @@ name: CMake
on:
push:
paths:
- ".github/workflows/cmake.yml"
- "src/**"
- "ext/**"
- "CMakeLists.txt"
@@ -22,7 +23,7 @@ jobs:
- { name: "Windows MSVC x86", os: windows-latest, artifact: windows-x86, arch: x86 }
- { name: "Windows MSVC x64", os: windows-latest, artifact: windows-x64 }
- { name: "Windows MSVC ARM64", os: windows-latest, artifact: windows-arm64, arch: amd64_arm64 }
- { name: "Ubuntu", artifact: "linux", os: ubuntu-latest }
- { name: "Ubuntu", artifact: "linux", os: ubuntu-latest, extra: "-DUSE_BUNDLED_ZSTD:BOOL=OFF" }
runs-on: ${{matrix.config.os}}
steps:
@@ -34,6 +35,11 @@ jobs:
if: ${{startsWith(matrix.config.os, 'windows')}}
with:
arch: ${{matrix.config.arch && matrix.config.arch || 'x64'}}
- uses: awalsh128/cache-apt-pkgs-action@latest
if: ${{matrix.config.artifact == 'linux'}}
with:
packages: libzstd-dev
version: 1.0
- name: Configure CMake
run: >-

View File

@@ -5,7 +5,13 @@ project(tmx2gba
HOMEPAGE_URL "https://github.com/ScrelliCopter/tmx2gba")
# Options
option(USE_ZLIB "Use zlib instead of bundled miniz" "${UNIX}")
option(USE_BUNDLED_PUGIXML "Use bundled PUGIXML" ON)
option(USE_BUNDLED_ZSTD "Use bundled libzstd" ON)
option(USE_BUNDLED_TMXLITE "Use bundled tmxlite" ON)
option(TMX2GBA_DKP_INSTALL "Install into DEVKITPRO prefix" OFF)
option(ENABLE_ASAN "Enable address sanitiser" OFF)
if (ENABLE_ASAN)
@@ -13,12 +19,32 @@ if (ENABLE_ASAN)
add_link_options(-fsanitize=address -shared-libasan)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
# Libraries
set(USE_ZSTD ON)
add_subdirectory(ext/miniz)
add_subdirectory(ext/pugixml)
add_subdirectory(ext/zstd)
add_subdirectory(ext/tmxlite)
if (USE_BUNDLED_PUGIXML)
add_subdirectory(ext/pugixml)
else()
find_package(PUGIXML REQUIRED)
endif()
if (USE_ZLIB)
find_package(ZLIB REQUIRED)
else()
add_subdirectory(ext/miniz)
endif()
if (USE_BUNDLED_ZSTD)
add_subdirectory(ext/zstd)
else()
find_package(ZSTD REQUIRED)
endif()
if (USE_BUNDLED_TMXLITE)
add_subdirectory(ext/tmxlite)
else()
find_package(TMXLITE REQUIRED)
endif()
# Main tmx2gba sources
add_subdirectory(src)

View File

@@ -38,4 +38,4 @@ if (ZSTD_FOUND)
message(STATUS "Found Zstd: ${ZSTD_LIBRARY}")
endif()
mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY)
mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY)

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

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