Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow building without serialization / json support #233

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 15 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
jcelerier marked this conversation as resolved.
Show resolved Hide resolved

option(TINYSPLINE_WARNINGS_AS_ERRORS "Treat warnings as errors" ON)

Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -702,6 +708,10 @@ 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")
endif()
list(APPEND TINYSPLINE_BINDING_CXX_DEFINITIONS "SWIG")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# TINYSPLINE_C_LINK_LIBRARIES TINYSPLINE_CXX_LINK_LIBRARIES
Expand Down Expand Up @@ -903,8 +913,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}
Expand Down
9 changes: 6 additions & 3 deletions src/tinyspline.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#define TINYSPLINE_EXPORT
#include "tinyspline.h"

#if !defined(TINYSPLINE_NO_SERIALIZATION)
#include "parson.h" /* serialization */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <stdio.h> can also be excluded as we only use FILE and fopen from it. I propose to move this line into the !defined(TINYSPLINE_NO_SERIALIZATION) block.

#include <stdio.h> /* FILE, fopen */
#endif

#include <stdlib.h> /* malloc, free */
#include <math.h> /* fabs, sqrt, acos */
#include <string.h> /* memcpy, memmove */
#include <stdio.h> /* FILE, fopen */
#include <stdarg.h> /* varargs */

/* Suppress some useless MSVC warnings. */
Expand Down Expand Up @@ -2818,7 +2821,7 @@ ts_bspline_morph(const tsBSpline *origin,
/*! @} */



#if !defined(TINYSPLINE_NO_SERIALIZATION)
/*! @name Serialization and Persistence
*
* @{
Expand Down Expand Up @@ -3138,7 +3141,7 @@ ts_bspline_load(const char *path,
TS_END_TRY_RETURN(err)
}
/*! @} */

#endif


/*! @name Vector Math
Expand Down
3 changes: 2 additions & 1 deletion src/tinyspline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2629,7 +2630,7 @@ tsError TINYSPLINE_API
ts_bspline_load(const char *path,
tsBSpline *spline,
tsStatus *status);

#endif


/*! @name Vector Math
Expand Down
4 changes: 4 additions & 0 deletions src/tinysplinecxx.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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
{
Expand All @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions src/tinysplinecxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,11 @@ class TINYSPLINECXX_API BSpline {
std::vector<real> *first = nullptr,
std::vector<real> *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);

Expand Down Expand Up @@ -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<real> &ctrlp);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading