[CMake] Check symbol in header files with dependencies

Alexander Koeppe format_c at online.de
Thu Feb 5 15:12:36 EST 2015


Hi Cmake user list,

I have a problem that I need to check the presence of a certain symbol
in a header file using CHECK_SYMBOL_EXISTS which has several dependencies.

The check fails because the header file also contains data types that
require an additional header file to be included by the test program. It
looks like CHECK_SYMBOL_EXISTS is not capable doing that.

To be more precise I want to check the presence if IP6T_SO_ORIGINAL_DST
is defined in linux/netfilter_ipv6/ip6_tables.h.

But the CMakeError.log shows why the check fails:
---
   Determining if the IP6T_SO_ORIGINAL_DST exist failed with the
following output:
[...]
   In file included from /usr/include/linux/netfilter.h:6:0,
                    from /usr/include/linux/netfilter_ipv6.h:11,
                    from /usr/include/linux/netfilter_ipv6/ip6_tables.h:20,
                    from /build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:2:
   /usr/include/linux/sysctl.h:40:2: error: unknown type name ‘size_t’
     size_t *oldlenp;
     ^
   /usr/include/linux/sysctl.h:42:2: error: unknown type name ‘size_t’
     size_t newlen;
     ^
   In file included from /usr/include/linux/netfilter_ipv6.h:11:0,
                    from /usr/include/linux/netfilter_ipv6/ip6_tables.h:20,
                    from /build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:2:
   /usr/include/linux/netfilter.h:67:17: error: field ‘in’ has
incomplete type
     struct in_addr in;
                    ^
   /usr/include/linux/netfilter.h:68:18: error: field ‘in6’ has
incomplete type
     struct in6_addr in6;
                     ^
[...]
   File /build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
   /* */
   #include <linux/netfilter_ipv6/ip6_tables.h>

   int main(int argc, char** argv)
   {
     (void)argv;
   #ifndef IP6T_SO_ORIGINAL_DST
     return ((int*)(&IP6T_SO_ORIGINAL_DST))[argc];
   #else
     (void)argc;
     return 0;
   #endif
   }
---

Does somebody have an advice how to overcome this issue? Maybe I have
missed a function or macro that does the trick?

Any help on that is much appreciated.
Cheers Alex



More information about the CMake mailing list