ENH: use .exe on vms
[cmake.git] / Source / cmStandardIncludes.h
blobe472d17f5d634374178e753394bebd377bbe6925
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmStandardIncludes.h,v $
5 Language: C++
6 Date: $Date: 2009-06-09 19:58:52 $
7 Version: $Revision: 1.75 $
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 // include configure generated header to define CMAKE_NO_ANSI_STREAM_HEADERS,
25 // CMAKE_NO_STD_NAMESPACE, and other macros.
26 #include "cmConfigure.h"
27 #include <cmsys/Configure.hxx>
29 #ifdef _MSC_VER
30 #pragma warning ( disable : 4786 )
31 #pragma warning ( disable : 4503 )
32 #pragma warning ( disable : 4512 ) /* operator=() could not be generated */
33 #define CMAKE_NO_ANSI_FOR_SCOPE
34 #endif
36 #ifdef __BORLANDC__
37 # pragma warn -8030 /* Temporary used for parameter */
38 # pragma warn -8027 /* 'for' not inlined. */
39 # pragma warn -8026 /* 'exception' not inlined. */
40 # pragma warn -8004 /* value never used */
41 #endif
43 #ifdef __ICL
44 #pragma warning ( disable : 985 )
45 #endif
47 #include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
49 // This is a hack to prevent warnings about these functions being
50 // declared but not referenced.
51 #if defined(__sgi) && !defined(__GNUC__)
52 # include <sys/termios.h>
53 class cmStandardIncludesHack
55 public:
56 enum
58 Ref1 = sizeof(cfgetospeed(0)),
59 Ref2 = sizeof(cfgetispeed(0)),
60 Ref3 = sizeof(tcgetattr(0, 0)),
61 Ref4 = sizeof(tcsetattr(0, 0, 0)),
62 Ref5 = sizeof(cfsetospeed(0,0)),
63 Ref6 = sizeof(cfsetispeed(0,0))
66 #endif
68 // Include stream compatibility layer from KWSys.
69 // This is needed to work with large file support
70 // on some platforms whose stream operators do not
71 // support the large integer types.
72 #if defined(CMAKE_BUILD_WITH_CMAKE)
73 # include <cmsys/IOStream.hxx>
74 # undef GetCurrentDirectory // Borland <iosfwd> includes windows.h
75 #endif
77 // Avoid warnings in system headers.
78 #if defined(_MSC_VER)
79 # pragma warning (push,1)
80 #endif
82 #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
83 # include <fstream>
84 # include <iostream>
85 # include <iomanip>
86 #else
87 # include <fstream.h>
88 # include <iostream.h>
89 # include <iomanip.h>
90 #endif
92 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
93 # include <sstream>
94 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
95 # include <strstream>
96 #else
97 # include <strstream.h>
98 #endif
100 // we must have stl with the standard include style
101 #include <vector>
102 #include <string>
103 #include <iterator>
104 #include <algorithm>
105 #include <functional>
106 #include <map>
107 #include <list>
108 #include <set>
109 #include <deque>
111 #if defined(_MSC_VER)
112 # pragma warning(pop)
113 #endif
115 // include the "c" string header
116 #include <string.h>
117 #include <stdio.h>
118 #include <stdlib.h>
120 // Borland C++ defines several of the stdlib.h and string.h symbols in
121 // sub-headers search.h and mem.h. These sub-headers have using
122 // declarations to pull functions from the std namespace to the global
123 // namespace, but they are defined only if the header was not included
124 // through the C++-style cstdlib or cstring header. These outer
125 // headers are included by the streams library in C++-style and
126 // include blockers are put in place that prevent including the
127 // C-style versions from ever including the sub-headers. Therefore we
128 // have to include the sub-headers here to get the using declarations.
129 #if defined(__BORLANDC__)
130 # include <mem.h> /* mem... functions from string.h */
131 # include <search.h> /* search functions from stdlib.h */
132 #endif
135 #if !defined(_WIN32) && defined(__COMO__)
136 // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
137 extern "C"
139 extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
140 extern int pclose (FILE *__stream) __THROW;
141 extern char *realpath (__const char *__restrict __name,
142 char *__restrict __resolved) __THROW;
143 extern char *strdup (__const char *__s) __THROW;
144 extern int putenv (char *__string) __THROW;
146 #endif
148 // if std:: is not supported, then just #define it away
149 #ifdef CMAKE_NO_STD_NAMESPACE
150 #define std
151 #endif
153 // if the compiler does not support ansi for scoping of vars use a
154 // #define hack
155 #ifdef CMAKE_NO_ANSI_FOR_SCOPE
156 #define for if(false) {} else for
157 #endif
159 // check for the 720 compiler on the SGI
160 // which has some strange properties that I don't think are worth
161 // checking for in a general way in configure
162 #if defined(__sgi) && !defined(__GNUC__)
163 # if (_COMPILER_VERSION >= 730)
164 # define CM_SGI_CC_730
165 # elif (_COMPILER_VERSION >= 720)
166 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
167 # endif
168 #endif
170 #ifdef __DECCXX_VER
171 # if __DECCXX_VER <= 60390008
172 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
173 # endif
174 #endif
176 #if defined( _MSC_VER )
177 typedef unsigned short mode_t;
178 #endif
181 #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
182 // some compilers have std:: but not for the stream library,
183 // so we have to bring it into the std namespace by hand.
184 namespace std {
185 using ::ostream;
186 using ::istream;
187 using ::ios;
188 using ::cout;
189 using ::cerr;
190 using ::cin;
191 using ::ifstream;
192 using ::ofstream;
194 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
195 using ::ostringstream;
196 using ::istringstream;
197 #else
198 using ::ostrstream;
199 using ::istrstream;
200 #endif
202 using ::endl;
203 using ::ends;
204 using ::flush;
205 using ::dec;
206 using ::hex;
207 using ::setw;
208 using ::setiosflags;
209 using ::setfill;
210 using ::setprecision;
212 // The string class is missing these operators so add them
213 #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
214 # define cmsys_STL_STRING_NO_NEQ_CHAR
215 inline bool operator!=(std::string const& a, const char* b)
216 { return !(a==std::string(b)); }
217 #endif
219 inline bool operator==(std::string const& a, const char* b)
220 { return (a==std::string(b)); }
221 # endif // end CM_SGI_CC_720
223 #if defined(__sgi) && !defined(__GNUC__)
224 # pragma set woff 1375 /* base class destructor not virtual */
225 #endif
227 // use this class to shrink the size of symbols in .o files
228 // std::string is really basic_string<....lots of stuff....>
229 // when combined with a map or set, the symbols can be > 2000 chars!
230 #include <cmsys/String.hxx>
231 typedef cmsys::String cmStdString;
233 // Define cmOStringStream and cmIStringStream wrappers to hide
234 // differences between std::stringstream and the old strstream.
235 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
236 class cmOStringStream: public std::ostringstream
238 public:
239 cmOStringStream() {}
240 private:
241 cmOStringStream(const cmOStringStream&);
242 void operator=(const cmOStringStream&);
244 class cmIStringStream: public std::istringstream
246 public:
247 typedef std::istringstream Superclass;
248 cmIStringStream() {}
249 cmIStringStream(const std::string& s): Superclass(s) {}
250 private:
251 cmIStringStream(const cmIStringStream&);
252 void operator=(const cmIStringStream&);
254 #else
255 class cmOStrStreamCleanup
257 public:
258 cmOStrStreamCleanup(std::ostrstream& ostr): OStrStream(ostr) {}
259 ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
260 static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
261 protected:
262 std::ostrstream& OStrStream;
265 class cmOStringStream: public std::ostrstream
267 public:
268 typedef std::ostrstream Superclass;
269 cmOStringStream() {}
270 std::string str()
272 cmOStrStreamCleanup cleanup(*this);
273 cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
274 int pcount = this->pcount();
275 const char* ptr = this->Superclass::str();
276 return std::string(ptr?ptr:"", pcount);
278 private:
279 cmOStringStream(const cmOStringStream&);
280 void operator=(const cmOStringStream&);
283 class cmIStringStream: private std::string, public std::istrstream
285 public:
286 typedef std::string StdString;
287 typedef std::istrstream IStrStream;
288 cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
289 cmIStringStream(const std::string& s):
290 StdString(s), IStrStream(StdString::c_str()) {}
291 std::string str() const { return *this; }
292 void str(const std::string& s)
294 // Very dangerous. If this throws, the object is hosed. When the
295 // destructor is later called, the program is hosed too.
296 this->~cmIStringStream();
297 new (this) cmIStringStream(s);
299 private:
300 cmIStringStream(const cmIStringStream&);
301 void operator=(const cmIStringStream&);
303 #endif
305 /* Poison this operator to avoid common mistakes. */
306 extern void operator << (std::ostream&, const cmOStringStream&);
308 /** Standard documentation entry for cmDocumentation's formatting. */
309 struct cmDocumentationEntry
311 std::string Name;
312 std::string Brief;
313 std::string Full;
314 cmDocumentationEntry(){};
315 cmDocumentationEntry(const char *doc[3])
316 { if (doc[0]) this->Name = doc[0];
317 if (doc[1]) this->Brief = doc[1];
318 if (doc[2]) this->Full = doc[2]; };
319 cmDocumentationEntry(const char *n, const char *b, const char *f)
320 { if (n) this->Name = n; if (b) this->Brief = b; if (f) this->Full = f; };
323 /** Data structure to represent a single command line. */
324 class cmCustomCommandLine: public std::vector<std::string>
326 public:
327 typedef std::vector<std::string> Superclass;
328 typedef Superclass::iterator iterator;
329 typedef Superclass::const_iterator const_iterator;
332 /** Data structure to represent a list of command lines. */
333 class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
335 public:
336 typedef std::vector<cmCustomCommandLine> Superclass;
337 typedef Superclass::iterator iterator;
338 typedef Superclass::const_iterator const_iterator;
341 #if defined(__sgi) && !defined(__GNUC__)
342 # pragma reset woff 1375 /* base class destructor not virtual */
343 #endif
345 // All subclasses of cmCommand or cmCTestGenericHandler should
346 // invoke this macro.
347 #define cmTypeMacro(thisClass,superclass) \
348 virtual const char* GetNameOfClass() { return #thisClass; } \
349 typedef superclass Superclass; \
350 static bool IsTypeOf(const char *type) \
352 if ( !strcmp(#thisClass,type) ) \
354 return true; \
356 return Superclass::IsTypeOf(type); \
358 virtual bool IsA(const char *type) \
360 return thisClass::IsTypeOf(type); \
362 static thisClass* SafeDownCast(cmObject *c) \
364 if ( c && c->IsA(#thisClass) ) \
366 return static_cast<thisClass *>(c); \
368 return 0;\
373 #endif