cmStandardIncludes.h 7.1 KB

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