cmStandardIncludes.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. // Provide std::ios_base on ancient GCC 2.9x
  128. #if defined(__GNUC__) && __GNUC__ < 3
  129. namespace std { typedef ios ios_base; }
  130. #endif
  131. // check for the 720 compiler on the SGI
  132. // which has some strange properties that I don't think are worth
  133. // checking for in a general way in configure
  134. #if defined(__sgi) && !defined(__GNUC__)
  135. # if (_COMPILER_VERSION >= 730)
  136. # define CM_SGI_CC_730
  137. # elif (_COMPILER_VERSION >= 720)
  138. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  139. # endif
  140. #endif
  141. #ifdef __DECCXX_VER
  142. # if __DECCXX_VER <= 60390008
  143. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  144. # endif
  145. #endif
  146. #if defined( _MSC_VER )
  147. typedef unsigned short mode_t;
  148. #endif
  149. #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  150. // some compilers have std:: but not for the stream library,
  151. // so we have to bring it into the std namespace by hand.
  152. namespace std {
  153. using ::ostream;
  154. using ::istream;
  155. using ::ios;
  156. using ::cout;
  157. using ::cerr;
  158. using ::cin;
  159. using ::ifstream;
  160. using ::ofstream;
  161. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  162. using ::ostringstream;
  163. using ::istringstream;
  164. #else
  165. using ::ostrstream;
  166. using ::istrstream;
  167. #endif
  168. using ::endl;
  169. using ::ends;
  170. using ::flush;
  171. using ::dec;
  172. using ::hex;
  173. using ::setw;
  174. using ::setiosflags;
  175. using ::setfill;
  176. using ::setprecision;
  177. }
  178. // The string class is missing these operators so add them
  179. #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
  180. # define cmsys_STL_STRING_NO_NEQ_CHAR
  181. inline bool operator!=(std::string const& a, const char* b)
  182. { return !(a==std::string(b)); }
  183. #endif
  184. inline bool operator==(std::string const& a, const char* b)
  185. { return (a==std::string(b)); }
  186. # endif // end CM_SGI_CC_720
  187. #if defined(__sgi) && !defined(__GNUC__)
  188. # pragma set woff 1375 /* base class destructor not virtual */
  189. #endif
  190. // use this class to shrink the size of symbols in .o files
  191. // std::string is really basic_string<....lots of stuff....>
  192. // when combined with a map or set, the symbols can be > 2000 chars!
  193. #include <cmsys/String.hxx>
  194. //typedef cmsys::String std::string;
  195. // Define cmOStringStream and cmIStringStream wrappers to hide
  196. // differences between std::stringstream and the old strstream.
  197. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  198. class cmOStringStream: public std::ostringstream
  199. {
  200. public:
  201. cmOStringStream();
  202. ~cmOStringStream();
  203. private:
  204. cmOStringStream(const cmOStringStream&);
  205. void operator=(const cmOStringStream&);
  206. };
  207. class cmIStringStream: public std::istringstream
  208. {
  209. public:
  210. typedef std::istringstream Superclass;
  211. cmIStringStream() {}
  212. cmIStringStream(const std::string& s): Superclass(s) {}
  213. private:
  214. cmIStringStream(const cmIStringStream&);
  215. void operator=(const cmIStringStream&);
  216. };
  217. #else
  218. class cmOStrStreamCleanup
  219. {
  220. public:
  221. cmOStrStreamCleanup(std::ostrstream& ostr): OStrStream(ostr) {}
  222. ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
  223. static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
  224. protected:
  225. std::ostrstream& OStrStream;
  226. };
  227. class cmOStringStream: public std::ostrstream
  228. {
  229. public:
  230. typedef std::ostrstream Superclass;
  231. cmOStringStream() {}
  232. std::string str()
  233. {
  234. cmOStrStreamCleanup cleanup(*this);
  235. cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
  236. int pcount = this->pcount();
  237. const char* ptr = this->Superclass::str();
  238. return std::string(ptr?ptr:"", pcount);
  239. }
  240. private:
  241. cmOStringStream(const cmOStringStream&);
  242. void operator=(const cmOStringStream&);
  243. };
  244. class cmIStringStream: private std::string, public std::istrstream
  245. {
  246. public:
  247. typedef std::string StdString;
  248. typedef std::istrstream IStrStream;
  249. cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
  250. cmIStringStream(const std::string& s):
  251. StdString(s), IStrStream(StdString::c_str()) {}
  252. std::string str() const { return *this; }
  253. void str(const std::string& s)
  254. {
  255. // Very dangerous. If this throws, the object is hosed. When the
  256. // destructor is later called, the program is hosed too.
  257. this->~cmIStringStream();
  258. new (this) cmIStringStream(s);
  259. }
  260. private:
  261. cmIStringStream(const cmIStringStream&);
  262. void operator=(const cmIStringStream&);
  263. };
  264. #endif
  265. /* Poison this operator to avoid common mistakes. */
  266. extern void operator << (std::ostream&, const cmOStringStream&);
  267. /** Standard documentation entry for cmDocumentation's formatting. */
  268. struct cmDocumentationEntry
  269. {
  270. std::string Name;
  271. std::string Brief;
  272. cmDocumentationEntry(){}
  273. cmDocumentationEntry(const char *doc[2])
  274. { if (doc[0]) this->Name = doc[0];
  275. if (doc[1]) this->Brief = doc[1];}
  276. cmDocumentationEntry(const char *n, const char *b)
  277. { if (n) this->Name = n; if (b) this->Brief = b; }
  278. };
  279. /** Data structure to represent a single command line. */
  280. class cmCustomCommandLine: public std::vector<std::string>
  281. {
  282. public:
  283. typedef std::vector<std::string> Superclass;
  284. typedef Superclass::iterator iterator;
  285. typedef Superclass::const_iterator const_iterator;
  286. };
  287. /** Data structure to represent a list of command lines. */
  288. class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
  289. {
  290. public:
  291. typedef std::vector<cmCustomCommandLine> Superclass;
  292. typedef Superclass::iterator iterator;
  293. typedef Superclass::const_iterator const_iterator;
  294. };
  295. #if defined(__sgi) && !defined(__GNUC__)
  296. # pragma reset woff 1375 /* base class destructor not virtual */
  297. #endif
  298. // All subclasses of cmCommand or cmCTestGenericHandler should
  299. // invoke this macro.
  300. #define cmTypeMacro(thisClass,superclass) \
  301. virtual const char* GetNameOfClass() { return #thisClass; } \
  302. typedef superclass Superclass; \
  303. static bool IsTypeOf(const char *type) \
  304. { \
  305. if ( !strcmp(#thisClass,type) ) \
  306. { \
  307. return true; \
  308. } \
  309. return Superclass::IsTypeOf(type); \
  310. } \
  311. virtual bool IsA(const char *type) \
  312. { \
  313. return thisClass::IsTypeOf(type); \
  314. } \
  315. static thisClass* SafeDownCast(cmObject *c) \
  316. { \
  317. if ( c && c->IsA(#thisClass) ) \
  318. { \
  319. return static_cast<thisClass *>(c); \
  320. } \
  321. return 0;\
  322. } \
  323. class cmTypeMacro_UseTrailingSemicolon
  324. inline bool cmHasLiteralPrefixImpl(const std::string &str1,
  325. const char *str2,
  326. size_t N)
  327. {
  328. return strncmp(str1.c_str(), str2, N) == 0;
  329. }
  330. inline bool cmHasLiteralPrefixImpl(const char* str1,
  331. const char *str2,
  332. size_t N)
  333. {
  334. return strncmp(str1, str2, N) == 0;
  335. }
  336. inline bool cmHasLiteralSuffixImpl(const std::string &str1,
  337. const char *str2,
  338. size_t N)
  339. {
  340. size_t len = str1.size();
  341. return len >= N && strcmp(str1.c_str() + len - N, str2) == 0;
  342. }
  343. inline bool cmHasLiteralSuffixImpl(const char* str1,
  344. const char* str2,
  345. size_t N)
  346. {
  347. size_t len = strlen(str1);
  348. return len >= N && strcmp(str1 + len - N, str2) == 0;
  349. }
  350. #if defined(_MSC_VER) && _MSC_VER < 1300 \
  351. || defined(__GNUC__) && __GNUC__ < 3
  352. #define cmArrayBegin(a) a
  353. #define cmArraySize(a) (sizeof(a)/sizeof(*a))
  354. #define cmArrayEnd(a) a + cmArraySize(a)
  355. #define cmHasLiteralPrefix(STR1, STR2) \
  356. cmHasLiteralPrefixImpl(STR1, "" STR2 "", sizeof(STR2) - 1)
  357. #define cmHasLiteralSuffix(STR1, STR2) \
  358. cmHasLiteralSuffixImpl(STR1, "" STR2 "", sizeof(STR2) - 1)
  359. #else
  360. template<typename T, size_t N>
  361. const T* cmArrayBegin(const T (&a)[N]) { return a; }
  362. template<typename T, size_t N>
  363. const T* cmArrayEnd(const T (&a)[N]) { return a + N; }
  364. template<typename T, size_t N>
  365. size_t cmArraySize(const T (&)[N]) { return N; }
  366. template<typename T, size_t N>
  367. bool cmHasLiteralPrefix(T str1, const char (&str2)[N])
  368. {
  369. return cmHasLiteralPrefixImpl(str1, str2, N - 1);
  370. }
  371. template<typename T, size_t N>
  372. bool cmHasLiteralSuffix(T str1, const char (&str2)[N])
  373. {
  374. return cmHasLiteralSuffixImpl(str1, str2, N - 1);
  375. }
  376. #endif
  377. struct cmStrCmp {
  378. cmStrCmp(const char *test) : m_test(test) {}
  379. cmStrCmp(const std::string &test) : m_test(test) {}
  380. bool operator()(const std::string& input) const
  381. {
  382. return m_test == input;
  383. }
  384. bool operator()(const char * input) const
  385. {
  386. return strcmp(input, m_test.c_str()) == 0;
  387. }
  388. private:
  389. const std::string m_test;
  390. };
  391. #endif