cmStandardIncludes.h 11 KB

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