Port Ceres to Windows
This is a preliminary, but full, port of Ceres to Windows.
Currently all tests compile and run, with only system_test
failing to work correctly due to a path issue.
Change-Id: I4152c1588bf51ffd7f4d9401ef9759f5d28c299c
diff --git a/include/ceres/internal/fixed_array.h b/include/ceres/internal/fixed_array.h
index aa1722c..e11b71b 100644
--- a/include/ceres/internal/fixed_array.h
+++ b/include/ceres/internal/fixed_array.h
@@ -69,6 +69,12 @@
// Non-POD types will be default-initialized just like regular vectors or
// arrays.
+#if defined(_WIN64)
+ typedef __int64 ssize_t;
+#elif defined(_WIN32)
+ typedef __int32 ssize_t;
+#endif
+
template <typename T, ssize_t inline_elements = -1>
class FixedArray {
public:
@@ -152,13 +158,13 @@
// Allocate some space, not an array of elements of type T, so that we can
// skip calling the T constructors and destructors for space we never use.
- ManualConstructor<InnerContainer> inline_space_[kInlineElements] CERES_ALIGN_ATTRIBUTE(16);
+ ManualConstructor<InnerContainer> CERES_ALIGN_ATTRIBUTE(16) inline_space_[kInlineElements];
};
// Implementation details follow
template <class T, ssize_t S>
-inline FixedArray<T, S>::FixedArray(FixedArray<T, S>::size_type n)
+inline FixedArray<T, S>::FixedArray(typename FixedArray<T, S>::size_type n)
: size_(n),
array_((n <= kInlineElements
? reinterpret_cast<InnerContainer*>(inline_space_)
diff --git a/include/ceres/internal/macros.h b/include/ceres/internal/macros.h
index 0e84e9c..83ec311 100644
--- a/include/ceres/internal/macros.h
+++ b/include/ceres/internal/macros.h
@@ -83,7 +83,7 @@
// That gcc wants both of these prototypes seems mysterious. VC, for
// its part, can't decide which to use (another mystery). Matching of
// template overloads: the final frontier.
-#ifndef COMPILER_MSVC
+#ifndef _WIN32
template <typename T, size_t N>
char (&ArraySizeHelper(const T (&array)[N]))[N];
#endif
@@ -131,12 +131,13 @@
//
// - wan 2005-11-16
//
-// Starting with Visual C++ 2005, WinNT.h includes ARRAYSIZE.
-#if !defined(COMPILER_MSVC) || (defined(_MSC_VER) && _MSC_VER < 1400)
-#define ARRAYSIZE(a) \
+// Starting with Visual C++ 2005, WinNT.h includes ARRAYSIZE. However,
+// the definition comes from the over-broad windows.h header that
+// introduces a macro, ERROR, that conflicts with the logging framework
+// that Ceres uses. Instead, rename ARRAYSIZE to CERES_ARRAYSIZE.
+#define CERES_ARRAYSIZE(a) \
((sizeof(a) / sizeof(*(a))) / \
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
-#endif
// Tell the compiler to warn about unused return values for functions declared
// with this macro. The macro should be used on function declarations