cmStandardIncludes.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. /**
  14. * Include header files as a function of the build process, compiler,
  15. * and operating system.
  16. */
  17. #ifndef cmStandardIncludes_h
  18. #define cmStandardIncludes_h
  19. #define CMAKE_TO_STRING(x) CMAKE_TO_STRING0(x)
  20. #define CMAKE_TO_STRING0(x) #x
  21. // include configure generated header to define CMAKE_NO_ANSI_STREAM_HEADERS,
  22. // CMAKE_NO_STD_NAMESPACE, and other macros.
  23. #include "cmConfigure.h"
  24. #include <cmsys/Configure.hxx>
  25. #define CMake_VERSION \
  26. CMAKE_TO_STRING(CMake_VERSION_MAJOR) "." \
  27. CMAKE_TO_STRING(CMake_VERSION_MINOR)
  28. #define CMake_VERSION_FULL \
  29. CMAKE_TO_STRING(CMake_VERSION_MAJOR) "." \
  30. CMAKE_TO_STRING(CMake_VERSION_MINOR) "." \
  31. CMAKE_TO_STRING(CMake_VERSION_PATCH)
  32. #define CMake_VERSION_ENCODE(major, minor, patch) \
  33. ((major)*0x10000u + (minor)*0x100u + (patch))
  34. #ifdef _MSC_VER
  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
  39. #endif
  40. #ifdef __BORLANDC__
  41. #pragma warn -8030 /* Temporary used for parameter */
  42. #endif
  43. #ifdef __ICL
  44. #pragma warning ( disable : 985 )
  45. #endif
  46. #include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
  47. // This is a hack to prevent warnings about these functions being
  48. // declared but not referenced.
  49. #if defined(__sgi) && !defined(__GNUC__)
  50. # include <sys/termios.h>
  51. class cmStandardIncludesHack
  52. {
  53. public:
  54. enum
  55. {
  56. Ref1 = sizeof(cfgetospeed(0)),
  57. Ref2 = sizeof(cfgetispeed(0)),
  58. Ref3 = sizeof(tcgetattr(0, 0)),
  59. Ref4 = sizeof(tcsetattr(0, 0, 0)),
  60. Ref5 = sizeof(cfsetospeed(0,0)),
  61. Ref6 = sizeof(cfsetispeed(0,0))
  62. };
  63. };
  64. #endif
  65. // Include stream compatibility layer from KWSys.
  66. // This is needed to work with large file support
  67. // on some platforms whose stream operators do not
  68. // support the large integer types.
  69. #if defined(CMAKE_BUILD_WITH_CMAKE)
  70. # include <cmsys/IOStream.hxx>
  71. #endif
  72. // Avoid warnings in system headers.
  73. #if defined(_MSC_VER)
  74. # pragma warning (push,1)
  75. #endif
  76. #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
  77. # include <fstream>
  78. # include <iostream>
  79. # include <iomanip>
  80. #else
  81. # include <fstream.h>
  82. # include <iostream.h>
  83. # include <iomanip.h>
  84. #endif
  85. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  86. # include <sstream>
  87. #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
  88. # include <strstream>
  89. #else
  90. # include <strstream.h>
  91. #endif
  92. // we must have stl with the standard include style
  93. #include <vector>
  94. #include <string>
  95. #include <iterator>
  96. #include <algorithm>
  97. #include <functional>
  98. #include <map>
  99. #include <list>
  100. #include <set>
  101. #include <deque>
  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. // check for the 720 compiler on the SGI
  144. // which has some strange properties that I don't think are worth
  145. // checking for in a general way in configure
  146. #if defined(__sgi) && !defined(__GNUC__)
  147. # if (_COMPILER_VERSION >= 730)
  148. # define CM_SGI_CC_730
  149. # elif (_COMPILER_VERSION >= 720)
  150. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  151. # endif
  152. #endif
  153. #ifdef __DECCXX_VER
  154. # if __DECCXX_VER <= 60390008
  155. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  156. # endif
  157. #endif
  158. #if defined( _MSC_VER )
  159. typedef unsigned short mode_t;
  160. #endif
  161. #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  162. // some compilers have std:: but not for the stream library,
  163. // so we have to bring it into the std namespace by hand.
  164. namespace std {
  165. using ::ostream;
  166. using ::istream;
  167. using ::ios;
  168. using ::cout;
  169. using ::cerr;
  170. using ::cin;
  171. using ::ifstream;
  172. using ::ofstream;
  173. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  174. using ::ostringstream;
  175. using ::istringstream;
  176. #else
  177. using ::ostrstream;
  178. using ::istrstream;
  179. #endif
  180. using ::endl;
  181. using ::ends;
  182. using ::flush;
  183. using ::dec;
  184. using ::hex;
  185. using ::setw;
  186. using ::setiosflags;
  187. using ::setfill;
  188. using ::setprecision;
  189. }
  190. // The string class is missing these operators so add them
  191. #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
  192. # define cmsys_STL_STRING_NO_NEQ_CHAR
  193. inline bool operator!=(std::string const& a, const char* b)
  194. { return !(a==std::string(b)); }
  195. #endif
  196. inline bool operator==(std::string const& a, const char* b)
  197. { return (a==std::string(b)); }
  198. # endif // end CM_SGI_CC_720
  199. #if defined(__sgi) && !defined(__GNUC__)
  200. # pragma set woff 1375 /* base class destructor not virtual */
  201. #endif
  202. // use this class to shrink the size of symbols in .o files
  203. // std::string is really basic_string<....lots of stuff....>
  204. // when combined with a map or set, the symbols can be > 2000 chars!
  205. #include <cmsys/String.hxx>
  206. typedef cmsys::String cmStdString;
  207. // Define cmOStringStream and cmIStringStream wrappers to hide
  208. // differences between std::stringstream and the old strstream.
  209. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  210. class cmOStringStream: public std::ostringstream
  211. {
  212. public:
  213. cmOStringStream() {}
  214. private:
  215. cmOStringStream(const cmOStringStream&);
  216. void operator=(const cmOStringStream&);
  217. };
  218. class cmIStringStream: public std::istringstream
  219. {
  220. public:
  221. typedef std::istringstream Superclass;
  222. cmIStringStream() {}
  223. cmIStringStream(const std::string& s): Superclass(s) {}
  224. private:
  225. cmIStringStream(const cmIStringStream&);
  226. void operator=(const cmIStringStream&);
  227. };
  228. #else
  229. class cmOStrStreamCleanup
  230. {
  231. public:
  232. cmOStrStreamCleanup(std::ostrstream& ostr): OStrStream(ostr) {}
  233. ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
  234. static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
  235. protected:
  236. std::ostrstream& OStrStream;
  237. };
  238. class cmOStringStream: public std::ostrstream
  239. {
  240. public:
  241. typedef std::ostrstream Superclass;
  242. cmOStringStream() {}
  243. std::string str()
  244. {
  245. cmOStrStreamCleanup cleanup(*this);
  246. cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
  247. int pcount = this->pcount();
  248. const char* ptr = this->Superclass::str();
  249. return std::string(ptr?ptr:"", pcount);
  250. }
  251. private:
  252. cmOStringStream(const cmOStringStream&);
  253. void operator=(const cmOStringStream&);
  254. };
  255. class cmIStringStream: private std::string, public std::istrstream
  256. {
  257. public:
  258. typedef std::string StdString;
  259. typedef std::istrstream IStrStream;
  260. cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
  261. cmIStringStream(const std::string& s):
  262. StdString(s), IStrStream(StdString::c_str()) {}
  263. std::string str() const { return *this; }
  264. void str(const std::string& s)
  265. {
  266. // Very dangerous. If this throws, the object is hosed. When the
  267. // destructor is later called, the program is hosed too.
  268. this->~cmIStringStream();
  269. new (this) cmIStringStream(s);
  270. }
  271. private:
  272. cmIStringStream(const cmIStringStream&);
  273. void operator=(const cmIStringStream&);
  274. };
  275. #endif
  276. /* Poison this operator to avoid common mistakes. */
  277. extern void operator << (std::ostream&, const cmOStringStream&);
  278. /** Standard documentation entry for cmDocumentation's formatting. */
  279. struct cmDocumentationEntry
  280. {
  281. std::string Name;
  282. std::string Brief;
  283. std::string Full;
  284. cmDocumentationEntry(){};
  285. cmDocumentationEntry(const char *doc[3])
  286. { if (doc[0]) this->Name = doc[0];
  287. if (doc[1]) this->Brief = doc[1];
  288. if (doc[2]) this->Full = doc[2]; };
  289. cmDocumentationEntry(const char *n, const char *b, const char *f)
  290. { if (n) this->Name = n; if (b) this->Brief = b; if (f) this->Full = f; };
  291. };
  292. /** Data structure to represent a single command line. */
  293. class cmCustomCommandLine: public std::vector<std::string>
  294. {
  295. public:
  296. typedef std::vector<std::string> Superclass;
  297. typedef Superclass::iterator iterator;
  298. typedef Superclass::const_iterator const_iterator;
  299. };
  300. /** Data structure to represent a list of command lines. */
  301. class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
  302. {
  303. public:
  304. typedef std::vector<cmCustomCommandLine> Superclass;
  305. typedef Superclass::iterator iterator;
  306. typedef Superclass::const_iterator const_iterator;
  307. };
  308. #if defined(__sgi) && !defined(__GNUC__)
  309. # pragma reset woff 1375 /* base class destructor not virtual */
  310. #endif
  311. // All subclasses of cmCommand or cmCTestGenericHandler should
  312. // invoke this macro.
  313. #define cmTypeMacro(thisClass,superclass) \
  314. virtual const char* GetNameOfClass() { return #thisClass; } \
  315. typedef superclass Superclass; \
  316. static bool IsTypeOf(const char *type) \
  317. { \
  318. if ( !strcmp(#thisClass,type) ) \
  319. { \
  320. return true; \
  321. } \
  322. return Superclass::IsTypeOf(type); \
  323. } \
  324. virtual bool IsA(const char *type) \
  325. { \
  326. return thisClass::IsTypeOf(type); \
  327. } \
  328. static thisClass* SafeDownCast(cmObject *c) \
  329. { \
  330. if ( c && c->IsA(#thisClass) ) \
  331. { \
  332. return static_cast<thisClass *>(c); \
  333. } \
  334. return 0;\
  335. }
  336. #endif