Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Modules / CheckStructHasMember.cmake
blobf8a7d32afe40ea71b934b5c1dd8bec0106656f4c
1 # - Check if the given struct or class has the specified member variable
2 # CHECK_STRUCT_HAS_MEMBER (STRUCT MEMBER HEADER VARIABLE)
4 #  STRUCT - the name of the struct or class you are interested in
5 #  MEMBER - the member which existence you want to check
6 #  HEADER - the header(s) where the prototype should be declared
7 #  VARIABLE - variable to store the result
9 # The following variables may be set before calling this macro to
10 # modify the way the check is run:
12 #  CMAKE_REQUIRED_FLAGS = string of compile command line flags
13 #  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
14 #  CMAKE_REQUIRED_INCLUDES = list of include directories
16 # Example: CHECK_STRUCT_HAS_MEMBER("struct timeval" tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC)
19 INCLUDE(CheckCSourceCompiles)
21 MACRO (CHECK_STRUCT_HAS_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
22    SET(_INCLUDE_FILES)
23    FOREACH (it ${_HEADER})
24       SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
25    ENDFOREACH (it)
27    SET(_CHECK_STRUCT_MEMBER_SOURCE_CODE "
28 ${_INCLUDE_FILES}
29 int main()
31    ${_STRUCT}* tmp;
32    tmp->${_MEMBER};
33   return 0;
36    CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
38 ENDMACRO (CHECK_STRUCT_HAS_MEMBER)