how to check for a struct in multiple headers?

Benjamin Reed rangerrick at gmail.com
Fri Mar 31 05:50:12 CEST 2006


I need to make the test for statfs try sys/mount.h, currently I get
the following when compiling kdecore:

---(snip!)---
/Users/ranger/cvs/kdelibs/kdecore/kmountpoint.cpp: In static member
function 'static QList<KSharedPtr<KMountPoint> >
KMountPoint::currentMountPoints(int)':
/Users/ranger/cvs/kdelibs/kdecore/kmountpoint.cpp:231: error: cannot
convert 'statvfs**' to 'statfs**' for argument '1' to 'int
getmntinfo(statfs**, int)'
/Users/ranger/cvs/kdelibs/kdecore/kmountpoint.cpp:236: error: invalid
use of undefined type 'struct statvfs'
/Users/ranger/cvs/kdelibs/kdecore/kmountpoint.cpp:226: error: forward
declaration of 'struct statvfs'
---(snip!)---

The problem is that we're testing 2 things, "have statvfs" and "have
sys/mount.h", and assuming that if both are true, then we should use
statvfs for mount (which is not true on OSX).

Right now, the tests look like this:

---(snip!)---
set(CMAKE_EXTRA_INCLUDE_FILES sys/statvfs.h)
check_type_size("struct statvfs" HAVE_STRUCT_STATVFS)
SET(CMAKE_EXTRA_INCLUDE_FILES)  #reset CMAKE_EXTRA_INCLUDE_FILES

set(CMAKE_EXTRA_INCLUDE_FILES sys/statfs.h)
check_type_size("struct statfs" HAVE_STRUCT_STATFS)
SET(CMAKE_EXTRA_INCLUDE_FILES)  #reset CMAKE_EXTRA_INCLUDE_FILES
---(snip!)---

The first ends up true, the second ends up false, because struct
statfs is defined in sys/mount.h instead.

If I just create another test that does:

---(snip!)---
set(CMAKE_EXTRA_INCLUDE_FILES sys/mount.h)
check_type_size("struct statfs" HAVE_STRUCT_STATFS)
SET(CMAKE_EXTRA_INCLUDE_FILES)  #reset CMAKE_EXTRA_INCLUDE_FILES
---(snip!)---

...I assume that means I'll be breaking the test for people that have
struct statfs inside sys/statfs.h.  Is that correct?

What I really want is for HAVE_STRUCT_STATFS to be set if struct
statfs is in sys/statfs.h *or* sys/mount.h.


More information about the Kde-buildsystem mailing list