cmStandardIncludes.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. /**
  11. * Include header files as a function of the build process, compiler,
  12. * and operating system.
  13. */
  14. #ifndef cmStandardIncludes_h
  15. #define cmStandardIncludes_h
  16. // include configure generated header to define CMAKE_NO_ANSI_STREAM_HEADERS,
  17. // CMAKE_NO_STD_NAMESPACE, and other macros.
  18. #include "cmConfigure.h"
  19. #include <cmsys/Configure.hxx>
  20. #ifdef _MSC_VER
  21. #pragma warning ( disable : 4786 )
  22. #pragma warning ( disable : 4503 )
  23. #pragma warning ( disable : 4512 ) /* operator=() could not be generated */
  24. #define CMAKE_NO_ANSI_FOR_SCOPE
  25. #endif
  26. #ifdef __BORLANDC__
  27. # pragma warn -8030 /* Temporary used for parameter */
  28. # pragma warn -8027 /* 'for' not inlined. */
  29. # pragma warn -8026 /* 'exception' not inlined. */
  30. # pragma warn -8004 /* value never used */
  31. #endif
  32. #ifdef __ICL
  33. #pragma warning ( disable : 985 )
  34. #endif
  35. #include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
  36. // This is a hack to prevent warnings about these functions being
  37. // declared but not referenced.
  38. #if defined(__sgi) && !defined(__GNUC__)
  39. # include <sys/termios.h>
  40. class cmStandardIncludesHack
  41. {
  42. public:
  43. enum
  44. {
  45. Ref1 = sizeof(cfgetospeed(0)),
  46. Ref2 = sizeof(cfgetispeed(0)),
  47. Ref3 = sizeof(tcgetattr(0, 0)),
  48. Ref4 = sizeof(tcsetattr(0, 0, 0)),
  49. Ref5 = sizeof(cfsetospeed(0,0)),
  50. Ref6 = sizeof(cfsetispeed(0,0))
  51. };
  52. };
  53. #endif
  54. // Include stream compatibility layer from KWSys.
  55. // This is needed to work with large file support
  56. // on some platforms whose stream operators do not
  57. // support the large integer types.
  58. #if defined(CMAKE_BUILD_WITH_CMAKE)
  59. # include <cmsys/IOStream.hxx>
  60. # undef GetCurrentDirectory // Borland <iosfwd> includes windows.h
  61. #endif
  62. // Avoid warnings in system headers.
  63. #if defined(_MSC_VER)
  64. # pragma warning (push,1)
  65. #endif
  66. #if defined(__BORLANDC__)
  67. # pragma warn -8008 /* condition is always false (RESET BELOW!) */
  68. # pragma warn -8066 /* unreachable code (RESET BELOW!) */
  69. #endif
  70. #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
  71. # include <fstream>
  72. # include <iostream>
  73. # include <iomanip>
  74. #else
  75. # include <fstream.h>
  76. # include <iostream.h>
  77. # include <iomanip.h>
  78. #endif
  79. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  80. # include <sstream>
  81. #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
  82. # include <strstream>
  83. #else
  84. # include <strstream.h>
  85. #endif
  86. // we must have stl with the standard include style
  87. #include <vector>
  88. #include <string>
  89. #include <iterator>
  90. #include <algorithm>
  91. #include <functional>
  92. #include <map>
  93. #include <list>
  94. #include <set>
  95. #include <deque>
  96. #if defined(__BORLANDC__)
  97. # pragma warn .8008 /* condition is always false (disabled above) */
  98. # pragma warn .8066 /* unreachable code (disabled above) */
  99. #endif
  100. #if defined(_MSC_VER)
  101. # pragma warning(pop)
  102. #endif
  103. // include the "c" string header
  104. #include <string.h>
  105. #include <stdio.h>
  106. #include <stdlib.h>
  107. // Borland C++ defines several of the stdlib.h and string.h symbols in
  108. // sub-headers search.h and mem.h. These sub-headers have using
  109. // declarations to pull functions from the std namespace to the global
  110. // namespace, but they are defined only if the header was not included
  111. // through the C++-style cstdlib or cstring header. These outer
  112. // headers are included by the streams library in C++-style and
  113. // include blockers are put in place that prevent including the
  114. // C-style versions from ever including the sub-headers. Therefore we
  115. // have to include the sub-headers here to get the using declarations.
  116. #if defined(__BORLANDC__)
  117. # include <mem.h> /* mem... functions from string.h */
  118. # include <search.h> /* search functions from stdlib.h */
  119. #endif
  120. #if !defined(_WIN32) && defined(__COMO__)
  121. // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
  122. extern "C"
  123. {
  124. extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
  125. extern int pclose (FILE *__stream) __THROW;
  126. extern char *realpath (__const char *__restrict __name,
  127. char *__restrict __resolved) __THROW;
  128. extern char *strdup (__const char *__s) __THROW;
  129. extern int putenv (char *__string) __THROW;
  130. }
  131. #endif
  132. // if std:: is not supported, then just #define it away
  133. #ifdef CMAKE_NO_STD_NAMESPACE
  134. #define std
  135. #endif
  136. // if the compiler does not support ansi for scoping of vars use a
  137. // #define hack
  138. #ifdef CMAKE_NO_ANSI_FOR_SCOPE
  139. #define for if(false) {} else for
  140. #endif
  141. // check for the 720 compiler on the SGI
  142. // which has some strange properties that I don't think are worth
  143. // checking for in a general way in configure
  144. #if defined(__sgi) && !defined(__GNUC__)
  145. # if (_COMPILER_VERSION >= 730)
  146. # define CM_SGI_CC_730
  147. # elif (_COMPILER_VERSION >= 720)
  148. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  149. # endif
  150. #endif
  151. #ifdef __DECCXX_VER
  152. # if __DECCXX_VER <= 60390008
  153. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  154. # endif
  155. #endif
  156. #if defined( _MSC_VER )
  157. typedef unsigned short mode_t;
  158. #endif
  159. #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  160. // some compilers have std:: but not for the stream library,
  161. // so we have to bring it into the std namespace by hand.
  162. namespace std {
  163. using ::ostream;
  164. using ::istream;
  165. using ::ios;
  166. using ::cout;
  167. using ::cerr;
  168. using ::cin;
  169. using ::ifstream;
  170. using ::ofstream;
  171. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  172. using ::ostringstream;
  173. using ::istringstream;
  174. #else
  175. using ::ostrstream;
  176. using ::istrstream;
  177. #endif
  178. using ::endl;
  179. using ::ends;
  180. using ::flush;
  181. using ::dec;
  182. using ::hex;
  183. using ::setw;
  184. using ::setiosflags;
  185. using ::setfill;
  186. using ::setprecision;
  187. }
  188. // The string class is missing these operators so add them
  189. #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
  190. # define cmsys_STL_STRING_NO_NEQ_CHAR
  191. inline bool operator!=(std::string const& a, const char* b)
  192. { return !(a==std::string(b)); }
  193. #endif
  194. inline bool operator==(std::string const& a, const char* b)
  195. { return (a==std::string(b)); }
  196. # endif // end CM_SGI_CC_720
  197. #if defined(__sgi) && !defined(__GNUC__)
  198. # pragma set woff 1375 /* base class destructor not virtual */
  199. #endif
  200. // use this class to shrink the size of symbols in .o files
  201. // std::string is really basic_string<....lots of stuff....>
  202. // when combined with a map or set, the symbols can be > 2000 chars!
  203. #include <cmsys/String.hxx>
  204. typedef cmsys::String cmStdString;
  205. // Define cmOStringStream and cmIStringStream wrappers to hide
  206. // differences between std::stringstream and the old strstream.
  207. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  208. class cmOStringStream: public std::ostringstream
  209. {
  210. public:
  211. cmOStringStream() {}
  212. private:
  213. cmOStringStream(const cmOStringStream&);
  214. void operator=(const cmOStringStream&);
  215. };
  216. class cmIStringStream: public std::istringstream
  217. {
  218. public:
  219. typedef std::istringstream Superclass;
  220. cmIStringStream() {}
  221. cmIStringStream(const std::string& s): Superclass(s) {}
  222. private:
  223. cmIStringStream(const cmIStringStream&);
  224. void operator=(const cmIStringStream&);
  225. };
  226. #else
  227. class cmOStrStreamCleanup
  228. {
  229. public:
  230. cmOStrStreamCleanup(std::ostrstream& ostr): OStrStream(ostr) {}
  231. ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
  232. static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
  233. protected:
  234. std::ostrstream& OStrStream;
  235. };
  236. class cmOStringStream: public std::ostrstream
  237. {
  238. public:
  239. typedef std::ostrstream Superclass;
  240. cmOStringStream() {}
  241. std::string str()
  242. {
  243. cmOStrStreamCleanup cleanup(*this);
  244. cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
  245. int pcount = this->pcount();
  246. const char* ptr = this->Superclass::str();
  247. return std::string(ptr?ptr:"", pcount);
  248. }
  249. private:
  250. cmOStringStream(const cmOStringStream&);
  251. void operator=(const cmOStringStream&);
  252. };
  253. class cmIStringStream: private std::string, public std::istrstream
  254. {
  255. public:
  256. typedef std::string StdString;
  257. typedef std::istrstream IStrStream;
  258. cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
  259. cmIStringStream(const std::string& s):
  260. StdString(s), IStrStream(StdString::c_str()) {}
  261. std::string str() const { return *this; }
  262. void str(const std::string& s)
  263. {
  264. // Very dangerous. If this throws, the object is hosed. When the
  265. // destructor is later called, the program is hosed too.
  266. this->~cmIStringStream();
  267. new (this) cmIStringStream(s);
  268. }
  269. private:
  270. cmIStringStream(const cmIStringStream&);
  271. void operator=(const cmIStringStream&);
  272. };
  273. #endif
  274. /* Poison this operator to avoid common mistakes. */
  275. extern void operator << (std::ostream&, const cmOStringStream&);
  276. /** Standard documentation entry for cmDocumentation's formatting. */
  277. struct cmDocumentationEntry
  278. {
  279. std::string Name;
  280. std::string Brief;
  281. std::string Full;
  282. cmDocumentationEntry(){};
  283. cmDocumentationEntry(const char *doc[3])
  284. { if (doc[0]) this->Name = doc[0];
  285. if (doc[1]) this->Brief = doc[1];
  286. if (doc[2]) this->Full = doc[2]; };
  287. cmDocumentationEntry(const char *n, const char *b, const char *f)
  288. { if (n) this->Name = n; if (b) this->Brief = b; if (f) this->Full = f; };
  289. };
  290. /** Data structure to represent a single command line. */
  291. class cmCustomCommandLine: public std::vector<std::string>
  292. {
  293. public:
  294. typedef std::vector<std::string> Superclass;
  295. typedef Superclass::iterator iterator;
  296. typedef Superclass::const_iterator const_iterator;
  297. };
  298. /** Data structure to represent a list of command lines. */
  299. class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
  300. {
  301. public:
  302. typedef std::vector<cmCustomCommandLine> Superclass;
  303. typedef Superclass::iterator iterator;
  304. typedef Superclass::const_iterator const_iterator;
  305. };
  306. #if defined(__sgi) && !defined(__GNUC__)
  307. # pragma reset woff 1375 /* base class destructor not virtual */
  308. #endif
  309. // All subclasses of cmCommand or cmCTestGenericHandler should
  310. // invoke this macro.
  311. #define cmTypeMacro(thisClass,superclass) \
  312. virtual const char* GetNameOfClass() { return #thisClass; } \
  313. typedef superclass Superclass; \
  314. static bool IsTypeOf(const char *type) \
  315. { \
  316. if ( !strcmp(#thisClass,type) ) \
  317. { \
  318. return true; \
  319. } \
  320. return Superclass::IsTypeOf(type); \
  321. } \
  322. virtual bool IsA(const char *type) \
  323. { \
  324. return thisClass::IsTypeOf(type); \
  325. } \
  326. static thisClass* SafeDownCast(cmObject *c) \
  327. { \
  328. if ( c && c->IsA(#thisClass) ) \
  329. { \
  330. return static_cast<thisClass *>(c); \
  331. } \
  332. return 0;\
  333. }
  334. #endif