Add USE_BUNDLED_LIBS

This commit is contained in:
2023-03-09 16:47:06 +01:00
parent 5ef773b3fb
commit 3a1582e887
6 changed files with 144 additions and 193 deletions
+37 -22
View File
@@ -9,38 +9,53 @@ set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_CXX_VISIBILITY_PRESET hidden)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON) option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
option(USE_BUNDLED_LIBS "Use bundled LZ4 PugiXML and Zlib" ON)
if(USE_BUNDLED_LIBS)
set(THIRD_PARTY_SRC
lz4/lz4.c
lz4/lz4.h
lz4/lz4hc.c
lz4/lz4hc.h
pugixml/pugixml.cpp
zlib/adler32.c
zlib/compress.c
zlib/crc32.c
zlib/deflate.c
zlib/gzclose.c
zlib/gzlib.c
zlib/gzread.c
zlib/gzwrite.c
zlib/inflate.c
zlib/infback.c
zlib/inftrees.c
zlib/inffast.c
zlib/trees.c
zlib/uncompr.c
zlib/zutil.c)
else(USE_BUNDLED_LIBS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LZ4 liblz4 IMPORTED_TARGET REQUIRED)
pkg_check_modules(PUGIXML pugixml IMPORTED_TARGET REQUIRED)
pkg_check_modules(ZLIB zlib IMPORTED_TARGET REQUIRED)
endif(USE_BUNDLED_LIBS)
add_library(XISF add_library(XISF
bytearray.cpp bytearray.cpp
bytearray.h
libXISF_global.h libXISF_global.h
libxisf.cpp libxisf.cpp
libxisf.h libxisf.h
utils.cpp utils.cpp
variant.cpp variant.cpp
variant.h ${THIRD_PARTY_SRC}
lz4/lz4.c
lz4/lz4.h
lz4/lz4hc.c
lz4/lz4hc.h
pugixml/pugixml.cpp
zlib/adler32.c
zlib/compress.c
zlib/crc32.c
zlib/deflate.c
zlib/gzclose.c
zlib/gzlib.c
zlib/gzread.c
zlib/gzwrite.c
zlib/inflate.c
zlib/infback.c
zlib/inftrees.c
zlib/inffast.c
zlib/trees.c
zlib/uncompr.c
zlib/zutil.c
) )
if(USE_BUNDLED_LIBS)
target_include_directories(XISF PRIVATE lz4 pugixml zlib)
else(USE_BUNDLED_LIBS)
target_link_libraries(XISF PUBLIC PkgConfig::LZ4 PkgConfig::PUGIXML PkgConfig::ZLIB)
endif(USE_BUNDLED_LIBS)
set_target_properties(XISF PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) set_target_properties(XISF PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
-29
View File
@@ -1,29 +0,0 @@
/************************************************************************
* LibXISF - library to load and save XISF files *
* Copyright (C) 2023 Dušan Poizl *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#ifndef LIBXISF_BYTEARRAY_H
#define LIBXISF_BYTEARRAY_H
namespace LibXISF
{
}
#endif // LIBXISF_BYTEARRAY_H
+4 -4
View File
@@ -23,10 +23,10 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <cstdlib> #include <cstdlib>
#include "lz4/lz4.h" #include <lz4.h>
#include "lz4/lz4hc.h" #include <lz4hc.h>
#include "pugixml/pugixml.hpp" #include <pugixml.hpp>
#include "zlib/zlib.h" #include <zlib.h>
namespace LibXISF namespace LibXISF
{ {
+101 -1
View File
@@ -25,7 +25,10 @@
#include <variant> #include <variant>
#include <fstream> #include <fstream>
#include <cstring> #include <cstring>
#include "variant.h" #include <vector>
#include <cstdint>
#include <memory>
#include <ctime>
namespace LibXISF namespace LibXISF
{ {
@@ -64,6 +67,103 @@ public:
void decodeHex(); void decodeHex();
}; };
struct Complex32
{
float real;
float imag;
};
struct Complex64
{
double real;
double imag;
};
template<typename T>
class Matrix
{
int _rows = 0;
int _cols = 0;
std::vector<T> _elem;
public:
using value_type = T;
Matrix() = default;
Matrix(int rows, int cols) : _rows(rows), _cols(cols), _elem(rows * cols) {}
void resize(int rows, int cols) { _rows = rows; _cols = cols; _elem.resize(rows * cols); }
T& operator()(int row, int col) { return _elem[row * _cols + col]; }
const T& operator()(int row, int col) const { return _elem[row * _cols + col]; }
int rows() const { return _rows; }
int cols() const { return _cols; }
};
typedef bool Boolean;
typedef int8_t Int8;
typedef uint8_t UInt8;
typedef int16_t Int16;
typedef uint16_t UInt16;
typedef int32_t Int32;
typedef uint32_t UInt32;
typedef int64_t Int64;
typedef uint64_t UInt64;
typedef float Float32;
typedef double Float64;
typedef std::string String;
typedef std::tm TimePoint;
typedef std::vector<int8_t> I8Vector;
typedef std::vector<uint8_t> UI8Vector;
typedef std::vector<int16_t> I16Vector;
typedef std::vector<uint16_t> UI16Vector;
typedef std::vector<int32_t> I32Vector;
typedef std::vector<uint32_t> UI32Vector;
typedef std::vector<int64_t> I64Vector;
typedef std::vector<uint64_t> UI64Vector;
typedef std::vector<float> F32Vector;
typedef std::vector<double> F64Vector;
typedef std::vector<Complex32> C32Vector;
typedef std::vector<Complex64> C64Vector;
typedef Matrix<Int8> I8Matrix;
typedef Matrix<UInt8> UI8Matrix;
typedef Matrix<Int16> I16Matrix;
typedef Matrix<UInt16> UI16Matrix;
typedef Matrix<Int32> I32Matrix;
typedef Matrix<UInt32> UI32Matrix;
typedef Matrix<Int64> I64Matrix;
typedef Matrix<UInt64> UI64Matrix;
typedef Matrix<float> F32Matrix;
typedef Matrix<double> F64Matrix;
typedef Matrix<Complex32> C32Matrix;
typedef Matrix<Complex64> C64Matrix;
class Variant
{
using StdVariant = std::variant<std::monostate, Boolean, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Float32, Float64,
Complex32, Complex64, String, TimePoint,
I8Vector, UI8Vector, I16Vector, UI16Vector, I32Vector, UI32Vector, I64Vector, UI64Vector, F32Vector, F64Vector, C32Vector, C64Vector,
I8Matrix, UI8Matrix, I16Matrix, UI16Matrix, I32Matrix, UI32Matrix, I64Matrix, UI64Matrix, F32Matrix, F64Matrix, C32Matrix, C64Matrix>;
StdVariant _value;
public:
enum class Type
{
Monostate, Boolean, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Float32, Float64,
Complex32, Complex64, String, TimePoint,
I8Vector, UI8Vector, I16Vector, UI16Vector, I32Vector, UI32Vector, I64Vector, UI64Vector, F32Vector, F64Vector, C32Vector, C64Vector,
I8Matrix, UI8Matrix, I16Matrix, UI16Matrix, I32Matrix, UI32Matrix, I64Matrix, UI64Matrix, F32Matrix, F64Matrix, C32Matrix, C64Matrix
};
Variant() = default;
template<typename T>
Variant(const T &t) : _value(t) {}
Type type() const;
const char *typeName() const;
template<typename T>
T& value() { return std::get<T>(_value); }
template<typename T>
const T& value() const { return std::get<T>(_value); }
template<typename T>
void setValue(const T& val) { _value = val; }
};
struct LIBXISF_EXPORT DataBlock struct LIBXISF_EXPORT DataBlock
{ {
enum CompressionCodec enum CompressionCodec
+2 -3
View File
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.* * along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/ ************************************************************************/
#include "variant.h"
#include <charconv> #include <charconv>
#include <type_traits> #include <type_traits>
#include <map> #include <map>
@@ -336,7 +335,7 @@ void serializeVariant(pugi::xml_node &node, const Variant &variant)
} }
node.append_attribute("length").set_value(len); node.append_attribute("length").set_value(len);
node.append_attribute("location").set_value("inline:base64"); node.append_attribute("location").set_value("inline:base64");
node.append_child(pugi::node_pcdata).set_value(data.constData(), data.size()); node.append_child(pugi::node_pcdata).set_value(data.constData());
} }
else if(variant.type() >= Variant::Type::I8Matrix && variant.type() <= Variant::Type::C64Matrix) else if(variant.type() >= Variant::Type::I8Matrix && variant.type() <= Variant::Type::C64Matrix)
{ {
@@ -363,7 +362,7 @@ void serializeVariant(pugi::xml_node &node, const Variant &variant)
node.append_attribute("rows").set_value(rows); node.append_attribute("rows").set_value(rows);
node.append_attribute("columns").set_value(cols); node.append_attribute("columns").set_value(cols);
node.append_attribute("location").set_value("inline:base64"); node.append_attribute("location").set_value("inline:base64");
node.append_child(pugi::node_pcdata).set_value(data.constData(), data.size()); node.append_child(pugi::node_pcdata).set_value(data.constData());
} }
else if(variant.type() == Variant::Type::TimePoint) else if(variant.type() == Variant::Type::TimePoint)
{ {
-134
View File
@@ -1,134 +0,0 @@
/************************************************************************
* LibXISF - library to load and save XISF files *
* Copyright (C) 2023 Dušan Poizl *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#ifndef LIBXISF_VARIANT_H
#define LIBXISF_VARIANT_H
#include <variant>
#include <cstdint>
#include <string>
#include <vector>
#include <memory>
#include <cstring>
#include <ctime>
#include <sstream>
#include "libXISF_global.h"
namespace LibXISF
{
struct Complex32
{
float real;
float imag;
};
struct Complex64
{
double real;
double imag;
};
template<typename T>
class Matrix
{
int _rows = 0;
int _cols = 0;
std::vector<T> _elem;
public:
using value_type = T;
Matrix() = default;
Matrix(int rows, int cols) : _rows(rows), _cols(cols), _elem(rows * cols) {}
void resize(int rows, int cols) { _rows = rows; _cols = cols; _elem.resize(rows * cols); }
T& operator()(int row, int col) { return _elem[row * _cols + col]; }
const T& operator()(int row, int col) const { return _elem[row * _cols + col]; }
int rows() const { return _rows; }
int cols() const { return _cols; }
};
typedef bool Boolean;
typedef int8_t Int8;
typedef uint8_t UInt8;
typedef int16_t Int16;
typedef uint16_t UInt16;
typedef int32_t Int32;
typedef uint32_t UInt32;
typedef int64_t Int64;
typedef uint64_t UInt64;
typedef float Float32;
typedef double Float64;
typedef std::string String;
typedef std::tm TimePoint;
typedef std::vector<int8_t> I8Vector;
typedef std::vector<uint8_t> UI8Vector;
typedef std::vector<int16_t> I16Vector;
typedef std::vector<uint16_t> UI16Vector;
typedef std::vector<int32_t> I32Vector;
typedef std::vector<uint32_t> UI32Vector;
typedef std::vector<int64_t> I64Vector;
typedef std::vector<uint64_t> UI64Vector;
typedef std::vector<float> F32Vector;
typedef std::vector<double> F64Vector;
typedef std::vector<Complex32> C32Vector;
typedef std::vector<Complex64> C64Vector;
typedef Matrix<Int8> I8Matrix;
typedef Matrix<UInt8> UI8Matrix;
typedef Matrix<Int16> I16Matrix;
typedef Matrix<UInt16> UI16Matrix;
typedef Matrix<Int32> I32Matrix;
typedef Matrix<UInt32> UI32Matrix;
typedef Matrix<Int64> I64Matrix;
typedef Matrix<UInt64> UI64Matrix;
typedef Matrix<float> F32Matrix;
typedef Matrix<double> F64Matrix;
typedef Matrix<Complex32> C32Matrix;
typedef Matrix<Complex64> C64Matrix;
class Variant
{
using StdVariant = std::variant<std::monostate, Boolean, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Float32, Float64,
Complex32, Complex64, String, TimePoint,
I8Vector, UI8Vector, I16Vector, UI16Vector, I32Vector, UI32Vector, I64Vector, UI64Vector, F32Vector, F64Vector, C32Vector, C64Vector,
I8Matrix, UI8Matrix, I16Matrix, UI16Matrix, I32Matrix, UI32Matrix, I64Matrix, UI64Matrix, F32Matrix, F64Matrix, C32Matrix, C64Matrix>;
StdVariant _value;
public:
enum class Type
{
Monostate, Boolean, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Float32, Float64,
Complex32, Complex64, String, TimePoint,
I8Vector, UI8Vector, I16Vector, UI16Vector, I32Vector, UI32Vector, I64Vector, UI64Vector, F32Vector, F64Vector, C32Vector, C64Vector,
I8Matrix, UI8Matrix, I16Matrix, UI16Matrix, I32Matrix, UI32Matrix, I64Matrix, UI64Matrix, F32Matrix, F64Matrix, C32Matrix, C64Matrix
};
Variant() = default;
template<typename T>
Variant(const T &t) : _value(t) {}
Type type() const;
const char *typeName() const;
template<typename T>
T& value() { return std::get<T>(_value); }
template<typename T>
const T& value() const { return std::get<T>(_value); }
template<typename T>
void setValue(const T& val) { _value = val; }
};
}
#endif // LIBXISF_VARIANT_H