Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmStandardIncludes.h
blob4633e76e5a84b24aff4ac2dbf5d434bc28dd38ce
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmStandardIncludes.h,v $
5 Language: C++
6 Date: $Date: 2007/12/29 04:07:14 $
7 Version: $Revision: 1.71 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 /**
18 * Include header files as a function of the build process, compiler,
19 * and operating system.
21 #ifndef cmStandardIncludes_h
22 #define cmStandardIncludes_h
24 #define CMAKE_TO_STRING(x) CMAKE_TO_STRING0(x)
25 #define CMAKE_TO_STRING0(x) #x
27 // include configure generated header to define CMAKE_NO_ANSI_STREAM_HEADERS,
28 // CMAKE_NO_STD_NAMESPACE, and other macros.
29 #include "cmConfigure.h"
30 #include <cmsys/Configure.hxx>
32 #define CMake_VERSION \
33 CMAKE_TO_STRING(CMake_VERSION_MAJOR) "." \
34 CMAKE_TO_STRING(CMake_VERSION_MINOR)
36 #define CMake_VERSION_FULL \
37 CMAKE_TO_STRING(CMake_VERSION_MAJOR) "." \
38 CMAKE_TO_STRING(CMake_VERSION_MINOR) "." \
39 CMAKE_TO_STRING(CMake_VERSION_PATCH)
41 #define CMake_VERSION_ENCODE(major, minor, patch) \
42 ((major)*0x10000u + (minor)*0x100u + (patch))
44 #ifdef _MSC_VER
45 #pragma warning ( disable : 4786 )
46 #pragma warning ( disable : 4503 )
47 #pragma warning ( disable : 4512 ) /* operator=() could not be generated */
48 #define CMAKE_NO_ANSI_FOR_SCOPE
49 #endif
51 #ifdef __BORLANDC__
52 #pragma warn -8030 /* Temporary used for parameter */
53 #endif
55 #ifdef __ICL
56 #pragma warning ( disable : 985 )
57 #endif
59 #include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
61 // This is a hack to prevent warnings about these functions being
62 // declared but not referenced.
63 #if defined(__sgi) && !defined(__GNUC__)
64 # include <sys/termios.h>
65 class cmStandardIncludesHack
67 public:
68 enum
70 Ref1 = sizeof(cfgetospeed(0)),
71 Ref2 = sizeof(cfgetispeed(0)),
72 Ref3 = sizeof(tcgetattr(0, 0)),
73 Ref4 = sizeof(tcsetattr(0, 0, 0)),
74 Ref5 = sizeof(cfsetospeed(0,0)),
75 Ref6 = sizeof(cfsetispeed(0,0))
78 #endif
80 // Include stream compatibility layer from KWSys.
81 // This is needed to work with large file support
82 // on some platforms whose stream operators do not
83 // support the large integer types.
84 #if defined(CMAKE_BUILD_WITH_CMAKE)
85 # include <cmsys/IOStream.hxx>
86 #endif
88 // Avoid warnings in system headers.
89 #if defined(_MSC_VER)
90 # pragma warning (push,1)
91 #endif
93 #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
94 # include <fstream>
95 # include <iostream>
96 # include <iomanip>
97 #else
98 # include <fstream.h>
99 # include <iostream.h>
100 # include <iomanip.h>
101 #endif
103 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
104 # include <sstream>
105 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
106 # include <strstream>
107 #else
108 # include <strstream.h>
109 #endif
111 // we must have stl with the standard include style
112 #include <vector>
113 #include <string>
114 #include <iterator>
115 #include <algorithm>
116 #include <functional>
117 #include <map>
118 #include <list>
119 #include <set>
120 #include <deque>
122 #if defined(_MSC_VER)
123 # pragma warning(pop)
124 #endif
126 // include the "c" string header
127 #include <string.h>
128 #include <stdio.h>
129 #include <stdlib.h>
131 // Borland C++ defines several of the stdlib.h and string.h symbols in
132 // sub-headers search.h and mem.h. These sub-headers have using
133 // declarations to pull functions from the std namespace to the global
134 // namespace, but they are defined only if the header was not included
135 // through the C++-style cstdlib or cstring header. These outer
136 // headers are included by the streams library in C++-style and
137 // include blockers are put in place that prevent including the
138 // C-style versions from ever including the sub-headers. Therefore we
139 // have to include the sub-headers here to get the using declarations.
140 #if defined(__BORLANDC__)
141 # include <mem.h> /* mem... functions from string.h */
142 # include <search.h> /* search functions from stdlib.h */
143 #endif
146 #if !defined(_WIN32) && defined(__COMO__)
147 // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
148 extern "C"
150 extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
151 extern int pclose (FILE *__stream) __THROW;
152 extern char *realpath (__const char *__restrict __name,
153 char *__restrict __resolved) __THROW;
154 extern char *strdup (__const char *__s) __THROW;
155 extern int putenv (char *__string) __THROW;
157 #endif
159 // if std:: is not supported, then just #define it away
160 #ifdef CMAKE_NO_STD_NAMESPACE
161 #define std
162 #endif
164 // if the compiler does not support ansi for scoping of vars use a
165 // #define hack
166 #ifdef CMAKE_NO_ANSI_FOR_SCOPE
167 #define for if(false) {} else for
168 #endif
170 // check for the 720 compiler on the SGI
171 // which has some strange properties that I don't think are worth
172 // checking for in a general way in configure
173 #if defined(__sgi) && !defined(__GNUC__)
174 # if (_COMPILER_VERSION >= 730)
175 # define CM_SGI_CC_730
176 # elif (_COMPILER_VERSION >= 720)
177 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
178 # endif
179 #endif
181 #ifdef __DECCXX_VER
182 # if __DECCXX_VER <= 60390008
183 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
184 # endif
185 #endif
187 #if defined( _MSC_VER )
188 typedef unsigned short mode_t;
189 #endif
192 #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
193 // some compilers have std:: but not for the stream library,
194 // so we have to bring it into the std namespace by hand.
195 namespace std {
196 using ::ostream;
197 using ::istream;
198 using ::ios;
199 using ::cout;
200 using ::cerr;
201 using ::cin;
202 using ::ifstream;
203 using ::ofstream;
205 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
206 using ::ostringstream;
207 using ::istringstream;
208 #else
209 using ::ostrstream;
210 using ::istrstream;
211 #endif
213 using ::endl;
214 using ::ends;
215 using ::flush;
216 using ::dec;
217 using ::hex;
218 using ::setw;
219 using ::setiosflags;
220 using ::setfill;
221 using ::setprecision;
223 // The string class is missing these operators so add them
224 #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
225 # define cmsys_STL_STRING_NO_NEQ_CHAR
226 inline bool operator!=(std::string const& a, const char* b)
227 { return !(a==std::string(b)); }
228 #endif
230 inline bool operator==(std::string const& a, const char* b)
231 { return (a==std::string(b)); }
232 # endif // end CM_SGI_CC_720
234 #if defined(__sgi) && !defined(__GNUC__)
235 # pragma set woff 1375 /* base class destructor not virtual */
236 #endif
238 // use this class to shrink the size of symbols in .o files
239 // std::string is really basic_string<....lots of stuff....>
240 // when combined with a map or set, the symbols can be > 2000 chars!
241 #include <cmsys/String.hxx>
242 typedef cmsys::String cmStdString;
244 // Define cmOStringStream and cmIStringStream wrappers to hide
245 // differences between std::stringstream and the old strstream.
246 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
247 class cmOStringStream: public std::ostringstream
249 public:
250 cmOStringStream() {}
251 private:
252 cmOStringStream(const cmOStringStream&);
253 void operator=(const cmOStringStream&);
255 class cmIStringStream: public std::istringstream
257 public:
258 typedef std::istringstream Superclass;
259 cmIStringStream() {}
260 cmIStringStream(const std::string& s): Superclass(s) {}
261 private:
262 cmIStringStream(const cmIStringStream&);
263 void operator=(const cmIStringStream&);
265 #else
266 class cmOStrStreamCleanup
268 public:
269 cmOStrStreamCleanup(std::ostrstream& ostr): OStrStream(ostr) {}
270 ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
271 static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
272 protected:
273 std::ostrstream& OStrStream;
276 class cmOStringStream: public std::ostrstream
278 public:
279 typedef std::ostrstream Superclass;
280 cmOStringStream() {}
281 std::string str()
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);
289 private:
290 cmOStringStream(const cmOStringStream&);
291 void operator=(const cmOStringStream&);
294 class cmIStringStream: private std::string, public std::istrstream
296 public:
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);
310 private:
311 cmIStringStream(const cmIStringStream&);
312 void operator=(const cmIStringStream&);
314 #endif
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
322 std::string Name;
323 std::string Brief;
324 std::string Full;
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>
337 public:
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>
346 public:
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 */
354 #endif
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) ) \
365 return true; \
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); \
379 return 0;\
384 #endif