packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmStandardIncludes.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
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 ============================================================================*/
12 /**
13  * Include header files as a function of the build process, compiler,
14  * and operating system.
15  */
16 #ifndef cmStandardIncludes_h
17 #define cmStandardIncludes_h
18
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>
23
24 #ifdef _MSC_VER
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
29 #endif
30
31 #ifdef __BORLANDC__
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 */
36 #endif
37
38 #ifdef __ICL
39 #pragma warning ( disable : 985 )
40 #pragma warning ( disable : 1572 ) /* floating-point equality test */
41 #endif
42
43 #include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
44
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
51 {
52 public:
53   enum
54   {
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))
61   };
62 };
63 #endif
64
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
72 #endif
73
74 // Avoid warnings in system headers.
75 #if defined(_MSC_VER)
76 # pragma warning (push,1)
77 #endif
78 #if defined(__BORLANDC__)
79 # pragma warn -8008 /* condition is always false (RESET BELOW!) */
80 # pragma warn -8066 /* unreachable code (RESET BELOW!) */
81 #endif
82
83 #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
84 #  include <fstream>
85 #  include <iostream>
86 #  include <iomanip>
87 #else
88 #  include <fstream.h>
89 #  include <iostream.h>
90 #  include <iomanip.h>
91 #endif
92
93 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
94 #  include <sstream>
95 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
96 #  include <strstream>
97 #else
98 #  include <strstream.h>
99 #endif
100
101 // we must have stl with the standard include style
102 #include <vector>
103 #include <string>
104 #include <iterator>
105 #include <algorithm>
106 #include <functional>
107 #include <map>
108 #include <list>
109 #include <set>
110 #include <deque>
111
112 #if defined(__BORLANDC__)
113 # pragma warn .8008 /* condition is always false (disabled above) */
114 # pragma warn .8066 /* unreachable code (disabled above) */
115 #endif
116 #if defined(_MSC_VER)
117 # pragma warning(pop)
118 #endif
119
120 // include the "c" string header
121 #include <string.h>
122 #include <stdio.h>
123 #include <stdlib.h>
124
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 */
137 #endif
138
139
140 #if !defined(_WIN32) && defined(__COMO__)
141 // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
142 extern "C"
143 {
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;
150 }
151 #endif
152
153 // if std:: is not supported, then just #define it away
154 #ifdef CMAKE_NO_STD_NAMESPACE
155 #define std
156 #endif
157
158 // if the compiler does not support ansi for scoping of vars use a
159 // #define hack
160 #ifdef CMAKE_NO_ANSI_FOR_SCOPE
161 #define for if(false) {} else for
162 #endif
163
164 // Provide std::ios_base on ancient GCC 2.9x
165 #if defined(__GNUC__) && __GNUC__ < 3
166 namespace std { typedef ios ios_base; }
167 #endif
168
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
177 #  endif
178 #endif
179
180 #ifdef __DECCXX_VER
181 # if __DECCXX_VER <= 60390008
182 #  define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
183 # endif
184 #endif
185
186 #if defined( _MSC_VER )
187 typedef unsigned short mode_t;
188 #endif
189
190
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.
194 namespace std {
195 using ::ostream;
196 using ::istream;
197 using ::ios;
198 using ::cout;
199 using ::cerr;
200 using ::cin;
201 using ::ifstream;
202 using ::ofstream;
203
204 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
205   using ::ostringstream;
206   using ::istringstream;
207 #else
208   using ::ostrstream;
209   using ::istrstream;
210 #endif
211
212 using ::endl;
213 using ::ends;
214 using ::flush;
215 using ::dec;
216 using ::hex;
217 using ::setw;
218 using ::setiosflags;
219 using ::setfill;
220 using ::setprecision;
221 }
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)); }
227 #endif
228
229 inline bool operator==(std::string const& a, const char* b)
230 { return (a==std::string(b)); }
231 # endif  // end CM_SGI_CC_720
232
233 #if defined(__sgi) && !defined(__GNUC__)
234 # pragma set woff 1375 /* base class destructor not virtual */
235 #endif
236
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;
242
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
247 {
248 public:
249   cmOStringStream();
250   ~cmOStringStream();
251 private:
252   cmOStringStream(const cmOStringStream&);
253   void operator=(const cmOStringStream&);
254 };
255 class cmIStringStream: public std::istringstream
256 {
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&);
264 };
265 #else
266 class cmOStrStreamCleanup
267 {
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;
274 };
275
276 class cmOStringStream: public std::ostrstream
277 {
278 public:
279   typedef std::ostrstream Superclass;
280   cmOStringStream() {}
281   std::string str()
282     {
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);
288     }
289 private:
290   cmOStringStream(const cmOStringStream&);
291   void operator=(const cmOStringStream&);
292 };
293
294 class cmIStringStream: private std::string, public std::istrstream
295 {
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)
304     {
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);
309     }
310 private:
311   cmIStringStream(const cmIStringStream&);
312   void operator=(const cmIStringStream&);
313 };
314 #endif
315
316 /* Poison this operator to avoid common mistakes.  */
317 extern void operator << (std::ostream&, const cmOStringStream&);
318
319 /** Standard documentation entry for cmDocumentation's formatting.  */
320 struct cmDocumentationEntry
321 {
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; };
332 };
333
334 /** Data structure to represent a single command line.  */
335 class cmCustomCommandLine: public std::vector<std::string>
336 {
337 public:
338   typedef std::vector<std::string> Superclass;
339   typedef Superclass::iterator iterator;
340   typedef Superclass::const_iterator const_iterator;
341 };
342
343 /** Data structure to represent a list of command lines.  */
344 class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
345 {
346 public:
347   typedef std::vector<cmCustomCommandLine> Superclass;
348   typedef Superclass::iterator iterator;
349   typedef Superclass::const_iterator const_iterator;
350 };
351
352 #if defined(__sgi) && !defined(__GNUC__)
353 # pragma reset woff 1375 /* base class destructor not virtual */
354 #endif
355
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) \
362 { \
363   if ( !strcmp(#thisClass,type) ) \
364     { \
365     return true; \
366     } \
367   return Superclass::IsTypeOf(type); \
368 } \
369 virtual bool IsA(const char *type) \
370 { \
371   return thisClass::IsTypeOf(type); \
372 } \
373 static thisClass* SafeDownCast(cmObject *c) \
374 { \
375   if ( c && c->IsA(#thisClass) ) \
376     { \
377     return static_cast<thisClass *>(c); \
378     } \
379   return 0;\
380 }
381
382
383
384 #endif