Hello, CheckStructHasMember does not support C++ only structs. 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 attached patch adds 2 new macros: - CHECK_CXX_STRUCT_HAS_MEMBER (similar to CHECK_STRUCT_HAS_MEMBER but uses the C++ compiler) - CHECK_C_STRUCT_HAS_MEMBER (identical to CHECK_STRUCT_HAS_MEMBER, added for symmetry) that can be used to check a struct, choosing the compiler to use. I'm not sure if this is the right way to fix this (i.e. if CHECK_C_STRUCT_HAS_MEMBER is required), or if it is a better idea to add a parameter to the existing macro. What do you think? Cheers, Daniele
>From d9467221a4caba2ade591f858c3c45dbfb15d871 Mon Sep 17 00:00:00 2001 From: "Daniele E. Domenichelli" <daniele.domeniche...@iit.it> Date: Fri, 20 Sep 2013 15:10:40 +0200 Subject: [PATCH] [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. This patch adds 2 new macros: - CHECK_C_STRUCT_HAS_MEMBER (identical to CHECK_STRUCT_HAS_MEMBER) - CHECK_CXX_STRUCT_HAS_MEMBER (similar, but uses the C++ compiler) --- Modules/CheckStructHasMember.cmake | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Modules/CheckStructHasMember.cmake b/Modules/CheckStructHasMember.cmake index ea2891c..f9032ce 100644 --- a/Modules/CheckStructHasMember.cmake +++ b/Modules/CheckStructHasMember.cmake @@ -1,5 +1,7 @@ # - Check if the given struct or class has the specified member variable # CHECK_STRUCT_HAS_MEMBER (STRUCT MEMBER HEADER VARIABLE) +# CHECK_C_STRUCT_HAS_MEMBER (STRUCT MEMBER HEADER VARIABLE) +# CHECK_CXX_STRUCT_HAS_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 @@ -29,8 +31,10 @@ # License text for the above reference.) include(CheckCSourceCompiles) +include(CheckCXXSourceCompiles) + +macro (_CHECK_STRUCT_HAS_MEMBER_BASE _STRUCT _MEMBER _HEADER _RESULT) -macro (CHECK_STRUCT_HAS_MEMBER _STRUCT _MEMBER _HEADER _RESULT) set(_INCLUDE_FILES) foreach (it ${_HEADER}) set(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n") @@ -45,7 +49,23 @@ int main() return 0; } ") + +endmacro () + + +macro (CHECK_STRUCT_HAS_MEMBER _STRUCT _MEMBER _HEADER _RESULT) + _CHECK_STRUCT_HAS_MEMBER_BASE(${ARGN}) CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT}) +endmacro () + +macro (CHECK_C_STRUCT_HAS_MEMBER _STRUCT _MEMBER _HEADER _RESULT) + _CHECK_STRUCT_HAS_MEMBER_BASE(${ARGN}) + CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT}) endmacro () + +macro (CHECK_CXX_STRUCT_HAS_MEMBER _STRUCT _MEMBER _HEADER _RESULT) + _CHECK_STRUCT_HAS_MEMBER_BASE(${ARGN}) + CHECK_CXX_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT}) +endmacro () -- 1.8.4.rc3
-- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers