diff --git a/include/vsg/core/Array.h b/include/vsg/core/Array.h index ebc3209a1..54cf11367 100644 --- a/include/vsg/core/Array.h +++ b/include/vsg/core/Array.h @@ -33,7 +33,7 @@ namespace vsg { template - class Array : public Data + class VSG_DECLSPEC Array : public Data { public: using value_type = T; @@ -101,7 +101,7 @@ namespace vsg _data(nullptr), _size(0) { - assign(data, offset, stride, l.size()); + assign(data, offset, stride, static_cast(l.size())); iterator itr = begin(); for (const value_type& v : l) { (*itr++) = v; } diff --git a/include/vsg/core/Export.h b/include/vsg/core/Export.h index 3e46bcc17..c5b5941f9 100644 --- a/include/vsg/core/Export.h +++ b/include/vsg/core/Export.h @@ -25,5 +25,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI # define VSG_DECLSPEC # endif #else -# define VSG_DECLSPEC +# if defined(VSG_SHARED_LIBRARY) || defined(VSG_EXPORTS) +# define VSG_DECLSPEC __attribute__((visibility("default"))) +# else +# define VSG_DECLSPEC +# endif #endif diff --git a/include/vsg/core/Object.h b/include/vsg/core/Object.h index fce17f532..1bbc1280e 100644 --- a/include/vsg/core/Object.h +++ b/include/vsg/core/Object.h @@ -22,6 +22,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include +#ifdef VSG_USE_DYNAMIC_CAST + #define VSG_CAST_DYNAMIC +#else + #undef VSG_CAST_DYNAMIC +#endif + namespace vsg { @@ -85,11 +91,19 @@ namespace vsg virtual const std::type_info& type_info() const noexcept { return typeid(Object); } virtual bool is_compatible(const std::type_info& type) const noexcept { return typeid(Object) == type; } - template - T* cast() { return is_compatible(typeid(T)) ? static_cast(this) : nullptr; } + #ifdef VSG_CAST_DYNAMIC + template + T* cast() { return dynamic_cast(this); } - template - const T* cast() const { return is_compatible(typeid(T)) ? static_cast(this) : nullptr; } + template + const T* cast() const { return dynamic_cast(this); } + #else + template + T* cast() { return is_compatible(typeid(T)) ? static_cast(this) : nullptr; } + + template + const T* cast() const { return is_compatible(typeid(T)) ? static_cast(this) : nullptr; } + #endif /// clone this object using CopyOp's duplicates map to decide whether to clone or to return the original object. /// The default clone(CopyOp&) implementation simply returns ref_ptr<> to this object rather attempt to clone. diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index 26e87199a..1a8fa27ff 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -426,6 +426,14 @@ target_link_libraries(vsg ${LIBRARIES}) if (BUILD_SHARED_LIBS) target_compile_definitions(vsg INTERFACE VSG_SHARED_LIBRARY) +else() + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if (VSG_USE_DYNAMIC_CAST) + target_compile_definitions(vsg PRIVATE VSG_USE_DYNAMIC_CAST) + else () + target_compile_definitions(vsg PRIVATE VSG_EXPORTS) + endif () + endif() endif() # install headers