[CMake] Macro for adding cflags, odd quirk with CHECK_C_COMPILER_FLAG

Brad King brad.king at kitware.com
Mon Dec 20 09:00:51 EST 2010


On 12/16/2010 01:07 PM, Campbell Barton wrote:
> My question is why this is needed?
> 	set(CFLAG_TEST "CFLAG_TEST")
> 	CHECK_C_COMPILER_FLAG("${_FLAG}" CFLAG_TEST)

The CHECK_C_COMPILER_FLAG macro stores its result in the CMake cache so
that it persists across multiple runs in the same build tree.  Otherwise
it will run the check every time which is far too expensive.  Every call
to this macro should have a unique name as the second argument to store
the result persistently.

> MACRO(CHECK_C_SOURCE_COMPILES SOURCE VAR)
>   IF("${VAR}" MATCHES "^${VAR}$")

This is check is a hack for

  if(NOT DEFINED ${VAR})

from before the "DEFINED" test was supported by CMake's if() command.
Some uses of the old hack are still floating around.  Note that the
purpose is to test if the variable named by "${VAR}" is defined, not
whether the variable "VAR" itself is defined.

-Brad


More information about the CMake mailing list