cmStandardIncludes.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. #define CMake_VERSION \
  25. CMAKE_TO_STRING(CMake_VERSION_MAJOR) "." \
  26. CMAKE_TO_STRING(CMake_VERSION_MINOR)
  27. #define CMake_VERSION_FULL \
  28. CMAKE_TO_STRING(CMake_VERSION_MAJOR) "." \
  29. CMAKE_TO_STRING(CMake_VERSION_MINOR) "." \
  30. CMAKE_TO_STRING(CMake_VERSION_PATCH)
  31. #ifdef _MSC_VER
  32. #pragma warning ( disable : 4786 )
  33. #pragma warning ( disable : 4503 )
  34. #define CMAKE_NO_ANSI_FOR_SCOPE
  35. #endif
  36. #ifdef __ICL
  37. #pragma warning ( disable : 985 )
  38. #endif
  39. #include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
  40. // This is a hack to prevent warnings about these functions being
  41. // declared but not referenced.
  42. #if defined(__sgi) && !defined(__GNUC__)
  43. # include <sys/termios.h>
  44. class cmStandardIncludesHack
  45. {
  46. public:
  47. enum
  48. {
  49. Ref1 = sizeof(cfgetospeed(0)),
  50. Ref2 = sizeof(cfgetispeed(0)),
  51. Ref3 = sizeof(tcgetattr(0, 0)),
  52. Ref4 = sizeof(tcsetattr(0, 0, 0)),
  53. Ref5 = sizeof(cfsetospeed(0,0)),
  54. Ref6 = sizeof(cfsetispeed(0,0))
  55. };
  56. };
  57. #endif
  58. #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
  59. # include <fstream>
  60. # include <iostream>
  61. # include <iomanip>
  62. #else
  63. # include <fstream.h>
  64. # include <iostream.h>
  65. # include <iomanip.h>
  66. #endif
  67. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  68. # include <sstream>
  69. #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
  70. # include <strstream>
  71. #else
  72. # include <strstream.h>
  73. #endif
  74. // we must have stl with the standard include style
  75. #include <vector>
  76. #include <string>
  77. #include <iterator>
  78. #include <algorithm>
  79. #include <functional>
  80. #include <map>
  81. #include <list>
  82. #include <set>
  83. #include <deque>
  84. // include the "c" string header
  85. #include <string.h>
  86. #include <stdio.h>
  87. #include <stdlib.h>
  88. #if !defined(_WIN32) && defined(__COMO__)
  89. // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
  90. extern "C"
  91. {
  92. extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
  93. extern int pclose (FILE *__stream) __THROW;
  94. extern char *realpath (__const char *__restrict __name,
  95. char *__restrict __resolved) __THROW;
  96. extern char *strdup (__const char *__s) __THROW;
  97. extern int putenv (char *__string) __THROW;
  98. }
  99. #endif
  100. // if std:: is not supported, then just #define it away
  101. #ifdef CMAKE_NO_STD_NAMESPACE
  102. #define std
  103. #endif
  104. // if the compiler does not support ansi for scoping of vars use a
  105. // #define hack
  106. #ifdef CMAKE_NO_ANSI_FOR_SCOPE
  107. #define for if(false) {} else for
  108. #endif
  109. // check for the 720 compiler on the SGI
  110. // which has some strange properties that I don't think are worth
  111. // checking for in a general way in configure
  112. #if defined(__sgi) && !defined(__GNUC__)
  113. # if (_COMPILER_VERSION >= 730)
  114. # define CM_SGI_CC_730
  115. # elif (_COMPILER_VERSION >= 720)
  116. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  117. # endif
  118. #endif
  119. #ifdef __DECCXX_VER
  120. # if __DECCXX_VER <= 60390008
  121. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  122. # endif
  123. #endif
  124. #if defined( _MSC_VER )
  125. typedef unsigned short mode_t;
  126. #endif
  127. #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  128. // some compilers have std:: but not for the stream library,
  129. // so we have to bring it into the std namespace by hand.
  130. namespace std {
  131. using ::ostream;
  132. using ::istream;
  133. using ::ios;
  134. using ::cout;
  135. using ::cerr;
  136. using ::cin;
  137. using ::ifstream;
  138. using ::ofstream;
  139. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  140. using ::ostringstream;
  141. using ::istringstream;
  142. #else
  143. using ::ostrstream;
  144. using ::istrstream;
  145. #endif
  146. using ::endl;
  147. using ::ends;
  148. using ::flush;
  149. using ::dec;
  150. using ::hex;
  151. using ::setw;
  152. using ::setiosflags;
  153. using ::setfill;
  154. using ::setprecision;
  155. }
  156. // The string class is missing these operators so add them
  157. #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
  158. # define cmsys_STL_STRING_NO_NEQ_CHAR
  159. inline bool operator!=(std::string const& a, const char* b)
  160. { return !(a==std::string(b)); }
  161. #endif
  162. inline bool operator==(std::string const& a, const char* b)
  163. { return (a==std::string(b)); }
  164. # endif // end CM_SGI_CC_720
  165. #if defined(__sgi) && !defined(__GNUC__)
  166. # pragma set woff 1375 /* base class destructor not virtual */
  167. #endif
  168. // use this class to shrink the size of symbols in .o files
  169. // std::string is really basic_string<....lots of stuff....>
  170. // when combined with a map or set, the symbols can be > 2000 chars!
  171. struct cmStdString : public std::string
  172. {
  173. typedef std::string StdString;
  174. typedef StdString::value_type value_type;
  175. typedef StdString::pointer pointer;
  176. typedef StdString::reference reference;
  177. typedef StdString::const_reference const_reference;
  178. typedef StdString::size_type size_type;
  179. typedef StdString::difference_type difference_type;
  180. typedef StdString::iterator iterator;
  181. typedef StdString::const_iterator const_iterator;
  182. typedef StdString::reverse_iterator reverse_iterator;
  183. typedef StdString::const_reverse_iterator const_reverse_iterator;
  184. cmStdString(): StdString() {}
  185. cmStdString(const value_type* s): StdString(s) {}
  186. cmStdString(const value_type* s, size_type n): StdString(s, n) {}
  187. cmStdString(const StdString& s, size_type pos=0, size_type n=npos):
  188. StdString(s, pos, n) {}
  189. };
  190. // Define cmOStringStream and cmIStringStream wrappers to hide
  191. // differences between std::stringstream and the old strstream.
  192. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  193. class cmOStringStream: public std::ostringstream
  194. {
  195. public:
  196. cmOStringStream() {}
  197. private:
  198. cmOStringStream(const cmOStringStream&);
  199. void operator=(const cmOStringStream&);
  200. };
  201. class cmIStringStream: public std::istringstream
  202. {
  203. public:
  204. typedef std::istringstream Superclass;
  205. cmIStringStream() {}
  206. cmIStringStream(const std::string& s): Superclass(s) {}
  207. private:
  208. cmIStringStream(const cmIStringStream&);
  209. void operator=(const cmIStringStream&);
  210. };
  211. #else
  212. class cmOStrStreamCleanup
  213. {
  214. public:
  215. cmOStrStreamCleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
  216. ~cmOStrStreamCleanup() { m_OStrStream.rdbuf()->freeze(0); }
  217. static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
  218. protected:
  219. std::ostrstream& m_OStrStream;
  220. };
  221. class cmOStringStream: public std::ostrstream
  222. {
  223. public:
  224. typedef std::ostrstream Superclass;
  225. cmOStringStream() {}
  226. std::string str()
  227. {
  228. cmOStrStreamCleanup cleanup(*this);
  229. cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
  230. int pcount = this->pcount();
  231. const char* ptr = this->Superclass::str();
  232. return std::string(ptr?ptr:"", pcount);
  233. }
  234. private:
  235. cmOStringStream(const cmOStringStream&);
  236. void operator=(const cmOStringStream&);
  237. };
  238. class cmIStringStream: private std::string, public std::istrstream
  239. {
  240. public:
  241. typedef std::string StdString;
  242. typedef std::istrstream IStrStream;
  243. cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
  244. cmIStringStream(const std::string& s):
  245. StdString(s), IStrStream(StdString::c_str()) {}
  246. std::string str() const { return *this; }
  247. void str(const std::string& s)
  248. {
  249. // Very dangerous. If this throws, the object is hosed. When the
  250. // destructor is later called, the program is hosed too.
  251. this->~cmIStringStream();
  252. new (this) cmIStringStream(s);
  253. }
  254. private:
  255. cmIStringStream(const cmIStringStream&);
  256. void operator=(const cmIStringStream&);
  257. };
  258. #endif
  259. /* Poison this operator to avoid common mistakes. */
  260. extern void operator << (std::ostream&, const cmOStringStream&);
  261. /** Standard documentation entry for cmDocumentation's formatting. */
  262. struct cmDocumentationEntry
  263. {
  264. const char* name;
  265. const char* brief;
  266. const char* full;
  267. };
  268. /** Data structure to represent a single command line. */
  269. class cmCustomCommandLine: public std::vector<std::string>
  270. {
  271. public:
  272. typedef std::vector<std::string> Superclass;
  273. typedef Superclass::iterator iterator;
  274. typedef Superclass::const_iterator const_iterator;
  275. };
  276. /** Data structure to represent a list of command lines. */
  277. class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
  278. {
  279. public:
  280. typedef std::vector<cmCustomCommandLine> Superclass;
  281. typedef Superclass::iterator iterator;
  282. typedef Superclass::const_iterator const_iterator;
  283. };
  284. #if defined(__sgi) && !defined(__GNUC__)
  285. # pragma reset woff 1375 /* base class destructor not virtual */
  286. #endif
  287. // All subclasses of cmCommand or cmCTestGenericHandler should invoke this macro.
  288. #define cmTypeMacro(thisClass,superclass) \
  289. virtual const char* GetNameOfClass() { return #thisClass; } \
  290. typedef superclass Superclass; \
  291. static bool IsTypeOf(const char *type) \
  292. { \
  293. if ( !strcmp(#thisClass,type) ) \
  294. { \
  295. return true; \
  296. } \
  297. return Superclass::IsTypeOf(type); \
  298. } \
  299. virtual bool IsA(const char *type) \
  300. { \
  301. return thisClass::IsTypeOf(type); \
  302. } \
  303. static thisClass* SafeDownCast(cmObject *c) \
  304. { \
  305. if ( c && c->IsA(#thisClass) ) \
  306. { \
  307. return (thisClass *)c; \
  308. } \
  309. return 0;\
  310. }
  311. #endif