| 1 |
# - Check if the given struct or class has the specified member variable |
| 2 |
# CHECK_STRUCT_MEMBER (STRUCT MEMBER HEADER VARIABLE) |
| 3 |
# |
| 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 |
| 8 |
# |
| 9 |
# The following variables may be set before calling this macro to |
| 10 |
# modify the way the check is run: |
| 11 |
# |
| 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 |
| 15 |
|
| 16 |
# Copyright (c) 2006, Alexander Neundorf, <[email protected]> |
| 17 |
# |
| 18 |
# Redistribution and use is allowed according to the terms of the BSD license. |
| 19 |
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
| 20 |
|
| 21 |
|
| 22 |
INCLUDE(CheckCSourceCompiles) |
| 23 |
|
| 24 |
MACRO (CHECK_STRUCT_MEMBER _STRUCT _MEMBER _HEADER _RESULT) |
| 25 |
SET(_INCLUDE_FILES) |
| 26 |
FOREACH (it ${_HEADER}) |
| 27 |
SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n") |
| 28 |
ENDFOREACH (it) |
| 29 |
|
| 30 |
SET(_CHECK_STRUCT_MEMBER_SOURCE_CODE " |
| 31 |
${_INCLUDE_FILES} |
| 32 |
int main() |
| 33 |
{ |
| 34 |
static ${_STRUCT} tmp; |
| 35 |
if (sizeof(tmp.${_MEMBER})) |
| 36 |
return 0; |
| 37 |
return 0; |
| 38 |
} |
| 39 |
") |
| 40 |
CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT}) |
| 41 |
|
| 42 |
ENDMACRO (CHECK_STRUCT_MEMBER) |
| 43 |
|