cmStandardIncludes.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. #ifdef _MSC_VER
  33. #pragma warning ( disable : 4786 )
  34. #pragma warning ( disable : 4503 )
  35. #define CMAKE_NO_ANSI_FOR_SCOPE
  36. #endif
  37. #ifdef __BORLANDC__
  38. #pragma warn -8030 /* Temporary used for parameter */
  39. #endif
  40. #ifdef __ICL
  41. #pragma warning ( disable : 985 )
  42. #endif
  43. #include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
  44. // This is a hack to prevent warnings about these functions being
  45. // declared but not referenced.
  46. #if defined(__sgi) && !defined(__GNUC__)
  47. # include <sys/termios.h>
  48. class cmStandardIncludesHack
  49. {
  50. public:
  51. enum
  52. {
  53. Ref1 = sizeof(cfgetospeed(0)),
  54. Ref2 = sizeof(cfgetispeed(0)),
  55. Ref3 = sizeof(tcgetattr(0, 0)),
  56. Ref4 = sizeof(tcsetattr(0, 0, 0)),
  57. Ref5 = sizeof(cfsetospeed(0,0)),
  58. Ref6 = sizeof(cfsetispeed(0,0))
  59. };
  60. };
  61. #endif
  62. #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
  63. # include <fstream>
  64. # include <iostream>
  65. # include <iomanip>
  66. #else
  67. # include <fstream.h>
  68. # include <iostream.h>
  69. # include <iomanip.h>
  70. #endif
  71. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  72. # include <sstream>
  73. #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
  74. # include <strstream>
  75. #else
  76. # include <strstream.h>
  77. #endif
  78. // we must have stl with the standard include style
  79. #include <vector>
  80. #include <string>
  81. #include <iterator>
  82. #include <algorithm>
  83. #include <functional>
  84. #include <map>
  85. #include <list>
  86. #include <set>
  87. #include <deque>
  88. // include the "c" string header
  89. #include <string.h>
  90. #include <stdio.h>
  91. #include <stdlib.h>
  92. // Borland C++ defines several of the stdlib.h and string.h symbols in
  93. // sub-headers search.h and mem.h. These sub-headers have using
  94. // declarations to pull functions from the std namespace to the global
  95. // namespace, but they are defined only if the header was not included
  96. // through the C++-style cstdlib or cstring header. These outer
  97. // headers are included by the streams library in C++-style and
  98. // include blockers are put in place that prevent including the
  99. // C-style versions from ever including the sub-headers. Therefore we
  100. // have to include the sub-headers here to get the using declarations.
  101. #if defined(__BORLANDC__)
  102. # include <mem.h> /* mem... functions from string.h */
  103. # include <search.h> /* search functions from stdlib.h */
  104. #endif
  105. #if !defined(_WIN32) && defined(__COMO__)
  106. // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
  107. extern "C"
  108. {
  109. extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
  110. extern int pclose (FILE *__stream) __THROW;
  111. extern char *realpath (__const char *__restrict __name,
  112. char *__restrict __resolved) __THROW;
  113. extern char *strdup (__const char *__s) __THROW;
  114. extern int putenv (char *__string) __THROW;
  115. }
  116. #endif
  117. // if std:: is not supported, then just #define it away
  118. #ifdef CMAKE_NO_STD_NAMESPACE
  119. #define std
  120. #endif
  121. // if the compiler does not support ansi for scoping of vars use a
  122. // #define hack
  123. #ifdef CMAKE_NO_ANSI_FOR_SCOPE
  124. #define for if(false) {} else for
  125. #endif
  126. // check for the 720 compiler on the SGI
  127. // which has some strange properties that I don't think are worth
  128. // checking for in a general way in configure
  129. #if defined(__sgi) && !defined(__GNUC__)
  130. # if (_COMPILER_VERSION >= 730)
  131. # define CM_SGI_CC_730
  132. # elif (_COMPILER_VERSION >= 720)
  133. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  134. # endif
  135. #endif
  136. #ifdef __DECCXX_VER
  137. # if __DECCXX_VER <= 60390008
  138. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  139. # endif
  140. #endif
  141. #if defined( _MSC_VER )
  142. typedef unsigned short mode_t;
  143. #endif
  144. #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  145. // some compilers have std:: but not for the stream library,
  146. // so we have to bring it into the std namespace by hand.
  147. namespace std {
  148. using ::ostream;
  149. using ::istream;
  150. using ::ios;
  151. using ::cout;
  152. using ::cerr;
  153. using ::cin;
  154. using ::ifstream;
  155. using ::ofstream;
  156. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  157. using ::ostringstream;
  158. using ::istringstream;
  159. #else
  160. using ::ostrstream;
  161. using ::istrstream;
  162. #endif
  163. using ::endl;
  164. using ::ends;
  165. using ::flush;
  166. using ::dec;
  167. using ::hex;
  168. using ::setw;
  169. using ::setiosflags;
  170. using ::setfill;
  171. using ::setprecision;
  172. }
  173. // The string class is missing these operators so add them
  174. #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
  175. # define cmsys_STL_STRING_NO_NEQ_CHAR
  176. inline bool operator!=(std::string const& a, const char* b)
  177. { return !(a==std::string(b)); }
  178. #endif
  179. inline bool operator==(std::string const& a, const char* b)
  180. { return (a==std::string(b)); }
  181. # endif // end CM_SGI_CC_720
  182. #if defined(__sgi) && !defined(__GNUC__)
  183. # pragma set woff 1375 /* base class destructor not virtual */
  184. #endif
  185. // use this class to shrink the size of symbols in .o files
  186. // std::string is really basic_string<....lots of stuff....>
  187. // when combined with a map or set, the symbols can be > 2000 chars!
  188. #include <cmsys/String.hxx>
  189. typedef cmsys::String cmStdString;
  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): OStrStream(ostr) {}
  216. ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
  217. static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
  218. protected:
  219. std::ostrstream& 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
  288. // invoke this macro.
  289. #define cmTypeMacro(thisClass,superclass) \
  290. virtual const char* GetNameOfClass() { return #thisClass; } \
  291. typedef superclass Superclass; \
  292. static bool IsTypeOf(const char *type) \
  293. { \
  294. if ( !strcmp(#thisClass,type) ) \
  295. { \
  296. return true; \
  297. } \
  298. return Superclass::IsTypeOf(type); \
  299. } \
  300. virtual bool IsA(const char *type) \
  301. { \
  302. return thisClass::IsTypeOf(type); \
  303. } \
  304. static thisClass* SafeDownCast(cmObject *c) \
  305. { \
  306. if ( c && c->IsA(#thisClass) ) \
  307. { \
  308. return static_cast<thisClass *>(c); \
  309. } \
  310. return 0;\
  311. }
  312. #endif