[CMake] issue with CHECK FUNCTION EXISTS() and friends

Brad King brad.king at kitware.com
Wed Jun 29 09:33:25 EDT 2005


Alexander Neundorf wrote:
>>   #cmakedefine HAVE_FOO 
>> 
>>in config.h.cmake do the right thing? 
> 
> I didn't know this exists. Is it documented somewhere ? 

In section 6.5 of "Mastering CMake".  It is also used in the CMake 
source itself in a few places.

> So this produces either 
>  
> #define HAVE_FOO 
> or  
> #undef HAVE_FOO 
>  
> So it does the right thing for this usage. But it doesn't work for 
> defines which should be either 0 or 1, e.g. libltdl and nano X use them a 
> lot: 

There is no reason you have to use the result of one of these built-in 
tests directly.  You can transform the result using CMake code:

   CHECK_INCLUDE_FILE("limits.h"       CMAKE_HAVE_LIMITS_H)
   IF(CMAKE_HAVE_LIMITS_H)
     SET(MYPROJ_HAVE_LIMITS_H 1)
   ELSE(CMAKE_HAVE_LIMITS_H)
     SET(MYPROJ_HAVE_LIMITS_H 0)
   ENDIF(CMAKE_HAVE_LIMITS_H)

Then in your configured header have

#define MYPROJ_HAVE_LIMITS_H @MYPROJ_HAVE_LIMITS_H@

OR

#define HAVE_LIMITS_H @MYPROJ_HAVE_LIMITS_H@

The translation to a 0/1 result could easily be put in a macro.

-Brad


More information about the CMake mailing list