1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmStandardIncludes.h,v $
6 Date: $Date: 2009-06-12 15:05:02 $
7 Version: $Revision: 1.76 $
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 =========================================================================*/
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>
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
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 */
44 #pragma warning ( disable : 985 )
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
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))
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
77 // Avoid warnings in system headers.
79 # pragma warning (push,1)
81 #if defined(__BORLANDC__)
82 # pragma warn -8008 /* condition is always false (RESET BELOW!) */
83 # pragma warn -8066 /* unreachable code (RESET BELOW!) */
86 #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
92 # include <iostream.h>
96 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
98 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
101 # include <strstream.h>
104 // we must have stl with the standard include style
109 #include <functional>
115 #if defined(__BORLANDC__)
116 # pragma warn .8008 /* condition is always false (disabled above) */
117 # pragma warn .8066 /* unreachable code (disabled above) */
119 #if defined(_MSC_VER)
120 # pragma warning(pop)
123 // include the "c" string header
128 // Borland C++ defines several of the stdlib.h and string.h symbols in
129 // sub-headers search.h and mem.h. These sub-headers have using
130 // declarations to pull functions from the std namespace to the global
131 // namespace, but they are defined only if the header was not included
132 // through the C++-style cstdlib or cstring header. These outer
133 // headers are included by the streams library in C++-style and
134 // include blockers are put in place that prevent including the
135 // C-style versions from ever including the sub-headers. Therefore we
136 // have to include the sub-headers here to get the using declarations.
137 #if defined(__BORLANDC__)
138 # include <mem.h> /* mem... functions from string.h */
139 # include <search.h> /* search functions from stdlib.h */
143 #if !defined(_WIN32) && defined(__COMO__)
144 // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
147 extern FILE *popen (__const
char *__command
, __const
char *__modes
) __THROW
;
148 extern int pclose (FILE *__stream
) __THROW
;
149 extern char *realpath (__const
char *__restrict __name
,
150 char *__restrict __resolved
) __THROW
;
151 extern char *strdup (__const
char *__s
) __THROW
;
152 extern int putenv (char *__string
) __THROW
;
156 // if std:: is not supported, then just #define it away
157 #ifdef CMAKE_NO_STD_NAMESPACE
161 // if the compiler does not support ansi for scoping of vars use a
163 #ifdef CMAKE_NO_ANSI_FOR_SCOPE
164 #define for if(false) {} else for
167 // check for the 720 compiler on the SGI
168 // which has some strange properties that I don't think are worth
169 // checking for in a general way in configure
170 #if defined(__sgi) && !defined(__GNUC__)
171 # if (_COMPILER_VERSION >= 730)
172 # define CM_SGI_CC_730
173 # elif (_COMPILER_VERSION >= 720)
174 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
179 # if __DECCXX_VER <= 60390008
180 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
184 #if defined( _MSC_VER )
185 typedef unsigned short mode_t
;
189 #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
190 // some compilers have std:: but not for the stream library,
191 // so we have to bring it into the std namespace by hand.
202 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
203 using ::ostringstream
;
204 using ::istringstream
;
218 using ::setprecision
;
220 // The string class is missing these operators so add them
221 #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
222 # define cmsys_STL_STRING_NO_NEQ_CHAR
223 inline bool operator!=(std::string
const& a
, const char* b
)
224 { return !(a
==std::string(b
)); }
227 inline bool operator==(std::string
const& a
, const char* b
)
228 { return (a
==std::string(b
)); }
229 # endif // end CM_SGI_CC_720
231 #if defined(__sgi) && !defined(__GNUC__)
232 # pragma set woff 1375 /* base class destructor not virtual */
235 // use this class to shrink the size of symbols in .o files
236 // std::string is really basic_string<....lots of stuff....>
237 // when combined with a map or set, the symbols can be > 2000 chars!
238 #include <cmsys/String.hxx>
239 typedef cmsys::String cmStdString
;
241 // Define cmOStringStream and cmIStringStream wrappers to hide
242 // differences between std::stringstream and the old strstream.
243 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
244 class cmOStringStream
: public std::ostringstream
249 cmOStringStream(const cmOStringStream
&);
250 void operator=(const cmOStringStream
&);
252 class cmIStringStream
: public std::istringstream
255 typedef std::istringstream Superclass
;
257 cmIStringStream(const std::string
& s
): Superclass(s
) {}
259 cmIStringStream(const cmIStringStream
&);
260 void operator=(const cmIStringStream
&);
263 class cmOStrStreamCleanup
266 cmOStrStreamCleanup(std::ostrstream
& ostr
): OStrStream(ostr
) {}
267 ~cmOStrStreamCleanup() { this->OStrStream
.rdbuf()->freeze(0); }
268 static void IgnoreUnusedVariable(const cmOStrStreamCleanup
&) {}
270 std::ostrstream
& OStrStream
;
273 class cmOStringStream
: public std::ostrstream
276 typedef std::ostrstream Superclass
;
280 cmOStrStreamCleanup
cleanup(*this);
281 cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup
);
282 int pcount
= this->pcount();
283 const char* ptr
= this->Superclass::str();
284 return std::string(ptr
?ptr
:"", pcount
);
287 cmOStringStream(const cmOStringStream
&);
288 void operator=(const cmOStringStream
&);
291 class cmIStringStream
: private std::string
, public std::istrstream
294 typedef std::string StdString
;
295 typedef std::istrstream IStrStream
;
296 cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
297 cmIStringStream(const std::string
& s
):
298 StdString(s
), IStrStream(StdString::c_str()) {}
299 std::string
str() const { return *this; }
300 void str(const std::string
& s
)
302 // Very dangerous. If this throws, the object is hosed. When the
303 // destructor is later called, the program is hosed too.
304 this->~cmIStringStream();
305 new (this) cmIStringStream(s
);
308 cmIStringStream(const cmIStringStream
&);
309 void operator=(const cmIStringStream
&);
313 /* Poison this operator to avoid common mistakes. */
314 extern void operator << (std::ostream
&, const cmOStringStream
&);
316 /** Standard documentation entry for cmDocumentation's formatting. */
317 struct cmDocumentationEntry
322 cmDocumentationEntry(){};
323 cmDocumentationEntry(const char *doc
[3])
324 { if (doc
[0]) this->Name
= doc
[0];
325 if (doc
[1]) this->Brief
= doc
[1];
326 if (doc
[2]) this->Full
= doc
[2]; };
327 cmDocumentationEntry(const char *n
, const char *b
, const char *f
)
328 { if (n
) this->Name
= n
; if (b
) this->Brief
= b
; if (f
) this->Full
= f
; };
331 /** Data structure to represent a single command line. */
332 class cmCustomCommandLine
: public std::vector
<std::string
>
335 typedef std::vector
<std::string
> Superclass
;
336 typedef Superclass::iterator iterator
;
337 typedef Superclass::const_iterator const_iterator
;
340 /** Data structure to represent a list of command lines. */
341 class cmCustomCommandLines
: public std::vector
<cmCustomCommandLine
>
344 typedef std::vector
<cmCustomCommandLine
> Superclass
;
345 typedef Superclass::iterator iterator
;
346 typedef Superclass::const_iterator const_iterator
;
349 #if defined(__sgi) && !defined(__GNUC__)
350 # pragma reset woff 1375 /* base class destructor not virtual */
353 // All subclasses of cmCommand or cmCTestGenericHandler should
354 // invoke this macro.
355 #define cmTypeMacro(thisClass,superclass) \
356 virtual const char* GetNameOfClass() { return #thisClass; } \
357 typedef superclass Superclass; \
358 static bool IsTypeOf(const char *type) \
360 if ( !strcmp(#thisClass,type) ) \
364 return Superclass::IsTypeOf(type); \
366 virtual bool IsA(const char *type) \
368 return thisClass::IsTypeOf(type); \
370 static thisClass* SafeDownCast(cmObject *c) \
372 if ( c && c->IsA(#thisClass) ) \
374 return static_cast<thisClass *>(c); \