diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 02e13c3..07852c5 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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: >- diff --git a/CMakeLists.txt b/CMakeLists.txt index c578149..94208cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/ext/tmxlite/cmake/modules/FindPUGIXML.cmake b/cmake/modules/FindPUGIXML.cmake similarity index 100% rename from ext/tmxlite/cmake/modules/FindPUGIXML.cmake rename to cmake/modules/FindPUGIXML.cmake diff --git a/ext/tmxlite/cmake/modules/FindTMXLITE.cmake b/cmake/modules/FindTMXLITE.cmake similarity index 100% rename from ext/tmxlite/cmake/modules/FindTMXLITE.cmake rename to cmake/modules/FindTMXLITE.cmake diff --git a/ext/tmxlite/cmake/modules/FindZstd.cmake b/cmake/modules/FindZSTD.cmake similarity index 95% rename from ext/tmxlite/cmake/modules/FindZstd.cmake rename to cmake/modules/FindZSTD.cmake index 98175e8..42c5dd9 100644 --- a/ext/tmxlite/cmake/modules/FindZstd.cmake +++ b/cmake/modules/FindZSTD.cmake @@ -38,4 +38,4 @@ if (ZSTD_FOUND) message(STATUS "Found Zstd: ${ZSTD_LIBRARY}") endif() -mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY) \ No newline at end of file +mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY) diff --git a/ext/pugixml/CMakeLists.txt b/ext/pugixml/CMakeLists.txt index 7e3eed7..5be6585 100644 --- a/ext/pugixml/CMakeLists.txt +++ b/ext/pugixml/CMakeLists.txt @@ -17,35 +17,31 @@ set(PUGIXML_PUBLIC_DEFINITIONS $<$:PUGIXML_NO_STL> $<$: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 $) -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) diff --git a/ext/tmxlite/CMakeLists.txt b/ext/tmxlite/CMakeLists.txt index c524f7d..237c733 100644 --- a/ext/tmxlite/CMakeLists.txt +++ b/ext/tmxlite/CMakeLists.txt @@ -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) diff --git a/ext/tmxlite/src/FreeFuncs.cpp b/ext/tmxlite/src/FreeFuncs.cpp index c4dc178..aca88f6 100644 --- a/ext/tmxlite/src/FreeFuncs.cpp +++ b/ext/tmxlite/src/FreeFuncs.cpp @@ -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 @@ -63,7 +63,7 @@ bool tmx::decompress(const char* source, std::vector& 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) diff --git a/ext/tmxlite/src/ImageLayer.cpp b/ext/tmxlite/src/ImageLayer.cpp index 1079d28..58954da 100644 --- a/ext/tmxlite/src/ImageLayer.cpp +++ b/ext/tmxlite/src/ImageLayer.cpp @@ -25,11 +25,7 @@ and must not be misrepresented as being the original software. source distribution. *********************************************************************/ -#ifdef USE_EXTLIBS #include -#else -#include "detail/pugixml.hpp" -#endif #include #include #include diff --git a/ext/tmxlite/src/LayerGroup.cpp b/ext/tmxlite/src/LayerGroup.cpp index 04551b5..be82d6c 100644 --- a/ext/tmxlite/src/LayerGroup.cpp +++ b/ext/tmxlite/src/LayerGroup.cpp @@ -25,11 +25,7 @@ and must not be misrepresented as being the original software. source distribution. *********************************************************************/ -#ifdef USE_EXTLIBS #include -#else -#include "detail/pugixml.hpp" -#endif #include #include #include diff --git a/ext/tmxlite/src/Map.cpp b/ext/tmxlite/src/Map.cpp index 5cb9ca7..515d2a4 100644 --- a/ext/tmxlite/src/Map.cpp +++ b/ext/tmxlite/src/Map.cpp @@ -25,11 +25,7 @@ and must not be misrepresented as being the original software. source distribution. *********************************************************************/ -#ifdef USE_EXTLIBS #include -#else -#include "detail/pugixml.hpp" -#endif #include #include #include diff --git a/ext/tmxlite/src/Object.cpp b/ext/tmxlite/src/Object.cpp index ef54743..8f90554 100644 --- a/ext/tmxlite/src/Object.cpp +++ b/ext/tmxlite/src/Object.cpp @@ -25,11 +25,7 @@ and must not be misrepresented as being the original software. source distribution. *********************************************************************/ -#ifdef USE_EXTLIBS #include -#else -#include "detail/pugixml.hpp" -#endif #include #include #include diff --git a/ext/tmxlite/src/ObjectGroup.cpp b/ext/tmxlite/src/ObjectGroup.cpp index 6a9dbdf..89a765e 100644 --- a/ext/tmxlite/src/ObjectGroup.cpp +++ b/ext/tmxlite/src/ObjectGroup.cpp @@ -25,11 +25,7 @@ and must not be misrepresented as being the original software. source distribution. *********************************************************************/ -#ifdef USE_EXTLIBS #include -#else -#include "detail/pugixml.hpp" -#endif #include #include #include diff --git a/ext/tmxlite/src/ObjectTypes.cpp b/ext/tmxlite/src/ObjectTypes.cpp index 8c31b2f..7677623 100644 --- a/ext/tmxlite/src/ObjectTypes.cpp +++ b/ext/tmxlite/src/ObjectTypes.cpp @@ -24,11 +24,7 @@ and must not be misrepresented as being the original software. source distribution. *********************************************************************/ -#ifdef USE_EXTLIBS #include -#else -#include "detail/pugixml.hpp" -#endif #include #include #include diff --git a/ext/tmxlite/src/Property.cpp b/ext/tmxlite/src/Property.cpp index 29ad718..363b897 100644 --- a/ext/tmxlite/src/Property.cpp +++ b/ext/tmxlite/src/Property.cpp @@ -25,11 +25,7 @@ and must not be misrepresented as being the original software. source distribution. *********************************************************************/ -#ifdef USE_EXTLIBS #include -#else -#include "detail/pugixml.hpp" -#endif #include #include #include diff --git a/ext/tmxlite/src/TileLayer.cpp b/ext/tmxlite/src/TileLayer.cpp index a7acb10..1f530c0 100644 --- a/ext/tmxlite/src/TileLayer.cpp +++ b/ext/tmxlite/src/TileLayer.cpp @@ -25,12 +25,7 @@ and must not be misrepresented as being the original software. source distribution. *********************************************************************/ -#ifdef USE_EXTLIBS #include -#include -#else -#include "detail/pugixml.hpp" -#endif #ifdef USE_ZSTD #include @@ -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]]; diff --git a/ext/tmxlite/src/Tileset.cpp b/ext/tmxlite/src/Tileset.cpp index dcebe9d..1cfa3f6 100644 --- a/ext/tmxlite/src/Tileset.cpp +++ b/ext/tmxlite/src/Tileset.cpp @@ -25,11 +25,7 @@ and must not be misrepresented as being the original software. source distribution. *********************************************************************/ -#ifdef USE_EXTLIBS #include -#else -#include "detail/pugixml.hpp" -#endif #include #include #include diff --git a/ext/tmxlite/src/detail/pugixml.hpp b/ext/tmxlite/src/detail/pugixml.hpp deleted file mode 100644 index fd95160..0000000 --- a/ext/tmxlite/src/detail/pugixml.hpp +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/ext/zstd/CMakeLists.txt b/ext/zstd/CMakeLists.txt index 7e27b5f..2e1b219 100644 --- a/ext/zstd/CMakeLists.txt +++ b/ext/zstd/CMakeLists.txt @@ -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)