From ac6eaee5832d8da90e46be4f88ddfe668f2bd94c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 10 May 2018 18:58:29 +0100 Subject: [PATCH] Fixed build when OSG_ENVVAR_SUPPORTED is disabled and quietened down warnings using OSG_UNUSED* macros --- include/osg/Export | 7 +++++++ include/osg/os_utils | 14 +++++++++++++- src/osg/os_utils.cpp | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/osg/Export b/include/osg/Export index cb23a796c..350f5a26d 100644 --- a/include/osg/Export +++ b/include/osg/Export @@ -56,6 +56,13 @@ #endif #endif +// helper macro's for quieten unused variable warnings +#define OSG_UNUSED(VAR) (void)(VAR) +#define OSG_UNUSED2(VAR1, VAR2) (void)(VAR1); (void)(VAR2); +#define OSG_UNUSED3(VAR1, VAR2, VAR3) (void)(VAR1); (void)(VAR2); (void)(VAR2); +#define OSG_UNUSED4(VAR1, VAR2, VAR3, VAR4) (void)(VAR1); (void)(VAR2); (void)(VAR3); (void)(VAR4); +#define OSG_UNUSED5(VAR1, VAR2, VAR3, VAR4, VAR5) (void)(VAR1); (void)(VAR2); (void)(VAR3); (void)(VAR4); (void)(VAR5); + /** \namespace osg diff --git a/include/osg/os_utils b/include/osg/os_utils index b46073f5b..27bdec2a2 100644 --- a/include/osg/os_utils +++ b/include/osg/os_utils @@ -30,6 +30,8 @@ extern OSG_EXPORT int osg_system(const char* str); #ifdef __cplusplus +#include + #if defined(OSG_ENVVAR_SUPPORTED) #include #include @@ -47,11 +49,16 @@ inline unsigned int getClampedLength(const char* str, unsigned int maxNumChars=4 inline std::string getEnvVar(const char* name) { +#ifdef OSG_ENVVAR_SUPPORTED std::string value; const char* ptr = getenv(name); if (ptr) value.assign(ptr, getClampedLength(ptr)); return value; - } +#else + OSG_UNUSED(name); + return std::string(); +#endif +} template @@ -65,6 +72,7 @@ inline bool getEnvVar(const char* name, T& value) str >> value; return !str.fail(); #else + OSG_UNUSED2(name, value); return false; #endif } @@ -79,6 +87,7 @@ inline bool getEnvVar(const char* name, std::string& value) value.assign(ptr, getClampedLength(ptr)); return true; #else + OSG_UNUSED2(name, value); return false; #endif } @@ -94,6 +103,7 @@ inline bool getEnvVar(const char* name, T1& value1, T2& value2) str >> value1 >> value2; return !str.fail(); #else + OSG_UNUSED3(name, value1, value2); return false; #endif } @@ -109,6 +119,7 @@ inline bool getEnvVar(const char* name, T1& value1, T2& value2, T3& value3) str >> value1 >> value2 >> value3; return !str.fail(); #else + OSG_UNUSED4(name, value1, value2, value3); return false; #endif } @@ -124,6 +135,7 @@ inline bool getEnvVar(const char* name, T1& value1, T2& value2, T3& value3, T4& str >> value1 >> value2 >> value3 >> value4; return !str.fail(); #else + OSG_UNUSED5(name, value1, value2, value3, value4); return false; #endif } diff --git a/src/osg/os_utils.cpp b/src/osg/os_utils.cpp index 1bb70c2fc..f5a85d60f 100644 --- a/src/osg/os_utils.cpp +++ b/src/osg/os_utils.cpp @@ -33,6 +33,8 @@ int osg_system(const char* command) #else // use tranditional C sysmtem call for osg_system implementation +#include + int osg_system(const char* command) { return system(command);