I have a #define in a separate header file:
#ifndef __sitkConfigure_h
#define __sitkConfigure_h
#define SITK_4D_IMAGES
#endif // __sitkConfigure_h
(full source: https://github.com/kaspermarstal/SimpleITK/blob/8be437486dce85da271576f866393cd54fe0f865/Code/Common/src/sitkConfigure.h.in. The define is managed by a #cmakedefine
and turns into #define SITK_4D_IMAGES
as expected when cmake is configured.)
As usual the header is included where the config is needed. For example:
#include "sitkConfigure.h"
#ifdef SITK_4D_IMAGES
/** \brief Constructor for 4D images where pixel type can be specified.
* @{
*/
Image( unsigned int width, unsigned int height, unsigned int depth, unsigned int length, PixelIDValueEnum valueEnum );
/**@}*/
#endif // #ifdef SITK_4D_IMAGES
and
#include "sitkConfigure.h"
#ifdef SITK_4D_IMAGES
Image::Image( unsigned int Width, unsigned int Height, unsigned int Depth, unsigned int Length, PixelIDValueEnum ValueEnum )
: m_PimpleImage( NULL )
{
Allocate ( Width, Height, Depth, Length, ValueEnum, 0 );
}
#endif // #ifdef SITK_4D_IMAGES
(full source: https://github.com/kaspermarstal/SimpleITK/blob/8be437486dce85da271576f866393cd54fe0f865/Code/Common/include/sitkImage.h and https://github.com/kaspermarstal/SimpleITK/blob/8be437486dce85da271576f866393cd54fe0f865/Code/Common/src/sitkImage.cxx)
Why are the #ifdef
not triggered by the #define
in sitkConfigure.h
? It is literally driving me nuts. If I put #define SITK_4D_IMAGES
directly in the files the #ifdef
s are triggered as expected. Further, if I write #define SITK_4D_IMAGES 1
in sitkConfigure.h
and #define SITK_4D_IMAGES 2
in the other files, the compiler complains about redefinitions of SITK_4D_IMAGES
, so it can clearly see the definition in the files from where the header is included.
Tested on Ubuntu 14.10 with GCC 4.8.9 and Mac OSX Yosemite with Apple Clang 600.0.56. You are most welcome to git clone -b development --single-branch git://github.com/kaspermarstal/SimpleITK.git
to reproduce.
Made a minimal example but was unable to reproduce the bug. The issue must be with SimpleITK's build infrastructure. In case anyone is interested it can be downloaded from dropbox.com/s/zlcnqtx32cq4q22/example.zip?dl=0.
Building instructions:
git clone -b development --single-branch git://github.com/kaspermarstal/SimpleITK.git
mkdir build
cd build
cmake ../SimpleITK/SuperBuild
ccmake .
Set SITK_4D_IMAGES
to ON
, configure, generate and make -j4
. The SuperBuild downloads, builds and installs all dependencies.
will take some diggingis ruled out by compiler complaining about redefinitions. As for the double underscore, I have to follow upstream conventions :/ – Kasper Marstal Mar 10 '15 at 20:08