1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
13 * Include header files as a function of the build process, compiler,
14 * and operating system.
16 #ifndef cmStandardIncludes_h
17 #define cmStandardIncludes_h
19 // include configure generated header to define CMAKE_NO_ANSI_STREAM_HEADERS,
20 // CMAKE_NO_STD_NAMESPACE, and other macros.
21 #include <cmConfigure.h>
22 #include <cmsys/Configure.hxx>
25 #pragma warning ( disable : 4786 )
26 #pragma warning ( disable : 4503 )
27 #pragma warning ( disable : 4512 ) /* operator=() could not be generated */
28 #define CMAKE_NO_ANSI_FOR_SCOPE
32 # pragma warn -8030 /* Temporary used for parameter */
33 # pragma warn -8027 /* 'for' not inlined. */
34 # pragma warn -8026 /* 'exception' not inlined. */
35 # pragma warn -8004 /* value never used */
39 #pragma warning ( disable : 985 )
40 #pragma warning ( disable : 1572 ) /* floating-point equality test */
43 #include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
45 // This is a hack to prevent warnings about these functions being
46 // declared but not referenced.
47 #if defined(__sgi) && !defined(__GNUC__)
48 # pragma set woff 3970 /* conversion from pointer to same-sized */
49 # include <sys/termios.h>
50 class cmStandardIncludesHack
55 Ref1 = sizeof(cfgetospeed(0)),
56 Ref2 = sizeof(cfgetispeed(0)),
57 Ref3 = sizeof(tcgetattr(0, 0)),
58 Ref4 = sizeof(tcsetattr(0, 0, 0)),
59 Ref5 = sizeof(cfsetospeed(0,0)),
60 Ref6 = sizeof(cfsetispeed(0,0))
65 // Include stream compatibility layer from KWSys.
66 // This is needed to work with large file support
67 // on some platforms whose stream operators do not
68 // support the large integer types.
69 #if defined(CMAKE_BUILD_WITH_CMAKE)
70 # include <cmsys/IOStream.hxx>
71 # undef GetCurrentDirectory // Borland <iosfwd> includes windows.h
74 // Avoid warnings in system headers.
76 # pragma warning (push,1)
78 #if defined(__BORLANDC__)
79 # pragma warn -8008 /* condition is always false (RESET BELOW!) */
80 # pragma warn -8066 /* unreachable code (RESET BELOW!) */
83 #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
89 # include <iostream.h>
93 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
95 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
98 # include <strstream.h>
101 // we must have stl with the standard include style
106 #include <functional>
112 #if defined(__BORLANDC__)
113 # pragma warn .8008 /* condition is always false (disabled above) */
114 # pragma warn .8066 /* unreachable code (disabled above) */
116 #if defined(_MSC_VER)
117 # pragma warning(pop)
120 // include the "c" string header
125 // Borland C++ defines several of the stdlib.h and string.h symbols in
126 // sub-headers search.h and mem.h. These sub-headers have using
127 // declarations to pull functions from the std namespace to the global
128 // namespace, but they are defined only if the header was not included
129 // through the C++-style cstdlib or cstring header. These outer
130 // headers are included by the streams library in C++-style and
131 // include blockers are put in place that prevent including the
132 // C-style versions from ever including the sub-headers. Therefore we
133 // have to include the sub-headers here to get the using declarations.
134 #if defined(__BORLANDC__)
135 # include <mem.h> /* mem... functions from string.h */
136 # include <search.h> /* search functions from stdlib.h */
140 #if !defined(_WIN32) && defined(__COMO__)
141 // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
144 extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
145 extern int pclose (FILE *__stream) __THROW;
146 extern char *realpath (__const char *__restrict __name,
147 char *__restrict __resolved) __THROW;
148 extern char *strdup (__const char *__s) __THROW;
149 extern int putenv (char *__string) __THROW;
153 // if std:: is not supported, then just #define it away
154 #ifdef CMAKE_NO_STD_NAMESPACE
158 // if the compiler does not support ansi for scoping of vars use a
160 #ifdef CMAKE_NO_ANSI_FOR_SCOPE
161 #define for if(false) {} else for
164 // Provide std::ios_base on ancient GCC 2.9x
165 #if defined(__GNUC__) && __GNUC__ < 3
166 namespace std { typedef ios ios_base; }
169 // check for the 720 compiler on the SGI
170 // which has some strange properties that I don't think are worth
171 // checking for in a general way in configure
172 #if defined(__sgi) && !defined(__GNUC__)
173 # if (_COMPILER_VERSION >= 730)
174 # define CM_SGI_CC_730
175 # elif (_COMPILER_VERSION >= 720)
176 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
181 # if __DECCXX_VER <= 60390008
182 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
186 #if defined( _MSC_VER )
187 typedef unsigned short mode_t;
191 #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
192 // some compilers have std:: but not for the stream library,
193 // so we have to bring it into the std namespace by hand.
204 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
205 using ::ostringstream;
206 using ::istringstream;
220 using ::setprecision;
222 // The string class is missing these operators so add them
223 #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
224 # define cmsys_STL_STRING_NO_NEQ_CHAR
225 inline bool operator!=(std::string const& a, const char* b)
226 { return !(a==std::string(b)); }
229 inline bool operator==(std::string const& a, const char* b)
230 { return (a==std::string(b)); }
231 # endif // end CM_SGI_CC_720
233 #if defined(__sgi) && !defined(__GNUC__)
234 # pragma set woff 1375 /* base class destructor not virtual */
237 // use this class to shrink the size of symbols in .o files
238 // std::string is really basic_string<....lots of stuff....>
239 // when combined with a map or set, the symbols can be > 2000 chars!
240 #include <cmsys/String.hxx>
241 typedef cmsys::String cmStdString;
243 // Define cmOStringStream and cmIStringStream wrappers to hide
244 // differences between std::stringstream and the old strstream.
245 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
246 class cmOStringStream: public std::ostringstream
252 cmOStringStream(const cmOStringStream&);
253 void operator=(const cmOStringStream&);
255 class cmIStringStream: public std::istringstream
258 typedef std::istringstream Superclass;
260 cmIStringStream(const std::string& s): Superclass(s) {}
262 cmIStringStream(const cmIStringStream&);
263 void operator=(const cmIStringStream&);
266 class cmOStrStreamCleanup
269 cmOStrStreamCleanup(std::ostrstream& ostr): OStrStream(ostr) {}
270 ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
271 static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
273 std::ostrstream& OStrStream;
276 class cmOStringStream: public std::ostrstream
279 typedef std::ostrstream Superclass;
283 cmOStrStreamCleanup cleanup(*this);
284 cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
285 int pcount = this->pcount();
286 const char* ptr = this->Superclass::str();
287 return std::string(ptr?ptr:"", pcount);
290 cmOStringStream(const cmOStringStream&);
291 void operator=(const cmOStringStream&);
294 class cmIStringStream: private std::string, public std::istrstream
297 typedef std::string StdString;
298 typedef std::istrstream IStrStream;
299 cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
300 cmIStringStream(const std::string& s):
301 StdString(s), IStrStream(StdString::c_str()) {}
302 std::string str() const { return *this; }
303 void str(const std::string& s)
305 // Very dangerous. If this throws, the object is hosed. When the
306 // destructor is later called, the program is hosed too.
307 this->~cmIStringStream();
308 new (this) cmIStringStream(s);
311 cmIStringStream(const cmIStringStream&);
312 void operator=(const cmIStringStream&);
316 /* Poison this operator to avoid common mistakes. */
317 extern void operator << (std::ostream&, const cmOStringStream&);
319 /** Standard documentation entry for cmDocumentation's formatting. */
320 struct cmDocumentationEntry
325 cmDocumentationEntry(){};
326 cmDocumentationEntry(const char *doc[3])
327 { if (doc[0]) this->Name = doc[0];
328 if (doc[1]) this->Brief = doc[1];
329 if (doc[2]) this->Full = doc[2]; };
330 cmDocumentationEntry(const char *n, const char *b, const char *f)
331 { if (n) this->Name = n; if (b) this->Brief = b; if (f) this->Full = f; };
334 /** Data structure to represent a single command line. */
335 class cmCustomCommandLine: public std::vector<std::string>
338 typedef std::vector<std::string> Superclass;
339 typedef Superclass::iterator iterator;
340 typedef Superclass::const_iterator const_iterator;
343 /** Data structure to represent a list of command lines. */
344 class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
347 typedef std::vector<cmCustomCommandLine> Superclass;
348 typedef Superclass::iterator iterator;
349 typedef Superclass::const_iterator const_iterator;
352 #if defined(__sgi) && !defined(__GNUC__)
353 # pragma reset woff 1375 /* base class destructor not virtual */
356 // All subclasses of cmCommand or cmCTestGenericHandler should
357 // invoke this macro.
358 #define cmTypeMacro(thisClass,superclass) \
359 virtual const char* GetNameOfClass() { return #thisClass; } \
360 typedef superclass Superclass; \
361 static bool IsTypeOf(const char *type) \
363 if ( !strcmp(#thisClass,type) ) \
367 return Superclass::IsTypeOf(type); \
369 virtual bool IsA(const char *type) \
371 return thisClass::IsTypeOf(type); \
373 static thisClass* SafeDownCast(cmObject *c) \
375 if ( c && c->IsA(#thisClass) ) \
377 return static_cast<thisClass *>(c); \