BUG: fix some bad changes in progress calc
[cmake.git] / Source / cmStandardIncludes.h
blob99001bec89e69b25405c659c092f8958566cc8ca
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmStandardIncludes.h,v $
5 Language: C++
6 Date: $Date: 2008-02-24 19:05:11 $
7 Version: $Revision: 1.72 $
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 # undef GetCurrentDirectory // Borland <iosfwd> includes windows.h
87 #endif
89 // Avoid warnings in system headers.
90 #if defined(_MSC_VER)
91 # pragma warning (push,1)
92 #endif
94 #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
95 # include <fstream>
96 # include <iostream>
97 # include <iomanip>
98 #else
99 # include <fstream.h>
100 # include <iostream.h>
101 # include <iomanip.h>
102 #endif
104 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
105 # include <sstream>
106 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
107 # include <strstream>
108 #else
109 # include <strstream.h>
110 #endif
112 // we must have stl with the standard include style
113 #include <vector>
114 #include <string>
115 #include <iterator>
116 #include <algorithm>
117 #include <functional>
118 #include <map>
119 #include <list>
120 #include <set>
121 #include <deque>
123 #if defined(_MSC_VER)
124 # pragma warning(pop)
125 #endif
127 // include the "c" string header
128 #include <string.h>
129 #include <stdio.h>
130 #include <stdlib.h>
132 // Borland C++ defines several of the stdlib.h and string.h symbols in
133 // sub-headers search.h and mem.h. These sub-headers have using
134 // declarations to pull functions from the std namespace to the global
135 // namespace, but they are defined only if the header was not included
136 // through the C++-style cstdlib or cstring header. These outer
137 // headers are included by the streams library in C++-style and
138 // include blockers are put in place that prevent including the
139 // C-style versions from ever including the sub-headers. Therefore we
140 // have to include the sub-headers here to get the using declarations.
141 #if defined(__BORLANDC__)
142 # include <mem.h> /* mem... functions from string.h */
143 # include <search.h> /* search functions from stdlib.h */
144 #endif
147 #if !defined(_WIN32) && defined(__COMO__)
148 // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
149 extern "C"
151 extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
152 extern int pclose (FILE *__stream) __THROW;
153 extern char *realpath (__const char *__restrict __name,
154 char *__restrict __resolved) __THROW;
155 extern char *strdup (__const char *__s) __THROW;
156 extern int putenv (char *__string) __THROW;
158 #endif
160 // if std:: is not supported, then just #define it away
161 #ifdef CMAKE_NO_STD_NAMESPACE
162 #define std
163 #endif
165 // if the compiler does not support ansi for scoping of vars use a
166 // #define hack
167 #ifdef CMAKE_NO_ANSI_FOR_SCOPE
168 #define for if(false) {} else for
169 #endif
171 // check for the 720 compiler on the SGI
172 // which has some strange properties that I don't think are worth
173 // checking for in a general way in configure
174 #if defined(__sgi) && !defined(__GNUC__)
175 # if (_COMPILER_VERSION >= 730)
176 # define CM_SGI_CC_730
177 # elif (_COMPILER_VERSION >= 720)
178 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
179 # endif
180 #endif
182 #ifdef __DECCXX_VER
183 # if __DECCXX_VER <= 60390008
184 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
185 # endif
186 #endif
188 #if defined( _MSC_VER )
189 typedef unsigned short mode_t;
190 #endif
193 #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
194 // some compilers have std:: but not for the stream library,
195 // so we have to bring it into the std namespace by hand.
196 namespace std {
197 using ::ostream;
198 using ::istream;
199 using ::ios;
200 using ::cout;
201 using ::cerr;
202 using ::cin;
203 using ::ifstream;
204 using ::ofstream;
206 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
207 using ::ostringstream;
208 using ::istringstream;
209 #else
210 using ::ostrstream;
211 using ::istrstream;
212 #endif
214 using ::endl;
215 using ::ends;
216 using ::flush;
217 using ::dec;
218 using ::hex;
219 using ::setw;
220 using ::setiosflags;
221 using ::setfill;
222 using ::setprecision;
224 // The string class is missing these operators so add them
225 #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
226 # define cmsys_STL_STRING_NO_NEQ_CHAR
227 inline bool operator!=(std::string const& a, const char* b)
228 { return !(a==std::string(b)); }
229 #endif
231 inline bool operator==(std::string const& a, const char* b)
232 { return (a==std::string(b)); }
233 # endif // end CM_SGI_CC_720
235 #if defined(__sgi) && !defined(__GNUC__)
236 # pragma set woff 1375 /* base class destructor not virtual */
237 #endif
239 // use this class to shrink the size of symbols in .o files
240 // std::string is really basic_string<....lots of stuff....>
241 // when combined with a map or set, the symbols can be > 2000 chars!
242 #include <cmsys/String.hxx>
243 typedef cmsys::String cmStdString;
245 // Define cmOStringStream and cmIStringStream wrappers to hide
246 // differences between std::stringstream and the old strstream.
247 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
248 class cmOStringStream: public std::ostringstream
250 public:
251 cmOStringStream() {}
252 private:
253 cmOStringStream(const cmOStringStream&);
254 void operator=(const cmOStringStream&);
256 class cmIStringStream: public std::istringstream
258 public:
259 typedef std::istringstream Superclass;
260 cmIStringStream() {}
261 cmIStringStream(const std::string& s): Superclass(s) {}
262 private:
263 cmIStringStream(const cmIStringStream&);
264 void operator=(const cmIStringStream&);
266 #else
267 class cmOStrStreamCleanup
269 public:
270 cmOStrStreamCleanup(std::ostrstream& ostr): OStrStream(ostr) {}
271 ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
272 static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
273 protected:
274 std::ostrstream& OStrStream;
277 class cmOStringStream: public std::ostrstream
279 public:
280 typedef std::ostrstream Superclass;
281 cmOStringStream() {}
282 std::string str()
284 cmOStrStreamCleanup cleanup(*this);
285 cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
286 int pcount = this->pcount();
287 const char* ptr = this->Superclass::str();
288 return std::string(ptr?ptr:"", pcount);
290 private:
291 cmOStringStream(const cmOStringStream&);
292 void operator=(const cmOStringStream&);
295 class cmIStringStream: private std::string, public std::istrstream
297 public:
298 typedef std::string StdString;
299 typedef std::istrstream IStrStream;
300 cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
301 cmIStringStream(const std::string& s):
302 StdString(s), IStrStream(StdString::c_str()) {}
303 std::string str() const { return *this; }
304 void str(const std::string& s)
306 // Very dangerous. If this throws, the object is hosed. When the
307 // destructor is later called, the program is hosed too.
308 this->~cmIStringStream();
309 new (this) cmIStringStream(s);
311 private:
312 cmIStringStream(const cmIStringStream&);
313 void operator=(const cmIStringStream&);
315 #endif
317 /* Poison this operator to avoid common mistakes. */
318 extern void operator << (std::ostream&, const cmOStringStream&);
320 /** Standard documentation entry for cmDocumentation's formatting. */
321 struct cmDocumentationEntry
323 std::string Name;
324 std::string Brief;
325 std::string Full;
326 cmDocumentationEntry(){};
327 cmDocumentationEntry(const char *doc[3])
328 { if (doc[0]) this->Name = doc[0];
329 if (doc[1]) this->Brief = doc[1];
330 if (doc[2]) this->Full = doc[2]; };
331 cmDocumentationEntry(const char *n, const char *b, const char *f)
332 { if (n) this->Name = n; if (b) this->Brief = b; if (f) this->Full = f; };
335 /** Data structure to represent a single command line. */
336 class cmCustomCommandLine: public std::vector<std::string>
338 public:
339 typedef std::vector<std::string> Superclass;
340 typedef Superclass::iterator iterator;
341 typedef Superclass::const_iterator const_iterator;
344 /** Data structure to represent a list of command lines. */
345 class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
347 public:
348 typedef std::vector<cmCustomCommandLine> Superclass;
349 typedef Superclass::iterator iterator;
350 typedef Superclass::const_iterator const_iterator;
353 #if defined(__sgi) && !defined(__GNUC__)
354 # pragma reset woff 1375 /* base class destructor not virtual */
355 #endif
357 // All subclasses of cmCommand or cmCTestGenericHandler should
358 // invoke this macro.
359 #define cmTypeMacro(thisClass,superclass) \
360 virtual const char* GetNameOfClass() { return #thisClass; } \
361 typedef superclass Superclass; \
362 static bool IsTypeOf(const char *type) \
364 if ( !strcmp(#thisClass,type) ) \
366 return true; \
368 return Superclass::IsTypeOf(type); \
370 virtual bool IsA(const char *type) \
372 return thisClass::IsTypeOf(type); \
374 static thisClass* SafeDownCast(cmObject *c) \
376 if ( c && c->IsA(#thisClass) ) \
378 return static_cast<thisClass *>(c); \
380 return 0;\
385 #endif