[CMake] CheckCSourceCompiles (revisited)
Michael Wild
themiwi at gmail.com
Fri Mar 6 10:08:22 EST 2009
On 6. Mar, 2009, at 14:50, Marcel Loose wrote:
> Hi all,
>
> With respect to my previous post.
> Is it possible to somehow reset the result variable from
> CheckCSourceCompiles(SOURCE VAR)?
>
> I wanted to run a number of tests in a foreach loop, using the same
> C-code snippet, but with one CMake variable being substituted, but I
> noticed that the test is run only once. Is there a way to reuse/reset
> the cache variable "result", or should I make the result variable
> unique, e.g. HAVE_${func_name}?
>
> foreach(func_name __PRETTY_FUNCTION__ __FUNCTION__)
> check_c_source_compiles("
> #include <stdio.h>
> int main() { puts(${func_name}); }
> " result)
> # if(result)
> # break()
> # endif(result)
> endforeach(func_name __PRETTY_FUNCTION__ __FUNCTION__)
That's really funny, I ran into exactly the same problem today. My
solution was to use unique variable names:
foreach(func_name __PRETTY_FUNCTION__ __FUNCTION__)
check_c_source_compiles("
#include <stdio.h>
int main() { puts(${func_name}); }
" result${func_name})
if(result${func_name})
set(result ${result${func_name}})
break()
endif(result${func_name})
endforeach(func_name __PRETTY_FUNCTION__ __FUNCTION__)
With CMake-CVS (or 2.6.3, but I'm not sure) you could also use
unset(func_name CACHE).
Michael
More information about the CMake
mailing list