[CMake] -DNDEBUG passed to Qt moc compiler

clinton at elemtech.com clinton at elemtech.com
Wed Sep 3 11:23:28 EDT 2008


On Wednesday 03 September 2008 5:41:53 am Nicolas Desprès wrote:
> Hi,
>
> I'm using cmake 2.6.0 and Qt-4.4.1 commercial on windows. While trying
> to compile my Qt application in release mode using
> -DCMAKE_BUILD_TYPE=Release, I met a problem with conditional Qt slots.
> In one of my header, I have something like that:
>
> #ifndef NDEBUG
>   void mySlot()
> #endif
>
> In debug mode, there is no problem. But in release mode my C++
> compiler complains that it cannot find the identifier "mySlot"  when
> it compiles the source file generated by Qt's moc compiler.
>
> Adding:
>  -D
>  NDEBUG
>
> in the parameter file given to moc in the build tree fixed the issue.
>
> I suggest that FindQt4 module could handle such issue automatically.
>


The generated cpp files get shared by multiple configurations and build types, 
so if you want the -DNDEBUG, you'll have to add it yourself.

QT_WRAP_CPP(mocfiles ${MOC_HEADERS} OPTIONS -DNDEBUG)

I don't see a way to correctly support this unless the generated cpp files go 
in per-configuration directories, like object files do, and conditionally add 
source files to the target based on build type.  To my knowledge, even Qt's 
qmake doesn't do this.

The latest CVS does a 
get_directory_properties(_defines COMPILE_DEFINITIONS)
to get any other defines you might declare, but NDEBUG isn't one that applies 
to all configurations.

Another options is to not use #ifndef NDEBUG, and just don't call the slot or 
connect to it in a release build.  I would suggest doing it this way.

Clint


More information about the CMake mailing list