[CMake] ADD_DEFINITIONS safety

William A. Hoffman billlist at nycap.rr.com
Tue Jun 6 20:39:45 EDT 2006


At 07:44 PM 6/6/2006, Brandon J. Van Every wrote:
>I erroneously had this code:
>
> CHECK_INCLUDE_FILE(winsock2.h HAVE_WINSOCK2_H)
> IF(HAVE_WINSOCK2_H)
>   ADD_DEFINITIONS(HAVE_WINSOCK2_H)
> ENDIF(HAVE_WINSOCK2_H)
>
>and of course CMakeSetup took it just fine because it thought I knew what I was doing.  When 'make' got around to .c compilation, gcc spewed a whole slew of really bizarre errors about HAVE_WINSOCK2_H not being a valid file.  Of course I should have used a -D
>
> CHECK_INCLUDE_FILE(winsock2.h HAVE_WINSOCK2_H)
> IF(HAVE_WINSOCK2_H)
>   ADD_DEFINITIONS(-DHAVE_WINSOCK2_H)
> ENDIF(HAVE_WINSOCK2_H)
>
>but it makes me think, if the purpose of the function is to add definitions, why not check whether those definitions are vaguely well formed?  Would it be difficult?  I mean, for any given generator, we know what -D or /D flags it takes.

There have been several reports about this problem.   The command is very
old in cmake, and really should work like they way you used it.  However,
at this point, I don't think we can break compatibility with it.  People
send all sorts of compiler flags via that function.  At some point, we
should create a new function ADD_COMPILER_DEFINE, and tell people to
use CMAKE_C_FLAGS or CMAKE_CXX_FLAGS to pass flags to the compiler.

-Bill



More information about the CMake mailing list