Skip to content

Commit

Permalink
COMP: Add support for customizing ITK namespace (draft)
Browse files Browse the repository at this point in the history
This commit introduces itkNamespace.h header providing the logic for
redefining "itk" only if a custom namespace has been provided. This ensures
that the default behavior remains unchanged.

To minimize the number of files to update, the itkNamespace.h may be included
through three mechanisms:

(1) Through itkConfigure.h
    => included either directly or indirectly by most files

(2) Through Export header
    => support case of header like "itkFEMSolution.h" only including the export header

(3) Through exlpicit include
    => support case of header without any includes (e.g "itkMakeFilled.h")
  • Loading branch information
jcfr authored and dzenanz committed May 30, 2024
1 parent 311b706 commit aacaefd
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CMake/ITKModuleMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ macro(itk_module_impl)
set(_export_header_file "${${itk-module}_BINARY_DIR}/include/${itk-module}Export.h")
endif()

set(_export_custom_content [=[#include "itkNamespace.h"]=])

# Generate the export macro header for symbol visibility/Windows DLL declspec
generate_export_header(
${itk-module}
Expand All @@ -236,7 +238,9 @@ macro(itk_module_impl)
NO_EXPORT_MACRO_NAME
${itk-module}_HIDDEN
STATIC_DEFINE
ITK_STATIC)
ITK_STATIC
CUSTOM_CONTENT_FROM_VARIABLE
_export_custom_content)
install(
FILES ${_export_header_file}
DESTINATION ${${itk-module}_INSTALL_INCLUDE_DIR}
Expand Down
2 changes: 2 additions & 0 deletions Modules/Core/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ set(ITK_USE_TBB ${Module_ITKTBB})

configure_file(src/itkConfigure.h.in itkConfigure.h)
configure_file(src/itkConfigurePrivate.h.in itkConfigurePrivate.h)
configure_file(src/itkNamespace.h.in itkNamespace.h)

set(ITKCommon_INCLUDE_DIRS ${ITKCommon_BINARY_DIR})
set(ITKCommon_LIBRARIES ITKCommon)
Expand All @@ -137,5 +138,6 @@ itk_module_impl()

install(
FILES ${ITKCommon_BINARY_DIR}/itkConfigure.h
${ITKCommon_BINARY_DIR}/itkNamespace.h
DESTINATION ${ITKCommon_INSTALL_INCLUDE_DIR}
COMPONENT Development)
2 changes: 2 additions & 0 deletions Modules/Core/Common/include/itkBitCast.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef itkBitCast_h
#define itkBitCast_h

#include "itkNamespace.h"

#include <cstring> // For memcpy.
#include <type_traits> // For is_trivially_copyable and remove_const_t.

Expand Down
2 changes: 2 additions & 0 deletions Modules/Core/Common/include/itkBoolean.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef itkBoolean_h
#define itkBoolean_h

#include "itkNamespace.h"

namespace itk
{

Expand Down
2 changes: 2 additions & 0 deletions Modules/Core/Common/include/itkMakeFilled.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef itkMakeFilled_h
#define itkMakeFilled_h

#include "itkNamespace.h"

namespace itk
{
/** Yields a container of the specified type, filled by the specified value, assigned to each of its elements.
Expand Down
2 changes: 2 additions & 0 deletions Modules/Core/Common/include/itkMakeUniqueForOverwrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <memory> // For unique_ptr.
#include <type_traits> // For remove_extent_t, false_type, etc.

#include "itkNamespace.h"

namespace itk
{

Expand Down
2 changes: 2 additions & 0 deletions Modules/Core/Common/include/itkPrintHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
# undef ITK_CASTXML_GCC_VECTOR_WORKAROUND
#endif

#include "itkNamespace.h"

namespace itk
{

Expand Down
2 changes: 2 additions & 0 deletions Modules/Core/Common/src/itkConfigure.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef itkConfigure_h
#define itkConfigure_h

#include "itkNamespace.h"

/*
* here is where system computed values get stored these values should only
* change when the target compile platform changes
Expand Down
28 changes: 28 additions & 0 deletions Modules/Core/Common/src/itkNamespace.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkNamespace_h
#define itkNamespace_h

#define ITK_NAMESPACE_IS_NOT_ITK
#define ITK_NAMESPACE slicer_itk

#if defined(ITK_NAMESPACE_IS_NOT_ITK) && !defined(itk)
#define itk ITK_NAMESPACE
#endif

#endif //itkNamespace_h
2 changes: 2 additions & 0 deletions Modules/Core/Common/test/itkRangeGTestUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <utility> // For move.
#include <iterator> // For begin and end.

#include "itkNamespace.h"

namespace itk
{
// Utilities for GoogleTest unit tests of iterator ranges.
Expand Down
2 changes: 2 additions & 0 deletions Modules/Core/QuadEdgeMesh/include/itkQuadEdgeMeshMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef itkQuadEdgeMeshMacro_h
#define itkQuadEdgeMeshMacro_h

#include "itkNamespace.h"

namespace itk
{
//////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions Modules/Core/SpatialObjects/include/itkSpatialObjectExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
# define ITKSpatialObjectExport
#endif

#include "itkNamespace.h"

#endif
2 changes: 2 additions & 0 deletions Modules/Filtering/FastMarching/include/itkNodePair.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <utility>

#include "itkNamespace.h"

namespace itk
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef itkLabelObjectLineComparator_h
#define itkLabelObjectLineComparator_h

#include "itkNamespace.h"

namespace itk
{
namespace Functor
Expand Down
2 changes: 2 additions & 0 deletions Modules/IO/MRC/src/itkMRCImageIOPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <utility>

#include "itkNamespace.h"

/*
* This code was contributed in the Insight Journal paper:
* "A Streaming IO Base Class and Support for Streaming the MRC and VTK File Format"
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/Expat/src/expat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ CONFIGURE_FILE(${ITK3P_EXPAT_SOURCE_DIR}/expatDllConfig.h.in

configure_file(expat_config.h.cmake "${ITK3P_EXPAT_BINARY_DIR}/expat_config.h")

set(MANGLE_PREFIX itk_expat)
set(MANGLE_PREFIX slicer_itk)
configure_file(itk_expat_mangle.h.in
"${ITK3P_EXPAT_BINARY_DIR}/itk_expat_mangle.h"
@ONLY)
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/HDF5/src/itkhdf5/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required (VERSION 3.12)
project (HDF5_SRC C)

# ITK --start
set(MANGLE_PREFIX itk)
set(MANGLE_PREFIX slicer_itk)
configure_file(${HDF5_SRC_DIR}/itk_hdf5_mangle.h.in
${HDF5_SRC_BINARY_DIR}/itk_hdf5_mangle.h
@ONLY)
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/JPEG/src/itkjpeg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ endif(WIN32)
configure_file(${ITK3P_JPEG_SOURCE_DIR}/jpegDllConfig.h.in
${ITK3P_JPEG_BINARY_DIR}/jpegDllConfig.h)

set(MANGLE_PREFIX itk_jpeg)
set(MANGLE_PREFIX slicer_itk)
configure_file(${ITK3P_JPEG_SOURCE_DIR}/itk_jpeg_mangle.h.in
${ITK3P_JPEG_BINARY_DIR}/itk_jpeg_mangle.h
@ONLY)
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/NrrdIO/src/NrrdIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ INCLUDE_DIRECTORIES(
${ITK3P_NrrdIO_BINARY_DIR}
)

set(MANGLE_PREFIX itk)
set(MANGLE_PREFIX slicer_itk)
configure_file(${ITK3P_NrrdIO_SOURCE_DIR}/itk_NrrdIO_mangle.h.in
${ITK3P_NrrdIO_BINARY_DIR}/itk_NrrdIO_mangle.h
@ONLY)
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/OpenJPEG/src/openjpeg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ CONFIGURE_FILE(${ITK3P_OpenJPEG_SOURCE_DIR}/opj_configure.h.in
# configure name mangling to allow multiple libraries to coexist
# peacefully
if(EXISTS ${ITK3P_OpenJPEG_SOURCE_DIR}/openjpeg_mangle.h.in)
set(MANGLE_PREFIX itk)
set(MANGLE_PREFIX slicer_itk)
configure_file(${ITK3P_OpenJPEG_SOURCE_DIR}/openjpeg_mangle.h.in
${ITK3P_OpenJPEG_BINARY_DIR}/openjpeg_mangle.h
@ONLY)
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/PNG/src/itkpng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endif(WIN32)
configure_file(${ITK3P_PNG_SOURCE_DIR}/pngDllConfig.h.in
${ITK3P_PNG_BINARY_DIR}/pngDllConfig.h)

set(MANGLE_PREFIX itk_png)
set(MANGLE_PREFIX slicer_itk)
configure_file(${ITK3P_PNG_SOURCE_DIR}/itk_png_mangle.h.in
${ITK3P_PNG_BINARY_DIR}/itk_png_mangle.h
@ONLY)
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/TIFF/src/itktiff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ configure_file(${ITK3P_TIFF_SOURCE_DIR}/tiffDllConfig.h.in
configure_file(${ITK3P_TIFF_SOURCE_DIR}/tif_config.h.in
${ITK3P_TIFF_BINARY_DIR}/itk_tif_config.h)

set(MANGLE_PREFIX itk_tiff)
set(MANGLE_PREFIX slicer_itk)
configure_file(${ITK3P_TIFF_SOURCE_DIR}/itk_tiff_mangle.h.in
${ITK3P_TIFF_BINARY_DIR}/itk_tiff_mangle.h
@ONLY)
Expand Down

0 comments on commit aacaefd

Please sign in to comment.