1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmStandardIncludes.h,v $
6 <<<<<<< cmStandardIncludes.h
7 Date: $Date: 2008/02/24 19:05:11 $
8 Version: $Revision: 1.72 $
10 Date: $Date: 2009-03-05 20:17:06 $
11 Version: $Revision: 1.73 $
14 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
15 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
17 This software is distributed WITHOUT ANY WARRANTY; without even
18 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 PURPOSE. See the above copyright notices for more information.
21 =========================================================================*/
23 * Include header files as a function of the build process, compiler,
24 * and operating system.
26 #ifndef cmStandardIncludes_h
27 #define cmStandardIncludes_h
29 // include configure generated header to define CMAKE_NO_ANSI_STREAM_HEADERS,
30 // CMAKE_NO_STD_NAMESPACE, and other macros.
31 #include "cmConfigure.h"
32 #include <cmsys/Configure.hxx>
35 #pragma warning ( disable : 4786 )
36 #pragma warning ( disable : 4503 )
37 #pragma warning ( disable : 4512 ) /* operator=() could not be generated */
38 #define CMAKE_NO_ANSI_FOR_SCOPE
42 #pragma warn -8030 /* Temporary used for parameter */
46 #pragma warning ( disable : 985 )
49 #include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
51 // This is a hack to prevent warnings about these functions being
52 // declared but not referenced.
53 #if defined(__sgi) && !defined(__GNUC__)
54 # include <sys/termios.h>
55 class cmStandardIncludesHack
60 Ref1
= sizeof(cfgetospeed(0)),
61 Ref2
= sizeof(cfgetispeed(0)),
62 Ref3
= sizeof(tcgetattr(0, 0)),
63 Ref4
= sizeof(tcsetattr(0, 0, 0)),
64 Ref5
= sizeof(cfsetospeed(0,0)),
65 Ref6
= sizeof(cfsetispeed(0,0))
70 // Include stream compatibility layer from KWSys.
71 // This is needed to work with large file support
72 // on some platforms whose stream operators do not
73 // support the large integer types.
74 #if defined(CMAKE_BUILD_WITH_CMAKE)
75 # include <cmsys/IOStream.hxx>
76 # undef GetCurrentDirectory // Borland <iosfwd> includes windows.h
79 // Avoid warnings in system headers.
81 # pragma warning (push,1)
84 #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
90 # include <iostream.h>
94 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
96 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
99 # include <strstream.h>
102 // we must have stl with the standard include style
107 #include <functional>
113 #if defined(_MSC_VER)
114 # pragma warning(pop)
117 // include the "c" string header
122 // Borland C++ defines several of the stdlib.h and string.h symbols in
123 // sub-headers search.h and mem.h. These sub-headers have using
124 // declarations to pull functions from the std namespace to the global
125 // namespace, but they are defined only if the header was not included
126 // through the C++-style cstdlib or cstring header. These outer
127 // headers are included by the streams library in C++-style and
128 // include blockers are put in place that prevent including the
129 // C-style versions from ever including the sub-headers. Therefore we
130 // have to include the sub-headers here to get the using declarations.
131 #if defined(__BORLANDC__)
132 # include <mem.h> /* mem... functions from string.h */
133 # include <search.h> /* search functions from stdlib.h */
137 #if !defined(_WIN32) && defined(__COMO__)
138 // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
141 extern FILE *popen (__const
char *__command
, __const
char *__modes
) __THROW
;
142 extern int pclose (FILE *__stream
) __THROW
;
143 extern char *realpath (__const
char *__restrict __name
,
144 char *__restrict __resolved
) __THROW
;
145 extern char *strdup (__const
char *__s
) __THROW
;
146 extern int putenv (char *__string
) __THROW
;
150 // if std:: is not supported, then just #define it away
151 #ifdef CMAKE_NO_STD_NAMESPACE
155 // if the compiler does not support ansi for scoping of vars use a
157 #ifdef CMAKE_NO_ANSI_FOR_SCOPE
158 #define for if(false) {} else for
161 // check for the 720 compiler on the SGI
162 // which has some strange properties that I don't think are worth
163 // checking for in a general way in configure
164 #if defined(__sgi) && !defined(__GNUC__)
165 # if (_COMPILER_VERSION >= 730)
166 # define CM_SGI_CC_730
167 # elif (_COMPILER_VERSION >= 720)
168 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
173 # if __DECCXX_VER <= 60390008
174 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
178 #if defined( _MSC_VER )
179 typedef unsigned short mode_t
;
183 #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
184 // some compilers have std:: but not for the stream library,
185 // so we have to bring it into the std namespace by hand.
196 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
197 using ::ostringstream
;
198 using ::istringstream
;
212 using ::setprecision
;
214 // The string class is missing these operators so add them
215 #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
216 # define cmsys_STL_STRING_NO_NEQ_CHAR
217 inline bool operator!=(std::string
const& a
, const char* b
)
218 { return !(a
==std::string(b
)); }
221 inline bool operator==(std::string
const& a
, const char* b
)
222 { return (a
==std::string(b
)); }
223 # endif // end CM_SGI_CC_720
225 #if defined(__sgi) && !defined(__GNUC__)
226 # pragma set woff 1375 /* base class destructor not virtual */
229 // use this class to shrink the size of symbols in .o files
230 // std::string is really basic_string<....lots of stuff....>
231 // when combined with a map or set, the symbols can be > 2000 chars!
232 #include <cmsys/String.hxx>
233 typedef cmsys::String cmStdString
;
235 // Define cmOStringStream and cmIStringStream wrappers to hide
236 // differences between std::stringstream and the old strstream.
237 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
238 class cmOStringStream
: public std::ostringstream
243 cmOStringStream(const cmOStringStream
&);
244 void operator=(const cmOStringStream
&);
246 class cmIStringStream
: public std::istringstream
249 typedef std::istringstream Superclass
;
251 cmIStringStream(const std::string
& s
): Superclass(s
) {}
253 cmIStringStream(const cmIStringStream
&);
254 void operator=(const cmIStringStream
&);
257 class cmOStrStreamCleanup
260 cmOStrStreamCleanup(std::ostrstream
& ostr
): OStrStream(ostr
) {}
261 ~cmOStrStreamCleanup() { this->OStrStream
.rdbuf()->freeze(0); }
262 static void IgnoreUnusedVariable(const cmOStrStreamCleanup
&) {}
264 std::ostrstream
& OStrStream
;
267 class cmOStringStream
: public std::ostrstream
270 typedef std::ostrstream Superclass
;
274 cmOStrStreamCleanup
cleanup(*this);
275 cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup
);
276 int pcount
= this->pcount();
277 const char* ptr
= this->Superclass::str();
278 return std::string(ptr
?ptr
:"", pcount
);
281 cmOStringStream(const cmOStringStream
&);
282 void operator=(const cmOStringStream
&);
285 class cmIStringStream
: private std::string
, public std::istrstream
288 typedef std::string StdString
;
289 typedef std::istrstream IStrStream
;
290 cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
291 cmIStringStream(const std::string
& s
):
292 StdString(s
), IStrStream(StdString::c_str()) {}
293 std::string
str() const { return *this; }
294 void str(const std::string
& s
)
296 // Very dangerous. If this throws, the object is hosed. When the
297 // destructor is later called, the program is hosed too.
298 this->~cmIStringStream();
299 new (this) cmIStringStream(s
);
302 cmIStringStream(const cmIStringStream
&);
303 void operator=(const cmIStringStream
&);
307 /* Poison this operator to avoid common mistakes. */
308 extern void operator << (std::ostream
&, const cmOStringStream
&);
310 /** Standard documentation entry for cmDocumentation's formatting. */
311 struct cmDocumentationEntry
316 cmDocumentationEntry(){};
317 cmDocumentationEntry(const char *doc
[3])
318 { if (doc
[0]) this->Name
= doc
[0];
319 if (doc
[1]) this->Brief
= doc
[1];
320 if (doc
[2]) this->Full
= doc
[2]; };
321 cmDocumentationEntry(const char *n
, const char *b
, const char *f
)
322 { if (n
) this->Name
= n
; if (b
) this->Brief
= b
; if (f
) this->Full
= f
; };
325 /** Data structure to represent a single command line. */
326 class cmCustomCommandLine
: public std::vector
<std::string
>
329 typedef std::vector
<std::string
> Superclass
;
330 typedef Superclass::iterator iterator
;
331 typedef Superclass::const_iterator const_iterator
;
334 /** Data structure to represent a list of command lines. */
335 class cmCustomCommandLines
: public std::vector
<cmCustomCommandLine
>
338 typedef std::vector
<cmCustomCommandLine
> Superclass
;
339 typedef Superclass::iterator iterator
;
340 typedef Superclass::const_iterator const_iterator
;
343 #if defined(__sgi) && !defined(__GNUC__)
344 # pragma reset woff 1375 /* base class destructor not virtual */
347 // All subclasses of cmCommand or cmCTestGenericHandler should
348 // invoke this macro.
349 #define cmTypeMacro(thisClass,superclass) \
350 virtual const char* GetNameOfClass() { return #thisClass; } \
351 typedef superclass Superclass; \
352 static bool IsTypeOf(const char *type) \
354 if ( !strcmp(#thisClass,type) ) \
358 return Superclass::IsTypeOf(type); \
360 virtual bool IsA(const char *type) \
362 return thisClass::IsTypeOf(type); \
364 static thisClass* SafeDownCast(cmObject *c) \
366 if ( c && c->IsA(#thisClass) ) \
368 return static_cast<thisClass *>(c); \