Blame README.namespacing

Packit 8dc392
------------------------------------------------
Packit 8dc392
 On the use of namespace in IlmBase and OpenEXR
Packit 8dc392
------------------------------------------------
Packit 8dc392
Packit 8dc392
v2.0 of the code base introduces user configurable namespaces for
Packit 8dc392
component libraries. This addition introduces the ability to deal with 
Packit 8dc392
multiple versions of these libraries loaded at runtime.
Packit 8dc392
An example case:
Packit 8dc392
    Application is built with OpenEXR v1.7, but the required plugin 
Packit 8dc392
    requires functionality from OpenEXR v2.0.
Packit 8dc392
    
Packit 8dc392
    By injecting the version number into the (mangled) symbols, via
Packit 8dc392
    the namespacing mechanism, and changing the soname, via the build
Packit 8dc392
    system, the developer can link his plugin against the v2.0 library
Packit 8dc392
    At run time the dynamic linker can load both the 1.7 and 2.0
Packit 8dc392
    versions of the library since the library soname are different and
Packit 8dc392
    the symbols are different.
Packit 8dc392
    
Packit 8dc392
Packit 8dc392
When building IlmBase or OpenEXR the following configure script options 
Packit 8dc392
are available:
Packit 8dc392
    --enable-namespaceversioning
Packit 8dc392
and
Packit 8dc392
    --enable-customusernamespace
Packit 8dc392
Packit 8dc392
Packit 8dc392
Packit 8dc392
-- Internal Library Namespace
Packit 8dc392
The option, --enable-namespaceversioning, controls the namespace that 
Packit 8dc392
is used in the library. Without an argument (see below) the library 
Packit 8dc392
will be built with a suffix made up of the major and minor versions.
Packit 8dc392
For example, for version 2.0.0, the internal library namespaces will be
Packit 8dc392
Imath_2_0, Iex_2_0, IlmThread_2_0 etc
Packit 8dc392
Packit 8dc392
For additional flexibility and control, this option can take an additional 
Packit 8dc392
argument in which case the internal library namespace will be suffixed 
Packit 8dc392
accordingly. 
Packit 8dc392
For example: 
Packit 8dc392
    ./configure --enable-namespaceversioning=ILM
Packit 8dc392
will result in the namespaces of the type Imath_ILM, Iex_ILM etc.
Packit 8dc392
Packit 8dc392
This can be useful for completely isolating your local build.
Packit 8dc392
Packit 8dc392
Code using the library should continue to use the namespace Imath, or for
Packit 8dc392
greater portability IMATH_NAMESPACE, to refer to objects in libImath. 
Packit 8dc392
In particular, the explicit use of the internal namespace is discouraged.
Packit 8dc392
This ensures that code will continue to compile with customised or future 
Packit 8dc392
versions of the library, which may have a different internal namespace.
Packit 8dc392
Packit 8dc392
Similarily, for other namespaces in the libraries: Iex, IlmThread and IlmImf.
Packit 8dc392
Packit 8dc392
Note that this scheme allows existing code to compile without modifications, 
Packit 8dc392
since the 'old' namespaces Imath, Iex, IlmThread and IlmImf continue to be 
Packit 8dc392
available, albeit in a slightly different form.
Packit 8dc392
This is achieved via the following, in the Imath case: 
Packit 8dc392
    namespace IMATH_INTERNAL_NAMESPACE {}
Packit 8dc392
    namespace IMATH_NAMESPACE 
Packit 8dc392
    {
Packit 8dc392
         using namespace IMATH_INTERNAL_NAMESPACE;
Packit 8dc392
    }
Packit 8dc392
This is included in all header files in the Imath library and similar ones
Packit 8dc392
are present for the libraries Iex, IlmThread and IlmImf.
Packit 8dc392
Packit 8dc392
The only exception to this is where user code has forward declarations of 
Packit 8dc392
objects in the Imf namespace, as these will forward declare symbols in an 
Packit 8dc392
incorrect namespace
Packit 8dc392
These forward declarations should be removed, and replaced with 
Packit 8dc392
    #include <ImfForward.h>, 
Packit 8dc392
which forward-declares all types correctly.
Packit 8dc392
Packit 8dc392
Packit 8dc392
Packit 8dc392
-- Public/User Library Namespace
Packit 8dc392
The option, --enable-customusernamespace, can override the namespace into 
Packit 8dc392
which we will 'export' the internal namespace. This takes an argument 
Packit 8dc392
that sets the name of the custom user namespace.
Packit 8dc392
In the example above, IMATH_NAMESPACE could be resolved into something other
Packit 8dc392
than Imath, say Imath_MySpecialNamespace.
Packit 8dc392
Packit 8dc392
In nearly all cases, this will not be used as per the above discussion
Packit 8dc392
regarding code compatibility.
Packit 8dc392
Its presence is to provide a mechanism for not prohibiting the case when 
Packit 8dc392
the application must pass objects from two different versions of the library.