cmStandardIncludes.h 8.0 KB

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