This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  79f96440eb8869f253a23f6747762f221c0069a6 (commit)
       via  e66277d5d692a22f3beb0c67c5797f16d7cdba29 (commit)
       via  945734ed1b5dc348512b8e297580e8730cef1757 (commit)
      from  c08f1c96b064a567b972e1cc954ded738c9cb9f3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=79f96440eb8869f253a23f6747762f221c0069a6
commit 79f96440eb8869f253a23f6747762f221c0069a6
Merge: c08f1c9 e66277d
Author:     Daniele E. Domenichelli <daniele.domeniche...@gmail.com>
AuthorDate: Wed Oct 2 07:09:47 2013 -0400
Commit:     CMake Topic Stage <kwro...@kitware.com>
CommitDate: Wed Oct 2 07:09:47 2013 -0400

    Merge topic 'CheckStructHasMember_CXX' into next
    
    e66277d CheckStructHasMember: Add unit tests
    945734e [CheckStructHasMember] Add support for C++


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e66277d5d692a22f3beb0c67c5797f16d7cdba29
commit e66277d5d692a22f3beb0c67c5797f16d7cdba29
Author:     Daniele E. Domenichelli <daniele.domeniche...@iit.it>
AuthorDate: Wed Oct 2 13:08:44 2013 +0200
Commit:     Daniele E. Domenichelli <daniele.domeniche...@iit.it>
CommitDate: Wed Oct 2 13:08:44 2013 +0200

    CheckStructHasMember: Add unit tests

diff --git a/Tests/CMakeOnly/CMakeLists.txt b/Tests/CMakeOnly/CMakeLists.txt
index be7ddbc..7586de6 100644
--- a/Tests/CMakeOnly/CMakeLists.txt
+++ b/Tests/CMakeOnly/CMakeLists.txt
@@ -19,6 +19,8 @@ add_CMakeOnly_test(CheckCXXCompilerFlag)
 
 add_CMakeOnly_test(CheckLanguage)
 
+add_CMakeOnly_test(CheckStructHasMember)
+
 add_CMakeOnly_test(CompilerIdC)
 add_CMakeOnly_test(CompilerIdCXX)
 if(CMAKE_Fortran_COMPILER)
diff --git a/Tests/CMakeOnly/CheckStructHasMember/CMakeLists.txt 
b/Tests/CMakeOnly/CheckStructHasMember/CMakeLists.txt
new file mode 100644
index 0000000..6902c38
--- /dev/null
+++ b/Tests/CMakeOnly/CheckStructHasMember/CMakeLists.txt
@@ -0,0 +1,94 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(CheckStructHasMember)
+
+set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}")
+
+include(CheckStructHasMember)
+
+foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
+    set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
+    unset(CSHM_RESULT_S1_${_config_type} CACHE)
+    unset(CSHM_RESULT_S2_${_config_type} CACHE)
+    unset(CSHM_RESULT_S3_${_config_type} CACHE)
+    message(STATUS "Testing configuration ${_config_type}")
+
+    check_struct_has_member("struct non_existent_struct" "foo" "cm_cshm.h" 
CSHM_RESULT_S1_${_config_type})
+    check_struct_has_member("struct struct_with_non_existent_members" "foo" 
"cm_cshm.h" CSHM_RESULT_S2_${_config_type})
+    check_struct_has_member("struct struct_with_member" "foo" "cm_cshm.h" 
CSHM_RESULT_S3_${_config_type})
+
+    if(CSHM_RESULT_S1_${_config_type} OR CSHM_RESULT_S2_${_config_type})
+        message(SEND_ERROR "CheckStructHasMember reported a nonexistent member 
as existing in configuration ${_config_type}")
+    endif()
+
+    if(NOT CSHM_RESULT_S3_${_config_type})
+        message(SEND_ERROR "CheckStructHasMember did not report an existent 
member as existing in configuration ${_config_type}")
+    endif()
+
+endforeach()
+
+foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
+    set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
+    unset(CSHM_RESULT_S1_${_config_type}_C CACHE)
+    unset(CSHM_RESULT_S2_${_config_type}_C CACHE)
+    unset(CSHM_RESULT_S3_${_config_type}_C CACHE)
+    message(STATUS "Testing configuration ${_config_type}")
+
+    check_struct_has_member("struct non_existent_struct" "foo" "cm_cshm.h" 
CSHM_RESULT_S1_${_config_type}_C LANGUAGE C)
+    check_struct_has_member("struct struct_with_non_existent_members" "foo" 
"cm_cshm.h" CSHM_RESULT_S2_${_config_type}_C LANGUAGE C)
+    check_struct_has_member("struct struct_with_member" "foo" "cm_cshm.h" 
CSHM_RESULT_S3_${_config_type}_C LANGUAGE C)
+
+    if(CSHM_RESULT_S1_${_config_type}_C OR CSHM_RESULT_S2_${_config_type}_C)
+        message(SEND_ERROR "CheckStructHasMember reported a nonexistent member 
as existing in configuration ${_config_type}")
+    endif()
+
+    if(NOT CSHM_RESULT_S3_${_config_type}_C)
+        message(SEND_ERROR "CheckStructHasMember did not report an existent 
member as existing in configuration ${_config_type}")
+    endif()
+endforeach()
+
+foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
+    set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
+    unset(CSHM_RESULT_S1_${_config_type}_CXX CACHE)
+    unset(CSHM_RESULT_S2_${_config_type}_CXX CACHE)
+    unset(CSHM_RESULT_S3_${_config_type}_CXX CACHE)
+    unset(CSHM_RESULT_C1_${_config_type}_CXX CACHE)
+    unset(CSHM_RESULT_C2_${_config_type}_CXX CACHE)
+    unset(CSHM_RESULT_C3_${_config_type}_CXX CACHE)
+
+    message(STATUS "Testing configuration ${_config_type}")
+
+    check_struct_has_member("non_existent_struct" "foo" "cm_cshm.h" 
CSHM_RESULT_S1_${_config_type}_CXX LANGUAGE CXX)
+    check_struct_has_member("struct_with_non_existent_members" "foo" 
"cm_cshm.h" CSHM_RESULT_S2_${_config_type}_CXX LANGUAGE CXX)
+    check_struct_has_member("struct_with_member" "foo" "cm_cshm.h" 
CSHM_RESULT_S3_${_config_type}_CXX LANGUAGE CXX)
+    check_struct_has_member("ns::non_existent_class" "foo" "cm_cshm.hxx" 
CSHM_RESULT_C1_${_config_type}_CXX LANGUAGE CXX)
+    check_struct_has_member("ns::class_with_non_existent_members" "foo" 
"cm_cshm.hxx" CSHM_RESULT_C2_${_config_type}_CXX LANGUAGE CXX)
+    check_struct_has_member("ns::class_with_member" "foo" "cm_cshm.hxx" 
CSHM_RESULT_C3_${_config_type}_CXX LANGUAGE CXX)
+
+    if(CSHM_RESULT_S1_${_config_type}_CXX OR 
CSHM_RESULT_S2_${_config_type}_CXX OR CSHM_RESULT_C1_${_config_type}_CXX OR 
CSHM_RESULT_C2_${_config_type}_CXX)
+        message(SEND_ERROR "CheckStructHasMember reported a nonexistent member 
as existing in configuration ${_config_type}")
+    endif()
+
+    if(NOT CSHM_RESULT_S3_${_config_type}_CXX OR NOT 
CSHM_RESULT_C3_${_config_type}_CXX)
+        message(SEND_ERROR "CheckStructHasMember did not report an existent 
member as existing in configuration ${_config_type}")
+    endif()
+endforeach()
+
+
+set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
+
+if (CMAKE_COMPILER_IS_GNUCC)
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
+    unset(CSHM_RESULT_O3 CACHE)
+    unset(CSHM_RESULT_O3_C CACHE)
+    unset(CSHM_RESULT_O3_CXX CACHE)
+    message(STATUS "Testing with optimization -O3")
+
+    check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" 
CSHM_RESULT_O3)
+    check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" 
CSHM_RESULT_O3_C LANGUAGE C)
+    check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" 
CSHM_RESULT_O3_CXX LANGUAGE CXX)
+
+  if (CSE_RESULT_O3 OR CSHM_RESULT_O3_C OR CSHM_RESULT_O3_CXX)
+    message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as 
existing with optimization -O3")
+  endif ()
+endif ()
diff --git a/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.h 
b/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.h
new file mode 100644
index 0000000..13ef129
--- /dev/null
+++ b/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.h
@@ -0,0 +1,11 @@
+#ifndef _CSHM_DUMMY_H
+#define _CSHM_DUMMY_H
+
+struct non_existent_struct;
+struct struct_with_non_existent_members {
+};
+struct struct_with_member {
+    int foo;
+};
+
+#endif
diff --git a/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.hxx 
b/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.hxx
new file mode 100644
index 0000000..458a99b
--- /dev/null
+++ b/Tests/CMakeOnly/CheckStructHasMember/cm_cshm.hxx
@@ -0,0 +1,16 @@
+#ifndef _CSHM_DUMMY_HXX
+#define _CSHM_DUMMY_HXX
+
+namespace ns {
+
+class non_existent_class;
+class class_with_non_existent_members {
+};
+class class_with_member {
+public:
+    int foo;
+};
+
+}
+
+#endif

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=945734ed1b5dc348512b8e297580e8730cef1757
commit 945734ed1b5dc348512b8e297580e8730cef1757
Author:     Daniele E. Domenichelli <daniele.domeniche...@iit.it>
AuthorDate: Fri Sep 20 15:10:40 2013 +0200
Commit:     Daniele E. Domenichelli <daniele.domeniche...@iit.it>
CommitDate: Wed Sep 25 18:12:45 2013 +0200

    [CheckStructHasMember] Add support for C++
    
    If headers required to check if a struct has a member can be compiled
    with C++ compiler only, the check will fail, because the C compiler
    will fail.
    As a consequence, the result variable is set to false, even if the
    struct has that particular member.
    
    The CHECK_C_STRUCT_HAS_MEMBER now accepts a new optional argument
    LANGUAGE that allows one to explicitly set the compiler to use.
    The new signature is therefore:
    
      CHECK_STRUCT_HAS_MEMBER (<struct> <member> <header> <variable>
                               [LANGUAGE <language>])

diff --git a/Modules/CheckStructHasMember.cmake 
b/Modules/CheckStructHasMember.cmake
index ea2891c..d28cc2a 100644
--- a/Modules/CheckStructHasMember.cmake
+++ b/Modules/CheckStructHasMember.cmake
@@ -1,10 +1,12 @@
 # - Check if the given struct or class has the specified member variable
-# CHECK_STRUCT_HAS_MEMBER (STRUCT MEMBER HEADER VARIABLE)
+# CHECK_STRUCT_HAS_MEMBER (<struct> <member> <header> <variable>
+#                          [LANGUAGE <language>])
 #
-#  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
+#  <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
+#  <language> - the compiler to use (C or CXX)
 #
 # The following variables may be set before calling this macro to
 # modify the way the check is run:
@@ -12,8 +14,9 @@
 #  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
+#  CMAKE_REQUIRED_LIBRARIES = list of libraries to link
 #
-# Example: CHECK_STRUCT_HAS_MEMBER("struct timeval" tv_sec sys/select.h 
HAVE_TIMEVAL_TV_SEC)
+# Example: CHECK_STRUCT_HAS_MEMBER("struct timeval" tv_sec sys/select.h 
HAVE_TIMEVAL_TV_SEC LANGUAGE C)
 
 #=============================================================================
 # Copyright 2007-2009 Kitware, Inc.
@@ -29,6 +32,7 @@
 #  License text for the above reference.)
 
 include(CheckCSourceCompiles)
+include(CheckCXXSourceCompiles)
 
 macro (CHECK_STRUCT_HAS_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
    set(_INCLUDE_FILES)
@@ -36,16 +40,29 @@ macro (CHECK_STRUCT_HAS_MEMBER _STRUCT _MEMBER _HEADER 
_RESULT)
       set(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
    endforeach ()
 
+   if("x${ARGN}" STREQUAL "x")
+      set(_lang C)
+   elseif("x${ARGN}" MATCHES "^xLANGUAGE;([a-zA-Z]+)$")
+      set(_lang "${CMAKE_MATCH_1}")
+   else()
+      message(FATAL_ERROR "Unknown arguments:\n  ${ARGN}\n")
+   endif()
+
    set(_CHECK_STRUCT_MEMBER_SOURCE_CODE "
 ${_INCLUDE_FILES}
 int main()
 {
    ${_STRUCT}* tmp;
    tmp->${_MEMBER};
-  return 0;
+   return 0;
 }
 ")
-   CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
 
+   if("${_lang}" STREQUAL "C")
+      CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
+   elseif("${_lang}" STREQUAL "CXX")
+      CHECK_CXX_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" 
${_RESULT})
+   else()
+      message(FATAL_ERROR "Unknown language:\n  ${_lang}\nSupported languages: 
C, CXX.\n")
+   endif()
 endmacro ()
-

-----------------------------------------------------------------------

Summary of changes:
 Modules/CheckStructHasMember.cmake                 |   35 ++++++--
 Tests/CMakeOnly/CMakeLists.txt                     |    2 +
 .../CMakeOnly/CheckStructHasMember/CMakeLists.txt  |   94 ++++++++++++++++++++
 Tests/CMakeOnly/CheckStructHasMember/cm_cshm.h     |   11 +++
 Tests/CMakeOnly/CheckStructHasMember/cm_cshm.hxx   |   16 ++++
 5 files changed, 149 insertions(+), 9 deletions(-)
 create mode 100644 Tests/CMakeOnly/CheckStructHasMember/CMakeLists.txt
 create mode 100644 Tests/CMakeOnly/CheckStructHasMember/cm_cshm.h
 create mode 100644 Tests/CMakeOnly/CheckStructHasMember/cm_cshm.hxx


hooks/post-receive
-- 
CMake
_______________________________________________
Cmake-commits mailing list
Cmake-commits@cmake.org
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-commits

Reply via email to