cmStandardIncludes.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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
  22. // CMAKE_NO_ANSI_STREAM_HEADERS and CMAKE_NO_STD_NAMESPACE
  23. #if defined(CMAKE_HAS_AUTOCONF) || defined(CMAKE_BUILD_WITH_CMAKE)
  24. #include "cmConfigure.h"
  25. #endif
  26. #define CMake_VERSION_STRING \
  27. CMAKE_TO_STRING(CMake_VERSION_MAJOR) "." \
  28. CMAKE_TO_STRING(CMake_VERSION_MINOR) "." \
  29. CMAKE_TO_STRING(CMake_VERSION_PATCH)
  30. #ifdef _MSC_VER
  31. #pragma warning ( disable : 4786 )
  32. #pragma warning ( disable : 4503 )
  33. #define CMAKE_NO_ANSI_FOR_SCOPE
  34. #endif
  35. #ifdef __ICL
  36. #pragma warning ( disable : 985 )
  37. #endif
  38. #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
  39. # include <fstream>
  40. # include <iostream>
  41. #else
  42. # include <fstream.h>
  43. # include <iostream.h>
  44. #endif
  45. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  46. # include <sstream>
  47. #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
  48. # include <strstream>
  49. #else
  50. # include <strstream.h>
  51. #endif
  52. // we must have stl with the standard include style
  53. #include <vector>
  54. #include <string>
  55. #include <iterator>
  56. #include <algorithm>
  57. #include <functional>
  58. #include <map>
  59. #include <list>
  60. #include <set>
  61. // include the "c" string header
  62. #include <string.h>
  63. #if !defined(_WIN32) && defined(__COMO__)
  64. // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
  65. extern "C"
  66. {
  67. extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
  68. extern int pclose (FILE *__stream) __THROW;
  69. extern char *realpath (__const char *__restrict __name,
  70. char *__restrict __resolved) __THROW;
  71. extern char *strdup (__const char *__s) __THROW;
  72. extern int putenv (char *__string) __THROW;
  73. }
  74. #endif
  75. // if std:: is not supported, then just #define it away
  76. #ifdef CMAKE_NO_STD_NAMESPACE
  77. #define std
  78. #endif
  79. // if the compiler does not support ansi for scoping of vars use a
  80. // #define hack
  81. #ifdef CMAKE_NO_ANSI_FOR_SCOPE
  82. #define for if(false) {} else for
  83. #endif
  84. // check for the 720 compiler on the SGI
  85. // which has some strange properties that I don't think are worth
  86. // checking for in a general way in configure
  87. #if defined(__sgi) && !defined(__GNUC__)
  88. # if (_COMPILER_VERSION >= 730)
  89. # define CM_SGI_CC_730
  90. # elif (_COMPILER_VERSION >= 720)
  91. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  92. # endif
  93. #endif
  94. #ifdef __DECCXX_VER
  95. # if __DECCXX_VER <= 60390008
  96. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  97. # endif
  98. #endif
  99. #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  100. // some compilers have std:: but not for the stream library,
  101. // so we have to bring it into the std namespace by hand.
  102. namespace std {
  103. using ::ostream;
  104. using ::istream;
  105. using ::ios;
  106. using ::cout;
  107. using ::cerr;
  108. using ::cin;
  109. using ::ifstream;
  110. using ::ofstream;
  111. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  112. using ::ostringstream;
  113. using ::istringstream;
  114. #else
  115. using ::ostrstream;
  116. using ::istrstream;
  117. #endif
  118. using ::endl;
  119. using ::ends;
  120. using ::flush;
  121. }
  122. // The string class is missing these operators so add them
  123. inline bool operator!=(std::string const& a, const char* b)
  124. { return !(a==std::string(b)); }
  125. inline bool operator==(std::string const& a, const char* b)
  126. { return (a==std::string(b)); }
  127. # endif // end CM_SGI_CC_720
  128. // use this class to shrink the size of symbols in .o files
  129. // std::string is really basic_string<....lots of stuff....>
  130. // when combined with a map or set, the symbols can be > 2000 chars!
  131. struct cmStdString : public std::string
  132. {
  133. typedef std::string StdString;
  134. typedef StdString::value_type value_type;
  135. typedef StdString::pointer pointer;
  136. typedef StdString::reference reference;
  137. typedef StdString::const_reference const_reference;
  138. typedef StdString::size_type size_type;
  139. typedef StdString::difference_type difference_type;
  140. typedef StdString::iterator iterator;
  141. typedef StdString::const_iterator const_iterator;
  142. typedef StdString::reverse_iterator reverse_iterator;
  143. typedef StdString::const_reverse_iterator const_reverse_iterator;
  144. cmStdString(): StdString() {}
  145. cmStdString(const value_type* s): StdString(s) {}
  146. cmStdString(const value_type* s, size_type n): StdString(s, n) {}
  147. cmStdString(const StdString& s, size_type pos=0, size_type n=npos):
  148. StdString(s, pos, n) {}
  149. };
  150. // Define cmOStringStream and cmIStringStream wrappers to hide
  151. // differences between std::stringstream and the old strstream.
  152. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  153. class cmOStringStream: public std::ostringstream
  154. {
  155. public:
  156. cmOStringStream() {}
  157. private:
  158. cmOStringStream(const cmOStringStream&);
  159. void operator=(const cmOStringStream&);
  160. };
  161. class cmIStringStream: public std::istringstream
  162. {
  163. public:
  164. typedef std::istringstream Superclass;
  165. cmIStringStream() {}
  166. cmIStringStream(const std::string& s): Superclass(s) {}
  167. private:
  168. cmIStringStream(const cmIStringStream&);
  169. void operator=(const cmIStringStream&);
  170. };
  171. #else
  172. class cmOStrStreamCleanup
  173. {
  174. public:
  175. cmOStrStreamCleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
  176. ~cmOStrStreamCleanup() { m_OStrStream.rdbuf()->freeze(0); }
  177. static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
  178. protected:
  179. std::ostrstream& m_OStrStream;
  180. };
  181. class cmOStringStream: public std::ostrstream
  182. {
  183. public:
  184. typedef std::ostrstream Superclass;
  185. cmOStringStream() {}
  186. std::string str()
  187. {
  188. cmOStrStreamCleanup cleanup(*this);
  189. cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
  190. int pcount = this->pcount();
  191. const char* ptr = this->Superclass::str();
  192. return std::string(ptr?ptr:"", pcount);
  193. }
  194. private:
  195. cmOStringStream(const cmOStringStream&);
  196. void operator=(const cmOStringStream&);
  197. };
  198. class cmIStringStream: private std::string, public std::istrstream
  199. {
  200. public:
  201. typedef std::string StdString;
  202. typedef std::istrstream IStrStream;
  203. cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
  204. cmIStringStream(const std::string& s):
  205. StdString(s), IStrStream(StdString::c_str()) {}
  206. std::string str() const { return *this; }
  207. void str(const std::string& s)
  208. {
  209. // Very dangerous. If this throws, the object is hosed. When the
  210. // destructor is later called, the program is hosed too.
  211. this->~cmIStringStream();
  212. new (this) cmIStringStream(s);
  213. }
  214. private:
  215. cmIStringStream(const cmIStringStream&);
  216. void operator=(const cmIStringStream&);
  217. };
  218. #endif
  219. #endif