mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Redesign our export headers to handle template exports.
This commit is contained in:
parent
f0413c4801
commit
4f43089fe3
79
CMake/VTKmExportHeaderTemplate.h.in
Normal file
79
CMake/VTKmExportHeaderTemplate.h.in
Normal file
@ -0,0 +1,79 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
//
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//
|
||||
// Copyright 2016 Sandia Corporation.
|
||||
// Copyright 2016 UT-Battelle, LLC.
|
||||
// Copyright 2016 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//
|
||||
//=============================================================================
|
||||
#ifndef @EXPORT_MACRO_NAME@_EXPORT_H
|
||||
#define @EXPORT_MACRO_NAME@_EXPORT_H
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# if @EXPORT_IS_BUILT_STATIC@
|
||||
/* This is a static component and has no need for exports
|
||||
elf based static libraries are able to have hidden/default visibility
|
||||
controls on symbols so we should propagate this information in that
|
||||
use case
|
||||
*/
|
||||
# define @EXPORT_MACRO_NAME@_EXPORT_DEFINE
|
||||
# define @EXPORT_MACRO_NAME@_IMPORT_DEFINE
|
||||
# define @EXPORT_MACRO_NAME@_NO_EXPORT_DEFINE
|
||||
# else
|
||||
# define @EXPORT_MACRO_NAME@_EXPORT_DEFINE __declspec(dllexport)
|
||||
# define @EXPORT_MACRO_NAME@_IMPORT_DEFINE __declspec(dllimport)
|
||||
# define @EXPORT_MACRO_NAME@_NO_EXPORT_DEFINE
|
||||
# endif
|
||||
#else
|
||||
# define @EXPORT_MACRO_NAME@_EXPORT_DEFINE __attribute__((visibility("default")))
|
||||
# define @EXPORT_MACRO_NAME@_IMPORT_DEFINE __attribute__((visibility("default")))
|
||||
# define @EXPORT_MACRO_NAME@_NO_EXPORT_DEFINE __attribute__((visibility("hidden")))
|
||||
#endif
|
||||
|
||||
#ifndef @EXPORT_MACRO_NAME@_EXPORT
|
||||
# if defined(@EXPORT_IMPORT_CONDITION@)
|
||||
/* We are building this library */
|
||||
# define @EXPORT_MACRO_NAME@_EXPORT @EXPORT_MACRO_NAME@_EXPORT_DEFINE
|
||||
# else
|
||||
/* We are using this library */
|
||||
# define @EXPORT_MACRO_NAME@_EXPORT @EXPORT_MACRO_NAME@_IMPORT_DEFINE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef @EXPORT_MACRO_NAME@_TEMPLATE_EXPORT
|
||||
# if defined(@EXPORT_IMPORT_CONDITION@) && defined(_MSC_VER)
|
||||
/* Warning C4910 on windows state that extern explicit template can't be
|
||||
labeled with __declspec(dllexport). So that is why we use a new custom
|
||||
define. But when other modules ( e.g. rendering ) include this header
|
||||
we need them to see that the extern template is actually being imported.
|
||||
*/
|
||||
/* We are building this library with MSVC */
|
||||
# define @EXPORT_MACRO_NAME@_TEMPLATE_EXPORT
|
||||
# elif defined(@EXPORT_IMPORT_CONDITION@)
|
||||
/* We are building this library */
|
||||
# define @EXPORT_MACRO_NAME@_TEMPLATE_EXPORT @EXPORT_MACRO_NAME@_EXPORT_DEFINE
|
||||
# else
|
||||
/* We are using this library */
|
||||
# define @EXPORT_MACRO_NAME@_TEMPLATE_EXPORT @EXPORT_MACRO_NAME@_IMPORT_DEFINE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef @EXPORT_MACRO_NAME@_NO_EXPORT
|
||||
#define @EXPORT_MACRO_NAME@_NO_EXPORT @EXPORT_MACRO_NAME@_NO_EXPORT_DEFINE
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -19,7 +19,6 @@
|
||||
##============================================================================
|
||||
|
||||
include(CMakeParseArguments)
|
||||
include(GenerateExportHeader)
|
||||
|
||||
# Utility to build a kit name from the current directory.
|
||||
function(vtkm_get_kit_name kitvar)
|
||||
@ -657,15 +656,28 @@ function(vtkm_library)
|
||||
)
|
||||
endif(VTKm_EXTRA_COMPILER_WARNINGS)
|
||||
|
||||
generate_export_header(${lib_name})
|
||||
#Now generate a header that holds the macros needed to easily export
|
||||
#template classes. This
|
||||
string(TOUPPER ${lib_name} BASE_NAME_UPPER)
|
||||
set(EXPORT_MACRO_NAME "${BASE_NAME_UPPER}")
|
||||
set(EXPORT_IS_BUILT_STATIC false)
|
||||
get_target_property(EXPORT_IMPORT_CONDITION ${lib_name} DEFINE_SYMBOL)
|
||||
if(NOT EXPORT_IMPORT_CONDITION)
|
||||
#If we are building statically set the define symbol
|
||||
set(EXPORT_IS_BUILT_STATIC true)
|
||||
#set EXPORT_IMPORT_CONDITION to what the DEFINE_SYMBOL would be when
|
||||
#building shared
|
||||
set(EXPORT_IMPORT_CONDITION ${lib_name}_EXPORTS)
|
||||
endif()
|
||||
|
||||
#generate_export_header creates the header in CMAKE_CURRENT_BINARY_DIR.
|
||||
#The build expects it in the install directory.
|
||||
file(COPY
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${lib_name}_export.h
|
||||
DESTINATION
|
||||
${CMAKE_BINARY_DIR}/${VTKm_INSTALL_INCLUDE_DIR}/${dir_prefix}
|
||||
)
|
||||
configure_file(
|
||||
${VTKm_SOURCE_DIR}/CMake/VTKmExportHeaderTemplate.h.in
|
||||
${CMAKE_BINARY_DIR}/${VTKm_INSTALL_INCLUDE_DIR}/${dir_prefix}/${lib_name}_export.h
|
||||
@ONLY)
|
||||
|
||||
unset(EXPORT_MACRO_NAME)
|
||||
unset(EXPORT_IMPORT_CONDITION)
|
||||
unset(EXPORT_IS_BUILT_STATIC)
|
||||
|
||||
install(TARGETS ${lib_name}
|
||||
EXPORT ${VTKm_EXPORT_NAME}
|
||||
|
@ -297,6 +297,7 @@ install(
|
||||
${VTKm_SOURCE_DIR}/CMake/VTKmConfigureComponents.cmake
|
||||
${VTKm_SOURCE_DIR}/CMake/VTKmCompilerOptimizations.cmake
|
||||
${VTKm_SOURCE_DIR}/CMake/VTKmDetectCUDAVersion.cu
|
||||
${VTKm_SOURCE_DIR}/CMake/VTKmExportHeaderTemplate.h.in
|
||||
DESTINATION ${VTKm_INSTALL_CMAKE_MODULE_DIR}
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user