cmStandardIncludes.h 9.5 KB

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