[CMake] Problem with CHECK_INCLUDE_FILE macro

Philippe Poilbarbe Philippe.Poilbarbe at cls.fr
Wed Dec 14 05:17:15 EST 2005


Brad King a écrit :

> 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

I have reread the IF description but nothing of this kind appears to me 
(I use the book Mastering CMake), there is only a description of DEFINED 
(but perhaps my english is not good enough :)).
Anyway, I have found the source of my problem: there was garbages in the 
cache file (due to previous tries). After deleting this file it worked well.

Thanks for the answer.
Ph. Poilbarbe



More information about the CMake mailing list