Add options for enabling ABI mangling namespace.

* CMake option VTK_ABI_NAMESPACE_NAME with default <DEFAULT>.
  * <DEFAULT> implies empty string or no namespace mangling.
* Configurable header vtkABINamespace.h.in added to Common::Core.
* Include vtkABINamespace.h in VTK modules.
* Link Common::Core to vtkTestOpenGLVersion which needs vtkABINamespace.h.
* VTK_NO_ABI_NAMESPACE can be used to disable namespace mangling for an
entire module (used in Wrapping/Tools).
HTGUnlimitedGradien
Ryan Krattiger 8 months ago
parent 9b98c6005f
commit 9519ee65b7

@ -0,0 +1,14 @@
#ifndef vtkABINamespace_h
#define vtkABINamespace_h
#ifndef VTK_NO_ABI_NAMESPACE
#if defined(__cplusplus)
#define VTK_ABI_NAMESPACE_BEGIN @VTK_ABI_NAMESPACE_BEGIN@
#define VTK_ABI_NAMESPACE_END @VTK_ABI_NAMESPACE_END@
#else
#define VTK_ABI_NAMESPACE_BEGIN
#define VTK_ABI_NAMESPACE_END
#endif
#endif // VTK_NO_ABI_NAMESPACE
#endif // vtkABINamespace_h

@ -3569,6 +3569,15 @@ function (vtk_module_add_module name)
"The ${_vtk_build_module} module has no source files.")
endif ()
set(_vtk_add_module_has_cxx FALSE)
foreach (source IN LISTS _vtk_add_module_SOURCES)
get_filename_component(source_ext "${source}" EXT)
if (source_ext MATCHES "cxx$")
set(_vtk_add_module_has_cxx TRUE)
break()
endif ()
endforeach ()
get_property(_vtk_add_module_third_party GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_third_party")
@ -3944,6 +3953,16 @@ function (vtk_module_add_module name)
"INTERFACE_vtk_module_implementable" 1)
endif ()
# Include the ABI Namespace macros if this is a module with C++ sources
if (_vtk_add_module_has_cxx)
# Include the ABI Namespace macros
string(APPEND _vtk_add_module_module_content
"
/* Include ABI Namespace */
#include \"vtkABINamespace.h\"
")
endif ()
if (_vtk_add_module_implementable OR _vtk_add_module_implements)
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY

@ -3,6 +3,29 @@ cmake_dependent_option(VTK_USE_64BIT_TIMESTAMPS "Build VTK with 64 bit timestamp
"NOT CMAKE_SIZEOF_VOID_P GREATER 4" ON)
mark_as_advanced(VTK_USE_64BIT_TIMESTAMPS)
# Mangle VTK symbols
set(VTK_ABI_NAMESPACE_NAME
"<DEFAULT>"
CACHE STRING "Inline namespace name for mangling VTK symbols.")
if (VTK_ABI_NAMESPACE_NAME STREQUAL "<DEFAULT>")
# The default is to not have an ABI namespace.
# This is consistent with the existing practice.
set(VTK_ABI_NAMESPACE_NAME "")
endif ()
mark_as_advanced(VTK_ABI_NAMESPACE_NAME)
if (VTK_ABI_NAMESPACE_NAME)
message(STATUS "VTK ABI namespace: ${VTK_ABI_NAMESPACE_NAME}")
set(VTK_ABI_NAMESPACE_BEGIN "inline namespace ${VTK_ABI_NAMESPACE_NAME} {")
set(VTK_ABI_NAMESPACE_END "}")
else ()
set(VTK_ABI_NAMESPACE_BEGIN "")
set(VTK_ABI_NAMESPACE_END "")
endif ()
configure_file(
"${vtk_cmake_dir}/vtkABINamespace.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/vtkABINamespace.h"
@ONLY)
if (CMAKE_SIZEOF_VOID_P GREATER 4)
set(vtk_use_64bit_ids_default ON)
else ()
@ -321,6 +344,7 @@ set(headers
vtkWindows.h
vtkWrappingHints.h
${vtk_smp_headers}
"${CMAKE_CURRENT_BINARY_DIR}/vtkABINamespace.h"
"${CMAKE_CURRENT_BINARY_DIR}/vtkArrayDispatchArrayList.h"
"${CMAKE_CURRENT_BINARY_DIR}/vtkMathConfigure.h"
"${CMAKE_CURRENT_BINARY_DIR}/vtkTypeListMacros.h"

@ -110,7 +110,7 @@ if (WIN32 AND (NOT CMAKE_CROSSCOMPILING OR DEFINED CMAKE_CROSSCOMPILING_EMULATOR
set_target_properties(vtkTestOpenGLVersion
PROPERTIES
WIN32_EXECUTABLE TRUE)
target_link_libraries(vtkTestOpenGLVersion PRIVATE opengl32)
target_link_libraries(vtkTestOpenGLVersion PRIVATE opengl32 VTK::CommonCore)
list(APPEND headers vtkTestOpenGLVersion.h)
endif ()

@ -40,6 +40,8 @@ set_property(SOURCE vtkParseMain.c
PROPERTY
COMPILE_DEFINITIONS "VTK_PARSE_VERSION=\"${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}\"")
add_definitions(-DVTK_NO_ABI_NAMESPACE)
vtk_module_add_module("${ns}::WrappingTools"
SOURCES ${sources}
HEADERS ${headers})

Loading…
Cancel
Save