CheckStructHasMember.cmake 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # - Check if the given struct or class has the specified member variable
  2. # CHECK_STRUCT_HAS_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. # Example: CHECK_STRUCT_HAS_MEMBER("struct timeval" tv_sec sys/select.h HAVE_TIMEVAL_TV_SEC)
  17. #=============================================================================
  18. # Copyright 2007-2009 Kitware, Inc.
  19. #
  20. # Distributed under the OSI-approved BSD License (the "License");
  21. # see accompanying file Copyright.txt for details.
  22. #
  23. # This software is distributed WITHOUT ANY WARRANTY; without even the
  24. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  25. # See the License for more information.
  26. #=============================================================================
  27. # (To distribute this file outside of CMake, substitute the full
  28. # License text for the above reference.)
  29. INCLUDE(CheckCSourceCompiles)
  30. MACRO (CHECK_STRUCT_HAS_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
  31. SET(_INCLUDE_FILES)
  32. FOREACH (it ${_HEADER})
  33. SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
  34. ENDFOREACH (it)
  35. SET(_CHECK_STRUCT_MEMBER_SOURCE_CODE "
  36. ${_INCLUDE_FILES}
  37. int main()
  38. {
  39. ${_STRUCT}* tmp;
  40. tmp->${_MEMBER};
  41. return 0;
  42. }
  43. ")
  44. CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
  45. ENDMACRO (CHECK_STRUCT_HAS_MEMBER)