cmStandardIncludes.h 11 KB

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