[CMake] How to query compiler definitions?

Michael Wild themiwi at gmail.com
Wed Jan 19 07:18:13 EST 2011


Just tried out my last approach, and found out that it doesn't work. The
executable target always depends on the library target, irrespective of
the build configuration.

On 01/19/2011 11:50 AM, SF Markus Elfring wrote:
>> For multi-config IDE's you *don't know* whether NDEBUG is defined or
>> not at CMake-time.
> 
> I imagine that the build system could keep control on all passed
> compilation parameters if calls for generation commands would be
> intercepted (by CMake).
> Does it get any feedback for changes of this preprocessor symbol?

You don't seem to understand the difference between CMake-time and Make-
(or build-) time.

CMake-time is when you run CMake to generate the actual build system
(Makefiles, Xcode project, VisualStudio project, etc.). This is when
your CMake code runs, when you have to specify all the source files etc.

Build-time is when the actual build system runs. Everything is static
here (except for custom commands). In particular, you can't change the
list of source files any more.

> 
> 
>> And AFAIK there's no way to specify that a source file is conditional
>> on the build configuration.
> 
> I can try an approximation. - Do I need to apply the variable
> "CMAKE_BUILD_TYPE" instead if I can not reuse the symbol's value?
> 

Again, that variable is useless for multi-config generators as it is
only meaningful for Makefile and other single-config generators.

> 
>> add_executable(super super.c)
> 
> I would like to construct the source file list that is passed to this
> command dynamically. Can unneeded stuff be avoided?

The problem is, you want to assemble that list at build-time, which is
not possible, because then CMake wouldn't know about them.

> 
> Regards,
> Markus


I don't quite understand why it is so important to you that these files
aren't passed to the compiler. If you exclude all of their contents with
"#ifndef NDEBUG", then each file should take less than a second to
compile, so you'd need a lot of those debug-only files for it to matter.

Michael


More information about the CMake mailing list