[CMake] issue with CHECK FUNCTION EXISTS() and friends
Alexander Neundorf
a.neundorf-work at gmx.net
Wed Jun 29 02:33:16 EDT 2005
Hi,
there is the family of CHECK_XXX_EXISTS() macros in the cmake Modules.
They work quite well but I have a problem with them.
If the item which was searched for has been found HAVE_FOO is set to "1".
This is ok and works in all cases:
in config.h.cmake:
#define HAVE_FOO ${HAVE_FOO}
in the sources:
//works, since it's defined
#ifdef HAVE_FOO
...
#endif
//works, becomes "#if 1"
#if HAVE_FOO
...
#endif
It leads to some problems in the case that it wasn't found, then HAVE_FOO
is empty.
So I get:
#define HAVE_FOO // the empty string, but still it is defined, an undef
would be better
//this will succeed, although it shouldn't, since HAVE_FOO is defined
#ifdef HAVE_FOO
...
#endif
//this will lead to a syntax error, since HAVE_FOO is empty: "#if"
#if HAVE_FOO
...
#endif
What's the right way to solve this situation ? Changing the sources is no
option.
Attached is a patch to CheckFunctionExists.cmake which introduces the
variable CMAKE_ZERO_ON_FAILURE. If set, HAVE_FOO will be set to 0 instead
to empty if the test failed. Then I could write code like this:
config.h.cmake:
#if ${HAVE_FOO}
# define HAVE_FOO
#else
# undef HAVE_FOO
#endif
and
#define HAVE_FOO ${HAVE_FOO}
will have the desired effect in the sources:
//this will become "#if 0" , so everything is ok
#if HAVE_FOO
...
#endif
What do you think ? Is there a better way to do this ? If you think this
is a good idea, I can also post patches for the other CHECK_XXX() macros.
Bye
Alex
--
5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
+++ GMX - die erste Adresse für Mail, Message, More +++
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CheckFunctionExists.cmake.diff
Type: text/x-diff
Size: 755 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20050629/6681f33e/CheckFunctionExists.cmake.bin
More information about the CMake
mailing list