aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2006-04-30 21:39:02 +0000
committerAlexander Neundorf <neundorf@kde.org>2006-04-30 21:39:02 +0000
commit4003d9108c0254fbaafb03b33f011cd63983510f (patch)
tree2c5abb1929f70cf040256f743f559ca0952316bd
parentdc05a7733224b1fce459fc633d1a952e451803b2 (diff)
downloadextra-cmake-modules-4003d9108c0254fbaafb03b33f011cd63983510f.tar.gz
extra-cmake-modules-4003d9108c0254fbaafb03b33f011cd63983510f.tar.bz2
-two cmake modules to check whether a given struct or pointer has a specified member variable
Alex svn path=/trunk/KDE/kdelibs/; revision=535981
-rw-r--r--modules/CheckPointerMember.cmake36
-rw-r--r--modules/CheckStructMember.cmake36
2 files changed, 72 insertions, 0 deletions
diff --git a/modules/CheckPointerMember.cmake b/modules/CheckPointerMember.cmake
new file mode 100644
index 00000000..fc6b231d
--- /dev/null
+++ b/modules/CheckPointerMember.cmake
@@ -0,0 +1,36 @@
+# - Check if the given struct or class has the specified member variable
+# CHECK_POINTER_MEMBER (POINTER MEMBER HEADER VARIABLE)
+#
+# POINTER - the name of the struct or class you are interested in
+# MEMBER - the member which existence you want to check
+# HEADER - the header(s) where the prototype should be declared
+# VARIABLE - variable to store the result
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+
+INCLUDE(CheckCXXSourceCompiles)
+
+MACRO (CHECK_POINTER_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
+ SET(_INCLUDE_FILES)
+ FOREACH (it ${_HEADER})
+ SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
+ ENDFOREACH (it)
+
+ SET(_CHECK_POINTER_MEMBER_SOURCE_CODE "
+${_INCLUDE_FILES}
+int main()
+{
+ ${_STRUCT} tmp;
+ tmp->${_MEMBER};
+ return 0;
+}
+")
+ CHECK_CXX_SOURCE_COMPILES("${_CHECK_POINTER_MEMBER_SOURCE_CODE}" ${_RESULT})
+
+ENDMACRO (CHECK_POINTER_MEMBER)
+
diff --git a/modules/CheckStructMember.cmake b/modules/CheckStructMember.cmake
new file mode 100644
index 00000000..fd5d3461
--- /dev/null
+++ b/modules/CheckStructMember.cmake
@@ -0,0 +1,36 @@
+# - Check if the given struct or class has the specified member variable
+# CHECK_STRUCT_MEMBER (STRUCT MEMBER HEADER VARIABLE)
+#
+# STRUCT - the name of the struct or class you are interested in
+# MEMBER - the member which existence you want to check
+# HEADER - the header(s) where the prototype should be declared
+# VARIABLE - variable to store the result
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+# CMAKE_REQUIRED_FLAGS = string of compile command line flags
+# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+# CMAKE_REQUIRED_INCLUDES = list of include directories
+
+INCLUDE(CheckCXXSourceCompiles)
+
+MACRO (CHECK_STRUCT_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
+ SET(_INCLUDE_FILES)
+ FOREACH (it ${_HEADER})
+ SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
+ ENDFOREACH (it)
+
+ SET(_CHECK_STRUCT_MEMBER_SOURCE_CODE "
+${_INCLUDE_FILES}
+int main()
+{
+ ${_STRUCT}* tmp;
+ tmp->${_MEMBER};
+ return 0;
+}
+")
+ CHECK_CXX_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
+
+ENDMACRO (CHECK_STRUCT_MEMBER)
+