Difference between revisions of "Proposals:Making MetaIO a configurable namespace"

From KitwarePublic
Jump to navigationJump to search
 
Line 15: Line 15:


=== Implementation ===
=== Implementation ===
1. Goto ftp://www.itk.org/pub/itk/UsersITK/metaio
1. Download MetaIO.tar.gz and metaio.patch from ftp://www.itk.org/pub/itk/UsersITK/metaio
2. Download MetaIO.tar.gz and metaio.patch
 
3. cd Insight/ && patch -p0 < /tmp/metaio.patch && cd Utilities/ && rm -rf MetaIO && tar xvzf /tmp/MetaIO.tar.gz
2. cd Insight/ && patch -p0 < /tmp/metaio.patch && cd Utilities/ && rm -rf MetaIO && tar xvzf /tmp/MetaIO.tar.gz
4. Configure, build as usual with CMake and you should be good to go.
 
3. Configure, build as usual with CMake and you should be good to go.


The configurable namespace stuff has just been added to VTK (in a branch) and will most likely move to the HEAD soon.
The configurable namespace stuff has just been added to VTK (in a branch) and will most likely move to the HEAD soon.

Revision as of 02:41, 20 March 2006

Motive

MetaIO is a library that is intended used by multiple projects. Stephen recently added it to a branch in VTK. Since it is shared by multiple projects (TIK and VTK here) function definitions will collide in projects that use both ITK and VTK.

Solution

Use a configurable namespace like KWsys (shared in ITK as itksys, vtksys, cmsys). The idea is that each project using MetaIO configures the MetaIO library namespace at compile time. The point is to share the same source tree for MetaIO in both ITK and VTK.

The CMake API to configure the namespace is simple. CMakeLists.txt provides the following options:

- USE_NAMESPACE_FOR_METAIO  (default off in ITK, on in VTK)
- METAIO_NAMESPACE = "itkmetaio" 
- METAIO_LIBRARY = "ITKMetaIO" # name of the library that will be built, defaults to the namespace name
- METAIO_BUILD_SHARED_LIBS = OFF/ON; Shared / static libs ?    

It is worth mentioning that the third option is redundant in ITK, which does not build any of the Utilities/ as shared libraries. The only shared library built is ITKCommon. In VTK, the Utilities are built as shared or static libraries depending on the BUILD_SHARED_LIBS flag.

Implementation

1. Download MetaIO.tar.gz and metaio.patch from ftp://www.itk.org/pub/itk/UsersITK/metaio

2. cd Insight/ && patch -p0 < /tmp/metaio.patch && cd Utilities/ && rm -rf MetaIO && tar xvzf /tmp/MetaIO.tar.gz

3. Configure, build as usual with CMake and you should be good to go.

The configurable namespace stuff has just been added to VTK (in a branch) and will most likely move to the HEAD soon.

Backward compatibility issues

Good news. Everything is 100% backward compatible.

Read on only if you are a user of the metaIO library (the internals). MetaIO traditionally never had a namespace. A namespace has just been added and the default in ITK is to open the namespace using namespace itkmetaio; and in VTK, the default is not to do so. This has been done to maintain backward compatibility in ITK. This can be controlled by a CMake option in both ITK and VTK: USE_NAMESPACE_FOR_METAIO

Nevertheless, when you write code, you are encouraged to use the following convention,

 #include "itkmetaio/metaImage.h"
 ...
 itkmetaio::MetaImage myMetaImage;

instead of

 #include "metaImage.h"
 ...
 MetaImage myMetaImage;

although both would work. The point being that if you did write code in VTK, your code would use the former convention.