cmStandardIncludes.h 10 KB

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