[cmake-developers] CheckStructHasMember does not support C++ only structs

2013-09-23 Thread Daniele E. Domenichelli
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" 
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

Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-09-23 Thread Daniele E. Domenichelli
Sorry disregard my previous mail...
My problem was actually different and the attached patch didn't work...

Regards,
 Daniele

On 23/09/13 10:27, Daniele E. Domenichelli wrote:
> 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
> 

--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-09-23 Thread Brad King
On 09/23/2013 04:27 AM, Daniele E. Domenichelli wrote:
> 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.

The existing convention for similar modules is to have separate C and
CXX versions, but this does not generalize well.

> 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.

One could add an optional extra parameter to specify the language
to be used for the check (C or CXX).  However, we should do something
that could be re-used in the similar modules too.  Would you mind
surveying all the check signatures we currently have and reporting
back on their need/use of per-language variants?

Thanks,
-Brad
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-09-24 Thread Daniele E. Domenichelli
On 23/09/13 17:50, Brad King wrote:
> One could add an optional extra parameter to specify the language
> to be used for the check (C or CXX).  However, we should do something
> that could be re-used in the similar modules too.  Would you mind
> surveying all the check signatures we currently have and reporting
> back on their need/use of per-language variants?


It looks like that the signatures are not very consistent...


CheckCCompilerFlag.cmakeCHECK_C_COMPILER_FLAG( )
CheckCXXCompilerFlag.cmake  CHECK_CXX_COMPILER_FLAG( )

CheckCSourceCompiles.cmake  CHECK_C_SOURCE_COMPILES(  
[FAIL_REGEX ])
CheckCXXSourceCompiles.cmakeCHECK_CXX_SOURCE_COMPILES(  
[FAIL_REGEX ])

CheckCSourceRuns.cmake  CHECK_C_SOURCE_RUNS( )
CheckCXXSourceRuns.cmakeCHECK_CXX_SOURCE_RUNS( )

CheckSymbolExists.cmake CHECK_SYMBOL_EXISTS(  
)
CheckCXXSymbolExists.cmake  CHECK_CXX_SYMBOL_EXISTS( 
 )

CheckFunctionExists.cmake   CHECK_FUNCTION_EXISTS( 
)
CheckFortranFunctionExists.cmakeCHECK_FORTRAN_FUNCTION_EXISTS(FUNCTION 
VARIABLE)

CheckIncludeFile.cmake  CHECK_INCLUDE_FILE(INCLUDE VARIABLE)
CheckIncludeFileCXX.cmake   CHECK_INCLUDE_FILE_CXX(INCLUDE VARIABLE)

CheckIncludeFiles.cmake CHECK_INCLUDE_FILES(INCLUDE VARIABLE)

CheckLanguage.cmake check_language()

CheckLibraryExists.cmakeCHECK_LIBRARY_EXISTS (LIBRARY FUNCTION 
LOCATION VARIABLE)

CheckPrototypeDefinition.cmake  check_prototype_definition(FUNCTION 
PROTOTYPE RETURN HEADER VARIABLE)

CheckStructHasMember.cmake  CHECK_STRUCT_HAS_MEMBER (STRUCT MEMBER 
HEADER VARIABLE)

CheckTypeSize.cmake CHECK_TYPE_SIZE(TYPE VARIABLE 
[BUILTIN_TYPES_ONLY])

CheckVariableExists.cmake   CHECK_VARIABLE_EXISTS(VAR VARIABLE)




 Daniele
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-09-24 Thread Brad King
On 09/24/2013 03:50 AM, Daniele E. Domenichelli wrote:
> It looks like that the signatures are not very consistent...

Yes, but they all have room for optional keyword-based arguments
following the main arguments.  How about

 CHECK_STRUCT_HAS_MEMBER (   
  [LANGUAGE ])

?  The LANGUAGE keyword will give the argument clear meaning.

-Brad
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-09-24 Thread Daniele E. Domenichelli
On 24/09/13 14:18, Brad King wrote:
> On 09/24/2013 03:50 AM, Daniele E. Domenichelli wrote:
>> It looks like that the signatures are not very consistent...
> 
> Yes, but they all have room for optional keyword-based arguments
> following the main arguments.  How about
> 
>  CHECK_STRUCT_HAS_MEMBER (   
>   [LANGUAGE ])
> 
> ?  The LANGUAGE keyword will give the argument clear meaning.

Any convention works for me... Perhaps also the other "Check" module
should follow the same convention, though.

I pushed a commit to the CheckStructHasMember_CXX topic, can you review
it? Am I supposed to check for CMAKE_MINIMUM_REQUIRED_VERSION and behave
differently depending on the version?

Cheers,
 Daniele

--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-09-24 Thread Brad King
On 09/24/2013 09:46 AM, Daniele E. Domenichelli wrote:
> Any convention works for me... Perhaps also the other "Check" module
> should follow the same convention, though.

If anyone wants to take this action then go for it.  I wouldn't consider
it a high priority though.

> I pushed a commit to the CheckStructHasMember_CXX topic, can you review
> it?

You can simplify the implementation using ${ARGN} to get the arguments
beyond those explicitly named in the signature.

> Am I supposed to check for CMAKE_MINIMUM_REQUIRED_VERSION and behave
> differently depending on the version?

No, since the new interface is compatible with the old.  Just be sure
the behavior is unchanged when the optional arguments are not given.

-Brad
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-09-24 Thread Daniele E. Domenichelli
On 24/09/13 16:44, Brad King wrote:
> On 09/24/2013 09:46 AM, Daniele E. Domenichelli wrote:
>> I pushed a commit to the CheckStructHasMember_CXX topic, can you review
>> it?
> You can simplify the implementation using ${ARGN} to get the arguments
> beyond those explicitly named in the signature.

You mean something like this?

   if("${ARGN}" STREQUAL "")
  set(_lang C)
   elseif("${ARGN}" MATCHES "^LANGUAGE;([a-zA-Z]+)$")
  set(_lang "${CMAKE_MATCH_1}")
   else()
  message(FATAL_ERROR "Unknown arguments:\n  ${ARGN}\n")
   endif()

   [...]

   if("${_lang}" STREQUAL "C")
  [...]
   elseif("${_lang}" STREQUAL "CXX")
  [...]
   else()
  message(FATAL_ERROR "Unknown language:\n  ${_lang}\nSupported languages: 
C, CXX.\n")
   endif()



Is the "MATCHES" using a list as a string "safe"? Or is there another way to
simplify it?
Otherwise I can do the same using list(LENGTH) and list(GET) instead of ARGC
and ARGV4/5, but it looks more complicated.


Cheers,
 Daniele
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-09-25 Thread Brad King
On 09/24/2013 05:28 PM, Daniele E. Domenichelli wrote:
> You mean something like this?
> 
>if("${ARGN}" STREQUAL "")
>   set(_lang C)
>elseif("${ARGN}" MATCHES "^LANGUAGE;([a-zA-Z]+)$")
>   set(_lang "${CMAKE_MATCH_1}")
>else()
>   message(FATAL_ERROR "Unknown arguments:\n  ${ARGN}\n")
>endif()

That should work, though I suggest using the 'x' trick:

  if("x${ARGN}" STREQUAL "x")
set(_lang C)
  elseif("x${ARGN}" MATCHES "^xLANGUAGE;([a-zA-Z]+)$")

to avoid possible collision of ${ARGN} with other if tests.

-Brad
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-09-25 Thread Daniele E. Domenichelli
On 25/09/13 14:16, Brad King wrote:
> That should work, though I suggest using the 'x' trick:
> 
>   if("x${ARGN}" STREQUAL "x")
> set(_lang C)
>   elseif("x${ARGN}" MATCHES "^xLANGUAGE;([a-zA-Z]+)$")


Done, thanks!
I updated the CheckStructHasMember_CXX topic.


Cheers,
 Daniele

--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-09-25 Thread Brad King
On 09/25/2013 12:16 PM, Daniele E. Domenichelli wrote:
> I updated the CheckStructHasMember_CXX topic.

That looks good, though I haven't tested it by hand myself.

While at this, please look at adding test cases covering this
module, both the old and new signatures.

Thanks,
-Brad
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-10-02 Thread Daniele E. Domenichelli
On 25/09/13 18:49, Brad King wrote:
> On 09/25/2013 12:16 PM, Daniele E. Domenichelli wrote:
>> I updated the CheckStructHasMember_CXX topic.
> 
> That looks good, though I haven't tested it by hand myself.
> 
> While at this, please look at adding test cases covering this
> module, both the old and new signatures.

Done... I merged the topic to next in order to check that the tests work
on all the build machines.
Please have a look and let me know if the tests are good enough.

Cheers,
 Daniele

--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-10-02 Thread Brad King
On 10/02/2013 07:14 AM, Daniele E. Domenichelli wrote:
> On 25/09/13 18:49, Brad King wrote:
>> On 09/25/2013 12:16 PM, Daniele E. Domenichelli wrote:
>>> I updated the CheckStructHasMember_CXX topic.
>>
>> That looks good, though I haven't tested it by hand myself.
>>
>> While at this, please look at adding test cases covering this
>> module, both the old and new signatures.
> 
> Done... I merged the topic to next in order to check that the tests work
> on all the build machines.
> Please have a look and let me know if the tests are good enough.

They look good to me.  We'll see how the dashboards do.

You could also add a RunCMake/CheckModules case to check the
error conditions (bad args and bad language).

Thanks,
-Brad
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-10-02 Thread Daniele E. Domenichelli
On 02/10/13 16:23, Brad King wrote:
> You could also add a RunCMake/CheckModules case to check the
> error conditions (bad args and bad language).

Done!

Cheers,
 Daniele

--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-10-02 Thread Brad King
On 10/02/2013 12:36 PM, Daniele E. Domenichelli wrote:
> On 02/10/13 16:23, Brad King wrote:
>> You could also add a RunCMake/CheckModules case to check the
>> error conditions (bad args and bad language).
> 
> Done!

Wonderful, thanks!

-Brad
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-10-04 Thread Daniele E. Domenichelli
Hello,

On 02/10/13 16:23, Brad King wrote:
> They look good to me.  We'll see how the dashboards do.

Unfortunately one test is failing on several machines:

http://open.cdash.org/testSummary.php?project=1&name=CMakeOnly.CheckStructHasMember&date=2013-10-03

This is the test that is failing, according to my knowledge of C it
should build, even with very old compilers...


struct struct_with_member
{
int foo;
};

int main()
{
struct struct_with_member *tmp;
tmp->foo;
return 0;
}


Am I missing something? Is it possible to access to the
Tests/CMakeOnly/CheckStructHasMember-build/CMakeFiles/CMakeError.log
files on the build machines to have a better idea of what is going on?

Cheers,
 Daniele
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-10-04 Thread Rolf Eike Beer

Am 04.10.2013 11:46, schrieb Daniele E. Domenichelli:

Hello,

On 02/10/13 16:23, Brad King wrote:

They look good to me.  We'll see how the dashboards do.


Unfortunately one test is failing on several machines:

http://open.cdash.org/testSummary.php?project=1&name=CMakeOnly.CheckStructHasMember&date=2013-10-03

This is the test that is failing, according to my knowledge of C it
should build, even with very old compilers...


struct struct_with_member
{
int foo;
};

int main()
{
struct struct_with_member *tmp;
tmp->foo;
return 0;
}


Am I missing something? Is it possible to access to the
Tests/CMakeOnly/CheckStructHasMember-build/CMakeFiles/CMakeError.log
files on the build machines to have a better idea of what is going on?


Just some thoughts:
-some compilers may error out because you dereference an uninitialized 
pointer
-some compilers may complain because you perform an operation that does 
nothing, maybe prepend it with a (void) to mark that as intentional


What about this:

 struct struct_with_member tmp, *tmpp;
 tmp.foo = 0;
 tmpp = &tmp;
 return tmpp->foo;

Eike
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-10-04 Thread Brad King
On 10/04/2013 05:46 AM, Daniele E. Domenichelli wrote:
> This is the test that is failing, according to my knowledge of C it
> should build, even with very old compilers...

The problem is the empty struct:

 struct struct_with_non_existent_members {
 };

Some C compilers reject that.  You'll have to add a dummy member.

-Brad
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-10-04 Thread Daniele E. Domenichelli
On 04/10/13 12:20, Rolf Eike Beer wrote:
> Just some thoughts:
> -some compilers may error out because you dereference an uninitialized 
> pointer
> -some compilers may complain because you perform an operation that does 
> nothing, maybe prepend it with a (void) to mark that as intentional

This is the test that is currently executed, I just added some tests...


> What about this:
> 
>   struct struct_with_member tmp, *tmpp;
>   tmp.foo = 0;
>   tmpp = &tmp;
>   return tmpp->foo;

I saw at leas one case where CheckStructHasMember is used to check if a
struct has a method, so "foo()" instead of "foo"...
With such a change "tmp.foo() = 0" will fail, so it looks like a non
compatible change to me.
Also this requires that the struct has a public constructor.

If you are not against it, I would also like to change "int main()" to
"int main(int argc, char **argv)" because I found a library (ACE [1])
that causes the test to fail on windows due to some weird define (see [2])

[1]http://www.cs.wustl.edu/~schmidt/ACE.html
[2]http://doxygen.theaceorb.nl/libace-doc/a01553_source.html


So what about something like this?

   int main(int argc, char **argv)
   {
  (void)(argc); // To avoid warnings for unused parameters
  (void)(argv);
  struct struct_with_member *tmp = 0;
  void *tmpv = (void*)&(tmp->foo);
  (void)(tmpv);
  return tmpv;
   }


Cheers,
 Daniele
--

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


Re: [cmake-developers] CheckStructHasMember does not support C++ only structs

2013-10-04 Thread Daniele E. Domenichelli
On 04/10/13 14:34, Brad King wrote:
> The problem is the empty struct:
> 
>  struct struct_with_non_existent_members {
>  };
> 
> Some C compilers reject that.  You'll have to add a dummy member.

Oh, I see! I will fix this!

Thanks!

Daniele

--

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