From 42a127dbbe7a66bdbc753378e9d3468a0cb8f352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Thu, 13 Jul 2023 10:13:01 -0400 Subject: [PATCH 1/3] Allow building without serialization / json support --- src/CMakeLists.txt | 17 ++++++++++++++++- src/tinyspline.c | 7 +++++-- src/tinyspline.h | 3 ++- src/tinysplinecxx.cxx | 4 ++++ src/tinysplinecxx.h | 10 ++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 41775ad34..7b983b7b4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -563,6 +563,7 @@ set(TINYSPLINE_INSTALL_PKGCONFIG_DIR ) option(TINYSPLINE_FLOAT_PRECISION "Build TinySpline with float precision." OFF) +option(TINYSPLINE_SERIALIZATION "Build TinySpline with serialization support." ON) option(TINYSPLINE_WARNINGS_AS_ERRORS "Treat warnings as errors" ON) @@ -626,6 +627,11 @@ if(DEFINED ENV{TINYSPLINE_FLOAT_PRECISION}) set(TINYSPLINE_FLOAT_PRECISION $ENV{TINYSPLINE_FLOAT_PRECISION}) endif() +if(DEFINED ENV{TINYSPLINE_SERIALIZATION}) + message(STATUS "Using environment variable 'TINYSPLINE_SERIALIZATION'") + set(TINYSPLINE_SERIALIZATION $ENV{TINYSPLINE_SERIALIZATION}) +endif() + if(DEFINED ENV{TINYSPLINE_PYTHON_VERSION}) message(STATUS "Using environment variable 'TINYSPLINE_PYTHON_VERSION'") set(TINYSPLINE_PYTHON_VERSION $ENV{TINYSPLINE_PYTHON_VERSION}) @@ -702,6 +708,11 @@ if(TINYSPLINE_FLOAT_PRECISION) list(APPEND TINYSPLINE_CXX_DEFINITIONS "TINYSPLINE_FLOAT_PRECISION") list(APPEND TINYSPLINE_BINDING_CXX_DEFINITIONS "TINYSPLINE_FLOAT_PRECISION") endif() +if(NOT TINYSPLINE_SERIALIZATION) + list(APPEND TINYSPLINE_C_DEFINITIONS "TINYSPLINE_NO_SERIALIZATION") + list(APPEND TINYSPLINE_CXX_DEFINITIONS "TINYSPLINE_NO_SERIALIZATION") + list(APPEND TINYSPLINE_BINDING_CXX_DEFINITIONS "TINYSPLINE_NO_SERIALIZATION") +endif() list(APPEND TINYSPLINE_BINDING_CXX_DEFINITIONS "SWIG") if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") # TINYSPLINE_C_LINK_LIBRARIES TINYSPLINE_CXX_LINK_LIBRARIES @@ -903,8 +914,12 @@ set(TINYSPLINE_CXX_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") # TINYSPLINE_C_SOURCE_FILES list(APPEND TINYSPLINE_C_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/tinyspline.c" - "${CMAKE_CURRENT_SOURCE_DIR}/parson.c" ) +if(TINYSPLINE_SERIALIZATION) + list(APPEND TINYSPLINE_C_SOURCE_FILES + "${CMAKE_CURRENT_SOURCE_DIR}/parson.c" + ) +endif() # TINYSPLINE_CXX_SOURCE_FILES list(APPEND TINYSPLINE_CXX_SOURCE_FILES ${TINYSPLINE_C_SOURCE_FILES} diff --git a/src/tinyspline.c b/src/tinyspline.c index 8b120299c..a25012c71 100644 --- a/src/tinyspline.c +++ b/src/tinyspline.c @@ -1,6 +1,9 @@ #define TINYSPLINE_EXPORT #include "tinyspline.h" + +#if !defined(TINYSPLINE_NO_SERIALIZATION) #include "parson.h" /* serialization */ +#endif #include /* malloc, free */ #include /* fabs, sqrt, acos */ @@ -2818,7 +2821,7 @@ ts_bspline_morph(const tsBSpline *origin, /*! @} */ - +#if !defined(TINYSPLINE_NO_SERIALIZATION) /*! @name Serialization and Persistence * * @{ @@ -3138,7 +3141,7 @@ ts_bspline_load(const char *path, TS_END_TRY_RETURN(err) } /*! @} */ - +#endif /*! @name Vector Math diff --git a/src/tinyspline.h b/src/tinyspline.h index 8ef9f9a90..4d403e8e0 100644 --- a/src/tinyspline.h +++ b/src/tinyspline.h @@ -2511,6 +2511,7 @@ ts_bspline_morph(const tsBSpline *origin, +#if !defined(TINYSPLINE_NO_SERIALIZATION) /*! @name Serialization and Persistence * * The following functions can be used to serialize and persist (i.e., store @@ -2629,7 +2630,7 @@ tsError TINYSPLINE_API ts_bspline_load(const char *path, tsBSpline *spline, tsStatus *status); - +#endif /*! @name Vector Math diff --git a/src/tinysplinecxx.cxx b/src/tinysplinecxx.cxx index 34012caa3..c5e614100 100644 --- a/src/tinysplinecxx.cxx +++ b/src/tinysplinecxx.cxx @@ -957,6 +957,7 @@ tinyspline::BSpline::interpolateCatmullRom(std_real_vector_in points, return BSpline(data); } +#if !defined(TINYSPLINE_NO_SERIALIZATION) tinyspline::BSpline tinyspline::BSpline::parseJson(std::string json) { @@ -976,6 +977,7 @@ tinyspline::BSpline::load(std::string path) throw std::runtime_error(status.message); return BSpline(data); } +#endif bool tinyspline::BSpline::knotsEqual(real x, real y) @@ -1278,6 +1280,7 @@ tinyspline::BSpline::chordLengths(size_t numSamples) const return chordLengths(uniformKnotSeq(numSamples)); } +#if !defined(TINYSPLINE_NO_SERIALIZATION) std::string tinyspline::BSpline::toJson() const { @@ -1297,6 +1300,7 @@ tinyspline::BSpline::save(std::string path) const if (ts_bspline_save(&m_spline, path.c_str(), &status)) throw std::runtime_error(status.message); } +#endif void tinyspline::BSpline::setControlPoints( diff --git a/src/tinysplinecxx.h b/src/tinysplinecxx.h index 2f9d87fd2..bb3ad5f6b 100644 --- a/src/tinysplinecxx.h +++ b/src/tinysplinecxx.h @@ -597,8 +597,11 @@ class TINYSPLINECXX_API BSpline { std::vector *first = nullptr, std::vector *last = nullptr, real epsilon = TS_POINT_EPSILON); + +#if !defined(TINYSPLINE_NO_SERIALIZATION) static BSpline parseJson(std::string json); static BSpline load(std::string path); +#endif static bool knotsEqual(real x, real y); @@ -640,9 +643,11 @@ class TINYSPLINECXX_API BSpline { ChordLengths chordLengths(std_real_vector_in knots) const; ChordLengths chordLengths(size_t numSamples = 200) const; +#if !defined(TINYSPLINE_NO_SERIALIZATION) /* Serialization */ std::string toJson() const; void save(std::string path) const; +#endif /* Modifications */ void setControlPoints(const std::vector &ctrlp); @@ -907,7 +912,10 @@ EMSCRIPTEN_BINDINGS(tinyspline) { .class_function("interpolateCatmullRom", &BSpline::interpolateCatmullRom, allow_raw_pointers()) + +#if !defined(TINYSPLINE_NO_SERIALIZATION) .class_function("parseJson", &BSpline::parseJson) +#endif .property("degree", &BSpline::degree) .property("order", &BSpline::order) @@ -935,8 +943,10 @@ EMSCRIPTEN_BINDINGS(tinyspline) { .function("bisect", &BSpline::bisect) .function("isClosed", &BSpline::isClosed) +#if !defined(TINYSPLINE_NO_SERIALIZATION) /* Serialization */ .function("toJson", &BSpline::toJson) +#endif /* Transformations */ .function("insertKnot", &BSpline::insertKnot) From f03d1cd7dc9293cd4ceef7e45a59ebcf86119870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Fri, 14 Jul 2023 11:22:15 -0400 Subject: [PATCH 2/3] Update with requested changes --- src/CMakeLists.txt | 1 - src/tinyspline.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7b983b7b4..8ec5c6c5a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -711,7 +711,6 @@ endif() if(NOT TINYSPLINE_SERIALIZATION) list(APPEND TINYSPLINE_C_DEFINITIONS "TINYSPLINE_NO_SERIALIZATION") list(APPEND TINYSPLINE_CXX_DEFINITIONS "TINYSPLINE_NO_SERIALIZATION") - list(APPEND TINYSPLINE_BINDING_CXX_DEFINITIONS "TINYSPLINE_NO_SERIALIZATION") endif() list(APPEND TINYSPLINE_BINDING_CXX_DEFINITIONS "SWIG") if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") diff --git a/src/tinyspline.c b/src/tinyspline.c index a25012c71..5befb0c8a 100644 --- a/src/tinyspline.c +++ b/src/tinyspline.c @@ -3,12 +3,12 @@ #if !defined(TINYSPLINE_NO_SERIALIZATION) #include "parson.h" /* serialization */ +#include /* FILE, fopen */ #endif #include /* malloc, free */ #include /* fabs, sqrt, acos */ #include /* memcpy, memmove */ -#include /* FILE, fopen */ #include /* varargs */ /* Suppress some useless MSVC warnings. */ From d6aec47be87b2a25a50d397b040dd7fe59bb0a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Fri, 14 Jul 2023 17:26:11 -0400 Subject: [PATCH 3/3] Add serialization to CI matrix --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22fb01189..5f473137d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,7 @@ jobs: os: [ubuntu-latest, windows-latest, macOS-latest] shared: [On, Off] float: [On, Off] + serialization: [On, Off] steps: - uses: actions/checkout@v3 @@ -30,7 +31,12 @@ jobs: - name: Configure CMake shell: bash working-directory: ${{runner.workspace}}/build - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_SHARED_LIBS=${{ matrix.shared }} -DTINYSPLINE_FLOAT_PRECISION=${{ matrix.float }} + run: | + cmake $GITHUB_WORKSPACE \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ + -DBUILD_SHARED_LIBS=${{ matrix.shared }} \ + -DTINYSPLINE_FLOAT_PRECISION=${{ matrix.float }} \ + -DTINYSPLINE_SERIALIZATION=${{ matrix.serialization }} - name: Configure Installation working-directory: ${{runner.workspace}}/build