Workaround for compilation on OpenBSD 5.6

On OpenBSD 5.6 sys/ucred.h uses NGROUP define, but misses include to
sys/param.h in which NGROUP is defined. sys/ucred.h is included in
sys/mount.h which we need to get the cached ram. Because of this include
chain our compilation will fail with missing NGROUP define. This can be
resolved by including in our code (and in correct order) system headers.
This commit is contained in:
Pawel "l0ner" Soltys 2015-01-26 19:48:56 +01:00
parent d516985146
commit c052f58eab
2 changed files with 17 additions and 1 deletions

@ -72,6 +72,9 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
message(STATUS "OpenBSD detected") message(STATUS "OpenBSD detected")
message(WARNING "OpenBSD is still experimental!") message(WARNING "OpenBSD is still experimental!")
set(METER_SOURCES "openbsd/memory.cc" "openbsd/cpu.cc" "openbsd/load.cc") set(METER_SOURCES "openbsd/memory.cc" "openbsd/cpu.cc" "openbsd/load.cc")
if(CMAKE_SYSTEM_VERSION VERSION_LESS 5.7)
add_definitions(-DOPENBSD_WORKAROUND=1)
endif()
else() else()
message(FATAL_ERROR "Cannot be compiled on this system") message(FATAL_ERROR "Cannot be compiled on this system")
endif() endif()

@ -18,9 +18,22 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
// Ugly fix to compilation on OpenBSD 5.6
// these need to be before include sys/mount.h
// and be in this exact order. Otherwise compiling on
// OpenBSD 5.6 will fail with missing NGROUPS define
// or missing gid_t typedefs
#ifdef OPENBSD_WORKAROUND
#include <sys/types.h> // typedefs
#include <sys/param.h> // missing NGROUPS
#include <sys/ucred.h>
#else
#include <sys/types.h>
#endif
#include <sys/mount.h> // VFS_* which we use to get cache #include <sys/mount.h> // VFS_* which we use to get cache
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/vmmeter.h> // vmtotal struct #include <sys/vmmeter.h> // vmtotal struct
#include "error.h" #include "error.h"