From 6bcabfd567479d7db7d19f725ae08f6d90ece36d Mon Sep 17 00:00:00 2001 From: Stinkfist0 Date: Mon, 11 Jul 2016 21:36:12 +0300 Subject: [PATCH] Dllimport/export for IfcGeom. Closes #77 --- cmake/CMakeLists.txt | 19 +++--------- src/ifcgeom/IfcGeom.h | 15 ++++++---- src/ifcgeom/IfcGeomElement.h | 1 + src/ifcgeom/IfcGeomFunctions.cpp | 23 ++++++++++----- src/ifcgeom/IfcGeomIterator.h | 8 +++++ src/ifcgeom/IfcGeomIteratorSettings.h | 5 ++-- src/ifcgeom/IfcGeomMaterial.h | 2 +- src/ifcgeom/IfcGeomRenderStyles.h | 5 ++-- src/ifcgeom/IfcGeomRepresentation.h | 6 ++-- src/ifcgeom/IfcRepresentationShapeItem.h | 2 +- src/ifcgeom/ifc_geom_api.h | 37 ++++++++++++++++++++++++ src/ifcparse/IfcParse_Export.h | 2 +- 12 files changed, 86 insertions(+), 39 deletions(-) create mode 100644 src/ifcgeom/ifc_geom_api.h diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 205fb336e3..6774bc8de2 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -432,11 +432,7 @@ if(NOT WIN32) LINK_DIRECTORIES(${LINK_DIRECTORIES} /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64) endif() -if(BUILD_SHARED_LIBS) - SET(IFCOPENSHELL_LIBRARIES IfcGeom) -else() - SET(IFCOPENSHELL_LIBRARIES IfcParse IfcGeom) -endif() +set(IFCOPENSHELL_LIBRARIES IfcParse IfcGeom) # IfcParse file(GLOB IFCPARSE_H_FILES ../src/ifcparse/*.h) @@ -464,17 +460,10 @@ file(GLOB IFCGEOM_H_FILES ../src/ifcgeom/*.h) file(GLOB IFCGEOM_CPP_FILES ../src/ifcgeom/*.cpp) set(IFCGEOM_FILES ${IFCGEOM_CPP_FILES} ${IFCGEOM_H_FILES}) -IF(BUILD_SHARED_LIBS) - message(WARNING "Building IfcGeom as shared library currently not supported depending on platform and compiler options") -ENDIF() +add_library(IfcGeom ${IFCGEOM_FILES}) +set_target_properties(IfcGeom PROPERTIES COMPILE_FLAGS -DIFC_GEOM_EXPORTS) -if(WIN32) - add_library(IfcGeom STATIC ${IFCGEOM_FILES}) -else() - add_library(IfcGeom ${IFCGEOM_FILES}) -endif() - -TARGET_LINK_LIBRARIES(IfcGeom IfcParse) +TARGET_LINK_LIBRARIES(IfcGeom IfcParse ${OPENCASCADE_LIBRARIES}) # IfcConvert file(GLOB IFCCONVERT_CPP_FILES ../src/ifcconvert/*.cpp) diff --git a/src/ifcgeom/IfcGeom.h b/src/ifcgeom/IfcGeom.h index 53d21d03be..bf679b5812 100644 --- a/src/ifcgeom/IfcGeom.h +++ b/src/ifcgeom/IfcGeom.h @@ -51,6 +51,7 @@ inline static bool ALMOST_THE_SAME(const T& a, const T& b, double tolerance=ALMO #include "../ifcgeom/IfcGeomRepresentation.h" #include "../ifcgeom/IfcRepresentationShapeItem.h" #include "../ifcgeom/IfcGeomShapeType.h" +#include "ifc_geom_api.h" // Define this in case you want to conserve memory usage at all cost. This has been // benchmarked extensively: https://github.com/IfcOpenShell/IfcOpenShell/pull/47 @@ -71,13 +72,13 @@ if ( it != cache.T.end() ) { e = it->second; return true; } namespace IfcGeom { -class Cache { +class IFC_GEOM_API Cache { public: #include "IfcRegisterCreateCache.h" std::map Shape; }; -class Kernel { +class IFC_GEOM_API Kernel { private: double deflection_tolerance; @@ -230,10 +231,12 @@ public: IfcSchema::IfcObjectDefinition* get_decomposing_entity(IfcSchema::IfcProduct*); template - IfcGeom::BRepElement

* create_brep_for_representation_and_product(const IteratorSettings&, IfcSchema::IfcRepresentation*, IfcSchema::IfcProduct*); + IfcGeom::BRepElement

* create_brep_for_representation_and_product( + const IteratorSettings&, IfcSchema::IfcRepresentation*, IfcSchema::IfcProduct*); template - IfcGeom::BRepElement

* create_brep_for_processed_representation(const IteratorSettings&, IfcSchema::IfcRepresentation*, IfcSchema::IfcProduct*, IfcGeom::BRepElement

*); + IfcGeom::BRepElement

* create_brep_for_processed_representation( + const IteratorSettings&, IfcSchema::IfcRepresentation*, IfcSchema::IfcProduct*, IfcGeom::BRepElement

*); const SurfaceStyle* get_style(const IfcSchema::IfcRepresentationItem*); const SurfaceStyle* get_style(const IfcSchema::IfcMaterial*); @@ -300,8 +303,8 @@ public: }; -IfcSchema::IfcProductDefinitionShape* tesselate(const TopoDS_Shape& shape, double deflection); -IfcSchema::IfcProductDefinitionShape* serialise(const TopoDS_Shape& shape, bool advanced); +IFC_GEOM_API IfcSchema::IfcProductDefinitionShape* tesselate(const TopoDS_Shape& shape, double deflection); +IFC_GEOM_API IfcSchema::IfcProductDefinitionShape* serialise(const TopoDS_Shape& shape, bool advanced); } #endif diff --git a/src/ifcgeom/IfcGeomElement.h b/src/ifcgeom/IfcGeomElement.h index 35477316ff..7d1410c938 100644 --- a/src/ifcgeom/IfcGeomElement.h +++ b/src/ifcgeom/IfcGeomElement.h @@ -27,6 +27,7 @@ #include "../ifcgeom/IfcGeomRepresentation.h" #include "../ifcgeom/IfcGeomIteratorSettings.h" +#include "ifc_geom_api.h" namespace IfcGeom { diff --git a/src/ifcgeom/IfcGeomFunctions.cpp b/src/ifcgeom/IfcGeomFunctions.cpp index 61fe2cb7c6..0c7fbe6fd7 100644 --- a/src/ifcgeom/IfcGeomFunctions.cpp +++ b/src/ifcgeom/IfcGeomFunctions.cpp @@ -1004,8 +1004,9 @@ IfcSchema::IfcRelVoidsElement::list::ptr IfcGeom::Kernel::find_openings(IfcSchem } template -IfcGeom::BRepElement

* IfcGeom::Kernel::create_brep_for_representation_and_product(const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product) { - +IfcGeom::BRepElement

* IfcGeom::Kernel::create_brep_for_representation_and_product( + const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product) +{ IfcGeom::Representation::BRep* shape; IfcGeom::IfcRepresentationShapeItems shapes, shapes2; @@ -1116,8 +1117,10 @@ IfcGeom::BRepElement

* IfcGeom::Kernel::create_brep_for_representation_and_pro } template -IfcGeom::BRepElement

* IfcGeom::Kernel::create_brep_for_processed_representation(const IteratorSettings& /*settings*/, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, IfcGeom::BRepElement

* brep) { - +IfcGeom::BRepElement

* IfcGeom::Kernel::create_brep_for_processed_representation( + const IteratorSettings& /*settings*/, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, + IfcGeom::BRepElement

* brep) +{ int parent_id = -1; try { IfcSchema::IfcObjectDefinition* parent_object = get_decomposing_entity(product); @@ -1210,11 +1213,15 @@ IfcSchema::IfcObjectDefinition* IfcGeom::Kernel::get_decomposing_entity(IfcSchem return parent; } -template IfcGeom::BRepElement* IfcGeom::Kernel::create_brep_for_representation_and_product(const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product); -template IfcGeom::BRepElement* IfcGeom::Kernel::create_brep_for_representation_and_product(const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product); +template IFC_GEOM_API IfcGeom::BRepElement* IfcGeom::Kernel::create_brep_for_representation_and_product( + const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product); +template IFC_GEOM_API IfcGeom::BRepElement* IfcGeom::Kernel::create_brep_for_representation_and_product( + const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product); -template IfcGeom::BRepElement* IfcGeom::Kernel::create_brep_for_processed_representation(const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, IfcGeom::BRepElement* brep); -template IfcGeom::BRepElement* IfcGeom::Kernel::create_brep_for_processed_representation(const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, IfcGeom::BRepElement* brep); +template IFC_GEOM_API IfcGeom::BRepElement* IfcGeom::Kernel::create_brep_for_processed_representation( + const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, IfcGeom::BRepElement* brep); +template IFC_GEOM_API IfcGeom::BRepElement* IfcGeom::Kernel::create_brep_for_processed_representation( + const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, IfcGeom::BRepElement* brep); std::pair IfcGeom::Kernel::initializeUnits(IfcSchema::IfcUnitAssignment* unit_assignment) { // Set default units, set length to meters, angles to undefined diff --git a/src/ifcgeom/IfcGeomIterator.h b/src/ifcgeom/IfcGeomIterator.h index 9f4528098e..0c155f4343 100644 --- a/src/ifcgeom/IfcGeomIterator.h +++ b/src/ifcgeom/IfcGeomIterator.h @@ -82,6 +82,14 @@ #include "../ifcgeom/IfcGeomIteratorSettings.h" #include "../ifcgeom/IfcRepresentationShapeItem.h" +// The infamous min & max Win32 #defines can leak here from OCE depending on the build configuration +#ifdef min +#undef min +#endif +#ifdef max +#undef max +#endif + namespace IfcGeom { template diff --git a/src/ifcgeom/IfcGeomIteratorSettings.h b/src/ifcgeom/IfcGeomIteratorSettings.h index 8e9f86b695..ae751aecbc 100644 --- a/src/ifcgeom/IfcGeomIteratorSettings.h +++ b/src/ifcgeom/IfcGeomIteratorSettings.h @@ -20,12 +20,13 @@ #ifndef IFCGEOMITERATORSETTINGS_H #define IFCGEOMITERATORSETTINGS_H +#include "ifc_geom_api.h" #include "../ifcparse/IfcException.h" #include "../ifcparse/IfcUtil.h" namespace IfcGeom { - class IteratorSettings + class IFC_GEOM_API IteratorSettings { public: /// Enumeration of setting identifiers. These settings define the @@ -142,7 +143,7 @@ namespace IfcGeom double deflection_tolerance_; }; - class ElementSettings : public IteratorSettings + class IFC_GEOM_API ElementSettings : public IteratorSettings { public: ElementSettings(const IteratorSettings& settings, diff --git a/src/ifcgeom/IfcGeomMaterial.h b/src/ifcgeom/IfcGeomMaterial.h index 9dc4dd7995..ead890698f 100644 --- a/src/ifcgeom/IfcGeomMaterial.h +++ b/src/ifcgeom/IfcGeomMaterial.h @@ -26,7 +26,7 @@ namespace IfcGeom { - class Material { + class IFC_GEOM_API Material { private: const IfcGeom::SurfaceStyle* style; public: diff --git a/src/ifcgeom/IfcGeomRenderStyles.h b/src/ifcgeom/IfcGeomRenderStyles.h index ca655f0971..5c499d58dc 100644 --- a/src/ifcgeom/IfcGeomRenderStyles.h +++ b/src/ifcgeom/IfcGeomRenderStyles.h @@ -20,6 +20,7 @@ #ifndef IFCGEOMRENDERSTYLES_H #define IFCGEOMRENDERSTYLES_H +#include "ifc_geom_api.h" #ifdef USE_IFC4 #include "../ifcparse/Ifc4.h" #else @@ -27,7 +28,7 @@ #endif namespace IfcGeom { - class SurfaceStyle { + class IFC_GEOM_API SurfaceStyle { public: class ColorComponent { private: @@ -92,7 +93,7 @@ namespace IfcGeom { boost::optional& Specularity() { return specularity; } }; - const SurfaceStyle* get_default_style(const std::string& ifc_type); + IFC_GEOM_API const SurfaceStyle* get_default_style(const std::string& ifc_type); } #endif diff --git a/src/ifcgeom/IfcGeomRepresentation.h b/src/ifcgeom/IfcGeomRepresentation.h index 472b049813..7a18dc4bab 100644 --- a/src/ifcgeom/IfcGeomRepresentation.h +++ b/src/ifcgeom/IfcGeomRepresentation.h @@ -41,7 +41,7 @@ namespace IfcGeom { namespace Representation { - class Representation { + class IFC_GEOM_API Representation { Representation(const Representation&); //N/A Representation& operator =(const Representation&); //N/A protected: @@ -54,7 +54,7 @@ namespace IfcGeom { virtual ~Representation() {} }; - class BRep : public Representation { + class IFC_GEOM_API BRep : public Representation { private: unsigned int id; const IfcGeom::IfcRepresentationShapeItems _shapes; @@ -73,7 +73,7 @@ namespace IfcGeom { const unsigned int& getId() const { return id; } }; - class Serialization : public Representation { + class IFC_GEOM_API Serialization : public Representation { private: int _id; std::string _brep_data; diff --git a/src/ifcgeom/IfcRepresentationShapeItem.h b/src/ifcgeom/IfcRepresentationShapeItem.h index 1d2c3fa8b5..29d5ca264b 100644 --- a/src/ifcgeom/IfcRepresentationShapeItem.h +++ b/src/ifcgeom/IfcRepresentationShapeItem.h @@ -26,7 +26,7 @@ #include "../ifcgeom/IfcGeomRenderStyles.h" namespace IfcGeom { - class IfcRepresentationShapeItem { + class IFC_GEOM_API IfcRepresentationShapeItem { private: gp_GTrsf placement; TopoDS_Shape shape; diff --git a/src/ifcgeom/ifc_geom_api.h b/src/ifcgeom/ifc_geom_api.h new file mode 100644 index 0000000000..1d916a61d0 --- /dev/null +++ b/src/ifcgeom/ifc_geom_api.h @@ -0,0 +1,37 @@ +/******************************************************************************** +* * +* This file is part of IfcOpenShell. * +* * +* IfcOpenShell is free software: you can redistribute it and/or modify * +* it under the terms of the Lesser GNU General Public License as published by * +* the Free Software Foundation, either version 3.0 of the License, or * +* (at your option) any later version. * +* * +* IfcOpenShell 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 * +* Lesser GNU General Public License for more details. * +* * +* You should have received a copy of the Lesser GNU General Public License * +* along with this program. If not, see . * +* * +********************************************************************************/ + +#ifndef IFC_GEOM_API_H +#define IFC_GEOM_API_H + +#ifdef BUILD_SHARED_LIBS + #ifdef _WIN32 + #ifdef IFC_GEOM_EXPORTS + #define IFC_GEOM_API __declspec(dllexport) + #else + #define IFC_GEOM_API __declspec(dllimport) + #endif + #else // simply assume GCC-like + #define IFC_GEOM_API __attribute__((visibility("default"))) + #endif +#else + #define IFC_GEOM_API +#endif + +#endif diff --git a/src/ifcparse/IfcParse_Export.h b/src/ifcparse/IfcParse_Export.h index 5c20672c09..dd120aadeb 100644 --- a/src/ifcparse/IfcParse_Export.h +++ b/src/ifcparse/IfcParse_Export.h @@ -21,7 +21,7 @@ #define IfcParse_EXPORT_H #ifdef BUILD_SHARED_LIBS - #ifdef _MSC_VER + #ifdef _WIN32 #ifdef IfcParse_EXPORTS #define IfcParse_EXPORT __declspec(dllexport) #else