Skip to content

Commit

Permalink
slightly simplify tmxlite subproject
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrelliCopter committed Mar 28, 2024
1 parent b06ad7c commit 849ff6b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 71 deletions.
42 changes: 15 additions & 27 deletions ext/tmxlite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
project(tmxlite VERSION 1.3.1)

set(USE_RTTI TRUE CACHE BOOL "Use run time type information?")

# 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_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})
file(GLOB PROJECT_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/tmxlite/*.hpp)
file(GLOB PROJECT_HEADERS_INL ${CMAKE_CURRENT_SOURCE_DIR}/include/tmxlite/*.inl)
file(GLOB PROJECT_HEADERS_DETAIL ${CMAKE_CURRENT_SOURCE_DIR}/include/tmxlite/detail/*.hpp)
list(APPEND PROJECT_SRC ${PROJECT_HEADERS} ${PROJECT_HEADERS_INL} ${PROJECT_HEADERS_DETAIL})

add_library(tmxlite STATIC ${PROJECT_SRC})
add_library(${PROJECT_NAME} STATIC ${PROJECT_SRC})

set_target_properties(tmxlite PROPERTIES
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON)

target_compile_definitions(tmxlite PRIVATE $<$<CONFIG:Debug>:_DEBUG_> TMXLITE_STATIC)
target_compile_options(tmxlite PRIVATE -Wall)
if (NOT USE_RTTI AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
target_compile_options(tmxlite PRIVATE -fno-rtti)
endif()

# disable msvc warning
if (MSVC)
target_compile_definitions(tmxlite PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include)

target_compile_definitions(tmxlite PRIVATE USE_ZSTD)
target_link_libraries(tmxlite base64::base64 pugixml Zstd::Zstd)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)

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(${PROJECT_NAME} PRIVATE
$<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS> # disable msvc warning
$<$<TARGET_EXISTS:ZLIB::ZLIB>:USE_ZLIB>)

target_include_directories(tmxlite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(${PROJECT_NAME} base64::base64 pugixml Zstd::Zstd
$<$<TARGET_EXISTS:ZLIB::ZLIB>:ZLIB::ZLIB>
$<$<TARGET_EXISTS:miniz::miniz>:miniz::miniz>)
33 changes: 0 additions & 33 deletions ext/tmxlite/include/tmxlite/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,5 @@ source distribution.

#pragma once

//check which platform we're on and create export macros as necessary
#if !defined(TMXLITE_STATIC)

#if defined(_WIN32)

//windows compilers need specific (and different) keywords for export
#define TMXLITE_EXPORT_API __declspec(dllexport)

//for vc compilers we also need to turn off this annoying C4251 warning
#ifdef _MSC_VER
#pragma warning(disable: 4251)
#endif //_MSC_VER

#else //linux, FreeBSD, Mac OS X

#if __GNUC__ >= 4

//gcc 4 has special keywords for showing/hiding symbols,
//the same keyword is used for both importing and exporting
#define TMXLITE_EXPORT_API __attribute__ ((__visibility__ ("default")))

#else

//gcc < 4 has no mechanism to explicitly hide symbols, everything's exported
#define TMXLITE_EXPORT_API
#endif //__GNUC__

#endif //_WIN32

#else

//static build doesn't need import/export macros
#define TMXLITE_EXPORT_API

#endif //TMXLITE_STATIC
6 changes: 3 additions & 3 deletions ext/tmxlite/include/tmxlite/detail/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ namespace tmx
}
};
}
#ifndef _DEBUG_
#ifdef NDEBUG
#define LOG(message, type)
#else
#define LOG(message, type) {\
std::stringstream ss; \
ss << message << " (" << __FILE__ << ", " << __LINE__ << ")"; \
tmx::Logger::log(ss.str(), type);}
#endif //_DEBUG_
#endif //NDEBUG

#endif //TMXLITE_LOGGER_HPP_
#endif //TMXLITE_LOGGER_HPP_
9 changes: 1 addition & 8 deletions ext/tmxlite/src/TileLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ source distribution.
*********************************************************************/

#include <pugixml.hpp>
#ifdef USE_ZSTD
# include <zstd.h>
#endif
#include <zstd.h>
#include "base64.h"
#include "tmxlite/FreeFuncs.hpp"
#include "tmxlite/TileLayer.hpp"
Expand Down Expand Up @@ -128,7 +126,6 @@ void TileLayer::parseBase64(const pugi::xml_node& node)
byteData.insert(byteData.end(), dataString.begin(), dataString.end());
break;
case CompressionType::Zstd:
#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);
Expand All @@ -140,10 +137,6 @@ void TileLayer::parseBase64(const pugi::xml_node& node)
}
}
break;
#else
Logger::log("Library must be built with USE_ZSTD for Zstd compression", Logger::Type::Error);
return {};
#endif
case CompressionType::GZip:
#ifndef USE_ZLIB
Logger::log("Library must be built with USE_ZLIB for GZip compression", Logger::Type::Error);
Expand Down

0 comments on commit 849ff6b

Please sign in to comment.