Skip to content

Commit

Permalink
COMP: Create _TEMPLATE_EXPORT macros.
Browse files Browse the repository at this point in the history
The CMake GenerateExportHeader is extended to provide
<module-name>_TEMPLATE_EXPORT macros. Unlike non-templated class
declarations, Windows must not have export specification to avoid the build
error:

  c:\d\itk-vs14\ITK\Modules\IO\TransformBase\include\itkTransformFileReader.hxx(33):
  error C2491:
  'itk::TransformFileReaderTemplate::TransformFileReaderTemplate': definition
  of dllimport function not allowed
  [C:\d\itk-vs14\ITK-build\Modules\IO\TransformBase\ITKIOTransformBaseHeaderTest1.vcxproj]

For itk::TransformFileWriterTemplate, GCC must have the export specification to avoid link errors like:

  itkTransformFileWriterTest.cxx:(.text+0x13): undefined reference to
  `typeinfo for itk::TransformFileWriterTemplate'

This macro is for templates with explicit instantiations built into a library.

Related to ITK-3393.

Change-Id: Ifecb23235f18811218ceb6b304c245c2e209ab1a
  • Loading branch information
thewtex committed Dec 21, 2015
1 parent ae27bc5 commit d9633b7
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 10 deletions.
21 changes: 17 additions & 4 deletions CMake/GenerateExportHeader.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# GENERATE_EXPORT_HEADER( LIBRARY_TARGET
# [BASE_NAME <base_name>]
# [EXPORT_MACRO_NAME <export_macro_name>]
# [TEMPLATE_EXPORT_MACRO_NAME <template_export_macro_name>]
# [EXPORT_FILE_NAME <export_file_name>]
# [DEPRECATED_MACRO_NAME <deprecated_macro_name>]
# [NO_EXPORT_MACRO_NAME <no_export_macro_name>]
Expand Down Expand Up @@ -59,9 +60,10 @@
#
# The CMake fragment will generate a file in the
# ``${CMAKE_CURRENT_BINARY_DIR}`` called ``somelib_export.h`` containing the
# macros ``SOMELIB_EXPORT``, ``SOMELIB_NO_EXPORT``, ``SOMELIB_DEPRECATED``,
# ``SOMELIB_DEPRECATED_EXPORT`` and ``SOMELIB_DEPRECATED_NO_EXPORT``. The
# resulting file should be installed with other headers in the library.
# macros ``SOMELIB_EXPORT``, ``SOMELIB_TEMPLATE_EXPORT``, ``SOMELIB_NO_EXPORT``,
# ``SOMELIB_DEPRECATED``, ``SOMELIB_DEPRECATED_EXPORT`` and
# ``SOMELIB_DEPRECATED_NO_EXPORT``.
# The resulting file should be installed with other headers in the library.
#
# The ``BASE_NAME`` argument can be used to override the file name and the
# names used for the macros:
Expand Down Expand Up @@ -257,6 +259,8 @@ macro(_DO_SET_MACRO_VALUES TARGET_LIBRARY)
set(DEFINE_DEPRECATED)
set(DEFINE_EXPORT)
set(DEFINE_IMPORT)
set(DEFINE_TEMPLATE_EXPORT)
set(DEFINE_TEMPLATE_IMPORT)
set(DEFINE_NO_EXPORT)

if (COMPILER_HAS_DEPRECATED_ATTR)
Expand All @@ -271,9 +275,13 @@ macro(_DO_SET_MACRO_VALUES TARGET_LIBRARY)
if(WIN32 OR CYGWIN)
set(DEFINE_EXPORT "__declspec(dllexport)")
set(DEFINE_IMPORT "__declspec(dllimport)")
set(DEFINE_TEMPLATE_EXPORT)
set(DEFINE_TEMPLATE_IMPORT)
elseif(COMPILER_HAS_HIDDEN_VISIBILITY AND USE_COMPILER_HIDDEN_VISIBILITY)
set(DEFINE_EXPORT "__attribute__((visibility(\"default\")))")
set(DEFINE_IMPORT "__attribute__((visibility(\"default\")))")
set(DEFINE_TEMPLATE_EXPORT "${DEFINE_EXPORT}")
set(DEFINE_TEMPLATE_IMPORT "${DEFINE_IMPORT}")
set(DEFINE_NO_EXPORT "__attribute__((visibility(\"hidden\")))")
endif()
endif()
Expand All @@ -282,7 +290,8 @@ endmacro()
macro(_DO_GENERATE_EXPORT_HEADER TARGET_LIBRARY)
# Option overrides
set(options DEFINE_NO_DEPRECATED)
set(oneValueArgs PREFIX_NAME BASE_NAME EXPORT_MACRO_NAME EXPORT_FILE_NAME
set(oneValueArgs PREFIX_NAME BASE_NAME EXPORT_MACRO_NAME
TEMPLATE_EXPORT_MACRO_NAME EXPORT_FILE_NAME
DEPRECATED_MACRO_NAME NO_EXPORT_MACRO_NAME STATIC_DEFINE
NO_DEPRECATED_MACRO_NAME)
set(multiValueArgs)
Expand All @@ -301,6 +310,7 @@ macro(_DO_GENERATE_EXPORT_HEADER TARGET_LIBRARY)

# Default options
set(EXPORT_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_EXPORT")
set(TEMPLATE_EXPORT_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_TEMPLATE_EXPORT")
set(NO_EXPORT_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_NO_EXPORT")
set(EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${BASE_NAME_LOWER}_export.h")
set(DEPRECATED_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_DEPRECATED")
Expand All @@ -315,6 +325,9 @@ macro(_DO_GENERATE_EXPORT_HEADER TARGET_LIBRARY)
if(_GEH_EXPORT_MACRO_NAME)
set(EXPORT_MACRO_NAME ${_GEH_PREFIX_NAME}${_GEH_EXPORT_MACRO_NAME})
endif()
if(_GEH_TEMPLATE_EXPORT_MACRO_NAME)
set(TEMPLATE_EXPORT_MACRO_NAME ${_GEH_PREFIX_NAME}${_GEH_TEMPLATE_EXPORT_MACRO_NAME})
endif()
string(MAKE_C_IDENTIFIER ${EXPORT_MACRO_NAME} EXPORT_MACRO_NAME)
if(_GEH_EXPORT_FILE_NAME)
if(IS_ABSOLUTE ${_GEH_EXPORT_FILE_NAME})
Expand Down
1 change: 1 addition & 0 deletions CMake/ITKModuleMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ macro(itk_module_impl)
generate_export_header(${itk-module}
EXPORT_FILE_NAME ${_export_header_file}
EXPORT_MACRO_NAME ${itk-module}_EXPORT
TEMPLATE_EXPORT_MACRO_NAME ${itk-module}_TEMPLATE_EXPORT
NO_EXPORT_MACRO_NAME ${itk-module}_HIDDEN
STATIC_DEFINE ITK_STATIC )
install(FILES
Expand Down
11 changes: 11 additions & 0 deletions CMake/exportheader.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#ifdef @STATIC_DEFINE@
# define @EXPORT_MACRO_NAME@
# define @TEMPLATE_EXPORT_MACRO_NAME@
# define @NO_EXPORT_MACRO_NAME@
#else
# ifndef @EXPORT_MACRO_NAME@
Expand All @@ -16,6 +17,16 @@
# endif
# endif

# ifndef @TEMPLATE_EXPORT_MACRO_NAME@
# ifdef @EXPORT_IMPORT_CONDITION@
/* We are building this library */
# define @TEMPLATE_EXPORT_MACRO_NAME@ @DEFINE_TEMPLATE_EXPORT@
# else
/* We are using this library */
# define @TEMPLATE_EXPORT_MACRO_NAME@ @DEFINE_TEMPLATE_IMPORT@
# endif
# endif

# ifndef @NO_EXPORT_MACRO_NAME@
# define @NO_EXPORT_MACRO_NAME@ @DEFINE_NO_EXPORT@
# endif
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkMetaDataObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace itk
* \ingroup ITKCommon
*/
template< typename MetaDataObjectType >
class MetaDataObject:public MetaDataObjectBase
class ITKCommon_TEMPLATE_EXPORT MetaDataObject:public MetaDataObjectBase
{
public:
/** Smart pointer typedef support. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace itk
* \ingroup ITKIOTransformBase
*/
template<typename TParametersValueType>
class CompositeTransformIOHelperTemplate
class ITKIOTransformBase_TEMPLATE_EXPORT CompositeTransformIOHelperTemplate
{
public:
typedef typename TransformIOBaseTemplate<TParametersValueType>::TransformType TransformType;
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/TransformBase/include/itkTransformFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace itk
* \endwiki
*/
template<typename TParametersValueType>
class ITKIOTransformBase_EXPORT TransformFileReaderTemplate: public LightProcessObject
class ITKIOTransformBase_TEMPLATE_EXPORT TransformFileReaderTemplate: public LightProcessObject
{
public:

Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/TransformBase/include/itkTransformFileWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace itk
* \endwiki
*/
template<typename TParametersValueType>
class ITKIOTransformBase_EXPORT TransformFileWriterTemplate:public LightProcessObject
class ITKIOTransformBase_TEMPLATE_EXPORT TransformFileWriterTemplate:public LightProcessObject
{
public:

Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/TransformBase/include/itkTransformIOFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef enum { ReadMode, WriteMode } TransformIOFactoryFileModeType;
* \ingroup ITKIOTransformBase
*/
template<typename TParametersValueType>
class TransformIOFactoryTemplate:public Object
class ITKIOTransformBase_TEMPLATE_EXPORT TransformIOFactoryTemplate:public Object
{
public:
/** Standard class typedefs. */
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/TransformHDF5/include/itkHDF5TransformIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct ITKIOTransformHDF5_EXPORT HDF5CommonPathNames
* \ingroup ITKIOTransformHDF5
*/
template<typename TParametersValueType>
class HDF5TransformIOTemplate:public TransformIOBaseTemplate<TParametersValueType>,
class ITKIOTransformBase_TEMPLATE_EXPORT HDF5TransformIOTemplate:public TransformIOBaseTemplate<TParametersValueType>,
private HDF5CommonPathNames
{
public:
Expand Down

0 comments on commit d9633b7

Please sign in to comment.