Skip to content

Commit 1581af7

Browse files
committed
Merge branch 'fix-cast-arm64' of https://github.com/hearga/VulkanSceneGraph into hearga-fix-cast-arm64
2 parents 193aae8 + 4bd274f commit 1581af7

9 files changed

Lines changed: 31 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ if (VSG_SUPPORTS_Windowing)
9898
endif()
9999
endif()
100100

101+
set(VSG_USE_DYNAMIC_CAST 0 CACHE STRING "Use dynamic_cast in vsg::Object::cast<T>(), 0 for off, 1 for enabled." )
102+
101103
# this line needs to be after the call to setup_build_vars()
102104
configure_file("${VSG_SOURCE_DIR}/src/vsg/core/Version.h.in" "${VSG_VERSION_HEADER}")
103105

include/vsg/core/Array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
3232
namespace vsg
3333
{
3434
template<typename T>
35-
class Array : public Data
35+
class VSG_DECLSPEC Array : public Data
3636
{
3737
public:
3838
using value_type = T;

include/vsg/core/Array2D.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace vsg
3030
{
3131

3232
template<typename T>
33-
class Array2D : public Data
33+
class VSG_DECLSPEC Array2D : public Data
3434
{
3535
public:
3636
using value_type = T;

include/vsg/core/Array3D.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
3030
namespace vsg
3131
{
3232
template<typename T>
33-
class Array3D : public Data
33+
class VSG_DECLSPEC Array3D : public Data
3434
{
3535
public:
3636
using value_type = T;

include/vsg/core/Export.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
2525
# define VSG_DECLSPEC
2626
# endif
2727
#else
28-
# define VSG_DECLSPEC
28+
# if defined(VSG_SHARED_LIBRARY) || defined(VSG_EXPORTS)
29+
# define VSG_DECLSPEC __attribute__((visibility("default")))
30+
# else
31+
# define VSG_DECLSPEC
32+
# endif
2933
#endif

include/vsg/core/Object.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,19 @@ namespace vsg
8585
virtual const std::type_info& type_info() const noexcept { return typeid(Object); }
8686
virtual bool is_compatible(const std::type_info& type) const noexcept { return typeid(Object) == type; }
8787

88-
template<class T>
89-
T* cast() { return is_compatible(typeid(T)) ? static_cast<T*>(this) : nullptr; }
90-
91-
template<class T>
92-
const T* cast() const { return is_compatible(typeid(T)) ? static_cast<const T*>(this) : nullptr; }
88+
#if VSG_USE_DYNAMIC_CAST == 1
89+
template<class T>
90+
T* cast() { return dynamic_cast<T*>(this); }
91+
92+
template<class T>
93+
const T* cast() const { return dynamic_cast<const T*>(this); }
94+
#else
95+
template<class T>
96+
T* cast() { return is_compatible(typeid(T)) ? static_cast<T*>(this) : nullptr; }
97+
98+
template<class T>
99+
const T* cast() const { return is_compatible(typeid(T)) ? static_cast<const T*>(this) : nullptr; }
100+
#endif
93101

94102
/// clone this object using CopyOp's duplicates map to decide whether to clone or to return the original object.
95103
/// The default clone(CopyOp&) implementation simply returns ref_ptr<> to this object rather attempt to clone.

include/vsg/core/Value.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
3636
namespace vsg
3737
{
3838
template<typename T>
39-
class Value : public Data
39+
class VSG_DECLSPEC Value : public Data
4040
{
4141
public:
4242
using value_type = T;

src/vsg/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ target_link_libraries(vsg ${LIBRARIES})
427427

428428
if (BUILD_SHARED_LIBS)
429429
target_compile_definitions(vsg INTERFACE VSG_SHARED_LIBRARY)
430+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT VSG_USE_DYNAMIC_CAST)
431+
# Static build, Clang, and we are not using dynamic_cast:
432+
# export Array/Value/etc. to stabilize typeid.
433+
target_compile_definitions(vsg PRIVATE VSG_EXPORTS)
430434
endif()
431435

432436
# install headers

src/vsg/core/Version.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ extern "C"
4545
/// Native Windowing support provided with vsg::Window::create(windowTraits) enabled when 1, disabled when 0
4646
#cmakedefine01 VSG_SUPPORTS_Windowing
4747

48+
/// Define VSG_USE_DYNAMIC_CAST to avoid typeid(T) comparisons in vsg::Object::cast<T>()
49+
#define VSG_USE_DYNAMIC_CAST @VSG_USE_DYNAMIC_CAST@
50+
4851
struct VsgVersion
4952
{
5053
unsigned int major;

0 commit comments

Comments
 (0)