Skip to content

Commit

Permalink
Merge topic 'ImageIOSharedLibraries'
Browse files Browse the repository at this point in the history
e55e67b ENH: Enabling shared IO modules on windows
6d369e1 ENH: Add option ENABLED_SHARED to itk_module for shared libraries
  • Loading branch information
blowekamp authored and kwrobot committed Jul 24, 2013
2 parents 5c1c986 + e55e67b commit e4b526a
Show file tree
Hide file tree
Showing 112 changed files with 258 additions and 154 deletions.
23 changes: 23 additions & 0 deletions CMake/ITKModuleMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ include(${_ITKModuleMacros_DIR}/ITKModuleAPI.cmake)
include(${_ITKModuleMacros_DIR}/ITKModuleDoxygen.cmake)
include(${_ITKModuleMacros_DIR}/ITKModuleHeaderTest.cmake)

include(GenerateExportHeader)

if(ITK_CPPCHECK_TEST)
include(${_ITKModuleMacros_DIR}/ITKModuleCPPCheckTest.cmake)
endif()
Expand All @@ -21,12 +23,16 @@ macro(itk_module _name)
set(ITK_MODULE_${itk-module-test}_DEPENDS "${itk-module}")
set(ITK_MODULE_${itk-module}_DESCRIPTION "description")
set(ITK_MODULE_${itk-module}_EXCLUDE_FROM_ALL 0)
set(ITK_MODULE_${itk-module}_ENABLE_SHARED 0)
foreach(arg ${ARGN})
if("${arg}" MATCHES "^(DEPENDS|TEST_DEPENDS|DESCRIPTION|DEFAULT)$")
set(_doing "${arg}")
elseif("${arg}" MATCHES "^EXCLUDE_FROM_ALL$")
set(_doing "")
set(ITK_MODULE_${itk-module}_EXCLUDE_FROM_ALL 1)
elseif("${arg}" MATCHES "^ENABLE_SHARED$")
set(_doing "")
set(ITK_MODULE_${itk-module}_ENABLE_SHARED 1)
elseif("${arg}" MATCHES "^[A-Z][A-Z][A-Z]$")
set(_doing "")
message(AUTHOR_WARNING "Unknown argument [${arg}]")
Expand Down Expand Up @@ -128,6 +134,23 @@ macro(itk_module_impl)
add_subdirectory(src)
endif()


if( ITK_MODULE_${itk-module}_ENABLE_SHARED )
# Generate the export macro header for symbol visibility/Windows DLL declspec
generate_export_header(${itk-module}
EXPORT_FILE_NAME ${ITKCommon_BINARY_DIR}/${itk-module}Export.h
EXPORT_MACRO_NAME ${itk-module}_EXPORT
NO_EXPORT_MACRO_NAME ${itk-module}_HIDDEN
STATIC_DEFINE ITK_STATIC )
if (BUILD_SHARED_LIBS)
# export flags are only added when building shared libs, they cause
# mismatched visibility warnings when building statically.
add_compiler_export_flags(my_abi_flags)
set_property(TARGET ${itk-module} APPEND
PROPERTY COMPILE_FLAGS "${my_abi_flags}")
endif()
endif()

set(itk-module-EXPORT_CODE-build "${${itk-module}_EXPORT_CODE_BUILD}")
set(itk-module-EXPORT_CODE-install "${${itk-module}_EXPORT_CODE_INSTALL}")

Expand Down
35 changes: 24 additions & 11 deletions CMake/UseITK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ITK_REQUIRED_LINK_FLAGS}
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ITK_REQUIRED_LINK_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${ITK_REQUIRED_LINK_FLAGS}")


# Add include directories needed to use ITK.
include_directories(BEFORE ${ITK_INCLUDE_DIRS})

# Add link directories needed to use ITK.
link_directories(${ITK_LIBRARY_DIRS})

macro(ADD_FACTORY_REGISTRATION _registration_list_var _names_list_var _module_name _factory_name)
if(${_module_name}_LOADED)
# note: this is an internal CMake variable and should not be used outside ITK
set(_abi)
if(ITK_MODULE_${_module_name}_ENABLE_SHARED)
set(_abi "ITK_ABI_IMPORT")
endif()
set(${_registration_list_var}
"${${_registration_list_var}}void ${_abi} ${_factory_name}FactoryRegister__Private(void);")
set(${_names_list_var} "${${_names_list_var}}${_factory_name}FactoryRegister__Private,")
endif()
endmacro()

if(NOT ITK_NO_IO_FACTORY_REGISTER_MANAGER)
#
# Infrastructure for registering automatically the factories of commonly used IO formats
Expand All @@ -27,19 +41,14 @@ if(NOT ITK_NO_IO_FACTORY_REGISTER_MANAGER)

foreach (ImageFormat Nifti Nrrd Gipl HDF5 JPEG GDCM BMP LSM PNG TIFF VTK Stimulate BioRad Meta MINC SCIFIO MGH )
string(TOUPPER ${ImageFormat} ImageFormat_UPPER) ## Need to check for uppercase name as well
if (ITKIO${ImageFormat}_LOADED OR ITKIO${ImageFormat_UPPER}_LOADED)
set (LIST_OF_FACTORIES_REGISTRATION "${LIST_OF_FACTORIES_REGISTRATION}void ${ImageFormat}ImageIOFactoryRegister__Private(void);")
set (LIST_OF_FACTORY_NAMES "${LIST_OF_FACTORY_NAMES}${ImageFormat}ImageIOFactoryRegister__Private,")
ADD_FACTORY_REGISTRATION("LIST_OF_FACTORIES_REGISTRATION" "LIST_OF_FACTORY_NAMES" ITKIO${ImageFormat} ${ImageFormat}ImageIO)
if(NOT "${ImageFormat}" STREQUAL "${ImageFormat_UPPER}")
ADD_FACTORY_REGISTRATION("LIST_OF_FACTORIES_REGISTRATION" "LIST_OF_FACTORY_NAMES" ITKIO${ImageFormat_UPPER} ${ImageFormat}ImageIO)
endif()
endforeach()

# add ImageIOs in review to the automatic registration
if (ITK_USE_REVIEW)
foreach (ImageFormat MRC)
set (LIST_OF_FACTORIES_REGISTRATION "${LIST_OF_FACTORIES_REGISTRATION}void ${ImageFormat}ImageIOFactoryRegister__Private(void);")
set (LIST_OF_FACTORY_NAMES "${LIST_OF_FACTORY_NAMES}${ImageFormat}ImageIOFactoryRegister__Private,")
endforeach()
endif()
ADD_FACTORY_REGISTRATION("LIST_OF_FACTORIES_REGISTRATION" "LIST_OF_FACTORY_NAMES" ITKReview MRCImageIO)

get_filename_component(_selfdir "${CMAKE_CURRENT_LIST_FILE}" PATH)
configure_file(${_selfdir}/itkImageIOFactoryRegisterManager.h.in
Expand All @@ -52,9 +61,13 @@ if(NOT ITK_NO_IO_FACTORY_REGISTER_MANAGER)
set(LIST_OF_FACTORY_NAMES "")

foreach (TransformFormat Matlab Txt HDF5)
set (LIST_OF_FACTORIES_REGISTRATION "${LIST_OF_FACTORIES_REGISTRATION}void ${TransformFormat}TransformIOFactoryRegister__Private(void);")
set (LIST_OF_FACTORY_NAMES "${LIST_OF_FACTORY_NAMES}${TransformFormat}TransformIOFactoryRegister__Private,")
ADD_FACTORY_REGISTRATION("LIST_OF_FACTORIES_REGISTRATION" "LIST_OF_FACTORY_NAMES"
ITKIOTransform${TransformFormat} ${TransformFormat}TransformIO)
endforeach()
ADD_FACTORY_REGISTRATION("LIST_OF_FACTORIES_REGISTRATION" "LIST_OF_FACTORY_NAMES"
ITKIOMINC MINCTransformIO)
ADD_FACTORY_REGISTRATION("LIST_OF_FACTORIES_REGISTRATION" "LIST_OF_FACTORY_NAMES"
ITKIOTransformInsightLegacy TxtTransformIO)

get_filename_component(_selfdir "${CMAKE_CURRENT_LIST_FILE}" PATH)
configure_file(${_selfdir}/itkTransformIOFactoryRegisterManager.h.in
Expand Down
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
cmake_minimum_required(VERSION 2.8.6 FATAL_ERROR)
include(CMakeDependentOption)
#
# use ExternalProject
include(ExternalProject)

if(WIN32)
cmake_minimum_required(VERSION 2.8.8)
elseif(NOT EXISTS /dev/urandom)
cmake_minimum_required(VERSION 2.8.5)
endif()

project(ITK)
Expand Down
24 changes: 3 additions & 21 deletions Modules/Core/Common/include/itkMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include "itkWin32Header.h"
#include "itkConfigure.h"
#include "ITKCommonExport.h"

#include <typeinfo>

Expand Down Expand Up @@ -101,6 +102,7 @@ namespace itk
#endif

// Setup symbol exports
// begin legacy
#if defined( _WIN32 ) || defined ( WIN32 )
#define ITK_ABI_IMPORT __declspec(dllimport)
#define ITK_ABI_EXPORT __declspec(dllexport)
Expand All @@ -116,27 +118,7 @@ namespace itk
#define ITK_ABI_HIDDEN
#endif
#endif

#define ITKCommon_HIDDEN ITK_ABI_HIDDEN

#if !defined( ITKSTATIC )
/* CMake adds "MyLibrary_EXPORTS" definition for MSVC platforms
* when building a DLL */
#ifdef ITKCommon_EXPORTS
#define ITKCommon_EXPORT ITK_ABI_EXPORT
#else
#define ITKCommon_EXPORT ITK_ABI_IMPORT
#endif /* ITKCommon_EXPORTS */
#else
/* ITKCommon is build as a static lib */
#if __GNUC__ >= 4
// Don't hide symbols in the static ITKCommon library in case
// -fvisibility=hidden is used
#define ITKCommon_EXPORT ITK_ABI_EXPORT
#else
#define ITKCommon_EXPORT
#endif
#endif
// end legacy

/** Define two object creation methods. The first method, New(),
* creates an object from a class, potentially deferring to a factory.
Expand Down
1 change: 1 addition & 0 deletions Modules/Core/Common/itk-module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ platform specific features. It is anticipated that most other ITK modules will
depend on this one.")

itk_module(ITKCommon
ENABLE_SHARED
DEPENDS
ITKVNLInstantiation
ITKKWSys
Expand Down
9 changes: 0 additions & 9 deletions Modules/Core/Common/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ endif()

### generating libraries
add_library( ITKCommon ${ITK_LIBRARY_BUILD_TYPE} ${ITKCommon_SRCS})
if(NOT WIN32 AND CMAKE_COMPILER_IS_GNUCXX AND BUILD_SHARED_LIBS)
set(ITKCommon_CXX_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")
ITK_CHECK_CXX_COMPILER_FLAG(${ITKCommon_CXX_FLAGS} ITKCommon_HAS_GCC_VISIBILITY_FLAGS)
if(ITKCommon_HAS_GCC_VISIBILITY_FLAGS)
set_target_properties(ITKCommon PROPERTIES
COMPILE_FLAGS "${ITKCommon_CXX_FLAGS}"
)
endif()
endif()

target_link_libraries(ITKCommon
itksys
Expand Down
3 changes: 2 additions & 1 deletion Modules/IO/BMP/include/itkBMPImageIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*=========================================================================*/
#ifndef __itkBMPImageIO_h
#define __itkBMPImageIO_h
#include "ITKIOBMPExport.h"


#include <fstream>
Expand All @@ -34,7 +35,7 @@ namespace itk
*
* \ingroup ITKIOBMP
*/
class BMPImageIO:public ImageIOBase
class ITKIOBMP_EXPORT BMPImageIO:public ImageIOBase
{
public:
/** Standard class typedefs. */
Expand Down
3 changes: 2 additions & 1 deletion Modules/IO/BMP/include/itkBMPImageIOFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*=========================================================================*/
#ifndef __itkBMPImageIOFactory_h
#define __itkBMPImageIOFactory_h
#include "ITKIOBMPExport.h"

#include "itkObjectFactoryBase.h"
#include "itkImageIOBase.h"
Expand All @@ -27,7 +28,7 @@ namespace itk
* \brief Create instances of BMPImageIO objects using an object factory.
* \ingroup ITKIOBMP
*/
class BMPImageIOFactory:public ObjectFactoryBase
class ITKIOBMP_EXPORT BMPImageIOFactory:public ObjectFactoryBase
{
public:
/** Standard class typedefs. */
Expand Down
1 change: 1 addition & 0 deletions Modules/IO/BMP/itk-module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(DOCUMENTATION "This module contains ImageIO classes for reading the
Microsoft Bitmap File Format (BMP).")

itk_module(ITKIOBMP
ENABLE_SHARED
DEPENDS
ITKIOImageBase
TEST_DEPENDS
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/BMP/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ itkBMPImageIO.cxx
itkBMPImageIOFactory.cxx
)

add_library(ITKIOBMP ${ITKIOBMP_SRC})
add_library(ITKIOBMP ${ITK_LIBRARY_BUILD_TYPE} ${ITKIOBMP_SRC})
target_link_libraries(ITKIOBMP ${ITKIOImageBase_LIBRARIES})
itk_module_target(ITKIOBMP)
2 changes: 1 addition & 1 deletion Modules/IO/BMP/src/itkBMPImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ BMPImageIOFactory::GetDescription() const

static bool BMPImageIOFactoryHasBeenRegistered;

void BMPImageIOFactoryRegister__Private(void)
void ITKIOBMP_EXPORT BMPImageIOFactoryRegister__Private(void)
{
if( ! BMPImageIOFactoryHasBeenRegistered )
{
Expand Down
3 changes: 2 additions & 1 deletion Modules/IO/BioRad/include/itkBioRadImageIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*=========================================================================*/
#ifndef __itkBioRadImageIO_h
#define __itkBioRadImageIO_h
#include "ITKIOBioRadExport.h"

#include "itkImageIOBase.h"
#include <fstream>
Expand All @@ -46,7 +47,7 @@ namespace itk
*
* \ingroup ITKIOBioRad
*/
class BioRadImageIO:public ImageIOBase
class ITKIOBioRad_EXPORT BioRadImageIO:public ImageIOBase
{
public:
/** Standard class typedefs. */
Expand Down
3 changes: 2 additions & 1 deletion Modules/IO/BioRad/include/itkBioRadImageIOFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*=========================================================================*/
#ifndef __itkBioRadImageIOFactory_h
#define __itkBioRadImageIOFactory_h
#include "ITKIOBioRadExport.h"

#include "itkObjectFactoryBase.h"
#include "itkImageIOBase.h"
Expand All @@ -37,7 +38,7 @@ namespace itk
* \brief Create instances of BioRadImageIO objects using an object factory.
* \ingroup ITKIOBioRad
*/
class BioRadImageIOFactory:public ObjectFactoryBase
class ITKIOBioRad_EXPORT BioRadImageIOFactory:public ObjectFactoryBase
{
public:
/** Standard class typedefs. */
Expand Down
1 change: 1 addition & 0 deletions Modules/IO/BioRad/itk-module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ href=\"http://www.bio-rad.com/\">Bio-Rad images.</a> The Bio-Rad file format is
used by confocal microscopes like MRC 1024 and MRC 600.")

itk_module(ITKIOBioRad
ENABLE_SHARED
DEPENDS
ITKIOImageBase
TEST_DEPENDS
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/BioRad/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ itkBioRadImageIOFactory.cxx
itkBioRadImageIO.cxx
)

add_library(ITKIOBioRad ${ITKIOBioRad_SRC})
add_library(ITKIOBioRad ${ITK_LIBRARY_BUILD_TYPE} ${ITKIOBioRad_SRC})
target_link_libraries(ITKIOBioRad ${ITKIOImageBase_LIBRARIES})
itk_module_target(ITKIOBioRad)
2 changes: 1 addition & 1 deletion Modules/IO/BioRad/src/itkBioRadImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ BioRadImageIOFactory::GetDescription() const

static bool BioRadImageIOFactoryHasBeenRegistered;

void BioRadImageIOFactoryRegister__Private(void)
void ITKIOBioRad_EXPORT BioRadImageIOFactoryRegister__Private(void)
{
if( ! BioRadImageIOFactoryHasBeenRegistered )
{
Expand Down
1 change: 1 addition & 0 deletions Modules/IO/GE/include/Ge4xHdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

#ifndef __Ge4xHdr_h
#define __Ge4xHdr_h
#include "ITKIOGEExport.h"

enum GE_4X_STUDYHDR_OFFSET
{
Expand Down
1 change: 1 addition & 0 deletions Modules/IO/GE/include/Ge5xHdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

#ifndef __Ge5xHdr_h
#define __Ge5xHdr_h
#include "ITKIOGEExport.h"

#define GE_5X_MAGIC_NUMBER 0x494d4746

Expand Down
3 changes: 2 additions & 1 deletion Modules/IO/GE/include/itkGE4ImageIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#ifndef __itkGE4ImageIO_h
#define __itkGE4ImageIO_h
#include "ITKIOGEExport.h"

#include "itkIPLCommonImageIO.h"

Expand All @@ -54,7 +55,7 @@ namespace itk
* \ingroup IOFilters
* \ingroup ITKIOGE
*/
class GE4ImageIO:public IPLCommonImageIO
class ITKIOGE_EXPORT GE4ImageIO:public IPLCommonImageIO
{
public:
/** Standard class typedefs. */
Expand Down
3 changes: 2 additions & 1 deletion Modules/IO/GE/include/itkGE4ImageIOFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*=========================================================================*/
#ifndef __itkGE4ImageIOFactory_h
#define __itkGE4ImageIOFactory_h
#include "ITKIOGEExport.h"


#include "itkObjectFactoryBase.h"
Expand All @@ -28,7 +29,7 @@ namespace itk
* \brief Create instances of GE4ImageIO objects using an object factory.
* \ingroup ITKIOGE
*/
class GE4ImageIOFactory:public ObjectFactoryBase
class ITKIOGE_EXPORT GE4ImageIOFactory:public ObjectFactoryBase
{
public:
/** Standard class typedefs. */
Expand Down
3 changes: 2 additions & 1 deletion Modules/IO/GE/include/itkGE5ImageIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#ifndef __itkGE5ImageIO_h
#define __itkGE5ImageIO_h
#include "ITKIOGEExport.h"


#include "itkIPLCommonImageIO.h"
Expand All @@ -47,7 +48,7 @@ namespace itk
*
* \ingroup ITKIOGE
*/
class GE5ImageIO:public IPLCommonImageIO
class ITKIOGE_EXPORT GE5ImageIO:public IPLCommonImageIO
{
public:
/** Standard class typedefs. */
Expand Down

0 comments on commit e4b526a

Please sign in to comment.