[CMake] Problem with CHECK_INCLUDE_FILE macro

Brad King brad.king at kitware.com
Tue Dec 13 13:35:01 EST 2005


Philippe Poilbarbe wrote:
> Hello,
> 
> I have a problem with the macro CHECK_INCLUDE_FILE which never find 
> anything.
> 
> Here are some lines:
> INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
> CHECK_INCLUDE_FILE("udunits.h" HAVE_UDUNITS_H)
> 
> on exit HAVE_UDUNITS_H is always false.
> 
> I have put some message trace in the macro and it seams that it never 
> reaches
> the second line; the line after:
>   IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
> because the test is always false in this macro (if I do the same test 
> outside
> the macro like "HAVE_UDUNITS_H" MATCHES "^HAVE_UDUNITS_H$"
> it is true as expected).
> 
> Is there something special to do ?
> 
> As a subsidiary question, why is this test here since it should always 
> be true ?
> I don't understand it or I should miss something.

Read the documentation of the IF command carefully.  This kind of IF 
test is a hack to test if a variable is defined left from before we had 
the IF(DEFINED ...) option.  If HAVE_UDUNITS_H is defined then the IF 
command will replace it with its value before evaluating the MATCHES. 
If it is not defined then the strings will match.

You probably have HAVE_UDUNITS_H in your CMakeCache.txt file so it is 
always defined already when this macro executes.  The idea is once the 
test is done the first time the result does not change so it is put in 
the cache.  Once it is in the cache the test is not run again.  This 
policy is not perfect but works well most of the time.

-Brad


More information about the CMake mailing list