From bca434de78b4069c0597697a0893bbde7702c40b Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 31 Dec 2014 16:34:22 +0500 Subject: Hopefully fix compilation error after recent update --- extern/libmv/CMakeLists.txt | 3 + extern/libmv/SConscript | 3 +- extern/libmv/bundle.sh | 7 +- extern/libmv/files.txt | 2 + extern/libmv/third_party/gflags/windows_port.cc | 71 +++++++++++++ extern/libmv/third_party/gflags/windows_port.h | 127 ++++++++++++++++++++++++ 6 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 extern/libmv/third_party/gflags/windows_port.cc create mode 100644 extern/libmv/third_party/gflags/windows_port.h (limited to 'extern/libmv') diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index 4528c0b4dd2..80e64046534 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -307,6 +307,9 @@ if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING)) third_party/glog/src/windows/glog/log_severity.h third_party/glog/src/windows/port.h third_party/glog/src/windows/config.h + + third_party/gflags/windows_port.cc + third_party/gflags/windows_port.h ) else() list(APPEND GLOG_SRC diff --git a/extern/libmv/SConscript b/extern/libmv/SConscript index 6211bf66512..251e5835d64 100644 --- a/extern/libmv/SConscript +++ b/extern/libmv/SConscript @@ -47,7 +47,6 @@ if env['WITH_BF_LIBMV']: src += env.Glob('libmv/numeric/*.cc') src += env.Glob('libmv/simple_pipeline/*.cc') src += env.Glob('libmv/tracking/*.cc') - src += env.Glob('third_party/gflags/*.cc') else: src = env.Glob("intern/stub.cc") @@ -57,10 +56,12 @@ env.BlenderLib(libname = 'extern_libmv', sources=src, includes=Split(incs), defi if env['WITH_BF_LIBMV'] or (env['WITH_BF_CYCLES'] and env['WITH_BF_CYCLES_LOGGING']): glog_src = [] + glog_src += env.Glob("third_party/gflags/*.cc") if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc', 'win64-mingw'): glog_src += ['./third_party/glog/src/logging.cc', './third_party/glog/src/raw_logging.cc', './third_party/glog/src/utilities.cc', './third_party/glog/src/vlog_is_on.cc'] glog_src += ['./third_party/glog/src/windows/port.cc'] else: + glog_src.remove('third_party/gflags/windows_port.cc') glog_src += env.Glob("third_party/glog/src/*.cc") env.BlenderLib(libname = 'extern_glog', sources=glog_src, includes=Split(incs), defines=defs, libtype=['extern', 'player'], priority=[20,137]) diff --git a/extern/libmv/bundle.sh b/extern/libmv/bundle.sh index f8aaaa966f4..c10a5fbbad2 100755 --- a/extern/libmv/bundle.sh +++ b/extern/libmv/bundle.sh @@ -75,7 +75,7 @@ for x in $src_dir $src_third_dir; do fi fi - if test `echo $x | grep -c windows ` -eq 0; then + if test `echo $x | grep -c "windows\|gflags" ` -eq 0; then if [ -z "$src" ]; then src=$t else @@ -262,6 +262,9 @@ ${third_gflags_headers} third_party/glog/src/windows/glog/log_severity.h third_party/glog/src/windows/port.h third_party/glog/src/windows/config.h + + third_party/gflags/windows_port.cc + third_party/gflags/windows_port.h ) else() list(APPEND GLOG_SRC @@ -328,10 +331,12 @@ env.BlenderLib(libname = 'extern_libmv', sources=src, includes=Split(incs), defi if env['WITH_BF_LIBMV'] or (env['WITH_BF_CYCLES'] and env['WITH_BF_CYCLES_LOGGING']): glog_src = [] + glog_src += env.Glob("third_party/gflags/*.cc") if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc', 'win64-mingw'): glog_src += ['./third_party/glog/src/logging.cc', './third_party/glog/src/raw_logging.cc', './third_party/glog/src/utilities.cc', './third_party/glog/src/vlog_is_on.cc'] glog_src += ['./third_party/glog/src/windows/port.cc'] else: + glog_src.remove('third_party/gflags/windows_port.cc') glog_src += env.Glob("third_party/glog/src/*.cc") env.BlenderLib(libname = 'extern_glog', sources=glog_src, includes=Split(incs), defines=defs, libtype=['extern', 'player'], priority=[20,137]) diff --git a/extern/libmv/files.txt b/extern/libmv/files.txt index 91a529beb5a..11f8ef24781 100644 --- a/extern/libmv/files.txt +++ b/extern/libmv/files.txt @@ -147,6 +147,8 @@ third_party/gflags/mutex.h third_party/gflags/NEWS.txt third_party/gflags/README.libmv third_party/gflags/util.h +third_party/gflags/windows_port.cc +third_party/gflags/windows_port.h third_party/glog/AUTHORS third_party/glog/ChangeLog third_party/glog/COPYING diff --git a/extern/libmv/third_party/gflags/windows_port.cc b/extern/libmv/third_party/gflags/windows_port.cc new file mode 100644 index 00000000000..1f40458e888 --- /dev/null +++ b/extern/libmv/third_party/gflags/windows_port.cc @@ -0,0 +1,71 @@ +/* Copyright (c) 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --- + * Author: Craig Silverstein + */ + +#ifndef _WIN32 +# error You should only be including windows/port.cc in a windows environment! +#endif + +#include // for strlen(), memset(), memcmp() +#include +#include // for va_list, va_start, va_end +#include + +#include "windows_port.h" + +// These call the windows _vsnprintf, but always NUL-terminate. +#if !defined(__MINGW32__) && !defined(__MINGW64__) /* mingw already defines */ + +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable: 4996) // ignore _vsnprintf security warning +#endif +int safe_vsnprintf(char *str, size_t size, const char *format, va_list ap) { + if (size == 0) // not even room for a \0? + return -1; // not what C99 says to do, but what windows does + str[size-1] = '\0'; + return _vsnprintf(str, size-1, format, ap); +} +#ifdef _MSC_VER +# pragma warning(pop) +#endif + +int snprintf(char *str, size_t size, const char *format, ...) { + int r; + va_list ap; + va_start(ap, format); + r = vsnprintf(str, size, format, ap); + va_end(ap); + return r; +} + +#endif /* #if !defined(__MINGW32__) && !defined(__MINGW64__) */ diff --git a/extern/libmv/third_party/gflags/windows_port.h b/extern/libmv/third_party/gflags/windows_port.h new file mode 100644 index 00000000000..c8ff24f8f00 --- /dev/null +++ b/extern/libmv/third_party/gflags/windows_port.h @@ -0,0 +1,127 @@ +/* Copyright (c) 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * --- + * Author: Craig Silverstein + * + * These are some portability typedefs and defines to make it a bit + * easier to compile this code under VC++. + * + * Several of these are taken from glib: + * http://developer.gnome.org/doc/API/glib/glib-windows-compatability-functions.html + */ + +#ifndef GFLAGS_WINDOWS_PORT_H_ +#define GFLAGS_WINDOWS_PORT_H_ + +#include "config.h" + +// This must be defined before the windows.h is included. +// It's needed for mutex.h, to give access to the TryLock method. +# if !defined(_WIN32_WINNT) && !(defined( __MINGW32__) || defined(__MINGW64__)) +# define _WIN32_WINNT 0x0400 +# endif +// We always want minimal includes +#ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include +#include /* for mkdir */ +#include /* for _putenv, getenv */ +#include /* need this to override stdio's snprintf, also defines _unlink used by unit tests */ +#include /* util.h uses va_copy */ +#include /* for _stricmp and _strdup */ + +/* We can't just use _vsnprintf and _snprintf as drop-in-replacements, + * because they don't always NUL-terminate. :-( We also can't use the + * name vsnprintf, since windows defines that (but not snprintf (!)). + */ +#if !defined(__MINGW32__) && !defined(__MINGW64__) /* mingw already defines */ +extern GFLAGS_DLL_DECL int snprintf(char *str, size_t size, + const char *format, ...); +extern int GFLAGS_DLL_DECL safe_vsnprintf(char *str, size_t size, + const char *format, va_list ap); +#define vsnprintf(str, size, format, ap) safe_vsnprintf(str, size, format, ap) +#define va_copy(dst, src) (dst) = (src) +#endif /* #if !defined(__MINGW32__) && !defined(__MINGW64__) */ + +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable: 4996) // ignore getenv security warning +#endif +inline void setenv(const char* name, const char* value, int) { + // In windows, it's impossible to set a variable to the empty string. + // We handle this by setting it to "0" and the NUL-ing out the \0. + // That is, we putenv("FOO=0") and then find out where in memory the + // putenv wrote "FOO=0", and change it in-place to "FOO=\0". + // c.f. http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/environ.cpp?r1=611451&r2=637508&pathrev=637508 + static const char* const kFakeZero = "0"; + if (*value == '\0') + value = kFakeZero; + // Apparently the semantics of putenv() is that the input + // must live forever, so we leak memory here. :-( + const size_t nameval_len = strlen(name) + 1 + strlen(value) + 1; + char* nameval = reinterpret_cast(malloc(nameval_len)); + snprintf(nameval, nameval_len, "%s=%s", name, value); + _putenv(nameval); + if (value == kFakeZero) { + nameval[nameval_len - 2] = '\0'; // works when putenv() makes no copy + if (*getenv(name) != '\0') + *getenv(name) = '\0'; // works when putenv() copies nameval + } +} +#ifdef _MSC_VER +# pragma warning(pop) +#endif + +#define strcasecmp _stricmp + +#if defined(_MSC_VER) && _MSC_VER >= 1400 +#define strdup _strdup +#define unlink _unlink +#endif + +#define PRId32 "d" +#define PRIu32 "u" +#define PRId64 "I64d" +#define PRIu64 "I64u" + +#if !defined(__MINGW32__) && !defined(__MINGW64__) +#define strtoq _strtoi64 +#define strtouq _strtoui64 +#define strtoll _strtoi64 +#define strtoull _strtoui64 +#define atoll _atoi64 +#endif + +#ifndef PATH_MAX +#define PATH_MAX 1024 +#endif + +#endif /* GFLAGS_WINDOWS_PORT_H_ */ -- cgit v1.2.3