[CMake] Macro Problem

Michael Hertling mhertling at online.de
Wed Jul 14 16:30:58 EDT 2010


On 07/14/2010 04:37 PM, Michael.Schmidt at L-3com.com wrote:
> Hello,
> 
> My project has third party source in a subdirectory.  The third party
> source has to be compiled without special options.  With autoconf, we
> had "CFLAGS =".  How would I do the same with cmake and restore CFLAGS
> to their original value in the parent directory?

In the third party sources' CMakeLists.txt, do:

SET_DIRECTORY_PROPERTIES(PROPERTIES COMPILE_DEFINITIONS "")
GET_DIRECTORY_PROPERTY(DEFS DEFINITIONS)
SEPARATE_ARGUMENTS(DEFS)
REMOVE_DEFINITIONS(${DEFS})

The GET_DIRECTORY_PROPERTY()/REMOVE_DEFINITIONS() combination should be
obvious, and the SEPARATE_ARGUMENTS() is necessary to prepare the flags
for removal. Unfortunately, it fails with defines like -DNAME="ABC XYZ"
that will be split at the space in -DNAME="ABC and XYZ", but luckily in
turn, REMOVE_DEFINITIONS() silently ignores such strange flags. Though,
these defines would still show up in the compilation lines, so remove
them with SET_DIRECTORY_PROPERTIES(). Of course, you mustn't have any
properties on targets or sources with additional flags or definitions
in that directory.

As a last resort, you can manipulate the CMAKE_<LANG>_COMPILE_OBJECT
variables in that directory only, i.e. remove <FLAGS> and <DEFINES>,
but this depends on a certain knowledge of these rule variables, i.e.
it's doubtful if this works the same for all platforms, compilers etc.

'hope that helps.

Regards,

Michael


More information about the CMake mailing list