Skip to content

Commit cba7e00

Browse files
committed
update CMake file to configure for Zstd compression
make sure to use C++14 not C++17
1 parent fdb7011 commit cba7e00

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

tmxlite/CMakeLists.txt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ SET(PROJECT_STATIC_RUNTIME FALSE CACHE BOOL "Use statically linked standard/runt
1313

1414
SET(USE_RTTI TRUE CACHE BOOL "Use run time type information?")
1515

16-
SET(USE_EXTLIBS FALSE CACHE BOOL "Use external zlib and pugixml libraries instead of the included source?")
16+
SET(USE_EXTLIBS FALSE CACHE BOOL "Use external zlib, zstd and pugixml libraries instead of the included source?")
17+
SET(USE_ZSTD FALSE CACHE BOOL "Enable zstd compression? (Already set to true if USE_EXTLIBS is true)")
1718

1819
if(USE_RTTI)
1920
if(CMAKE_COMPILER_IS_GNUCXX OR APPLE)
@@ -62,17 +63,28 @@ include(${PROJECT_DIR}/CMakeLists.txt)
6263
#if we want external zip and xml libs find them and tell the compiler
6364
if(USE_EXTLIBS)
6465
add_definitions(-DUSE_EXTLIBS)
66+
add_definitions(-DUSE_ZSTD)
6567

6668
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
6769

6870
find_package(ZLIB REQUIRED)
6971
find_package(PUGIXML REQUIRED)
72+
find_package(Zstd REQUIRED)
7073

71-
include_directories(${ZLIB_INCLUDE_DIRS} ${PUGIXML_INCLUDE_DIR})
74+
include_directories(${ZLIB_INCLUDE_DIRS} ${PUGIXML_INCLUDE_DIR} ${ZSTD_INCLUDE_DIR})
7275

7376
else()
7477
#add miniz and pugixml from source
7578
SET(PROJECT_SRC ${PROJECT_SRC} ${LIB_SRC})
79+
80+
if(USE_ZSTD)
81+
add_definitions(-DUSE_ZSTD)
82+
83+
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
84+
find_package(Zstd REQUIRED)
85+
include_directories(${ZSTD_INCLUDE_DIR})
86+
endif()
87+
7688
endif()
7789

7890
if(WIN32)
@@ -90,7 +102,11 @@ else()
90102
endif()
91103

92104
if(USE_EXTLIBS)
93-
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES} ${PUGIXML_LIBRARY})
105+
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES} ${PUGIXML_LIBRARY} ${ZSTD_LIBRARY})
106+
else()
107+
if(USE_ZSTD)
108+
target_link_libraries(${PROJECT_NAME} ${ZSTD_LIBRARY})
109+
endif()
94110
endif()
95111

96112
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tmxlite.pc.in ${CMAKE_CURRENT_BINARY_DIR}/tmxlite.pc

tmxlite/src/TileLayer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,20 @@ void TileLayer::parseBase64(const pugi::xml_node& node)
135135
break;
136136
case CompressionType::Zstd:
137137
#if defined USE_ZSTD || defined USE_EXTLIBS
138-
if (std::size_t result = ZSTD_decompress(byteData.data(), expectedSize, &dataString[0], dataSize); ZSTD_isError(result))
139138
{
140-
std::string err = ZSTD_getErrorName(result);
141-
LOG("Failed to decompress layer data, node skipped.\nError: " + err, Logger::Type::Error);
139+
std::size_t dataSize = dataString.length() * sizeof(unsigned char);
140+
std::size_t result = ZSTD_decompress(byteData.data(), expectedSize, &dataString[0], dataSize);
141+
142+
if (ZSTD_isError(result))
143+
{
144+
std::string err = ZSTD_getErrorName(result);
145+
LOG("Failed to decompress layer data, node skipped.\nError: " + err, Logger::Type::Error);
146+
}
142147
}
143148
#else
144149
Logger::log("Library must be built with USE_EXTLIBS or USE_ZSTD for Zstd compression", Logger::Type::Error);
145150
return {};
146151
#endif
147-
break;
148152
case CompressionType::GZip:
149153
#ifndef USE_EXTLIBS
150154
Logger::log("Library must be built with USE_EXTLIBS for GZip compression", Logger::Type::Error);

0 commit comments

Comments
 (0)