cmStandardIncludes.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. /**
  11. * Include header files as a function of the build process, compiler,
  12. * and operating system.
  13. */
  14. #ifndef cmStandardIncludes_h
  15. #define cmStandardIncludes_h
  16. // include configure generated header to define CMAKE_NO_ANSI_STREAM_HEADERS,
  17. // CMAKE_NO_STD_NAMESPACE, and other macros.
  18. #include <cmConfigure.h>
  19. #include <cmsys/Configure.hxx>
  20. #ifdef _MSC_VER
  21. #pragma warning ( disable : 4786 )
  22. #pragma warning ( disable : 4503 )
  23. #pragma warning ( disable : 4512 ) /* operator=() could not be generated */
  24. #define CMAKE_NO_ANSI_FOR_SCOPE
  25. #endif
  26. #ifdef __ICL
  27. #pragma warning ( disable : 985 )
  28. #pragma warning ( disable : 1572 ) /* floating-point equality test */
  29. #endif
  30. // Provide fixed-size integer types.
  31. #include <cmIML/INT.h>
  32. #include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
  33. // This is a hack to prevent warnings about these functions being
  34. // declared but not referenced.
  35. #if defined(__sgi) && !defined(__GNUC__)
  36. # pragma set woff 3970 /* conversion from pointer to same-sized */
  37. # include <sys/termios.h>
  38. class cmStandardIncludesHack
  39. {
  40. public:
  41. enum
  42. {
  43. Ref1 = sizeof(cfgetospeed(0)),
  44. Ref2 = sizeof(cfgetispeed(0)),
  45. Ref3 = sizeof(tcgetattr(0, 0)),
  46. Ref4 = sizeof(tcsetattr(0, 0, 0)),
  47. Ref5 = sizeof(cfsetospeed(0,0)),
  48. Ref6 = sizeof(cfsetispeed(0,0))
  49. };
  50. };
  51. #endif
  52. // Include stream compatibility layer from KWSys.
  53. // This is needed to work with large file support
  54. // on some platforms whose stream operators do not
  55. // support the large integer types.
  56. #if defined(CMAKE_BUILD_WITH_CMAKE)
  57. # include <cmsys/IOStream.hxx>
  58. # undef GetCurrentDirectory // Borland <iosfwd> includes windows.h
  59. #endif
  60. // Avoid warnings in system headers.
  61. #if defined(_MSC_VER)
  62. # pragma warning (push,1)
  63. #endif
  64. #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
  65. # include <fstream>
  66. # include <iostream>
  67. # include <iomanip>
  68. #else
  69. # include <fstream.h>
  70. # include <iostream.h>
  71. # include <iomanip.h>
  72. #endif
  73. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  74. # include <sstream>
  75. #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
  76. # include <strstream>
  77. #else
  78. # include <strstream.h>
  79. #endif
  80. // we must have stl with the standard include style
  81. #include <vector>
  82. #include <string>
  83. #include <iterator>
  84. #include <algorithm>
  85. #include <functional>
  86. #include <map>
  87. #include <list>
  88. #include <set>
  89. #include <deque>
  90. #if defined(_MSC_VER)
  91. # pragma warning(pop)
  92. #endif
  93. // include the "c" string header
  94. #include <string.h>
  95. #include <stdio.h>
  96. #include <stdlib.h>
  97. // Borland C++ defines several of the stdlib.h and string.h symbols in
  98. // sub-headers search.h and mem.h. These sub-headers have using
  99. // declarations to pull functions from the std namespace to the global
  100. // namespace, but they are defined only if the header was not included
  101. // through the C++-style cstdlib or cstring header. These outer
  102. // headers are included by the streams library in C++-style and
  103. // include blockers are put in place that prevent including the
  104. // C-style versions from ever including the sub-headers. Therefore we
  105. // have to include the sub-headers here to get the using declarations.
  106. #if !defined(_WIN32) && defined(__COMO__)
  107. // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
  108. extern "C"
  109. {
  110. extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
  111. extern int pclose (FILE *__stream) __THROW;
  112. extern char *realpath (__const char *__restrict __name,
  113. char *__restrict __resolved) __THROW;
  114. extern char *strdup (__const char *__s) __THROW;
  115. extern int putenv (char *__string) __THROW;
  116. }
  117. #endif
  118. // if std:: is not supported, then just #define it away
  119. #ifdef CMAKE_NO_STD_NAMESPACE
  120. #define std
  121. #endif
  122. // if the compiler does not support ansi for scoping of vars use a
  123. // #define hack
  124. #ifdef CMAKE_NO_ANSI_FOR_SCOPE
  125. #define for if(false) {} else for
  126. #endif
  127. // check for the 720 compiler on the SGI
  128. // which has some strange properties that I don't think are worth
  129. // checking for in a general way in configure
  130. #if defined(__sgi) && !defined(__GNUC__)
  131. # if (_COMPILER_VERSION >= 730)
  132. # define CM_SGI_CC_730
  133. # elif (_COMPILER_VERSION >= 720)
  134. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  135. # endif
  136. #endif
  137. #ifdef __DECCXX_VER
  138. # if __DECCXX_VER <= 60390008
  139. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  140. # endif
  141. #endif
  142. #if defined( _MSC_VER )
  143. typedef unsigned short mode_t;
  144. #endif
  145. #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  146. // some compilers have std:: but not for the stream library,
  147. // so we have to bring it into the std namespace by hand.
  148. namespace std {
  149. using ::ostream;
  150. using ::istream;
  151. using ::ios;
  152. using ::cout;
  153. using ::cerr;
  154. using ::cin;
  155. using ::ifstream;
  156. using ::ofstream;
  157. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  158. using ::ostringstream;
  159. using ::istringstream;
  160. #else
  161. using ::ostrstream;
  162. using ::istrstream;
  163. #endif
  164. using ::endl;
  165. using ::ends;
  166. using ::flush;
  167. using ::dec;
  168. using ::hex;
  169. using ::setw;
  170. using ::setiosflags;
  171. using ::setfill;
  172. using ::setprecision;
  173. }
  174. // The string class is missing these operators so add them
  175. #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
  176. # define cmsys_STL_STRING_NO_NEQ_CHAR
  177. inline bool operator!=(std::string const& a, const char* b)
  178. { return !(a==std::string(b)); }
  179. #endif
  180. inline bool operator==(std::string const& a, const char* b)
  181. { return (a==std::string(b)); }
  182. # endif // end CM_SGI_CC_720
  183. #if defined(__sgi) && !defined(__GNUC__)
  184. # pragma set woff 1375 /* base class destructor not virtual */
  185. #endif
  186. // use this class to shrink the size of symbols in .o files
  187. // std::string is really basic_string<....lots of stuff....>
  188. // when combined with a map or set, the symbols can be > 2000 chars!
  189. #include <cmsys/String.hxx>
  190. //typedef cmsys::String std::string;
  191. // Define cmOStringStream and cmIStringStream wrappers to hide
  192. // differences between std::stringstream and the old strstream.
  193. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  194. class cmOStringStream: public std::ostringstream
  195. {
  196. public:
  197. cmOStringStream();
  198. ~cmOStringStream();
  199. private:
  200. cmOStringStream(const cmOStringStream&);
  201. void operator=(const cmOStringStream&);
  202. };
  203. class cmIStringStream: public std::istringstream
  204. {
  205. public:
  206. typedef std::istringstream Superclass;
  207. cmIStringStream() {}
  208. cmIStringStream(const std::string& s): Superclass(s) {}
  209. private:
  210. cmIStringStream(const cmIStringStream&);
  211. void operator=(const cmIStringStream&);
  212. };
  213. #else
  214. class cmOStrStreamCleanup
  215. {
  216. public:
  217. cmOStrStreamCleanup(std::ostrstream& ostr): OStrStream(ostr) {}
  218. ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
  219. static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
  220. protected:
  221. std::ostrstream& OStrStream;
  222. };
  223. class cmOStringStream: public std::ostrstream
  224. {
  225. public:
  226. typedef std::ostrstream Superclass;
  227. cmOStringStream() {}
  228. std::string str()
  229. {
  230. cmOStrStreamCleanup cleanup(*this);
  231. cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
  232. int pcount = this->pcount();
  233. const char* ptr = this->Superclass::str();
  234. return std::string(ptr?ptr:"", pcount);
  235. }
  236. private:
  237. cmOStringStream(const cmOStringStream&);
  238. void operator=(const cmOStringStream&);
  239. };
  240. class cmIStringStream: private std::string, public std::istrstream
  241. {
  242. public:
  243. typedef std::string StdString;
  244. typedef std::istrstream IStrStream;
  245. cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
  246. cmIStringStream(const std::string& s):
  247. StdString(s), IStrStream(StdString::c_str()) {}
  248. std::string str() const { return *this; }
  249. void str(const std::string& s)
  250. {
  251. // Very dangerous. If this throws, the object is hosed. When the
  252. // destructor is later called, the program is hosed too.
  253. this->~cmIStringStream();
  254. new (this) cmIStringStream(s);
  255. }
  256. private:
  257. cmIStringStream(const cmIStringStream&);
  258. void operator=(const cmIStringStream&);
  259. };
  260. #endif
  261. /* Poison this operator to avoid common mistakes. */
  262. extern void operator << (std::ostream&, const cmOStringStream&);
  263. /** Standard documentation entry for cmDocumentation's formatting. */
  264. struct cmDocumentationEntry
  265. {
  266. std::string Name;
  267. std::string Brief;
  268. cmDocumentationEntry(){}
  269. cmDocumentationEntry(const char *doc[2])
  270. { if (doc[0]) this->Name = doc[0];
  271. if (doc[1]) this->Brief = doc[1];}
  272. cmDocumentationEntry(const char *n, const char *b)
  273. { if (n) this->Name = n; if (b) this->Brief = b; }
  274. };
  275. /** Data structure to represent a single command line. */
  276. class cmCustomCommandLine: public std::vector<std::string>
  277. {
  278. public:
  279. typedef std::vector<std::string> Superclass;
  280. typedef Superclass::iterator iterator;
  281. typedef Superclass::const_iterator const_iterator;
  282. };
  283. /** Data structure to represent a list of command lines. */
  284. class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
  285. {
  286. public:
  287. typedef std::vector<cmCustomCommandLine> Superclass;
  288. typedef Superclass::iterator iterator;
  289. typedef Superclass::const_iterator const_iterator;
  290. };
  291. #if defined(__sgi) && !defined(__GNUC__)
  292. # pragma reset woff 1375 /* base class destructor not virtual */
  293. #endif
  294. // All subclasses of cmCommand or cmCTestGenericHandler should
  295. // invoke this macro.
  296. #define cmTypeMacro(thisClass,superclass) \
  297. virtual const char* GetNameOfClass() { return #thisClass; } \
  298. typedef superclass Superclass; \
  299. static bool IsTypeOf(const char *type) \
  300. { \
  301. if ( !strcmp(#thisClass,type) ) \
  302. { \
  303. return true; \
  304. } \
  305. return Superclass::IsTypeOf(type); \
  306. } \
  307. virtual bool IsA(const char *type) \
  308. { \
  309. return thisClass::IsTypeOf(type); \
  310. } \
  311. static thisClass* SafeDownCast(cmObject *c) \
  312. { \
  313. if ( c && c->IsA(#thisClass) ) \
  314. { \
  315. return static_cast<thisClass *>(c); \
  316. } \
  317. return 0;\
  318. } \
  319. class cmTypeMacro_UseTrailingSemicolon
  320. inline bool cmHasLiteralPrefixImpl(const std::string &str1,
  321. const char *str2,
  322. size_t N)
  323. {
  324. return strncmp(str1.c_str(), str2, N) == 0;
  325. }
  326. inline bool cmHasLiteralPrefixImpl(const char* str1,
  327. const char *str2,
  328. size_t N)
  329. {
  330. return strncmp(str1, str2, N) == 0;
  331. }
  332. inline bool cmHasLiteralSuffixImpl(const std::string &str1,
  333. const char *str2,
  334. size_t N)
  335. {
  336. size_t len = str1.size();
  337. return len >= N && strcmp(str1.c_str() + len - N, str2) == 0;
  338. }
  339. inline bool cmHasLiteralSuffixImpl(const char* str1,
  340. const char* str2,
  341. size_t N)
  342. {
  343. size_t len = strlen(str1);
  344. return len >= N && strcmp(str1 + len - N, str2) == 0;
  345. }
  346. template<typename T, size_t N>
  347. const T* cmArrayBegin(const T (&a)[N]) { return a; }
  348. template<typename T, size_t N>
  349. const T* cmArrayEnd(const T (&a)[N]) { return a + N; }
  350. template<typename T, size_t N>
  351. size_t cmArraySize(const T (&)[N]) { return N; }
  352. template<typename T, size_t N>
  353. bool cmHasLiteralPrefix(T str1, const char (&str2)[N])
  354. {
  355. return cmHasLiteralPrefixImpl(str1, str2, N - 1);
  356. }
  357. template<typename T, size_t N>
  358. bool cmHasLiteralSuffix(T str1, const char (&str2)[N])
  359. {
  360. return cmHasLiteralSuffixImpl(str1, str2, N - 1);
  361. }
  362. struct cmStrCmp {
  363. cmStrCmp(const char *test) : m_test(test) {}
  364. cmStrCmp(const std::string &test) : m_test(test) {}
  365. bool operator()(const std::string& input) const
  366. {
  367. return m_test == input;
  368. }
  369. bool operator()(const char * input) const
  370. {
  371. return strcmp(input, m_test.c_str()) == 0;
  372. }
  373. private:
  374. const std::string m_test;
  375. };
  376. #endif