1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517
|
/*=========================================================================
Program: GCC-XML
Module: $RCSfile: gxConfiguration.cxx,v $
Language: C++
Date: $Date: 2010-02-10 14:29:32 $
Version: $Revision: 1.71 $
Copyright (c) 2002-2007 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "gxConfiguration.h"
#ifdef CMAKE_INTDIR
# define GCCXML_EXE_BUILD_DIR GCCXML_EXECUTABLE_DIR "/" CMAKE_INTDIR
#else
# define GCCXML_EXE_BUILD_DIR GCCXML_EXECUTABLE_DIR
#endif
#include <gxsys/RegularExpression.hxx>
#include <gxsys/ios/sstream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//----------------------------------------------------------------------------
const char* gxConfigurationVc6Registry =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
"DevStudio\\6.0\\Products\\Microsoft Visual C++;ProductDir";
const char* gxConfigurationVc7Registry =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.0\\Setup\\VC;ProductDir";
const char* gxConfigurationVc71Registry =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.1\\Setup\\VC;ProductDir";
const char* gxConfigurationVc8Registry =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\Setup\\VC;ProductDir";
const char* gxConfigurationVc8RegistryVersion =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0;CLR Version";
const char* gxConfigurationVc8exRegistry =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\8.0\\Setup\\VC;ProductDir";
const char* gxConfigurationVc8sdkRegistry =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3;Install Dir";
const char* gxConfigurationVc8sdk2Registry =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1;Install Dir";
const char* gxConfigurationVc9Registry =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0\\Setup\\VC;ProductDir";
const char* gxConfigurationVc9exRegistry =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\9.0\\Setup\\VC;ProductDir";
const char* gxConfigurationVc9sdkRegistry =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v6.0A;InstallationFolder";
//----------------------------------------------------------------------------
gxConfiguration::gxConfiguration()
{
m_HelpFlag = false;
m_VersionFlag = false;
m_PrintFlag = false;
m_PreprocessFlag = false;
m_DebugFlag = false;
m_ManFlag = false;
m_CopyrightFlag = false;
m_HelpHTMLFlag = false;
m_HaveGCCXML_CXXFLAGS = false;
m_HaveGCCXML_ROOT = false;
m_RunningInBuildTree = false;
}
//----------------------------------------------------------------------------
bool gxConfiguration::Configure(int argc, const char*const * argv)
{
// Find our working paths.
this->FindRoots(argv[0]);
// Process the command line.
if(!this->ProcessCommandLine(argc, argv)) { return false; }
// If a config file was not specified on the command line, check the
// environment now.
bool checkedEnvironment;
if(m_GCCXML_CONFIG.empty())
{
this->CheckEnvironment();
checkedEnvironment = true;
}
// Read the configuration file if it exists.
if(!this->CheckConfigFile()) { return false; }
// If we didn't earlier check the environment, do it now.
if(!checkedEnvironment)
{
this->CheckEnvironment();
}
// Check the alternative environment settings for "CXX" and
// "CXXFLAGS" as a last resort to get the compiler setting.
this->CheckCxxEnvironment();
// If no root has been set, use the data root.
if(m_GCCXML_ROOT.empty())
{
// The user has not explicitly set a GCCXML_ROOT.
m_GCCXML_ROOT = m_DataRoot;
}
else if(!gxSystemTools::SameFile(m_GCCXML_ROOT.c_str(),
m_DataRoot.c_str()))
{
// The user has explicitly set a GCCXML_ROOT.
m_HaveGCCXML_ROOT = true;
}
// If no executable has been set, see if there is one in the
// executable root.
if(m_GCCXML_EXECUTABLE.empty())
{
std::string loc = m_ExecutableRoot;
#ifdef CMAKE_INTDIR
if(m_RunningInBuildTree)
{
loc += "/" CMAKE_INTDIR;
}
#endif
loc += "/gccxml_cc1plus";
#ifdef _WIN32
loc += ".exe";
#endif
if(gxSystemTools::FileExists(loc.c_str()) &&
!gxSystemTools::FileIsDirectory(loc.c_str()))
{
m_GCCXML_EXECUTABLE = loc;
}
}
// If no executable has been set, try looking in the system path.
if(m_GCCXML_EXECUTABLE.empty())
{
m_GCCXML_EXECUTABLE = gxSystemTools::FindProgram("gccxml_cc1plus");
}
gxSystemTools::ConvertToUnixSlashes(m_GCCXML_ROOT);
gxSystemTools::ConvertToUnixSlashes(m_GCCXML_EXECUTABLE);
gxSystemTools::ConvertToUnixSlashes(m_GCCXML_CONFIG);
gxSystemTools::ConvertToUnixSlashes(m_GCCXML_COMPILER);
// If no preprocessor has been set, see if there is one next to the
// gccxml_cc1plus executable.
if(m_GCCXML_CPP.empty() && m_GCCXML_EXECUTABLE.length() > 0)
{
std::string loc =
gxSystemTools::GetFilenamePath(m_GCCXML_EXECUTABLE.c_str());
loc += "/gccxml_cpp0";
#ifdef _WIN32
loc += ".exe";
#endif
if(gxSystemTools::FileExists(loc.c_str()) &&
!gxSystemTools::FileIsDirectory(loc.c_str()))
{
m_GCCXML_CPP = loc;
}
}
// If no preprocessor has been set, try looking in the system path.
if(m_GCCXML_CPP.empty())
{
m_GCCXML_CPP = gxSystemTools::FindProgram("gccxml_cpp0");
}
// As a last resort, assume the preprocessor is built into the
// gccxml_cc1plus executable. This is the case when gccxml_cc1plus
// is gcc 3.3 or higher.
if(m_GCCXML_CPP.empty())
{
m_GCCXML_CPP = m_GCCXML_EXECUTABLE;
}
gxSystemTools::ConvertToUnixSlashes(m_GCCXML_CPP);
return true;
}
//----------------------------------------------------------------------------
bool gxConfiguration::ConfigureFlags()
{
if(!this->CheckFlags())
{
return false;
}
return true;
}
//----------------------------------------------------------------------------
void gxConfiguration::PrintConfiguration(std::ostream& os) const
{
os << "Configuration settings:\n"
<< " GCCXML_CONFIG=\"" << m_GCCXML_CONFIG.c_str() << "\"\n"
<< " GCCXML_COMPILER=\"" << m_GCCXML_COMPILER.c_str() << "\"\n"
<< " GCCXML_CXXFLAGS=\"" << m_GCCXML_CXXFLAGS.c_str() << "\"\n"
<< " GCCXML_EXECUTABLE=\"" << m_GCCXML_EXECUTABLE.c_str() << "\"\n"
<< " GCCXML_CPP=\"" << m_GCCXML_CPP.c_str() << "\"\n"
<< " GCCXML_FLAGS=\"" << m_GCCXML_FLAGS.c_str() << "\"\n"
<< " GCCXML_USER_FLAGS=\"" << m_GCCXML_USER_FLAGS.c_str() << "\"\n"
<< " GCCXML_ROOT=\"" << m_GCCXML_ROOT.c_str() << "\"\n";
if(!m_HaveGCCXML_ROOT && m_RunningInBuildTree)
{
os << " GCCXML_ROOT_SRC=\"" << GCCXML_SOURCE_DIR "/Support" << "\"\n";
}
}
//----------------------------------------------------------------------------
const std::vector<std::string>& gxConfiguration::GetArguments() const
{
return m_Arguments;
}
//----------------------------------------------------------------------------
void gxConfiguration::AddArguments(std::vector<std::string>& arguments) const
{
// Decide whether the preprocessor is built into a cc1plus
// executable or is given separately.
bool ppIsCC = (m_GCCXML_CPP.find("cpp0") == m_GCCXML_CPP.npos);
// Add standard arguments.
if(!this->GetPreprocessFlag() || ppIsCC)
{
// These arguments should not be used for a separate preprocessor.
arguments.push_back("-quiet");
arguments.push_back("-fsyntax-only");
arguments.push_back("-w");
#if !defined(GCCXML_NATIVE_CC1PLUS)
// If gccxml_cc1plus is provided separately, it will not have the
// gccxml-specific -iwrapper option. We need the -I- option
// instead.
arguments.push_back("-I-");
#endif
}
if(this->GetPreprocessFlag() && ppIsCC)
{
arguments.push_back("-E");
}
if(!this->GetPreprocessFlag())
{
// Thse arguments should not be used while preprocessing.
arguments.push_back("-o");
#if defined(_WIN32) && !defined(__CYGWIN__)
arguments.push_back("NUL");
#else
arguments.push_back("/dev/null");
#endif
}
// Remove preprocessor include paths built into the GCC parser.
arguments.push_back("-nostdinc");
// Remove preprocessor definitions built into the GCC parser.
arguments.push_back("-undef");
// Allow source code to be aware of GCC-XML.
gxsys_ios::ostringstream version;
version << "-D__GCCXML__=" << int(GCCXML_VERSION_MAJOR*10000 +
GCCXML_VERSION_MINOR*100 +
GCCXML_VERSION_PATCH);
arguments.push_back(version.str().c_str());
arguments.push_back("-D__GCCXML_GNUC__=4");
arguments.push_back("-D__GCCXML_GNUC_MINOR__=2");
arguments.push_back("-D__GCCXML_GNUC_PATCHLEVEL__=1");
// Add user arguments.
for(std::vector<std::string>::const_iterator i=m_Arguments.begin();
i != m_Arguments.end(); ++i)
{
arguments.push_back(*i);
}
}
//----------------------------------------------------------------------------
bool gxConfiguration::GetHelpFlag() const
{
return m_HelpFlag;
}
//----------------------------------------------------------------------------
bool gxConfiguration::GetVersionFlag() const
{
return m_VersionFlag;
}
//----------------------------------------------------------------------------
bool gxConfiguration::GetPrintFlag() const
{
return m_PrintFlag;
}
//----------------------------------------------------------------------------
bool gxConfiguration::GetPreprocessFlag() const
{
return m_PreprocessFlag;
}
//----------------------------------------------------------------------------
bool gxConfiguration::GetDebugFlag() const
{
return m_DebugFlag;
}
//----------------------------------------------------------------------------
bool gxConfiguration::GetManFlag() const
{
return m_ManFlag;
}
//----------------------------------------------------------------------------
bool gxConfiguration::GetCopyrightFlag() const
{
return m_CopyrightFlag;
}
//----------------------------------------------------------------------------
bool gxConfiguration::GetHelpHTMLFlag() const
{
return m_HelpHTMLFlag;
}
//----------------------------------------------------------------------------
const std::string& gxConfiguration::GetGCCXML_EXECUTABLE() const
{
return m_GCCXML_EXECUTABLE;
}
//----------------------------------------------------------------------------
const std::string& gxConfiguration::GetGCCXML_CPP() const
{
return m_GCCXML_CPP;
}
//----------------------------------------------------------------------------
const std::string& gxConfiguration::GetGCCXML_FLAGS() const
{
return m_GCCXML_FLAGS;
}
//----------------------------------------------------------------------------
const std::string& gxConfiguration::GetGCCXML_USER_FLAGS() const
{
return m_GCCXML_USER_FLAGS;
}
//----------------------------------------------------------------------------
void gxConfiguration::FindRoots(const char* argv0)
{
// Find our own executable's location.
std::string av0 = argv0;
gxSystemTools::ConvertToUnixSlashes(av0);
std::string::size_type pos = av0.find_last_of("/");
if(pos == std::string::npos)
{
av0 = gxSystemTools::FindProgram(argv0);
pos = av0.find_last_of("/");
}
std::string selfPath;
if(pos != std::string::npos)
{
selfPath = gxSystemTools::CollapseDirectory(av0.substr(0, pos).c_str());
}
else
{
selfPath = gxSystemTools::CollapseDirectory(".");
}
// Construct the name of the executable.
std::string exeName = argv0;
if(pos != std::string::npos)
{
exeName = av0.substr(pos+1).c_str();
}
#ifdef _WIN32
exeName = gxSystemTools::LowerCase(exeName.c_str());
if(exeName.length() < 4 || exeName.substr(exeName.length()-4) != ".exe")
{
exeName += ".exe";
}
#endif
// Construct the full path to this executable as if it were in the
// build tree, if it exists there.
std::string ePath="<GCCXML_EXECUTABLE_DIR-DOES-NOT-EXIST>";
if(gxSystemTools::FileIsDirectory(GCCXML_EXE_BUILD_DIR))
{
ePath = gxSystemTools::CollapseDirectory(GCCXML_EXE_BUILD_DIR);
ePath += "/";
ePath += exeName;
}
// Construct the full path to the executable from argv[0].
std::string sPath = selfPath;
sPath += "/";
sPath += exeName;
// If we are running from the build directory, use the source
// directory as the data root.
if(gxSystemTools::SameFile(sPath.c_str(), ePath.c_str()))
{
// The build location of the executable and the argv[0] are the
// same file. We are running from the build tree.
m_ExecutableRoot =
gxSystemTools::CollapseDirectory(GCCXML_EXECUTABLE_DIR);
m_DataRoot =
gxSystemTools::CollapseDirectory(GCCXML_BINARY_DIR "/Support");
m_RunningInBuildTree = true;
}
else
{
// Use our own location as the executable root.
m_ExecutableRoot = selfPath;
// Find the data files.
std::string sharePath = selfPath+"/../share/gccxml-" GCCXML_VERSION;
if(gxSystemTools::FileIsDirectory(sharePath.c_str()))
{
// The data files are in the share path next to the bin path.
m_DataRoot = gxSystemTools::CollapseDirectory(sharePath.c_str());
}
else
{
// Just assume that the data are next to the executable in the
// intallation.
m_DataRoot = m_ExecutableRoot;
}
}
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindData(const char* name)
{
std::string path;
return this->FindData(name, path, false);
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindData(const char* name, std::string& path,
bool required)
{
std::string loc1;
std::string loc2;
// Look in the configured root directory.
loc1 = m_GCCXML_ROOT + "/" + name;
if(gxSystemTools::FileExists(loc1.c_str()))
{
path = gxSystemTools::CollapseDirectory(loc1.c_str());
return true;
}
// Check the source tree data directory if the user did not
// explicitly configure a root.
if(!m_HaveGCCXML_ROOT && m_RunningInBuildTree)
{
loc2 = GCCXML_SOURCE_DIR "/Support/";
loc2 += name;
if(gxSystemTools::FileExists(loc2.c_str()))
{
path = gxSystemTools::CollapseDirectory(loc2.c_str());
return true;
}
}
// Report an error if the item is required.
if(required)
{
std::cerr << "Support item " << name << " is not available:\n";
std::cerr << " checked \"" << loc1 << "\"\n";
if(!loc2.empty())
{
std::cerr << " checked \"" << loc2 << "\"\n";
}
}
return false;
}
//----------------------------------------------------------------------------
bool gxConfiguration::ProcessCommandLine(int argc, const char*const* argv)
{
for(int i=1; i < argc;++i)
{
if(strcmp(argv[i], "--gccxml-compiler") == 0)
{
if(++i < argc)
{
m_GCCXML_COMPILER = argv[i];
}
else
{
std::cerr << "Option --gccxml-compiler requires an argument.\n";
return false;
}
}
else if(strcmp(argv[i], "--gccxml-cxxflags") == 0)
{
if(++i < argc)
{
m_GCCXML_CXXFLAGS = argv[i];
m_HaveGCCXML_CXXFLAGS = true;
}
else
{
std::cerr << "Option --gccxml-cxxflags requires an argument.\n";
return false;
}
}
else if(strcmp(argv[i], "--gccxml-executable") == 0)
{
if(++i < argc)
{
m_GCCXML_EXECUTABLE = argv[i];
}
else
{
std::cerr << "Option --gccxml-executable requires an argument.\n";
return false;
}
}
else if(strcmp(argv[i], "--gccxml-cpp") == 0)
{
if(++i < argc)
{
m_GCCXML_CPP = argv[i];
}
else
{
std::cerr << "Option --gccxml-cpp requires an argument.\n";
return false;
}
}
else if(strcmp(argv[i], "--gccxml-config") == 0)
{
if(++i < argc)
{
m_GCCXML_CONFIG = argv[i];
}
else
{
std::cerr << "Option --gccxml-config requires an argument.\n";
return false;
}
}
else if(strcmp(argv[i], "--gccxml-root") == 0)
{
if(++i < argc)
{
m_GCCXML_ROOT = argv[i];
}
else
{
std::cerr << "Option --gccxml-root requires an argument.\n";
return false;
}
}
else if(strcmp(argv[i], "--gccxml-gcc-options") == 0)
{
if(++i < argc)
{
if(!this->ReadArgumentFile(argv[i]))
{
std::cerr << "Error reading options from file \""
<< argv[i] << "\".\n";
return false;
}
}
else
{
std::cerr << "Option --gccxml-gcc-options requires an argument.\n";
return false;
}
}
else if(strcmp(argv[i], "--help") == 0)
{
m_HelpFlag = true;
}
else if(strcmp(argv[i], "--version") == 0)
{
m_VersionFlag = true;
}
else if(strcmp(argv[i], "--print") == 0)
{
m_PrintFlag = true;
}
else if((strcmp(argv[i], "--preprocess") == 0) ||
(strcmp(argv[i], "-E") == 0))
{
m_PreprocessFlag = true;
}
else if(strcmp(argv[i], "--debug") == 0)
{
m_DebugFlag = true;
}
else if(strcmp(argv[i], "--man") == 0)
{
m_ManFlag = true;
}
else if(strcmp(argv[i], "--copyright") == 0)
{
m_CopyrightFlag = true;
}
else if(strcmp(argv[i], "--help-html") == 0)
{
m_HelpHTMLFlag = true;
}
else if(strcmp(argv[i], "-c") == 0)
{
// Accept and ignore "-c" for ccache.
}
else if(strcmp(argv[i], "-o") == 0)
{
// Convert "-o" to "-fxml=" for ccache.
if(++i < argc)
{
m_Arguments.push_back(std::string("-fxml=") + argv[i]);
}
else
{
std::cerr << "Option -o requires an argument.\n";
return false;
}
}
else
{
m_Arguments.push_back(argv[i]);
}
}
return true;
}
//----------------------------------------------------------------------------
bool gxConfiguration::ReadArgumentFile(const char* fname)
{
std::ifstream fin(fname, std::ios::in);
if(!fin)
{
return false;
}
std::string option;
while(std::getline(fin, option))
{
// Remove leading and trailing whitespace.
std::string::size_type first = option.find_first_not_of(" \t");
std::string::size_type last = option.find_last_not_of(" \t");
if(first != std::string::npos && last != std::string::npos)
{
// There is at least one non-whitespace character.
option = option.substr(first, last-first+1);
// Look for comments.
if(option[0] != '#')
{
m_Arguments.push_back(option);
}
}
}
return true;
}
//----------------------------------------------------------------------------
void gxConfiguration::CheckEnvironment()
{
// Check for any settings we don't yet have in the environment.
if(m_GCCXML_CONFIG.empty())
{
gxSystemTools::GetEnv("GCCXML_CONFIG", m_GCCXML_CONFIG);
}
if(m_GCCXML_COMPILER.empty())
{
gxSystemTools::GetEnv("GCCXML_COMPILER", m_GCCXML_COMPILER);
}
if(!m_HaveGCCXML_CXXFLAGS)
{
m_HaveGCCXML_CXXFLAGS =
gxSystemTools::GetEnv("GCCXML_CXXFLAGS", m_GCCXML_CXXFLAGS);
}
if(m_GCCXML_EXECUTABLE.empty())
{
gxSystemTools::GetEnv("GCCXML_EXECUTABLE", m_GCCXML_EXECUTABLE);
}
if(m_GCCXML_CPP.empty())
{
gxSystemTools::GetEnv("GCCXML_CPP", m_GCCXML_CPP);
}
if(m_GCCXML_ROOT.empty())
{
gxSystemTools::GetEnv("GCCXML_ROOT", m_GCCXML_ROOT);
}
if(m_GCCXML_FLAGS.empty())
{
gxSystemTools::GetEnv("GCCXML_FLAGS", m_GCCXML_FLAGS);
}
if(m_GCCXML_USER_FLAGS.empty())
{
gxSystemTools::GetEnv("GCCXML_USER_FLAGS", m_GCCXML_USER_FLAGS);
}
}
//----------------------------------------------------------------------------
void gxConfiguration::CheckCxxEnvironment()
{
if(m_GCCXML_COMPILER.empty())
{
gxSystemTools::GetEnv("CXX", m_GCCXML_COMPILER);
}
if(!m_HaveGCCXML_CXXFLAGS)
{
m_HaveGCCXML_CXXFLAGS =
gxSystemTools::GetEnv("CXXFLAGS", m_GCCXML_CXXFLAGS);
}
}
//----------------------------------------------------------------------------
bool gxConfiguration::CheckConfigFile()
{
// If we don't have a config file, guess its location.
if(m_GCCXML_CONFIG.empty())
{
if(!this->FindConfigFile())
{
return true;
}
}
return this->ReadConfigFile();
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindConfigFile()
{
std::string home;
std::string config;
// Check for a configuration file in the home directory if not
// running from the build tree.
if(!m_RunningInBuildTree &&
gxSystemTools::GetEnv("HOME", home) && !home.empty())
{
home += "/.gccxml/config";
config = gxSystemTools::CollapseDirectory(home.c_str());
if(gxSystemTools::FileExists(config.c_str()))
{
m_GCCXML_CONFIG = config;
return true;
}
}
// Check for a configuration file in the data root directory.
config = m_DataRoot+"/gccxml_config";
if(gxSystemTools::FileExists(config.c_str()))
{
m_GCCXML_CONFIG = config;
return true;
}
return false;
}
//----------------------------------------------------------------------------
bool gxConfiguration::ReadConfigFile()
{
if(!gxSystemTools::FileExists(m_GCCXML_CONFIG.c_str()))
{
std::cerr << "Configuration file \"" << m_GCCXML_CONFIG.c_str()
<< "\" does not exist.\n";
return false;
}
std::ifstream config(m_GCCXML_CONFIG.c_str());
if(!config)
{
std::cerr << "Error opening configuration file \""
<< m_GCCXML_CONFIG.c_str() << "\".\n";
return false;
}
char buf[4096];
// Parse config values and set them if not already set.
while(config.getline(buf, 4096))
{
std::string key;
std::string value;
if(this->ParseConfigLine(buf, key, value))
{
if(key == "GCCXML_COMPILER")
{
if(m_GCCXML_COMPILER.empty()) { m_GCCXML_COMPILER = value; }
}
else if(key == "GCCXML_CXXFLAGS")
{
if(!m_HaveGCCXML_CXXFLAGS)
{
m_GCCXML_CXXFLAGS = value;
m_HaveGCCXML_CXXFLAGS = true;
}
}
else if(key == "GCCXML_EXECUTABLE")
{
if(m_GCCXML_EXECUTABLE.empty()) { m_GCCXML_EXECUTABLE = value; }
}
else if(key == "GCCXML_CPP")
{
if(m_GCCXML_CPP.empty()) { m_GCCXML_CPP = value; }
}
else if(key == "GCCXML_ROOT")
{
if(m_GCCXML_ROOT.empty()) { m_GCCXML_ROOT = value; }
}
else if(key == "GCCXML_FLAGS")
{
if(m_GCCXML_FLAGS.empty()) { m_GCCXML_FLAGS = value; }
}
else if(key == "GCCXML_USER_FLAGS")
{
if(m_GCCXML_USER_FLAGS.empty()) { m_GCCXML_USER_FLAGS = value; }
}
else
{
std::cerr << "Warning: ignoring setting for unknown key \""
<< key.c_str() << "\"\n";
}
}
}
return true;
}
//----------------------------------------------------------------------------
bool gxConfiguration::ParseConfigLine(const char* in_line, std::string& key,
std::string& value)
{
std::string line = in_line;
std::string::size_type lpos;
std::string::size_type rpos;
lpos = line.find_first_not_of(" \t\r");
// Ignore comments and blank lines.
if(lpos == std::string::npos) { return false; }
if(line[lpos] == '#') { return false; }
rpos = line.find("=", lpos);
if(rpos == std::string::npos)
{
std::cerr << "Warning: ignoring invalid config file line:\n"
<< line.c_str() << "\n";
return false;
}
// Have the key.
key = line.substr(lpos, rpos-lpos);
std::string rawValue = line.substr(rpos+1);
// Pull off the value with no leading or trailing whitespace.
lpos = rawValue.find_first_not_of(" \t\r");
rpos = rawValue.find_last_not_of(" \t\r");
if((lpos == std::string::npos) || (rpos == std::string::npos))
{
value = "";
return true;
}
// If the value is double quoted, remove the end quotes.
std::string strippedValue = rawValue.substr(lpos, rpos-lpos+1);
if((rawValue.length() >= 2) && (*strippedValue.begin() == '"')
&& (*(strippedValue.end()-1) == '"'))
{
strippedValue = strippedValue.substr(1, strippedValue.length()-2);
}
value = strippedValue;
return true;
}
//----------------------------------------------------------------------------
bool gxConfiguration::CheckCompiler()
{
// Make sure a compiler has been selected.
if(m_GCCXML_COMPILER.length() > 0) { return true; }
std::cerr << "Could not determine compiler setting.\n";
return false;
}
//----------------------------------------------------------------------------
bool gxConfiguration::CheckFlags()
{
// See if there are already flags set.
if(m_GCCXML_FLAGS.length() > 0) { return true; }
// No flags, need compiler setting to guess flags.
if(!this->CheckCompiler() || !this->FindFlags())
{
std::cerr << "Could not determine GCCXML_FLAGS setting.\n";
return false;
}
return true;
}
//----------------------------------------------------------------------------
// Implemented below (at the bottom of the cxx file) to avoid windows.h
// mangling of #define symbols...
int GetPID();
//----------------------------------------------------------------------------
std::string AttemptTempFileName(const char* prefix, const char* ext)
{
std::string dir;
std::string file;
// Get TMP, TEMP or "/tmp" dir if one exists,
// or if not, use "." (current dir)
//
gxSystemTools::GetEnv("TMP", dir);
if(dir.empty() || !gxSystemTools::FileExists(dir.c_str()))
{
gxSystemTools::GetEnv("TEMP", dir);
}
if(dir.empty() || !gxSystemTools::FileExists(dir.c_str()))
{
dir = "/tmp";
}
if(dir.empty() || !gxSystemTools::FileExists(dir.c_str()))
{
dir = ".";
}
gxSystemTools::ConvertToUnixSlashes(dir);
file = dir;
if(!gxSystemTools::StringEndsWith(file.c_str(), "/"))
{
file += "/";
}
if(prefix)
{
file += prefix;
}
gxsys_ios::ostringstream oss;
oss << GetPID();
file += oss.str();
if(ext)
{
file += ext;
}
return file;
}
//----------------------------------------------------------------------------
std::string GetTempFileName(const char* prefix, const char* ext)
{
std::string name(AttemptTempFileName(prefix, ext));
int counter = 1;
// Use counter to unique-ify and return a name that does not
// currently exist:
//
while (gxSystemTools::FileExists(name.c_str()))
{
gxsys_ios::ostringstream oss;
oss << "x";
oss << counter;
if (ext)
{
oss << ext;
}
name = AttemptTempFileName(prefix, oss.str().c_str());
counter++;
}
return name;
}
//----------------------------------------------------------------------------
std::string gxConfiguration::GetCompilerId()
{
// This method uses the technique formerly found in the shell script
// "${GCCXML_SOURCE_DIR}/Support/gccxml_find_flags" to identify the
// compiler whose executable file is m_GCCXML_COMPILER. It presently
// depends on the compiler being able to preprocess a ".cpp" input file
// via the -E command line argument with no other flags.
//
// An arguably better approach (but one that is more complex) would be
// to mimic what CMake does: compile its Modules/CMakeCXXCompilerId.cpp
// file and analyze the resulting compiler produced files for strings.
//
std::string compilerID("ERROR_unsupported_compiler_in_gxConfiguration_GetCompilerId");
std::string cppFile;
if(!this->FindData("gccxml_identify_compiler.cc", cppFile))
{
return "ERROR_cannot_find_compiler_id_source";
}
// Try running the compiler against the temp file with -E to preprocess
// the input. Then analyze the output looking for the id chunk.
//
std::string output;
int retVal=0;
std::string cmd = m_GCCXML_COMPILER;
cmd += " ";
cmd += m_GCCXML_CXXFLAGS;
cmd += " -E \"";
cmd += cppFile;
cmd += "\"";
if(gxSystemTools::RunCommand(cmd.c_str(), output, retVal) && (0 == retVal))
{
gxsys::RegularExpression reId;
reId.compile("GCCXML_SUPPORT[ ]*=[ ]*\"(.*)\"");
std::vector<gxsys::String> lines = gxSystemTools::SplitString(output.c_str(), '\n');
std::vector<gxsys::String>::iterator it;
for(it = lines.begin(); it != lines.end(); ++it)
{
if(reId.find(it->c_str()))
{
compilerID = reId.match(1);
break;
}
}
}
else
{
std::cerr << "error: could not identify compiler via -E preprocessing" << std::endl;
}
return compilerID;
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindFlags()
{
#if defined(_WIN32) && !defined(__CYGWIN__)
// This is a Windows environment. We must check the compiler name.
std::string compilerName = m_GCCXML_COMPILER;
compilerName = gxSystemTools::LowerCase(compilerName.c_str());
std::string::size_type pos = compilerName.find_last_of("/");
if(pos != std::string::npos)
{
compilerName = compilerName.substr(pos+1);
}
pos = compilerName.rfind(".exe");
if(pos != std::string::npos)
{
compilerName = compilerName.substr(0, pos);
}
// Dispatch to find compiler.
if(compilerName == "msvc6")
{
return this->FindFlagsMSVC6();
}
else if(compilerName == "msvc7")
{
return this->FindFlagsMSVC7();
}
else if(compilerName == "msvc71")
{
return this->FindFlagsMSVC71();
}
else if(compilerName == "msvc8")
{
std::string loc;
bool have8ex =
gxSystemTools::ReadRegistryValue(gxConfigurationVc8exRegistry, loc);
if(have8ex)
{
return this->FindFlagsMSVC8ex();
}
else
{
return this->FindFlagsMSVC8();
}
}
else if(compilerName == "msvc9")
{
std::string loc;
bool have9ex = false;
// gxSystemTools::ReadRegistryValue(gxConfigurationVc9exRegistry, loc);
if(have9ex)
{
return false; // this->FindFlagsMSVC8ex();
}
else
{
return this->FindFlagsMSVC9();
}
}
else if(compilerName == "cl")
{
// We must decide if this is MSVC 6, 7, 7.1, or 8.
std::string loc;
bool have6 = gxSystemTools::ReadRegistryValue(gxConfigurationVc6Registry,
loc);
bool have7 = gxSystemTools::ReadRegistryValue(gxConfigurationVc7Registry,
loc);
bool have71 = gxSystemTools::ReadRegistryValue(gxConfigurationVc71Registry,
loc);
bool have8ex =
gxSystemTools::ReadRegistryValue(gxConfigurationVc8exRegistry, loc);
bool have9 =
(gxSystemTools::ReadRegistryValue(gxConfigurationVc9Registry, loc) ||
gxSystemTools::ReadRegistryValue(gxConfigurationVc9exRegistry, loc));
// Look for a VS8 that is not the beta release.
bool have8 = false;
if(gxSystemTools::ReadRegistryValue(gxConfigurationVc8Registry, loc))
{
// The "CLR Version" registry entry in VS 8 has value "v2.0.40607"
// for the beta and "v2.0.50727" for the release.
std::string version;
if(gxSystemTools::ReadRegistryValue(gxConfigurationVc8RegistryVersion,
version))
{
int vnum;
if((sscanf(version.c_str(), "v2.0.%d", &vnum) == 1) &&
vnum >= 50727)
{
have8 = true;
}
}
}
// See if only one is installed.
if(have6 && !have7 && !have71 && !have8 && !have8ex && !have9)
{
return this->FindFlagsMSVC6();
}
else if(!have6 && have7 && !have71 && !have8 && !have8ex && !have9)
{
return this->FindFlagsMSVC7();
}
else if(!have6 && !have7 && have71 && !have8 && !have8ex && !have9)
{
return this->FindFlagsMSVC71();
}
else if(!have6 && !have7 && !have71 && have8 && !have8ex && !have9)
{
return this->FindFlagsMSVC8();
}
else if(!have6 && !have7 && !have71 && !have8 && have8ex && !have9)
{
return this->FindFlagsMSVC8ex();
}
else if(!have6 && !have7 && !have71 && !have8 && !have8ex && have9)
{
return this->FindFlagsMSVC9();
}
else if(have6 || have7 || have71 || have8 || have8ex || have9)
{
// Find available support directories.
bool support6 = have6 && this->FindData("Vc6");
bool support7 = have7 && this->FindData("Vc7");
bool support71 = have71 && this->FindData("Vc71");
bool support8 = have8 && this->FindData("Vc8");
bool support8ex = have8ex && this->FindData("Vc8ex");
bool support9 = have9 && this->FindData("Vc9");
// Have more than one. See if only one has the support
// directory available.
if(support6 && !support7 && !support71 && !support8 &&
!support8ex && !support9)
{
return this->FindFlagsMSVC6();
}
else if(!support6 && support7 && !support71 && !support8 &&
!support8ex && !support9)
{
return this->FindFlagsMSVC7();
}
else if(!support6 && !support7 && support71 && !support8 &&
!support8ex && !support9)
{
return this->FindFlagsMSVC71();
}
else if(!support6 && !support7 && !support71 && support8 &&
!support8ex && !support9)
{
return this->FindFlagsMSVC8();
}
else if(!support6 && !support7 && !support71 && !support8 &&
support8ex && !support9)
{
return this->FindFlagsMSVC8ex();
}
else if(!support6 && !support7 && !support71 && !support8 &&
!support8ex && support9)
{
return this->FindFlagsMSVC9();
}
else if(!support6 && !support7 && !support71 && !support8 &&
!support8ex && !support9)
{
std::cerr << "Compiler \"" << m_GCCXML_COMPILER
<< "\" is not supported by GCC_XML because none of \n"
<< "the Vc6, Vc7, Vc71, Vc8, or Vc8ex "
<< "support directories exists.\n";
return false;
}
// Can support either. See if one is found in the path.
std::string cl = gxSystemTools::FindProgram("cl");
if(cl.length() > 0)
{
// Found cl in the path. Look at full location.
gxSystemTools::ConvertToUnixSlashes(cl);
if((cl.find("/VC98/") != std::string::npos) ||
(cl.find("/vc98/") != std::string::npos) ||
(cl.find("/Vc98/") != std::string::npos))
{
return this->FindFlagsMSVC6();
}
else if((cl.find("/VC7/") != std::string::npos) ||
(cl.find("/vc7/") != std::string::npos) ||
(cl.find("/Vc7/") != std::string::npos))
{
// This is a cl from 7 or 7.1. Use one if we have it.
if(have7 && !have71)
{
return this->FindFlagsMSVC7();
}
else if(!have7 && have71)
{
return this->FindFlagsMSVC71();
}
}
// Couldn't tell from program location. Try running it.
std::string output;
int retVal=0;
if(gxSystemTools::RunCommand("cl", output, retVal) && (retVal == 0))
{
// The compiler ran. Get version from output.
if(output.find("Compiler Version 12.") != std::string::npos)
{
return this->FindFlagsMSVC6();
}
else if(output.find("Compiler Version 13.0") != std::string::npos)
{
return this->FindFlagsMSVC7();
}
else if(output.find("Compiler Version 13.1") != std::string::npos)
{
return this->FindFlagsMSVC71();
}
else if(output.find("Compiler Version 14.") != std::string::npos)
{
if(have8)
{
return this->FindFlagsMSVC8();
}
else if(have8ex)
{
return this->FindFlagsMSVC8ex();
}
}
else if(output.find("Compiler Version 15.") != std::string::npos)
{
return this->FindFlagsMSVC9();
}
}
// Couldn't tell by running the compiler.
}
// Couldn't tell by finding the compiler. Guess based on which
// was used to build this executable.
const char* const clText =
"Compiler \"cl\" specified, but more than one of "
"MSVC 6, 7, 7.1, 8, and 9 are installed.\n"
"Please specify \"msvc6\", \"msvc7\", \"msvc71\", \"msvc8\", "
"\"msvc8ex\", or \"msvc9\" for "
"the GCCXML_COMPILER setting.\n";
#if defined(_MSC_VER) && ((_MSC_VER >= 1200) && (_MSC_VER < 1300))
std::cerr << "Warning:\n" << clText
<< "Using MSVC 6 because it was used to build GCC-XML.\n"
<< "\n";
return this->FindFlagsMSVC6();
#elif defined(_MSC_VER) && ((_MSC_VER >= 1300) && (_MSC_VER < 1310))
std::cerr << "Warning:\n" << clText
<< "Using MSVC 7 because it was used to build GCC-XML.\n"
<< "\n";
return this->FindFlagsMSVC7();
#elif defined(_MSC_VER) && ((_MSC_VER >= 1310) && (_MSC_VER < 1400))
std::cerr << "Warning:\n" << clText
<< "Using MSVC 7.1 because it was used to build GCC-XML.\n"
<< "\n";
return this->FindFlagsMSVC71();
#elif defined(_MSC_VER) && ((_MSC_VER >= 1400) && (_MSC_VER < 1500))
std::cerr << "Warning:\n" << clText
<< "Using MSVC 8 because it was used to build GCC-XML.\n"
<< "\n";
if(have8)
{
return this->FindFlagsMSVC8();
}
else if(have8ex)
{
return this->FindFlagsMSVC8ex();
}
else
{
std::cerr << "No installed version of MSVC 8 was found!\n";
}
#elif defined(_MSC_VER) && ((_MSC_VER >= 1500) && (_MSC_VER < 1600))
std::cerr << "Warning:\n" << clText
<< "Using MSVC 9 because it was used to build GCC-XML.\n"
<< "\n";
return this->FindFlagsMSVC9();
#else
// Give up. The user must specify one.
std::cerr << clText;
return false;
#endif
}
else
{
std::cerr << "Compiler \"" << m_GCCXML_COMPILER
<< "\" is not supported by GCC_XML because "
<< "none of MSVC 6, 7, 7.1, 8, or 9 is installed.\n";
return false;
}
}
else if(compilerName == "bcc32")
{
// Compiler must be in the path. Find it.
std::string bcc32 = gxSystemTools::FindProgram("bcc32");
if(bcc32.length() > 0)
{
// Check if the compiler location gives its version.
if((bcc32.find("BCC55/") != bcc32.npos) ||
(bcc32.find("Bcc55/") != bcc32.npos) ||
(bcc32.find("bcc55/") != bcc32.npos))
{
return this->FindFlagsBCC55(bcc32.c_str());
}
// Couldn't tell from program location. Try running it.
std::string output;
int retVal=0;
if(gxSystemTools::RunCommand("bcc32", output, retVal) && (retVal == 0))
{
// The compiler ran. Get version from output.
if(output.find("Borland C++ 5.5") != std::string::npos)
{
return this->FindFlagsBCC55(bcc32.c_str());
}
}
}
}
std::string compilerID = this->GetCompilerId();
if(compilerID == "GCC")
{
return this->FindFlagsGCC();
}
else if(compilerID == "Intel")
{
return this->FindFlagsIntel();
}
else if(compilerID == "MIPSpro")
{
return this->FindFlagsMIPSpro();
}
// Didn't find / couldn't identify supported compiler.
//
std::cerr << std::endl;
std::cerr << "m_GCCXML_COMPILER: " << m_GCCXML_COMPILER << std::endl;
std::cerr << "compilerName: " << compilerName << std::endl;
std::cerr << "compilerID: " << compilerID << std::endl;
std::cerr << std::endl;
std::cerr << "Compiler \"" << m_GCCXML_COMPILER
<< "\" is not supported by GCC_XML.\n"
<< "(gxConfiguration::FindFlags)\n";
return false;
#else
// Determine the compiler.
std::string compilerID = this->GetCompilerId();
// For GCC use our C++ implementation to find flags.
if(compilerID == "GCC")
{
return this->FindFlagsGCC();
}
// For other compilers fall back to the old shell scripts.
std::string findFlags;
if(!this->FindData((compilerID+"/find_flags").c_str(), findFlags, true))
{
return false;
}
std::string gccxmlFindFlags = "\"";
gccxmlFindFlags += findFlags;
gccxmlFindFlags += "\" ";
gccxmlFindFlags += m_GCCXML_COMPILER;
gccxmlFindFlags += " ";
gccxmlFindFlags += m_GCCXML_CXXFLAGS;
int err;
std::string flags;
if(!gxSystemTools::RunCommand(gccxmlFindFlags.c_str(), flags, err) || err)
{
std::cerr << "Error executing \"" << gccxmlFindFlags << "\"\n";
return false;
}
// Remove newlines from the flags.
std::string::size_type pos = flags.find_first_of("\r\n");
while(pos != std::string::npos)
{
flags[pos] = ' ';
pos = flags.find_first_of("\r\n", pos+1);
}
m_GCCXML_FLAGS = flags;
return true;
#endif
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindFlagsGCC()
{
// C++ translation of the script "${GCCXML_SOURCE_DIR}/Support/GCC/find_flags"
//
int MAJOR_VERSION = -1;
int MINOR_VERSION = -1;
std::string MACROS;
std::string INCLUDES;
std::string SPECIAL;
gxsys::String s;
std::string supportPath;
// The support headers are located in "${GCCXML_SOURCE_DIR}/Support/GCC"
//
this->FindData("GCC", supportPath, true);
// Run the compiler preprocessor against an empty input file to get the list
// of macros that are pre-defined by the compiler:
//
std::string output;
int retVal=0;
if(gxSystemTools::RunCommand((std::string("echo \"\" | \"") + m_GCCXML_COMPILER + "\" -x c++ -E -dM " +
m_GCCXML_CXXFLAGS + " -").c_str(), output, retVal) && (retVal == 0))
{
std::vector<gxsys::String> lines = gxSystemTools::SplitString(output.c_str(), '\n');
gxsys::RegularExpression reDefine;
reDefine.compile("#define ([A-Za-z_][A-Za-z0-9_()]*) (.*)");
std::vector<gxsys::String>::iterator it;
for(it = lines.begin(); it != lines.end(); ++it)
{
if(reDefine.find(it->c_str()))
{
// __BLOCKS__ is an Apple extension to gcc unknown to gccxml.
if(reDefine.match(1) == "__BLOCKS__")
{
continue;
}
if (MACROS == "")
{
MACROS = "-D";
}
else
{
MACROS += " -D";
}
MACROS += reDefine.match(1);
MACROS += "='";
MACROS += reDefine.match(2);
MACROS += "'";
if (-1 == MAJOR_VERSION)
{
if (reDefine.match(1) == "__GNUC__")
{
MAJOR_VERSION = atoi(reDefine.match(2).c_str());
}
}
if (-1 == MINOR_VERSION)
{
if (reDefine.match(1) == "__GNUC_MINOR__")
{
MINOR_VERSION = atoi(reDefine.match(2).c_str());
}
}
}
}
}
if (-1 == MAJOR_VERSION)
{
std::cerr << "error: gxConfiguration::FindFlagsGCC did not find __GNUC__ definition.\n";
return false;
}
if (-1 == MINOR_VERSION)
{
std::cerr << "error: gxConfiguration::FindFlagsGCC did not find __GNUC_MINOR__ definition.\n";
return false;
}
// Run the compiler with "-v" against an empty input file to get the list
// of default include paths used by the compiler:
//
output = "";
retVal = 0;
if(gxSystemTools::RunCommand((std::string("echo \"\" | \"") + m_GCCXML_COMPILER + "\" -v -x c++ -E " +
m_GCCXML_CXXFLAGS + " 2>&1 -").c_str(), output, retVal) && (retVal == 0))
{
std::vector<gxsys::String> lines = gxSystemTools::SplitString(output.c_str(), '\n');
bool collecting = false;
gxsys::RegularExpression reBeginCollecting;
reBeginCollecting.compile("#include <\\.\\.\\.");
gxsys::RegularExpression reByeByeWhiteSpace;
reByeByeWhiteSpace.compile("^[ ]*(.*)[ ]*$");
std::vector<gxsys::String>::iterator it;
for(it = lines.begin(); it != lines.end(); ++it)
{
if(collecting)
{
if(it->c_str()[0] == ' ' || it->c_str()[0] == '/')
{
if(reByeByeWhiteSpace.find(it->c_str()))
{
s = reByeByeWhiteSpace.match(1);
}
else
{
s = *it;
}
if (INCLUDES != "")
{
INCLUDES += " ";
}
if(s.find("/Frameworks") != s.npos)
{
INCLUDES += "-F";
}
else
{
INCLUDES += "-isystem";
}
INCLUDES += "\"";
INCLUDES += s;
INCLUDES += "\"";
}
else
{
collecting = false;
}
}
else if(reBeginCollecting.find(*it))
{
collecting = true;
}
}
}
// hack to handle bad gcc 4.0 on RedHat
if(4 == MAJOR_VERSION && INCLUDES.find("c++/3.4") != INCLUDES.npos)
{
MAJOR_VERSION = 3;
MINOR_VERSION = 4;
}
// Extra INCLUDES and SPECIAL settings according to GCC version:
//
if(MAJOR_VERSION < 3)
{
INCLUDES = "-iwrapper\"" + supportPath + "/2.95\" " + INCLUDES;
if(MINOR_VERSION == 96)
{
INCLUDES = "-iwrapper\"" + supportPath + "/2.96\" " + INCLUDES;
}
}
else if(MAJOR_VERSION >= 4)
{
gxsys_ios::ostringstream includes;
includes << "-iwrapper\"" << supportPath << "/"
<< MAJOR_VERSION << "." << MINOR_VERSION << "\" "
<< INCLUDES;
INCLUDES = includes.str();
SPECIAL = "-include \"gccxml_builtins.h\"";
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION >= 4)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.4\" " + INCLUDES;
SPECIAL = "-include \"gccxml_builtins.h\"";
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 3)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.3\" " + INCLUDES;
SPECIAL = "-include \"gccxml_builtins.h\"";
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 2)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.2\" " + INCLUDES;
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 1)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.1\" " + INCLUDES;
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 0)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.0\" " + INCLUDES;
}
// Set the full flags string to "$MACROS $INCLUDES $SPECIAL"
//
std::string flags(MACROS);
if (INCLUDES != "")
{
if (flags != "")
{
flags += " ";
}
flags += INCLUDES;
}
if (SPECIAL != "")
{
if (flags != "")
{
flags += " ";
}
flags += SPECIAL;
}
m_GCCXML_FLAGS = flags;
return (m_GCCXML_FLAGS != "");
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindFlagsIntel()
{
// C++ translation of the script "${GCCXML_SOURCE_DIR}/Support/Intel/find_flags"
//
int MAJOR_VERSION = -1;
int MINOR_VERSION = -1;
std::cerr << "gxConfiguration::FindFlagsIntel not implemented yet.\n"
<< "Use GCC_XML/Support/Intel/find_flags until implemented.\n";
return false;
// TODO - finish Intel translation from sh/find_flags to C++
std::string MACROS;
std::string INCLUDES;
std::string SPECIAL;
gxsys::String s;
std::string supportPath;
// The support headers are located in "${GCCXML_SOURCE_DIR}/Support/Intel"
//
this->FindData("Intel", supportPath, true);
// Run the compiler preprocessor against an empty input file to get the list
// of macros that are pre-defined by the compiler:
//
std::string output;
int retVal=0;
if(gxSystemTools::RunCommand((std::string("echo \"\" | \"") + m_GCCXML_COMPILER + "\" -x c++ -E -dM " +
m_GCCXML_CXXFLAGS + " -").c_str(), output, retVal) && (retVal == 0))
{
std::vector<gxsys::String> lines = gxSystemTools::SplitString(output.c_str(), '\n');
gxsys::RegularExpression reDefine;
reDefine.compile("#define ([A-Za-z_][A-Za-z0-9_()]*) (.*)");
std::vector<gxsys::String>::iterator it;
for(it = lines.begin(); it != lines.end(); ++it)
{
if(reDefine.find(it->c_str()))
{
if (MACROS == "")
{
MACROS = "-D";
}
else
{
MACROS += " -D";
}
MACROS += reDefine.match(1);
MACROS += "='";
MACROS += reDefine.match(2);
MACROS += "'";
if (-1 == MAJOR_VERSION)
{
if (reDefine.match(1) == "__GNUC__")
{
MAJOR_VERSION = atoi(reDefine.match(2).c_str());
}
}
if (-1 == MINOR_VERSION)
{
if (reDefine.match(1) == "__GNUC_MINOR__")
{
MINOR_VERSION = atoi(reDefine.match(2).c_str());
}
}
}
}
}
if (-1 == MAJOR_VERSION)
{
std::cerr << "error: gxConfiguration::FindFlagsIntel did not find __GNUC__ definition.\n";
return false;
}
if (-1 == MINOR_VERSION)
{
std::cerr << "error: gxConfiguration::FindFlagsIntel did not find __GNUC_MINOR__ definition.\n";
return false;
}
// Run the compiler with "-v" against an empty input file to get the list
// of default include paths used by the compiler:
//
output = "";
retVal = 0;
if(gxSystemTools::RunCommand((std::string("echo \"\" | \"") + m_GCCXML_COMPILER + "\" -v -x c++ -E " +
m_GCCXML_CXXFLAGS + " -").c_str(), output, retVal) && (retVal == 0))
{
std::vector<gxsys::String> lines = gxSystemTools::SplitString(output.c_str(), '\n');
bool collecting = false;
gxsys::RegularExpression reBeginCollecting;
reBeginCollecting.compile("#include <\\.\\.\\.");
gxsys::RegularExpression reByeByeWhiteSpace;
reByeByeWhiteSpace.compile("^[ ]*(.*)[ ]*$");
std::vector<gxsys::String>::iterator it;
for(it = lines.begin(); it != lines.end(); ++it)
{
if(collecting)
{
if(it->c_str()[0] == ' ' || it->c_str()[0] == '/')
{
if(reByeByeWhiteSpace.find(it->c_str()))
{
s = reByeByeWhiteSpace.match(1);
}
else
{
s = *it;
}
if (INCLUDES != "")
{
INCLUDES += " ";
}
if (s.find(' ') == s.npos)
{
INCLUDES += "-I";
INCLUDES += s;
}
else
{
INCLUDES += "-I\"";
INCLUDES += s;
INCLUDES += "\"";
}
}
else
{
collecting = false;
}
}
else if(reBeginCollecting.find(*it))
{
collecting = true;
}
}
}
// hack to handle bad gcc 4.0 on RedHat
if(4 == MAJOR_VERSION && INCLUDES.find("c++/3.4") != INCLUDES.npos)
{
MAJOR_VERSION = 3;
MINOR_VERSION = 4;
}
// Extra INCLUDES and SPECIAL settings according to GCC version:
//
if(MAJOR_VERSION < 3)
{
INCLUDES = "-iwrapper\"" + supportPath + "/2.95\" " + INCLUDES;
if(MINOR_VERSION == 96)
{
INCLUDES = "-iwrapper\"" + supportPath + "/2.96\" " + INCLUDES;
}
}
else if(MAJOR_VERSION == 4 && MINOR_VERSION >= 1)
{
INCLUDES = "-iwrapper\"" + supportPath + "/4.1\" " + INCLUDES;
SPECIAL = "-include \"" + supportPath + "/4.1/gccxml_builtins.h\"";
}
else if(MAJOR_VERSION == 4 && MINOR_VERSION == 0)
{
INCLUDES = "-iwrapper\"" + supportPath + "/4.0\" " + INCLUDES;
SPECIAL = "-include \"" + supportPath + "/4.0/gccxml_builtins.h\"";
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION >= 4)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.4\" " + INCLUDES;
SPECIAL = "-include \"" + supportPath + "/3.4/gccxml_builtins.h\"";
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 3)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.3\" " + INCLUDES;
SPECIAL = "-include \"" + supportPath + "/3.3/gccxml_builtins.h\"";
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 2)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.2\" " + INCLUDES;
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 1)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.1\" " + INCLUDES;
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 0)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.0\" " + INCLUDES;
}
// Set the full flags string to "$MACROS $INCLUDES $SPECIAL"
//
std::string flags(MACROS);
if (INCLUDES != "")
{
if (flags != "")
{
flags += " ";
}
flags += INCLUDES;
}
if (SPECIAL != "")
{
if (flags != "")
{
flags += " ";
}
flags += SPECIAL;
}
m_GCCXML_FLAGS = flags;
return (m_GCCXML_FLAGS != "");
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindFlagsMIPSpro()
{
// C++ translation of the script "${GCCXML_SOURCE_DIR}/Support/MIPSpro/find_flags"
//
int MAJOR_VERSION = -1;
int MINOR_VERSION = -1;
std::cerr << "gxConfiguration::FindFlagsMIPSpro not implemented yet.\n"
<< "Use GCC_XML/Support/MIPSpro/find_flags until implemented.\n";
return false;
// TODO - finish MIPSPro translation from sh/find_flags to C++
std::string MACROS;
std::string INCLUDES;
std::string SPECIAL;
gxsys::String s;
std::string supportPath;
// The support headers are located in "${GCCXML_SOURCE_DIR}/Support/MIPSpro"
//
this->FindData("MIPSpro", supportPath, true);
// Run the compiler preprocessor against an empty input file to get the list
// of macros that are pre-defined by the compiler:
//
std::string output;
int retVal=0;
if(gxSystemTools::RunCommand((std::string("echo \"\" | \"") + m_GCCXML_COMPILER + "\" -x c++ -E -dM " +
m_GCCXML_CXXFLAGS + " -").c_str(), output, retVal) && (retVal == 0))
{
std::vector<gxsys::String> lines = gxSystemTools::SplitString(output.c_str(), '\n');
gxsys::RegularExpression reDefine;
reDefine.compile("#define ([A-Za-z_][A-Za-z0-9_()]*) (.*)");
std::vector<gxsys::String>::iterator it;
for(it = lines.begin(); it != lines.end(); ++it)
{
if(reDefine.find(it->c_str()))
{
if (MACROS == "")
{
MACROS = "-D";
}
else
{
MACROS += " -D";
}
MACROS += reDefine.match(1);
MACROS += "='";
MACROS += reDefine.match(2);
MACROS += "'";
if (-1 == MAJOR_VERSION)
{
if (reDefine.match(1) == "__GNUC__")
{
MAJOR_VERSION = atoi(reDefine.match(2).c_str());
}
}
if (-1 == MINOR_VERSION)
{
if (reDefine.match(1) == "__GNUC_MINOR__")
{
MINOR_VERSION = atoi(reDefine.match(2).c_str());
}
}
}
}
}
if (-1 == MAJOR_VERSION)
{
std::cerr << "error: gxConfiguration::FindFlagsMIPSpro did not find __GNUC__ definition.\n";
return false;
}
if (-1 == MINOR_VERSION)
{
std::cerr << "error: gxConfiguration::FindFlagsMIPSpro did not find __GNUC_MINOR__ definition.\n";
return false;
}
// Run the compiler with "-v" against an empty input file to get the list
// of default include paths used by the compiler:
//
output = "";
retVal = 0;
if(gxSystemTools::RunCommand((std::string("echo \"\" | \"") + m_GCCXML_COMPILER + "\" -v -x c++ -E " +
m_GCCXML_CXXFLAGS + " -").c_str(), output, retVal) && (retVal == 0))
{
std::vector<gxsys::String> lines = gxSystemTools::SplitString(output.c_str(), '\n');
bool collecting = false;
gxsys::RegularExpression reBeginCollecting;
reBeginCollecting.compile("#include <\\.\\.\\.");
gxsys::RegularExpression reByeByeWhiteSpace;
reByeByeWhiteSpace.compile("^[ ]*(.*)[ ]*$");
std::vector<gxsys::String>::iterator it;
for(it = lines.begin(); it != lines.end(); ++it)
{
if(collecting)
{
if(it->c_str()[0] == ' ' || it->c_str()[0] == '/')
{
if(reByeByeWhiteSpace.find(it->c_str()))
{
s = reByeByeWhiteSpace.match(1);
}
else
{
s = *it;
}
if (INCLUDES != "")
{
INCLUDES += " ";
}
if (s.find(' ') == s.npos)
{
INCLUDES += "-isystem";
INCLUDES += s;
}
else
{
INCLUDES += "-isystem\"";
INCLUDES += s;
INCLUDES += "\"";
}
}
else
{
collecting = false;
}
}
else if(reBeginCollecting.find(*it))
{
collecting = true;
}
}
}
// hack to handle bad gcc 4.0 on RedHat
if(4 == MAJOR_VERSION && INCLUDES.find("c++/3.4") != INCLUDES.npos)
{
MAJOR_VERSION = 3;
MINOR_VERSION = 4;
}
// Extra INCLUDES and SPECIAL settings according to GCC version:
//
if(MAJOR_VERSION < 3)
{
INCLUDES = "-iwrapper\"" + supportPath + "/2.95\" " + INCLUDES;
if(MINOR_VERSION == 96)
{
INCLUDES = "-iwrapper\"" + supportPath + "/2.96\" " + INCLUDES;
}
}
else if(MAJOR_VERSION == 4 && MINOR_VERSION >= 1)
{
INCLUDES = "-iwrapper\"" + supportPath + "/4.1\" " + INCLUDES;
SPECIAL = "-include \"" + supportPath + "/4.1/gccxml_builtins.h\"";
}
else if(MAJOR_VERSION == 4 && MINOR_VERSION == 0)
{
INCLUDES = "-iwrapper\"" + supportPath + "/4.0\" " + INCLUDES;
SPECIAL = "-include \"" + supportPath + "/4.0/gccxml_builtins.h\"";
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION >= 4)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.4\" " + INCLUDES;
SPECIAL = "-include \"" + supportPath + "/3.4/gccxml_builtins.h\"";
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 3)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.3\" " + INCLUDES;
SPECIAL = "-include \"" + supportPath + "/3.3/gccxml_builtins.h\"";
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 2)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.2\" " + INCLUDES;
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 1)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.1\" " + INCLUDES;
}
else if(MAJOR_VERSION == 3 && MINOR_VERSION == 0)
{
INCLUDES = "-iwrapper\"" + supportPath + "/3.0\" " + INCLUDES;
}
// Set the full flags string to "$MACROS $INCLUDES $SPECIAL"
//
std::string flags(MACROS);
if (INCLUDES != "")
{
if (flags != "")
{
flags += " ";
}
flags += INCLUDES;
}
if (SPECIAL != "")
{
if (flags != "")
{
flags += " ";
}
flags += SPECIAL;
}
m_GCCXML_FLAGS = flags;
return (m_GCCXML_FLAGS != "");
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindFlagsMSVC6()
{
// The registry key to use when attempting to automatically find the
// MSVC include files.
std::string msvcPath;
if(!gxSystemTools::ReadRegistryValue(gxConfigurationVc6Registry, msvcPath))
{
std::cerr << "Error finding MSVC 6.0 from registry.\n";
return false;
}
msvcPath += "/Include";
gxSystemTools::ConvertToUnixSlashes(msvcPath);
std::string vcIncludePath;
if(!this->FindData("Vc6/Include", vcIncludePath))
{
return false;
}
m_GCCXML_FLAGS =
"-U__STDC__ -U__STDC_HOSTED__ "
"-D__stdcall=__attribute__((__stdcall__)) "
"-D__cdecl=__attribute__((__cdecl__)) "
"-D__fastcall=__attribute__((__fastcall__)) "
"-D_stdcall=__attribute__((__stdcall__)) "
"-D_cdecl=__attribute__((__cdecl__)) "
"-D_fastcall=__attribute__((__fastcall__)) "
"-D__declspec(x)=__attribute__((x)) "
"-D_inline=inline -D__uuidof(x)=IID() -D__int64=\"long long\" "
"-D__cplusplus -D_MSC_VER=1200 -D_MSC_EXTENSIONS "
"-D_WIN32 -D_M_IX86 -D_WCHAR_T_DEFINED -D_INTEGRAL_MAX_BITS=64 "
"-DPASCAL= -DRPC_ENTRY= -DSHSTDAPI=HRESULT -DSHSTDAPI_(x)=x "
"-iwrapper\""+vcIncludePath+"\" -I\""+msvcPath+"\" ";
return true;
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindFlagsMSVC7()
{
// The registry key to use when attempting to automatically find the
// MSVC include files.
std::string msvcPath;
if(!gxSystemTools::ReadRegistryValue(gxConfigurationVc7Registry, msvcPath))
{
std::cerr << "Error finding MSVC 7.0 from registry.\n";
return false;
}
std::string msvcPath1 = msvcPath+"/Include";
std::string msvcPath2 = msvcPath+"/PlatformSDK/Include";
msvcPath1 = gxSystemTools::CollapseDirectory(msvcPath1.c_str());
msvcPath2 = gxSystemTools::CollapseDirectory(msvcPath2.c_str());
std::string vcIncludePath1;
std::string vcIncludePath2;
if(!this->FindData("Vc7/Include", vcIncludePath1) ||
!this->FindData("Vc7/PlatformSDK", vcIncludePath2))
{
return false;
}
m_GCCXML_FLAGS =
"-U__STDC__ -U__STDC_HOSTED__ "
"-D__stdcall=__attribute__((__stdcall__)) "
"-D__cdecl=__attribute__((__cdecl__)) "
"-D__fastcall=__attribute__((__fastcall__)) "
"-D_stdcall=__attribute__((__stdcall__)) "
"-D_cdecl=__attribute__((__cdecl__)) "
"-D_fastcall=__attribute__((__fastcall__)) "
"-D__declspec(x)=__attribute__((x)) "
"-D__cplusplus -D_inline=inline -D__forceinline=__inline "
"-D_MSC_VER=1300 -D_MSC_EXTENSIONS -D_WIN32 -D_M_IX86 "
"-D_WCHAR_T_DEFINED -DPASCAL= -DRPC_ENTRY= -DSHSTDAPI=HRESULT "
"-D_INTEGRAL_MAX_BITS=64 "
"-D__uuidof(x)=IID() -DSHSTDAPI_(x)=x -D__w64= -D__int64=\"long long\" "
"-iwrapper\""+vcIncludePath1+"\" "
"-iwrapper\""+vcIncludePath2+"\" "
"-I\""+msvcPath1+"\" "
"-I\""+msvcPath2+"\" ";
return true;
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindFlagsMSVC71()
{
// The registry key to use when attempting to automatically find the
// MSVC include files.
std::string msvcPath;
if(!gxSystemTools::ReadRegistryValue(gxConfigurationVc71Registry, msvcPath))
{
std::cerr << "Error finding MSVC 7.1 from registry.\n";
return false;
}
std::string msvcPath1 = msvcPath+"/Include";
std::string msvcPath2 = msvcPath+"/PlatformSDK/Include";
msvcPath1 = gxSystemTools::CollapseDirectory(msvcPath1.c_str());
msvcPath2 = gxSystemTools::CollapseDirectory(msvcPath2.c_str());
std::string vcIncludePath1;
std::string vcIncludePath2;
if(!this->FindData("Vc71/Include", vcIncludePath1) ||
!this->FindData("Vc71/PlatformSDK", vcIncludePath2))
{
return false;
}
m_GCCXML_FLAGS =
"-U__STDC__ -U__STDC_HOSTED__ "
"-D__stdcall=__attribute__((__stdcall__)) "
"-D__cdecl=__attribute__((__cdecl__)) "
"-D__fastcall=__attribute__((__fastcall__)) "
"-D_stdcall=__attribute__((__stdcall__)) "
"-D_cdecl=__attribute__((__cdecl__)) "
"-D_fastcall=__attribute__((__fastcall__)) "
"-D__declspec(x)=__attribute__((x)) "
"-D__cplusplus -D_inline=inline -D__forceinline=__inline "
"-D_MSC_VER=1310 -D_MSC_EXTENSIONS -D_WIN32 -D_M_IX86 "
"-D_WCHAR_T_DEFINED -DPASCAL= -DRPC_ENTRY= -DSHSTDAPI=HRESULT "
"-D_INTEGRAL_MAX_BITS=64 "
"-D__uuidof(x)=IID() -DSHSTDAPI_(x)=x -D__w64= -D__int64=\"long long\" "
"-iwrapper\""+vcIncludePath1+"\" "
"-iwrapper\""+vcIncludePath2+"\" "
"-I\""+msvcPath1+"\" "
"-I\""+msvcPath2+"\" ";
return true;
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindFlagsMSVC8()
{
// The registry key to use when attempting to automatically find the
// MSVC include files.
std::string msvcPath;
if(!gxSystemTools::ReadRegistryValue(gxConfigurationVc8Registry, msvcPath))
{
std::cerr << "Error finding MSVC 8 from registry.\n";
return false;
}
std::string msvcPath1 = msvcPath+"/Include";
std::string msvcPath2 = msvcPath+"/PlatformSDK/Include";
msvcPath1 = gxSystemTools::CollapseDirectory(msvcPath1.c_str());
msvcPath2 = gxSystemTools::CollapseDirectory(msvcPath2.c_str());
std::string vcIncludePath1;
std::string vcIncludePath2;
if(!this->FindData("Vc8/Include", vcIncludePath1) ||
!this->FindData("Vc8/PlatformSDK", vcIncludePath2))
{
return false;
}
m_GCCXML_FLAGS =
"-U__STDC__ -U__STDC_HOSTED__ "
"-D__stdcall=__attribute__((__stdcall__)) "
"-D__cdecl=__attribute__((__cdecl__)) "
"-D__fastcall=__attribute__((__fastcall__)) "
"-D__thiscall=__attribute__((__thiscall__)) "
"-D_stdcall=__attribute__((__stdcall__)) "
"-D_cdecl=__attribute__((__cdecl__)) "
"-D_fastcall=__attribute__((__fastcall__)) "
"-D_thiscall=__attribute__((__thiscall__)) "
"-D__declspec(x)=__attribute__((x)) -D__pragma(x)= "
"-D__cplusplus -D_inline=inline -D__forceinline=__inline "
"-D_MSC_VER=1400 -D_MSC_EXTENSIONS -D_WIN32 "
"-D_M_IX86 "
"-D_WCHAR_T_DEFINED -DPASCAL= -DRPC_ENTRY= -DSHSTDAPI=HRESULT "
"-D_INTEGRAL_MAX_BITS=64 "
"-D__uuidof(x)=IID() -DSHSTDAPI_(x)=x "
"-D__w64= "
"-D__int8=char "
"-D__int16=short "
"-D__int32=int "
"-D__int64=\"long long\" "
"-D__ptr64= "
"-DSTRSAFE_NO_DEPRECATE "
"-D_CRT_FAR_MAPPINGS_NO_DEPRECATE "
"-D_CRT_MANAGED_FP_NO_DEPRECATE "
"-D_CRT_MANAGED_HEAP_NO_DEPRECATE "
"-D_CRT_NONSTDC_NO_DEPRECATE "
"-D_CRT_OBSOLETE_NO_DEPRECATE "
"-D_CRT_SECURE_NO_DEPRECATE "
"-D_CRT_SECURE_NO_DEPRECATE_GLOBALS "
"-D_CRT_VCCLRIT_NO_DEPRECATE "
"-D_SCL_SECURE_NO_DEPRECATE "
"-D_WINDOWS_SECURE_NO_DEPRECATE "
"-iwrapper\""+vcIncludePath1+"\" "
"-iwrapper\""+vcIncludePath2+"\" "
"-I\""+msvcPath1+"\" "
"-I\""+msvcPath2+"\" ";
return true;
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindFlagsMSVC8ex()
{
// The registry key to use when attempting to automatically find the
// MSVC include files.
std::string msvcPath;
if(!gxSystemTools::ReadRegistryValue(gxConfigurationVc8exRegistry, msvcPath))
{
std::cerr << "Error finding MSVC 8 Express from registry.\n";
return false;
}
std::string msvcPath1 = msvcPath+"/Include";
msvcPath1 = gxSystemTools::CollapseDirectory(msvcPath1.c_str());
std::string vcIncludePath1;
if(!this->FindData("Vc8ex/Include", vcIncludePath1))
{
return false;
}
std::string psdkPath;
bool havePSDK =
gxSystemTools::ReadRegistryValue(gxConfigurationVc8sdk2Registry,
psdkPath) ||
gxSystemTools::ReadRegistryValue(gxConfigurationVc8sdkRegistry,
psdkPath);
std::string msvcPath2;
std::string vcIncludePath2;
if(havePSDK)
{
msvcPath2 = psdkPath+"/Include";
msvcPath2 = gxSystemTools::CollapseDirectory(msvcPath2.c_str());
if(!this->FindData("Vc8ex/PlatformSDK", vcIncludePath2))
{
return false;
}
}
m_GCCXML_FLAGS =
"-U__STDC__ -U__STDC_HOSTED__ "
"-D__stdcall=__attribute__((__stdcall__)) "
"-D__cdecl=__attribute__((__cdecl__)) "
"-D__fastcall=__attribute__((__fastcall__)) "
"-D__thiscall=__attribute__((__thiscall__)) "
"-D_stdcall=__attribute__((__stdcall__)) "
"-D_cdecl=__attribute__((__cdecl__)) "
"-D_fastcall=__attribute__((__fastcall__)) "
"-D_thiscall=__attribute__((__thiscall__)) "
"-D__declspec(x)=__attribute__((x)) -D__pragma(x)= "
"-D__cplusplus -D_inline=inline -D__forceinline=__inline "
"-D_MSC_VER=1400 -D_MSC_EXTENSIONS -D_WIN32 "
"-D_M_IX86 "
"-D_WCHAR_T_DEFINED -DPASCAL= -DRPC_ENTRY= -DSHSTDAPI=HRESULT "
"-D_INTEGRAL_MAX_BITS=64 "
"-D__uuidof(x)=IID() -DSHSTDAPI_(x)=x "
"-D__w64= "
"-D__int8=char "
"-D__int16=short "
"-D__int32=int "
"-D__int64=\"long long\" "
"-D__ptr64= "
"-DSTRSAFE_NO_DEPRECATE "
"-D_CRT_FAR_MAPPINGS_NO_DEPRECATE "
"-D_CRT_MANAGED_FP_NO_DEPRECATE "
"-D_CRT_MANAGED_HEAP_NO_DEPRECATE "
"-D_CRT_NONSTDC_NO_DEPRECATE "
"-D_CRT_OBSOLETE_NO_DEPRECATE "
"-D_CRT_SECURE_NO_DEPRECATE "
"-D_CRT_SECURE_NO_DEPRECATE_GLOBALS "
"-D_CRT_VCCLRIT_NO_DEPRECATE "
"-D_SCL_SECURE_NO_DEPRECATE "
"-D_WINDOWS_SECURE_NO_DEPRECATE ";
m_GCCXML_FLAGS += "-iwrapper\""+vcIncludePath1+"\" ";
if(havePSDK)
{
m_GCCXML_FLAGS += "-iwrapper\""+vcIncludePath2+"\" ";
}
m_GCCXML_FLAGS += "-I\""+msvcPath1+"\" ";
if(havePSDK)
{
m_GCCXML_FLAGS += "-I\""+msvcPath2+"\" ";
}
return true;
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindFlagsMSVC9()
{
// The registry key to use when attempting to automatically find the
// MSVC include files.
std::string msvcPath;
if(!gxSystemTools::ReadRegistryValue(gxConfigurationVc9Registry, msvcPath) &&
!gxSystemTools::ReadRegistryValue(gxConfigurationVc9exRegistry, msvcPath))
{
std::cerr << "Error finding MSVC 9 from registry.\n";
return false;
}
std::string psdkPath;
if(!gxSystemTools::ReadRegistryValue(gxConfigurationVc9sdkRegistry, psdkPath))
{
std::cerr << "Error finding MSVC 9 Platform SDK from registry.\n";
return false;
}
std::string msvcPath1 = msvcPath+"/Include";
std::string msvcPath2 = psdkPath+"/Include";
msvcPath1 = gxSystemTools::CollapseDirectory(msvcPath1.c_str());
msvcPath2 = gxSystemTools::CollapseDirectory(msvcPath2.c_str());
std::string vcIncludePath1;
std::string vcIncludePath2;
if(!this->FindData("Vc9/Include", vcIncludePath1) ||
!this->FindData("Vc9/PlatformSDK", vcIncludePath2))
{
return false;
}
m_GCCXML_FLAGS =
"-U__STDC__ -U__STDC_HOSTED__ "
"-D__stdcall=__attribute__((__stdcall__)) "
"-D__cdecl=__attribute__((__cdecl__)) "
"-D__fastcall=__attribute__((__fastcall__)) "
"-D__thiscall=__attribute__((__thiscall__)) "
"-D_stdcall=__attribute__((__stdcall__)) "
"-D_cdecl=__attribute__((__cdecl__)) "
"-D_fastcall=__attribute__((__fastcall__)) "
"-D_thiscall=__attribute__((__thiscall__)) "
"-D__declspec(x)=__attribute__((x)) -D__pragma(x)= "
"-D__cplusplus -D_inline=inline -D__forceinline=__inline "
"-D_MSC_VER=1500 -D_MSC_EXTENSIONS -D_WIN32 "
"-D_M_IX86 "
"-D_WCHAR_T_DEFINED -DPASCAL= -DRPC_ENTRY= -DSHSTDAPI=HRESULT "
"-D_INTEGRAL_MAX_BITS=64 "
"-D__uuidof(x)=IID() -DSHSTDAPI_(x)=x "
"-D__w64= "
"-D__int8=char "
"-D__int16=short "
"-D__int32=int "
"-D__int64=\"long long\" "
"-D__ptr64= "
"-DSTRSAFE_NO_DEPRECATE "
"-D_CRT_FAR_MAPPINGS_NO_DEPRECATE "
"-D_CRT_MANAGED_FP_NO_DEPRECATE "
"-D_CRT_MANAGED_HEAP_NO_DEPRECATE "
"-D_CRT_NONSTDC_NO_DEPRECATE "
"-D_CRT_OBSOLETE_NO_DEPRECATE "
"-D_CRT_SECURE_NO_DEPRECATE "
"-D_CRT_SECURE_NO_DEPRECATE_GLOBALS "
"-D_CRT_VCCLRIT_NO_DEPRECATE "
"-D_SCL_SECURE_NO_DEPRECATE "
"-D_WINDOWS_SECURE_NO_DEPRECATE "
"-iwrapper\""+vcIncludePath1+"\" "
"-iwrapper\""+vcIncludePath2+"\" "
"-I\""+msvcPath1+"\" "
"-I\""+msvcPath2+"\" ";
return true;
}
//----------------------------------------------------------------------------
bool gxConfiguration::FindFlagsBCC55(const char* inBcc32)
{
// Find the support include directory.
std::string include2;
if(!this->FindData("Borland/5.5", include2))
{
return false;
}
std::string include1 = include2;
include1 += "/Wrappers";
// Find the compiler's include directory.
std::string include3 = inBcc32;
include3 = include3.substr(0, include3.rfind('/'));
include3 = include3.substr(0, include3.rfind('/'));
include3 += "/Include";
if(!gxSystemTools::FileIsDirectory(include3.c_str()))
{
std::cerr << "Borland C++ 5.5 include directory cannot be found.\n";
std::cerr << "Checked \"" << include3.c_str()
<< "\" because it is the standard location relative to the "
<< "executable, which is located at \""
<< inBcc32 << "\".\n";
return false;
}
m_GCCXML_FLAGS =
"-D__stdcall=__attribute__((__stdcall__)) "
"-D__cdecl=__attribute__((__cdecl__)) "
"-D__fastcall=__attribute__((__fastcall__)) "
"-D_stdcall=__attribute__((__stdcall__)) "
"-D_cdecl=__attribute__((__cdecl__)) "
"-D_fastcall=__attribute__((__fastcall__)) "
"-D__declspec(x)=__attribute__((x)) "
"-D__cplusplus=1 -D_inline=inline -D__forceinline=__inline "
"-D__rtti= -D_WIN32=1 -D__WIN32__=1 -D_M_IX86 "
"-D_WCHAR_T_DEFINED -DPASCAL= -DRPC_ENTRY= -DSHSTDAPI=HRESULT "
"-D__uuidof(x)=IID() -DSHSTDAPI_(x)=x -D__w64= -D__int64=\"long long\" "
"-D__TURBOC__=0x0551 -D__BORLANDC__=0x0551 "
"-U__STDC__ -U__STDC_HOSTED__ -U__PTRDIFF_TYPE__ -U__SIZE_TYPE__ "
"-iwrapper\""+include1+"\" "
"-iwrapper\""+include2+"\" "
"-I\""+include3+"\" ";
return true;
}
//----------------------------------------------------------------------------
// Keep this section here (at the bottom of the cxx file) to avoid windows.h
// mangling of #define symbols...
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/types.h>
#include <unistd.h>
#endif
//----------------------------------------------------------------------------
int GetPID()
{
#ifdef _WIN32
return (int) GetCurrentProcessId();
#else
return (int) getpid();
#endif
}
|