From ad184c3810ee404fbb249a800bd4aed46f446572 Mon Sep 17 00:00:00 2001 From: Clifford Yapp <238416+starseeker@users.noreply.github.com> Date: Tue, 3 Aug 2021 17:19:16 -0400 Subject: [PATCH 1/3] Add dllexport/dllimport definitions. --- poly2tri/common/shapes.h | 116 +++++++++++++++++++++++---------------- poly2tri/sweep/cdt.h | 34 +++++++++--- 2 files changed, 95 insertions(+), 55 deletions(-) diff --git a/poly2tri/common/shapes.h b/poly2tri/common/shapes.h index 5bf8c8f..e150212 100644 --- a/poly2tri/common/shapes.h +++ b/poly2tri/common/shapes.h @@ -33,6 +33,26 @@ #ifndef SHAPES_H #define SHAPES_H +#if defined(_WIN32) +# define COMPILER_DLLEXPORT __declspec(dllexport) +# define COMPILER_DLLIMPORT __declspec(dllimport) +#else +# define COMPILER_DLLEXPORT __attribute__ ((visibility ("default"))) +# define COMPILER_DLLIMPORT __attribute__ ((visibility ("default"))) +#endif + +#ifndef P2T_EXPORT +# if defined(P2T_DLL_EXPORTS) && defined(P2T_DLL_IMPORTS) +# error "Only P2T_DLL_EXPORTS or P2T_DLL_IMPORTS can be defined, not both." +# elif defined(P2T_DLL_EXPORTS) +# define P2T_EXPORT COMPILER_DLLEXPORT +# elif defined(P2T_DLL_IMPORTS) +# define P2T_EXPORT COMPILER_DLLIMPORT +# else +# define P2T_EXPORT +# endif +#endif + #include #include #include @@ -47,7 +67,7 @@ struct Point { double x, y; /// Default constructor does nothing (for performance). - Point() + P2T_EXPORT Point() { x = 0.0; y = 0.0; @@ -60,21 +80,21 @@ struct Point { Point(double x, double y); /// Set this point to all zeros. - void set_zero() + P2T_EXPORT void set_zero() { x = 0.0; y = 0.0; } /// Set this point to some specified coordinates. - void set(double x_, double y_) + P2T_EXPORT void set(double x_, double y_) { x = x_; y = y_; } /// Negate this point. - Point operator -() const + P2T_EXPORT Point operator -() const { Point v; v.set(-x, -y); @@ -82,34 +102,34 @@ struct Point { } /// Add a point to this point. - void operator +=(const Point& v) + P2T_EXPORT void operator +=(const Point& v) { x += v.x; y += v.y; } /// Subtract a point from this point. - void operator -=(const Point& v) + P2T_EXPORT void operator -=(const Point& v) { x -= v.x; y -= v.y; } /// Multiply this point by a scalar. - void operator *=(double a) + P2T_EXPORT void operator *=(double a) { x *= a; y *= a; } /// Get the length of this point (the norm). - double Length() const + P2T_EXPORT double Length() const { return sqrt(x * x + y * y); } /// Convert this point into a unit point. Returns the Length. - double Normalize() + P2T_EXPORT double Normalize() { const double len = Length(); x /= len; @@ -127,7 +147,7 @@ struct Edge { Point* p, *q; /// Constructor - Edge(Point& p1, Point& p2) : p(&p1), q(&p2) + P2T_EXPORT Edge(Point& p1, Point& p2) : p(&p1), q(&p2) { if (p1.y > p2.y) { q = &p1; @@ -153,64 +173,64 @@ class Triangle { public: /// Constructor -Triangle(Point& a, Point& b, Point& c); +P2T_EXPORT Triangle(Point& a, Point& b, Point& c); /// Flags to determine if an edge is a Constrained edge bool constrained_edge[3]; /// Flags to determine if an edge is a Delauney edge bool delaunay_edge[3]; -Point* GetPoint(int index); -Point* PointCW(const Point& point); -Point* PointCCW(const Point& point); -Point* OppositePoint(Triangle& t, const Point& p); +P2T_EXPORT Point* GetPoint(int index); +P2T_EXPORT Point* PointCW(const Point& point); +P2T_EXPORT Point* PointCCW(const Point& point); +P2T_EXPORT Point* OppositePoint(Triangle& t, const Point& p); -Triangle* GetNeighbor(int index); -void MarkNeighbor(Point* p1, Point* p2, Triangle* t); -void MarkNeighbor(Triangle& t); +P2T_EXPORT Triangle* GetNeighbor(int index); +P2T_EXPORT void MarkNeighbor(Point* p1, Point* p2, Triangle* t); +P2T_EXPORT void MarkNeighbor(Triangle& t); -void MarkConstrainedEdge(int index); -void MarkConstrainedEdge(Edge& edge); -void MarkConstrainedEdge(Point* p, Point* q); +P2T_EXPORT void MarkConstrainedEdge(int index); +P2T_EXPORT void MarkConstrainedEdge(Edge& edge); +P2T_EXPORT void MarkConstrainedEdge(Point* p, Point* q); -int Index(const Point* p); -int EdgeIndex(const Point* p1, const Point* p2); +P2T_EXPORT int Index(const Point* p); +P2T_EXPORT int EdgeIndex(const Point* p1, const Point* p2); -Triangle* NeighborAcross(const Point& point); -Triangle* NeighborCW(const Point& point); -Triangle* NeighborCCW(const Point& point); -bool GetConstrainedEdgeCCW(const Point& p); -bool GetConstrainedEdgeCW(const Point& p); -void SetConstrainedEdgeCCW(const Point& p, bool ce); -void SetConstrainedEdgeCW(const Point& p, bool ce); -bool GetDelunayEdgeCCW(const Point& p); -bool GetDelunayEdgeCW(const Point& p); -void SetDelunayEdgeCCW(const Point& p, bool e); -void SetDelunayEdgeCW(const Point& p, bool e); +P2T_EXPORT Triangle* NeighborAcross(const Point& point); +P2T_EXPORT Triangle* NeighborCW(const Point& point); +P2T_EXPORT Triangle* NeighborCCW(const Point& point); +P2T_EXPORT bool GetConstrainedEdgeCCW(const Point& p); +P2T_EXPORT bool GetConstrainedEdgeCW(const Point& p); +P2T_EXPORT void SetConstrainedEdgeCCW(const Point& p, bool ce); +P2T_EXPORT void SetConstrainedEdgeCW(const Point& p, bool ce); +P2T_EXPORT bool GetDelunayEdgeCCW(const Point& p); +P2T_EXPORT bool GetDelunayEdgeCW(const Point& p); +P2T_EXPORT void SetDelunayEdgeCCW(const Point& p, bool e); +P2T_EXPORT void SetDelunayEdgeCW(const Point& p, bool e); -bool Contains(const Point* p); -bool Contains(const Edge& e); -bool Contains(const Point* p, const Point* q); -void Legalize(Point& point); -void Legalize(Point& opoint, Point& npoint); +P2T_EXPORT bool Contains(const Point* p); +P2T_EXPORT bool Contains(const Edge& e); +P2T_EXPORT bool Contains(const Point* p, const Point* q); +P2T_EXPORT void Legalize(Point& point); +P2T_EXPORT void Legalize(Point& opoint, Point& npoint); /** * Clears all references to all other triangles and points */ -void Clear(); -void ClearNeighbor(const Triangle *triangle); -void ClearNeighbors(); -void ClearDelunayEdges(); +P2T_EXPORT void Clear(); +P2T_EXPORT void ClearNeighbor(const Triangle *triangle); +P2T_EXPORT void ClearNeighbors(); +P2T_EXPORT void ClearDelunayEdges(); -inline bool IsInterior(); -inline void IsInterior(bool b); +P2T_EXPORT inline bool IsInterior(); +P2T_EXPORT inline void IsInterior(bool b); -void DebugPrint(); +P2T_EXPORT void DebugPrint(); -bool CircumcicleContains(const Point&) const; +P2T_EXPORT bool CircumcicleContains(const Point&) const; private: -bool IsCounterClockwise() const; +P2T_EXPORT bool IsCounterClockwise() const; /// Triangle points Point* points_[3]; diff --git a/poly2tri/sweep/cdt.h b/poly2tri/sweep/cdt.h index efeeda3..cadde7d 100644 --- a/poly2tri/sweep/cdt.h +++ b/poly2tri/sweep/cdt.h @@ -32,6 +32,26 @@ #ifndef CDT_H #define CDT_H +#if defined(_WIN32) +# define COMPILER_DLLEXPORT __declspec(dllexport) +# define COMPILER_DLLIMPORT __declspec(dllimport) +#else +# define COMPILER_DLLEXPORT __attribute__ ((visibility ("default"))) +# define COMPILER_DLLIMPORT __attribute__ ((visibility ("default"))) +#endif + +#ifndef P2T_EXPORT +# if defined(P2T_DLL_EXPORTS) && defined(P2T_DLL_IMPORTS) +# error "Only P2T_DLL_EXPORTS or P2T_DLL_IMPORTS can be defined, not both." +# elif defined(P2T_DLL_EXPORTS) +# define P2T_EXPORT COMPILER_DLLEXPORT +# elif defined(P2T_DLL_IMPORTS) +# define P2T_EXPORT COMPILER_DLLIMPORT +# else +# define P2T_EXPORT +# endif +#endif + #include "advancing_front.h" #include "sweep_context.h" #include "sweep.h" @@ -53,41 +73,41 @@ public: * * @param polyline */ - CDT(const std::vector& polyline); + P2T_EXPORT CDT(const std::vector& polyline); /** * Destructor - clean up memory */ - ~CDT(); + P2T_EXPORT ~CDT(); /** * Add a hole * * @param polyline */ - void AddHole(const std::vector& polyline); + P2T_EXPORT void AddHole(const std::vector& polyline); /** * Add a steiner point * * @param point */ - void AddPoint(Point* point); + P2T_EXPORT void AddPoint(Point* point); /** * Triangulate - do this AFTER you've added the polyline, holes, and Steiner points */ - void Triangulate(); + P2T_EXPORT void Triangulate(); /** * Get CDT triangles */ - std::vector GetTriangles(); + P2T_EXPORT std::vector GetTriangles(); /** * Get triangle map */ - std::list GetMap(); + P2T_EXPORT std::list GetMap(); private: From 7f5846b72d549ef2cd56a9fb713ccbba05f67fc4 Mon Sep 17 00:00:00 2001 From: Pierre Dejoue Date: Sun, 17 Apr 2022 14:12:01 +0200 Subject: [PATCH 2/3] Retakes on dllexport/dllimport --- poly2tri/common/dll_symbol.h | 56 ++++++++++++++++ poly2tri/common/shapes.h | 126 +++++++++++++++-------------------- poly2tri/sweep/cdt.h | 38 +++-------- 3 files changed, 120 insertions(+), 100 deletions(-) create mode 100644 poly2tri/common/dll_symbol.h diff --git a/poly2tri/common/dll_symbol.h b/poly2tri/common/dll_symbol.h new file mode 100644 index 0000000..92c50cb --- /dev/null +++ b/poly2tri/common/dll_symbol.h @@ -0,0 +1,56 @@ +/* + * Poly2Tri Copyright (c) 2009-2022, Poly2Tri Contributors + * https://github.com/jhasse/poly2tri + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Poly2Tri nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef DLL_SYMBOL_H +#define DLL_SYMBOL_H + +#if defined(_WIN32) +# define P2T_COMPILER_DLLEXPORT __declspec(dllexport) +# define P2T_COMPILER_DLLIMPORT __declspec(dllimport) +#elif defined(__GNUC__) +# define P2T_COMPILER_DLLEXPORT __attribute__ ((visibility ("default"))) +# define P2T_COMPILER_DLLIMPORT __attribute__ ((visibility ("default"))) +#else +# define P2T_COMPILER_DLLEXPORT +# define P2T_COMPILER_DLLIMPORT +#endif + +#ifndef P2T_DLL_SYMBOL +# if defined(P2T_STATIC_EXPORTS) +# define P2T_DLL_SYMBOL +# elif defined(P2T_SHARED_EXPORTS) +# define P2T_DLL_SYMBOL P2T_COMPILER_DLLEXPORT +# else +# define P2T_DLL_SYMBOL P2T_COMPILER_DLLIMPORT +# endif +#endif + +#endif diff --git a/poly2tri/common/shapes.h b/poly2tri/common/shapes.h index e150212..489558d 100644 --- a/poly2tri/common/shapes.h +++ b/poly2tri/common/shapes.h @@ -33,25 +33,7 @@ #ifndef SHAPES_H #define SHAPES_H -#if defined(_WIN32) -# define COMPILER_DLLEXPORT __declspec(dllexport) -# define COMPILER_DLLIMPORT __declspec(dllimport) -#else -# define COMPILER_DLLEXPORT __attribute__ ((visibility ("default"))) -# define COMPILER_DLLIMPORT __attribute__ ((visibility ("default"))) -#endif - -#ifndef P2T_EXPORT -# if defined(P2T_DLL_EXPORTS) && defined(P2T_DLL_IMPORTS) -# error "Only P2T_DLL_EXPORTS or P2T_DLL_IMPORTS can be defined, not both." -# elif defined(P2T_DLL_EXPORTS) -# define P2T_EXPORT COMPILER_DLLEXPORT -# elif defined(P2T_DLL_IMPORTS) -# define P2T_EXPORT COMPILER_DLLIMPORT -# else -# define P2T_EXPORT -# endif -#endif +#include "dll_symbol.h" #include #include @@ -62,12 +44,12 @@ namespace p2t { struct Edge; -struct Point { +struct P2T_DLL_SYMBOL Point { double x, y; /// Default constructor does nothing (for performance). - P2T_EXPORT Point() + Point() { x = 0.0; y = 0.0; @@ -80,21 +62,21 @@ struct Point { Point(double x, double y); /// Set this point to all zeros. - P2T_EXPORT void set_zero() + void set_zero() { x = 0.0; y = 0.0; } /// Set this point to some specified coordinates. - P2T_EXPORT void set(double x_, double y_) + void set(double x_, double y_) { x = x_; y = y_; } /// Negate this point. - P2T_EXPORT Point operator -() const + Point operator -() const { Point v; v.set(-x, -y); @@ -102,34 +84,34 @@ struct Point { } /// Add a point to this point. - P2T_EXPORT void operator +=(const Point& v) + void operator +=(const Point& v) { x += v.x; y += v.y; } /// Subtract a point from this point. - P2T_EXPORT void operator -=(const Point& v) + void operator -=(const Point& v) { x -= v.x; y -= v.y; } /// Multiply this point by a scalar. - P2T_EXPORT void operator *=(double a) + void operator *=(double a) { x *= a; y *= a; } /// Get the length of this point (the norm). - P2T_EXPORT double Length() const + double Length() const { return sqrt(x * x + y * y); } /// Convert this point into a unit point. Returns the Length. - P2T_EXPORT double Normalize() + double Normalize() { const double len = Length(); x /= len; @@ -139,15 +121,15 @@ struct Point { }; -std::ostream& operator<<(std::ostream&, const Point&); +P2T_DLL_SYMBOL std::ostream& operator<<(std::ostream&, const Point&); // Represents a simple polygon's edge -struct Edge { +struct P2T_DLL_SYMBOL Edge { Point* p, *q; /// Constructor - P2T_EXPORT Edge(Point& p1, Point& p2) : p(&p1), q(&p2) + Edge(Point& p1, Point& p2) : p(&p1), q(&p2) { if (p1.y > p2.y) { q = &p1; @@ -169,68 +151,68 @@ struct Edge { // Triangle-based data structures are know to have better performance than quad-edge structures // See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator" // "Triangulations in CGAL" -class Triangle { +class P2T_DLL_SYMBOL Triangle { public: /// Constructor -P2T_EXPORT Triangle(Point& a, Point& b, Point& c); +Triangle(Point& a, Point& b, Point& c); /// Flags to determine if an edge is a Constrained edge bool constrained_edge[3]; /// Flags to determine if an edge is a Delauney edge bool delaunay_edge[3]; -P2T_EXPORT Point* GetPoint(int index); -P2T_EXPORT Point* PointCW(const Point& point); -P2T_EXPORT Point* PointCCW(const Point& point); -P2T_EXPORT Point* OppositePoint(Triangle& t, const Point& p); +Point* GetPoint(int index); +Point* PointCW(const Point& point); +Point* PointCCW(const Point& point); +Point* OppositePoint(Triangle& t, const Point& p); -P2T_EXPORT Triangle* GetNeighbor(int index); -P2T_EXPORT void MarkNeighbor(Point* p1, Point* p2, Triangle* t); -P2T_EXPORT void MarkNeighbor(Triangle& t); +Triangle* GetNeighbor(int index); +void MarkNeighbor(Point* p1, Point* p2, Triangle* t); +void MarkNeighbor(Triangle& t); -P2T_EXPORT void MarkConstrainedEdge(int index); -P2T_EXPORT void MarkConstrainedEdge(Edge& edge); -P2T_EXPORT void MarkConstrainedEdge(Point* p, Point* q); +void MarkConstrainedEdge(int index); +void MarkConstrainedEdge(Edge& edge); +void MarkConstrainedEdge(Point* p, Point* q); -P2T_EXPORT int Index(const Point* p); -P2T_EXPORT int EdgeIndex(const Point* p1, const Point* p2); +int Index(const Point* p); +int EdgeIndex(const Point* p1, const Point* p2); -P2T_EXPORT Triangle* NeighborAcross(const Point& point); -P2T_EXPORT Triangle* NeighborCW(const Point& point); -P2T_EXPORT Triangle* NeighborCCW(const Point& point); -P2T_EXPORT bool GetConstrainedEdgeCCW(const Point& p); -P2T_EXPORT bool GetConstrainedEdgeCW(const Point& p); -P2T_EXPORT void SetConstrainedEdgeCCW(const Point& p, bool ce); -P2T_EXPORT void SetConstrainedEdgeCW(const Point& p, bool ce); -P2T_EXPORT bool GetDelunayEdgeCCW(const Point& p); -P2T_EXPORT bool GetDelunayEdgeCW(const Point& p); -P2T_EXPORT void SetDelunayEdgeCCW(const Point& p, bool e); -P2T_EXPORT void SetDelunayEdgeCW(const Point& p, bool e); +Triangle* NeighborAcross(const Point& point); +Triangle* NeighborCW(const Point& point); +Triangle* NeighborCCW(const Point& point); +bool GetConstrainedEdgeCCW(const Point& p); +bool GetConstrainedEdgeCW(const Point& p); +void SetConstrainedEdgeCCW(const Point& p, bool ce); +void SetConstrainedEdgeCW(const Point& p, bool ce); +bool GetDelunayEdgeCCW(const Point& p); +bool GetDelunayEdgeCW(const Point& p); +void SetDelunayEdgeCCW(const Point& p, bool e); +void SetDelunayEdgeCW(const Point& p, bool e); -P2T_EXPORT bool Contains(const Point* p); -P2T_EXPORT bool Contains(const Edge& e); -P2T_EXPORT bool Contains(const Point* p, const Point* q); -P2T_EXPORT void Legalize(Point& point); -P2T_EXPORT void Legalize(Point& opoint, Point& npoint); +bool Contains(const Point* p); +bool Contains(const Edge& e); +bool Contains(const Point* p, const Point* q); +void Legalize(Point& point); +void Legalize(Point& opoint, Point& npoint); /** * Clears all references to all other triangles and points */ -P2T_EXPORT void Clear(); -P2T_EXPORT void ClearNeighbor(const Triangle *triangle); -P2T_EXPORT void ClearNeighbors(); -P2T_EXPORT void ClearDelunayEdges(); +void Clear(); +void ClearNeighbor(const Triangle *triangle); +void ClearNeighbors(); +void ClearDelunayEdges(); -P2T_EXPORT inline bool IsInterior(); -P2T_EXPORT inline void IsInterior(bool b); +inline bool IsInterior(); +inline void IsInterior(bool b); -P2T_EXPORT void DebugPrint(); +void DebugPrint(); -P2T_EXPORT bool CircumcicleContains(const Point&) const; +bool CircumcicleContains(const Point&) const; private: -P2T_EXPORT bool IsCounterClockwise() const; +bool IsCounterClockwise() const; /// Triangle points Point* points_[3]; @@ -344,7 +326,7 @@ inline void Triangle::IsInterior(bool b) } /// Is this set a valid delaunay triangulation? -bool IsDelaunay(const std::vector&); +P2T_DLL_SYMBOL bool IsDelaunay(const std::vector&); } diff --git a/poly2tri/sweep/cdt.h b/poly2tri/sweep/cdt.h index cadde7d..7e3a45a 100644 --- a/poly2tri/sweep/cdt.h +++ b/poly2tri/sweep/cdt.h @@ -32,30 +32,12 @@ #ifndef CDT_H #define CDT_H -#if defined(_WIN32) -# define COMPILER_DLLEXPORT __declspec(dllexport) -# define COMPILER_DLLIMPORT __declspec(dllimport) -#else -# define COMPILER_DLLEXPORT __attribute__ ((visibility ("default"))) -# define COMPILER_DLLIMPORT __attribute__ ((visibility ("default"))) -#endif - -#ifndef P2T_EXPORT -# if defined(P2T_DLL_EXPORTS) && defined(P2T_DLL_IMPORTS) -# error "Only P2T_DLL_EXPORTS or P2T_DLL_IMPORTS can be defined, not both." -# elif defined(P2T_DLL_EXPORTS) -# define P2T_EXPORT COMPILER_DLLEXPORT -# elif defined(P2T_DLL_IMPORTS) -# define P2T_EXPORT COMPILER_DLLIMPORT -# else -# define P2T_EXPORT -# endif -#endif - #include "advancing_front.h" #include "sweep_context.h" #include "sweep.h" +#include "../common/dll_symbol.h" + /** * * @author Mason Green @@ -64,7 +46,7 @@ namespace p2t { -class CDT +class P2T_DLL_SYMBOL CDT { public: @@ -73,41 +55,41 @@ public: * * @param polyline */ - P2T_EXPORT CDT(const std::vector& polyline); + CDT(const std::vector& polyline); /** * Destructor - clean up memory */ - P2T_EXPORT ~CDT(); + ~CDT(); /** * Add a hole * * @param polyline */ - P2T_EXPORT void AddHole(const std::vector& polyline); + void AddHole(const std::vector& polyline); /** * Add a steiner point * * @param point */ - P2T_EXPORT void AddPoint(Point* point); + void AddPoint(Point* point); /** * Triangulate - do this AFTER you've added the polyline, holes, and Steiner points */ - P2T_EXPORT void Triangulate(); + void Triangulate(); /** * Get CDT triangles */ - P2T_EXPORT std::vector GetTriangles(); + std::vector GetTriangles(); /** * Get triangle map */ - P2T_EXPORT std::list GetMap(); + std::list GetMap(); private: From 49a12eb378422bd7da98a900d9927605069e835b Mon Sep 17 00:00:00 2001 From: Pierre Dejoue Date: Wed, 20 Apr 2022 22:12:21 +0200 Subject: [PATCH 3/3] Set the API export symbols based on CMake BUILD_SHARED_LIBS By default poly2tri is built as a static library. --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50d6e31..1a237b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,13 @@ file(GLOB HEADERS poly2tri/*.h poly2tri/common/*.h poly2tri/sweep/*.h) add_library(poly2tri ${SOURCES} ${HEADERS}) target_include_directories(poly2tri INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) +get_target_property(poly2tri_target_type poly2tri TYPE) +if(poly2tri_target_type STREQUAL SHARED_LIBRARY) + target_compile_definitions(poly2tri PRIVATE P2T_SHARED_EXPORTS) +else() + target_compile_definitions(poly2tri PUBLIC P2T_STATIC_EXPORTS) +endif() + if(P2T_BUILD_TESTS) enable_testing() add_subdirectory(unittest)