[CMake] add_definitions() bug?

David Cole david.cole at kitware.com
Thu May 28 18:12:41 EDT 2009


It's not a bug in add_definitions.

Quotes matter. With a space in the string inside the quotes, you are telling
add_definitions that there is a single definition with a space in it.
Without the quotes, you are telling add_definitions that there are two
definitions separated by the space.

The basic syntax for CMake commands is arguments are space separated. If you
quote a string, then it counts as a single argument to the command including
spaces that are inside of it.

These are *not* equivalent:
 add_defintions("-DMYDEF -DMYOTHERDEF") # space embedded in a single string
arg
 add_defintions(-DMYDEF -DMYOTHERDEF) # space separates args

But these *are* equivalent:
 add_defintions("-DMYDEF" "-DMYOTHERDEF") # space separates args (not inside
"")
 add_defintions(-DMYDEF -DMYOTHERDEF) # space separates args


Hopefully, this helps somewhat.

David


On Thu, May 28, 2009 at 3:55 AM, Marcel Loose <loose at astron.nl> wrote:

> Hi all,
>
> I ran into this while trying to compile a few assembly sources (see
> thread: Problem with ASM and COMPILE_DEFINITIONS).
>
> Definitions added using add_definitions() with a quoted string
> containing more than one argument are NOT discarded by CMake
> when /usr/bin/as is called. For example, when using:
>
>  add_defintions("-DMYDEF -DMYOTHERDEF")
>
> these definitions remain as arguments to /usr/bin/as.
>
> However, when supplying only a single argument, quotes don't seem to
> matter. Also, when removing the quotes on the multiple arguments above,
> CMake properly discards these preprocessor variables when
> invoking /usr/bin/as.
>
> Is this a bug in add_definitions?
>
> Best regards,
> Marcel Loose.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090528/5c10b5c5/attachment.htm>


More information about the CMake mailing list