cmStandardIncludes.h 7.4 KB

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