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 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file LICENSE.rst or https://cmake.org/licensing for details.
include_guard(GLOBAL)
#[=======================================================================[.rst:
ExternalProject
---------------
.. only:: html
.. contents::
External Project Definition
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. command:: ExternalProject_Add
The ``ExternalProject_Add()`` function creates a custom target to drive
download, update/patch, configure, build, install and test steps of an
external project:
.. code-block:: cmake
ExternalProject_Add(<name> [<option>...])
The individual steps within the process can be driven independently if
required (e.g. for CDash submission) and extra custom steps can be defined,
along with the ability to control the step dependencies. The directory
structure used for the management of the external project can also be
customized. The function supports a large number of options which can be used
to tailor the external project behavior.
Directory Options
"""""""""""""""""
Most of the time, the default directory layout is sufficient. It is largely
an implementation detail that the main project usually doesn't need to
change. In some circumstances, however, control over the directory layout
can be useful or necessary. The directory options are potentially more
useful from the point of view that the main build can use the
:command:`ExternalProject_Get_Property` command to retrieve their values,
thereby allowing the main project to refer to build artifacts of the
external project.
``PREFIX <dir>``
Root directory for the external project. Unless otherwise noted below,
all other directories associated with the external project will be
created under here.
``TMP_DIR <dir>``
Directory in which to store temporary files.
``STAMP_DIR <dir>``
Directory in which to store the timestamps of each step. Log files from
individual steps are also created in here unless overridden by LOG_DIR
(see *Logging Options* below).
``LOG_DIR <dir>``
.. versionadded:: 3.14
Directory in which to store the logs of each step.
``DOWNLOAD_DIR <dir>``
Directory in which to store downloaded files before unpacking them. This
directory is only used by the URL download method, all other download
methods use ``SOURCE_DIR`` directly instead.
``SOURCE_DIR <dir>``
Source directory into which downloaded contents will be unpacked, or for
non-URL download methods, the directory in which the repository should be
checked out, cloned, etc. If no download method is specified, this must
point to an existing directory where the external project has already
been unpacked or cloned/checked out.
.. note::
If a download method is specified, any existing contents of the source
directory may be deleted. Only the URL download method checks whether
this directory is either missing or empty before initiating the
download, stopping with an error if it is not empty. All other
download methods silently discard any previous contents of the source
directory.
``BINARY_DIR <dir>``
Specify the build directory location. This option is ignored if
``BUILD_IN_SOURCE`` is enabled.
``INSTALL_DIR <dir>``
Installation prefix to be placed in the ``<INSTALL_DIR>`` placeholder.
This does not actually configure the external project to install to
the given prefix. That must be done by passing appropriate arguments
to the external project configuration step, e.g. using ``<INSTALL_DIR>``.
If any of the above ``..._DIR`` options are not specified, their defaults
are computed as follows. If the ``PREFIX`` option is given or the
``EP_PREFIX`` directory property is set, then an external project is built
and installed under the specified prefix::
TMP_DIR = <prefix>/tmp
STAMP_DIR = <prefix>/src/<name>-stamp
DOWNLOAD_DIR = <prefix>/src
SOURCE_DIR = <prefix>/src/<name>
BINARY_DIR = <prefix>/src/<name>-build
INSTALL_DIR = <prefix>
LOG_DIR = <STAMP_DIR>
Otherwise, if the ``EP_BASE`` directory property is set then components
of an external project are stored under the specified base::
TMP_DIR = <base>/tmp/<name>
STAMP_DIR = <base>/Stamp/<name>
DOWNLOAD_DIR = <base>/Download/<name>
SOURCE_DIR = <base>/Source/<name>
BINARY_DIR = <base>/Build/<name>
INSTALL_DIR = <base>/Install/<name>
LOG_DIR = <STAMP_DIR>
If no ``PREFIX``, ``EP_PREFIX``, or ``EP_BASE`` is specified, then the
default is to set ``PREFIX`` to ``<name>-prefix``. Relative paths are
interpreted with respect to :variable:`CMAKE_CURRENT_BINARY_DIR` at the
point where ``ExternalProject_Add()`` is called.
Download Step Options
"""""""""""""""""""""
A download method can be omitted if the ``SOURCE_DIR`` option is used to
point to an existing non-empty directory. Otherwise, one of the download
methods below must be specified (multiple download methods should not be
given) or a custom ``DOWNLOAD_COMMAND`` provided.
``DOWNLOAD_COMMAND <cmd>...``
Overrides the command used for the download step
(:manual:`generator expressions <cmake-generator-expressions(7)>` are
supported). If this option is specified, all other download options will
be ignored. Providing an empty string for ``<cmd>`` effectively disables
the download step.
URL
~~~
``URL <url1> [<url2>...]``
List of paths and/or URL(s) of the external project's source. When more
than one URL is given, they are tried in turn until one succeeds. A URL
may be an ordinary path in the local file system (in which case it
must be the only URL provided) or any downloadable URL supported by the
:command:`file(DOWNLOAD)` command. A local filesystem path may refer to
either an existing directory or to an archive file, whereas a URL is
expected to point to a file which can be treated as an archive. When an
archive is used, it will be unpacked automatically unless the
``DOWNLOAD_NO_EXTRACT`` option is set to prevent it. The archive type
is determined by inspecting the actual content rather than using logic
based on the file extension.
.. versionchanged:: 3.7
Multiple URLs are allowed.
``URL_HASH <algo>=<hashValue>``
Hash of the archive file to be downloaded. The argument should be of
the form ``<algo>=<hashValue>`` where ``algo`` can be any of the hashing
algorithms supported by the :command:`file()` command. Specifying this
option is strongly recommended for URL downloads, as it ensures the
integrity of the downloaded content. It is also used as a check for a
previously downloaded file, allowing connection to the remote location
to be avoided altogether if the local directory already has a file from
an earlier download that matches the specified hash.
``URL_MD5 <md5>``
Equivalent to ``URL_HASH MD5=<md5>``.
``DOWNLOAD_NAME <fname>``
File name to use for the downloaded file. If not given, the end of the
URL is used to determine the file name. This option is rarely needed,
the default name is generally suitable and is not normally used outside
of code internal to the ``ExternalProject`` module.
``DOWNLOAD_EXTRACT_TIMESTAMP <bool>``
.. versionadded:: 3.24
When specified with a true value, the timestamps of the extracted
files will match those in the archive. When false, the timestamps of
the extracted files will reflect the time at which the extraction
was performed. If the download URL changes, timestamps based off
those in the archive can result in dependent targets not being rebuilt
when they potentially should have been. Therefore, unless the file
timestamps are significant to the project in some way, use a false
value for this option. If ``DOWNLOAD_EXTRACT_TIMESTAMP`` is not given,
the default is false. See policy :policy:`CMP0135`.
``DOWNLOAD_NO_EXTRACT <bool>``
.. versionadded:: 3.6
Allows the extraction part of the download step to be disabled by
passing a boolean true value for this option. If this option is not
given, the downloaded contents will be unpacked automatically if
required. If extraction has been disabled, the full path to the
downloaded file is available as ``<DOWNLOADED_FILE>`` in subsequent
steps or as the property ``DOWNLOADED_FILE`` with the
:command:`ExternalProject_Get_Property` command.
``DOWNLOAD_NO_PROGRESS <bool>``
Can be used to disable logging the download progress. If this option is
not given, download progress messages will be logged.
``TIMEOUT <seconds>``
Maximum time allowed for file download operations.
``INACTIVITY_TIMEOUT <seconds>``
.. versionadded:: 3.19
Terminate the operation after a period of inactivity.
``HTTP_USERNAME <username>``
.. versionadded:: 3.7
Username for the download operation if authentication is required.
``HTTP_PASSWORD <password>``
.. versionadded:: 3.7
Password for the download operation if authentication is required.
``HTTP_HEADER <header1> [<header2>...]``
.. versionadded:: 3.7
Provides an arbitrary list of HTTP headers for the download operation.
This can be useful for accessing content in systems like AWS, etc.
``TLS_VERSION <min>``
.. versionadded:: 3.30
Specify minimum TLS version for ``https://`` URLs. If this option is
not provided, the value of the :variable:`CMAKE_TLS_VERSION` variable
or the :envvar:`CMAKE_TLS_VERSION` environment variable will be used
instead (see :command:`file(DOWNLOAD)`).
This option also applies to ``git clone`` invocations, although the
default behavior is different. If none of the ``TLS_VERSION`` option,
:variable:`CMAKE_TLS_VERSION` variable, or :envvar:`CMAKE_TLS_VERSION`
environment variable is specified, the behavior will be determined by
git's default or a ``http.sslVersion`` git config option the user may
have set at a global level.
``TLS_VERIFY <bool>``
Specifies whether certificate verification should be performed for
``https://`` URLs. If this option is not provided, the value of the
:variable:`CMAKE_TLS_VERIFY` variable or the :envvar:`CMAKE_TLS_VERIFY`
environment variable will be used instead (see :command:`file(DOWNLOAD)`).
If neither of those is set, certificate verification will not be performed.
In situations where ``URL_HASH`` cannot be provided, this option can
be an alternative verification measure.
This option also applies to ``git clone`` invocations, although the
default behavior is different. If none of the ``TLS_VERIFY`` option,
:variable:`CMAKE_TLS_VERIFY` variable, or :envvar:`CMAKE_TLS_VERIFY`
environment variable is specified, the behavior will be determined by
git's default (true) or a ``http.sslVerify`` git config option the
user may have set at a global level.
.. versionchanged:: 3.6
Previously this option did not apply to ``git clone`` invocations.
.. versionchanged:: 3.30
Previously the :envvar:`CMAKE_TLS_VERIFY` environment variable
was not checked.
``TLS_CAINFO <file>``
Specify a custom certificate authority file to use if ``TLS_VERIFY``
is enabled. If this option is not specified, the value of the
:variable:`CMAKE_TLS_CAINFO` variable will be used instead (see
:command:`file(DOWNLOAD)`)
``NETRC <level>``
.. versionadded:: 3.11
Specify whether the ``.netrc`` file is to be used for operation.
If this option is not specified, the value of the
:variable:`CMAKE_NETRC` variable will be used instead
(see :command:`file(DOWNLOAD)`). Valid levels are:
``IGNORED``
The ``.netrc`` file is ignored.
This is the default.
``OPTIONAL``
The ``.netrc`` file is optional, and information in the URL
is preferred. The file will be scanned to find which ever
information is not specified in the URL.
``REQUIRED``
The ``.netrc`` file is required, and information in the URL
is ignored.
``NETRC_FILE <file>``
.. versionadded:: 3.11
Specify an alternative ``.netrc`` file to the one in your home directory
if the ``NETRC`` level is ``OPTIONAL`` or ``REQUIRED``. If this option
is not specified, the value of the :variable:`CMAKE_NETRC_FILE` variable
will be used instead (see :command:`file(DOWNLOAD)`)
.. versionadded:: 3.1
Added support for `tbz2`, `.tar.xz`, `.txz`, and `.7z` extensions.
.. versionadded:: 4.1
All archive types that :option:`cmake -E tar <cmake-E tar>` can extract
are supported regardless of file extension.
Git
~~~
NOTE: A git version of 1.6.5 or later is required if this download method
is used.
``GIT_REPOSITORY <url>``
URL of the git repository. Any URL understood by the ``git`` command
may be used.
.. versionchanged:: 3.27
A relative URL will be resolved based on the parent project's
remote, subject to :policy:`CMP0150`. See the policy documentation
for how the remote is selected, including conditions where the
remote selection can fail. Local filesystem remotes should
always use absolute paths.
``GIT_TAG <tag>``
Git branch name, tag or commit hash. Note that branch names and tags
should generally be specified as remote names (i.e. ``origin/myBranch``
rather than simply ``myBranch``). This ensures that if the remote end
has its tag moved or branch rebased or history rewritten, the local
clone will still be updated correctly. In general, however, specifying
a commit hash should be preferred for a number of reasons:
- If the local clone already has the commit corresponding to the hash,
no ``git fetch`` needs to be performed to check for changes each time
CMake is re-run. This can result in a significant speed up if many
external projects are being used.
- Using a specific git hash ensures that the main project's own history
is fully traceable to a specific point in the external project's
evolution. If a branch or tag name is used instead, then checking out
a specific commit of the main project doesn't necessarily pin the
whole build to a specific point in the life of the external project.
The lack of such deterministic behavior makes the main project lose
traceability and repeatability.
If ``GIT_SHALLOW`` is enabled then ``GIT_TAG`` works only with
branch names and tags. A commit hash is not allowed.
Note that if not provided, ``GIT_TAG`` defaults to ``master``, not the
default Git branch name.
``GIT_REMOTE_NAME <name>``
The optional name of the remote. If this option is not specified, it
defaults to ``origin``.
``GIT_SUBMODULES <module>...``
Specific git submodules that should also be updated. If this option is
not provided, all git submodules will be updated.
.. versionchanged:: 3.16
When :policy:`CMP0097` is set to ``NEW``, if this value is set
to an empty string then no submodules are initialized or updated.
``GIT_SUBMODULES_RECURSE <bool>``
.. versionadded:: 3.17
Specify whether git submodules (if any) should update recursively by
passing the ``--recursive`` flag to ``git submodule update``.
If not specified, the default is on.
``GIT_SHALLOW <bool>``
.. versionadded:: 3.6
When this option is enabled, the ``git clone`` operation will be given
the ``--depth 1`` option. This performs a shallow clone, which avoids
downloading the whole history and instead retrieves just the commit
denoted by the ``GIT_TAG`` option.
``GIT_PROGRESS <bool>``
.. versionadded:: 3.8
When enabled, this option instructs the ``git clone`` operation to
report its progress by passing it the ``--progress`` option. Without
this option, the clone step for large projects may appear to make the
build stall, since nothing will be logged until the clone operation
finishes. While this option can be used to provide progress to prevent
the appearance of the build having stalled, it may also make the build
overly noisy if lots of external projects are used.
``GIT_CONFIG <option1> [<option2>...]``
.. versionadded:: 3.8
Specify a list of config options to pass to ``git clone``. Each option
listed will be transformed into its own ``--config <option>`` on the
``git clone`` command line, with each option required to be in the
form ``key=value``.
``GIT_REMOTE_UPDATE_STRATEGY <strategy>``
.. versionadded:: 3.18
When ``GIT_TAG`` refers to a remote branch, this option can be used to
specify how the update step behaves. The ``<strategy>`` must be one of
the following:
``CHECKOUT``
Ignore the local branch and always checkout the branch specified by
``GIT_TAG``.
``REBASE``
Try to rebase the current branch to the one specified by ``GIT_TAG``.
If there are local uncommitted changes, they will be stashed first
and popped again after rebasing. If rebasing or popping stashed
changes fail, abort the rebase and halt with an error.
When ``GIT_REMOTE_UPDATE_STRATEGY`` is not present, this is the
default strategy unless the default has been overridden with
``CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY`` (see below).
Note that if the branch specified in ``GIT_TAG`` is different to
the upstream branch currently being tracked, it is not safe to
perform a rebase. In that situation, ``REBASE`` will silently be
treated as ``CHECKOUT`` instead.
``REBASE_CHECKOUT``
Same as ``REBASE`` except if the rebase fails, an annotated tag will
be created at the original ``HEAD`` position from before the rebase
and then checkout ``GIT_TAG`` just like the ``CHECKOUT`` strategy.
The message stored on the annotated tag will give information about
what was attempted and the tag name will include a timestamp so that
each failed run will add a new tag. This strategy ensures no changes
will be lost, but updates should always succeed if ``GIT_TAG`` refers
to a valid ref unless there are uncommitted changes that cannot be
popped successfully.
The variable ``CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY`` can be set to
override the default strategy. This variable should not be set by a
project, it is intended for the user to set. It is primarily intended
for use in continuous integration scripts to ensure that when history
is rewritten on a remote branch, the build doesn't end up with
unintended changes or failed builds resulting from conflicts during
rebase operations.
Subversion
~~~~~~~~~~
``SVN_REPOSITORY <url>``
URL of the Subversion repository.
``SVN_REVISION -r<rev>``
Revision to checkout from the Subversion repository.
``SVN_USERNAME <username>``
Username for the Subversion checkout and update.
``SVN_PASSWORD <password>``
Password for the Subversion checkout and update.
``SVN_TRUST_CERT <bool>``
Specifies whether to trust the Subversion server site certificate. If
enabled, the ``--trust-server-cert`` option is passed to the ``svn``
checkout and update commands.
Mercurial
~~~~~~~~~
``HG_REPOSITORY <url>``
URL of the mercurial repository.
``HG_TAG <tag>``
Mercurial branch name, tag or commit id.
CVS
~~~
``CVS_REPOSITORY <cvsroot>``
CVSROOT of the CVS repository.
``CVS_MODULE <mod>``
Module to checkout from the CVS repository.
``CVS_TAG <tag>``
Tag to checkout from the CVS repository.
Update Step Options
"""""""""""""""""""
Whenever CMake is re-run, by default the external project's sources will be
updated if the download method supports updates (e.g. a git repository
would be checked if the ``GIT_TAG`` does not refer to a specific commit).
``UPDATE_COMMAND <cmd>...``
Overrides the download method's update step with a custom command.
The command may use
:manual:`generator expressions <cmake-generator-expressions(7)>`.
``UPDATE_DISCONNECTED <bool>``
.. versionadded:: 3.2
When enabled, this option causes the update step to be skipped (but see
below for changed behavior where this is not the case). It does not
prevent the download step. The update step can still be
added as a step target (see :command:`ExternalProject_Add_StepTargets`)
and called manually. This is useful if you want to allow developers to
build the project when disconnected from the network (the network may
still be needed for the download step though).
.. versionchanged:: 3.27
When ``UPDATE_DISCONNECTED`` is true, the update step will be executed
if any details about the update or download step are changed.
Furthermore, if using the git download/update method, the update
logic will be modified to skip attempts to contact the remote.
If the ``GIT_TAG`` mentions a ref that is not known locally, the
update step will halt with a fatal error.
When this option is present, it is generally advisable to make the value
a cache variable under the developer's control rather than hard-coding
it. If this option is not present, the default value is taken from the
``EP_UPDATE_DISCONNECTED`` directory property. If that is also not
defined, updates are performed as normal. The ``EP_UPDATE_DISCONNECTED``
directory property is intended as a convenience for controlling the
``UPDATE_DISCONNECTED`` behavior for an entire section of a project's
directory hierarchy and may be a more convenient method of giving
developers control over whether or not to perform updates (assuming the
project also provides a cache variable or some other convenient method
for setting the directory property).
This may cause a step target to be created automatically for the
``download`` step. See policy :policy:`CMP0114`.
Patch Step Options
""""""""""""""""""
``PATCH_COMMAND <cmd>...``
Specifies a custom command to patch the sources after an update. By
default, no patch command is defined. Note that it can be quite difficult
to define an appropriate patch command that performs robustly, especially
for download methods such as git where changing the ``GIT_TAG`` will not
discard changes from a previous patch, but the patch command will be
called again after updating to the new tag.
Configure Step Options
""""""""""""""""""""""
The configure step is run after the download and update steps. By default,
the external project is assumed to be a CMake project, but this can be
overridden if required.
``CONFIGURE_COMMAND <cmd>...``
The default configure command runs CMake with a few options based on
the main project. The options added are typically only those needed to
use the same generator as the main project, but the ``CMAKE_GENERATOR``
option can be given to override this. The project is responsible for
adding any toolchain details, flags or other settings it wants to
reuse from the main project or otherwise specify (see ``CMAKE_ARGS``,
``CMAKE_CACHE_ARGS`` and ``CMAKE_CACHE_DEFAULT_ARGS`` below).
For non-CMake external projects, the ``CONFIGURE_COMMAND`` option must
be used to override the default configure command
(:manual:`generator expressions <cmake-generator-expressions(7)>` are
supported). For projects that require no configure step, specify this
option with an empty string as the command to execute.
``CMAKE_COMMAND /.../cmake``
Specify an alternative cmake executable for the configure step (use an
absolute path). This is generally not recommended, since it is
usually desirable to use the same CMake version throughout the whole
build. This option is ignored if a custom configure command has been
specified with ``CONFIGURE_COMMAND``.
``CMAKE_GENERATOR <gen>``
Override the CMake generator used for the configure step. Without this
option, the same generator as the main build will be used. This option is
ignored if a custom configure command has been specified with the
``CONFIGURE_COMMAND`` option.
``CMAKE_GENERATOR_PLATFORM <platform>``
.. versionadded:: 3.1
Pass a generator-specific platform name to the CMake command (see
:variable:`CMAKE_GENERATOR_PLATFORM`). It is an error to provide this
option without the ``CMAKE_GENERATOR`` option.
``CMAKE_GENERATOR_TOOLSET <toolset>``
Pass a generator-specific toolset name to the CMake command (see
:variable:`CMAKE_GENERATOR_TOOLSET`). It is an error to provide this
option without the ``CMAKE_GENERATOR`` option.
``CMAKE_GENERATOR_INSTANCE <instance>``
.. versionadded:: 3.11
Pass a generator-specific instance selection to the CMake command (see
:variable:`CMAKE_GENERATOR_INSTANCE`). It is an error to provide this
option without the ``CMAKE_GENERATOR`` option.
``CMAKE_ARGS <arg>...``
The specified arguments are passed to the :program:`cmake` command line.
They can be any argument the :program:`cmake` command understands, not just
cache values defined by ``-D...`` arguments (see also
:manual:`CMake Options <cmake(1)>`).
.. versionadded:: 3.3
Arguments may use
:manual:`generator expressions <cmake-generator-expressions(7)>`.
``CMAKE_CACHE_ARGS <arg>...``
This is an alternate way of specifying cache variables where command line
length issues may become a problem. The arguments are expected to be in
the form ``-Dvar:STRING=value``, which are then transformed into
CMake :command:`set` commands with the ``FORCE`` option used. These
``set()`` commands are written to a pre-load script which is then applied
using the :manual:`cmake -C <cmake(1)>` command line option.
.. versionadded:: 3.3
Arguments may use
:manual:`generator expressions <cmake-generator-expressions(7)>`.
``CMAKE_CACHE_DEFAULT_ARGS <arg>...``
.. versionadded:: 3.2
This is the same as the ``CMAKE_CACHE_ARGS`` option except the ``set()``
commands do not include the ``FORCE`` keyword. This means the values act
as initial defaults only and will not override any variables already set
from a previous run. Use this option with care, as it can lead to
different behavior depending on whether the build starts from a fresh
build directory or reuses previous build contents.
.. versionadded:: 3.15
If the CMake generator is the ``Green Hills MULTI`` and not overridden,
the original project's settings for the GHS toolset and target system
customization cache variables are propagated into the external project.
``SOURCE_SUBDIR <dir>``
.. versionadded:: 3.7
When no ``CONFIGURE_COMMAND`` option is specified, the configure step
assumes the external project has a ``CMakeLists.txt`` file at the top of
its source tree (i.e. in ``SOURCE_DIR``). The ``SOURCE_SUBDIR`` option
can be used to point to an alternative directory within the source tree
to use as the top of the CMake source tree instead. This must be a
relative path and it will be interpreted as being relative to
``SOURCE_DIR``.
.. versionadded:: 3.14
When ``BUILD_IN_SOURCE`` option is enabled, the ``BUILD_COMMAND``
is used to point to an alternative directory within the source tree.
``CONFIGURE_HANDLED_BY_BUILD <bool>``
.. versionadded:: 3.20
Enabling this option relaxes the dependencies of the configure step on
other external projects to order-only. This means the configure step will
be executed after its external project dependencies are built but it will
not be marked dirty when one of its external project dependencies is
rebuilt. This option can be enabled when the build step is smart enough
to figure out if the configure step needs to be rerun. CMake and Meson are
examples of build systems whose build step is smart enough to know if the
configure step needs to be rerun.
Build Step Options
""""""""""""""""""
If the configure step assumed the external project uses CMake as its build
system, the build step will also. Otherwise, the build step will assume a
Makefile-based build and simply run ``make`` with no arguments as the
default build step. This can be overridden with custom build commands if
required.
If both the main project and the external project use make as their build
tool, the build step of the external project is invoked as a recursive
make using ``$(MAKE)``. This will communicate some build tool settings
from the main project to the external project. If either the main project
or external project is not using make, no build tool settings will be
passed to the external project other than those established by the
configure step (i.e. running ``ninja -v`` in the main project will not
pass ``-v`` to the external project's build step, even if it also uses
``ninja`` as its build tool).
``BUILD_COMMAND <cmd>...``
Overrides the default build command
(:manual:`generator expressions <cmake-generator-expressions(7)>` are
supported). If this option is not given, the default build command will
be chosen to integrate with the main build in the most appropriate way
(e.g. using recursive ``make`` for Makefile generators or
:option:`cmake --build` if the project uses a CMake build). This option
can be specified with an empty string as the command to make the build
step do nothing.
``BUILD_IN_SOURCE <bool>``
When this option is enabled, the build will be done directly within the
external project's source tree. This should generally be avoided, the use
of a separate build directory is usually preferred, but it can be useful
when the external project assumes an in-source build. The ``BINARY_DIR``
option should not be specified if building in-source.
``BUILD_ALWAYS <bool>``
Enabling this option forces the build step to always be run. This can be
the easiest way to robustly ensure that the external project's own build
dependencies are evaluated rather than relying on the default
success timestamp-based method. This option is not normally needed unless
developers are expected to modify something the external project's build
depends on in a way that is not detectable via the step target
dependencies (e.g. ``SOURCE_DIR`` is used without a download method and
developers might modify the sources in ``SOURCE_DIR``).
``BUILD_BYPRODUCTS <file>...``
.. versionadded:: 3.2
Specifies files that will be generated by the build command but which
might or might not have their modification time updated by subsequent
builds. This may also be required to explicitly declare dependencies
when using the :generator:`Ninja` generator.
These ultimately get passed through as ``BYPRODUCTS`` to the
build step's own underlying call to :command:`add_custom_command`, which
has additional documentation.
``BUILD_JOB_SERVER_AWARE <bool>``
.. versionadded:: 3.28
Specifies that the build step is aware of the GNU Make job server.
See the :command:`add_custom_command` documentation of its
``JOB_SERVER_AWARE`` option for details. This option is relevant
only when an explicit ``BUILD_COMMAND`` is specified.
Install Step Options
""""""""""""""""""""
If the configure step assumed the external project uses CMake as its build
system, the install step will also. Otherwise, the install step will assume
a Makefile-based build and simply run ``make install`` as the default build
step. This can be overridden with custom install commands if required.
``INSTALL_COMMAND <cmd>...``
The external project's own install step is invoked as part of the main
project's *build*. It is done after the external project's build step
and may be before or after the external project's test step (see the
``TEST_BEFORE_INSTALL`` option below). The external project's install
rules are not part of the main project's install rules, so if anything
from the external project should be installed as part of the main build,
these need to be specified in the main build as additional
:command:`install` commands. The default install step builds the
``install`` target of the external project, but this can be overridden
with a custom command using this option
(:manual:`generator expressions <cmake-generator-expressions(7)>` are
supported). Passing an empty string as the ``<cmd>`` makes the install
step do nothing.
``INSTALL_BYPRODUCTS <file>...``
.. versionadded:: 3.26
Specifies files that will be generated by the install command but which
might or might not have their modification time updated by subsequent
installs. This may also be required to explicitly declare dependencies
when using the :generator:`Ninja` generator.
These ultimately get passed through as ``BYPRODUCTS`` to the
install step's own underlying call to :command:`add_custom_command`, which
has additional documentation.
``INSTALL_JOB_SERVER_AWARE <bool>``
.. versionadded:: 4.0
Specifies that the install step is aware of the GNU Make job server.
See the :command:`add_custom_command` documentation of its
``JOB_SERVER_AWARE`` option for details. This option is relevant
only when an explicit ``INSTALL_COMMAND`` is specified.
.. note::
If the :envvar:`CMAKE_INSTALL_MODE` environment variable is set when the
main project is built, it will only have an effect if the following
conditions are met:
* The main project's configure step assumed the external project uses
CMake as its build system.
* The external project's install command actually runs. Note that due
to the way ``ExternalProject`` may use timestamps internally, if
nothing the install step depends on needs to be re-executed, the
install command might also not need to run.
Note also that ``ExternalProject`` does not check whether the
:envvar:`CMAKE_INSTALL_MODE` environment variable changes from one run
to another.
Test Step Options
"""""""""""""""""
The test step is only defined if at least one of the following ``TEST_...``
options are provided.
``TEST_COMMAND <cmd>...``
Overrides the default test command
(:manual:`generator expressions <cmake-generator-expressions(7)>` are
supported). If this option is not given, the default behavior of the test
step is to build the external project's own ``test`` target. This option
can be specified with ``<cmd>`` as an empty string, which allows the test
step to still be defined, but it will do nothing. Do not specify any of
the other ``TEST_...`` options if providing an empty string as the test
command, but prefer to omit all ``TEST_...`` options altogether if the
test step target is not needed.
``TEST_BEFORE_INSTALL <bool>``
When this option is enabled, the test step will be executed before the
install step. The default behavior is for the test step to run after the
install step.
``TEST_AFTER_INSTALL <bool>``
This option is mainly useful as a way to indicate that the test step is
desired but all default behavior is sufficient. Specifying this option
with a boolean true value ensures the test step is defined and that it
comes after the install step. If both ``TEST_BEFORE_INSTALL`` and
``TEST_AFTER_INSTALL`` are enabled, the latter is silently ignored.
``TEST_EXCLUDE_FROM_MAIN <bool>``
.. versionadded:: 3.2
If enabled, the main build's default ALL target will not depend on the
test step. This can be a useful way of ensuring the test step is defined
but only gets invoked when manually requested.
This may cause a step target to be created automatically for either
the ``install`` or ``build`` step. See policy :policy:`CMP0114`.
Output Logging Options
""""""""""""""""""""""
Each of the following ``LOG_...`` options can be used to wrap the relevant
step in a script to capture its output to files. The log files will be
created in ``LOG_DIR`` if supplied or otherwise the ``STAMP_DIR``
directory with step-specific file names.
``LOG_DOWNLOAD <bool>``
When enabled, the output of the download step is logged to files.
``LOG_UPDATE <bool>``
When enabled, the output of the update step is logged to files.
``LOG_PATCH <bool>``
.. versionadded:: 3.14
When enabled, the output of the patch step is logged to files.
``LOG_CONFIGURE <bool>``
When enabled, the output of the configure step is logged to files.
``LOG_BUILD <bool>``
When enabled, the output of the build step is logged to files.
``LOG_INSTALL <bool>``
When enabled, the output of the install step is logged to files.
``LOG_TEST <bool>``
When enabled, the output of the test step is logged to files.
``LOG_MERGED_STDOUTERR <bool>``
.. versionadded:: 3.14
When enabled, stdout and stderr will be merged for any step whose
output is being logged to files.
``LOG_OUTPUT_ON_FAILURE <bool>``
.. versionadded:: 3.14
This option only has an effect if at least one of the other ``LOG_<step>``
options is enabled. If an error occurs for a step which has logging to
file enabled, that step's output will be printed to the console if
``LOG_OUTPUT_ON_FAILURE`` is set to true. For cases where a large amount
of output is recorded, just the end of that output may be printed to the
console.
Terminal Access Options
"""""""""""""""""""""""
.. versionadded:: 3.4
Steps can be given direct access to the terminal in some cases. Giving a
step access to the terminal may allow it to receive terminal input if
required, such as for authentication details not provided by other options.
With the :generator:`Ninja` generator, these options place the steps in the
``console`` :prop_gbl:`job pool <JOB_POOLS>`. Each step can be given access
to the terminal individually via the following options:
``USES_TERMINAL_DOWNLOAD <bool>``
Give the download step access to the terminal.
``USES_TERMINAL_UPDATE <bool>``
Give the update step access to the terminal.
``USES_TERMINAL_PATCH <bool>``
.. versionadded:: 3.23
Give the patch step access to the terminal.
``USES_TERMINAL_CONFIGURE <bool>``
Give the configure step access to the terminal.
``USES_TERMINAL_BUILD <bool>``
Give the build step access to the terminal.
``USES_TERMINAL_INSTALL <bool>``
Give the install step access to the terminal.
``USES_TERMINAL_TEST <bool>``
Give the test step access to the terminal.
Target Options
""""""""""""""
``DEPENDS <targets>...``
Specify other targets on which the external project depends. The other
targets will be brought up to date before any of the external project's
steps are executed. Because the external project uses additional custom
targets internally for each step, the ``DEPENDS`` option is the most
convenient way to ensure all of those steps depend on the other targets.
Simply doing
:command:`add_dependencies(\<name\> \<targets\>) <add_dependencies>` will
not make any of the steps dependent on ``<targets>``.
``EXCLUDE_FROM_ALL <bool>``
When enabled, this option excludes the external project from the default
ALL target of the main build.
``STEP_TARGETS <step-target>...``
Generate custom targets for the specified steps. This is required if the
steps need to be triggered manually or if they need to be used as
dependencies of other targets. If this option is not specified, the
default value is taken from the ``EP_STEP_TARGETS`` directory property.
See :command:`ExternalProject_Add_StepTargets` below for further
discussion of the effects of this option.
``INDEPENDENT_STEP_TARGETS <step-target>...``
.. deprecated:: 3.19
This is allowed only if policy :policy:`CMP0114` is not set to ``NEW``.
Generates custom targets for the specified steps and prevent these targets
from having the usual dependencies applied to them. If this option is not
specified, the default value is taken from the
``EP_INDEPENDENT_STEP_TARGETS`` directory property. This option is mostly
useful for allowing individual steps to be driven independently, such as
for a CDash setup where each step should be initiated and reported
individually rather than as one whole build. See
:command:`ExternalProject_Add_StepTargets` below for further discussion
of the effects of this option.
Miscellaneous Options
"""""""""""""""""""""
``LIST_SEPARATOR <sep>``
For any of the various ``..._COMMAND`` options, and ``CMAKE_ARGS``,
``ExternalProject`` will replace ``<sep>`` with ``;`` in the specified
command lines. This can be used to ensure a command has a literal ``;`` in it
where direct usage would otherwise be interpreted as argument separators to
CMake APIs instead. Note that the separator should be chosen to avoid being
confused for non-list-separator usages of the sequence. For example, using
``LIST_SEPARATOR`` allows for passing list values to CMake cache variables on
the command line:
.. code-block:: cmake
ExternalProject_Add(example
... # Download options, etc.
LIST_SEPARATOR ","
CMAKE_ARGS "-DCMAKE_PREFIX_PATH:STRING=${first_prefix},${second_prefix}"
)
``COMMAND <cmd>...``
Any of the other ``..._COMMAND`` options can have additional commands
appended to them by following them with as many ``COMMAND ...`` options
as needed
(:manual:`generator expressions <cmake-generator-expressions(7)>` are
supported). For example:
.. code-block:: cmake
ExternalProject_Add(example
... # Download options, etc.
BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Starting $<CONFIG> build"
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG>
COMMAND ${CMAKE_COMMAND} -E echo "$<CONFIG> build complete"
)
It should also be noted that each build step is created via a call to
:command:`ExternalProject_Add_Step`. See that command's documentation for the
automatic substitutions that are supported for some options.
Obtaining Project Properties
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. command:: ExternalProject_Get_Property
The ``ExternalProject_Get_Property()`` function retrieves external project
target properties:
.. code-block:: cmake
ExternalProject_Get_Property(<name> <prop1> [<prop2>...])
The function stores property values in variables of the same name. Property
names correspond to the keyword argument names of ``ExternalProject_Add()``.
For example, the source directory might be retrieved like so:
.. code-block:: cmake
ExternalProject_Get_property(myExtProj SOURCE_DIR)
message("Source dir of myExtProj = ${SOURCE_DIR}")
Explicit Step Management
^^^^^^^^^^^^^^^^^^^^^^^^
The ``ExternalProject_Add()`` function on its own is often sufficient for
incorporating an external project into the main build. Certain scenarios
require additional work to implement desired behavior, such as adding in a
custom step or making steps available as manually triggerable targets. The
``ExternalProject_Add_Step()``, ``ExternalProject_Add_StepTargets()`` and
``ExternalProject_Add_StepDependencies`` functions provide the lower level
control needed to implement such step-level capabilities.
.. command:: ExternalProject_Add_Step
The ``ExternalProject_Add_Step()`` function specifies an additional custom
step for an external project defined by an earlier call to
:command:`ExternalProject_Add`:
.. code-block:: cmake
ExternalProject_Add_Step(<name> <step> [<option>...])
``<name>`` is the same as the name passed to the original call to
:command:`ExternalProject_Add`. The specified ``<step>`` must not be one of
the pre-defined steps (``mkdir``, ``download``, ``update``,
``patch``, ``configure``, ``build``, ``install`` or ``test``). The supported
options are:
``COMMAND <cmd>...``
The command line to be executed by this custom step
(:manual:`generator expressions <cmake-generator-expressions(7)>` are
supported). This option can be repeated multiple times to specify multiple
commands to be executed in order.
``COMMENT "<text>..."``
Text to be printed when the custom step executes.
``DEPENDEES <step>...``
Other steps (custom or pre-defined) on which this step depends.
``DEPENDERS <step>...``
Other steps (custom or pre-defined) that depend on this new custom step.
``DEPENDS <file>...``
Files on which this custom step depends.
``INDEPENDENT <bool>``
.. versionadded:: 3.19
Specifies whether this step is independent of the external dependencies
specified by the :command:`ExternalProject_Add`'s ``DEPENDS`` option.
The default is ``FALSE``. Steps marked as independent may depend only
on other steps marked independent. See policy :policy:`CMP0114`.
Note that this use of the term "independent" refers only to independence
from external targets specified by the ``DEPENDS`` option and is
orthogonal to a step's dependencies on other steps.
If a step target is created for an independent step by the
:command:`ExternalProject_Add` ``STEP_TARGETS`` option or by the
:command:`ExternalProject_Add_StepTargets` function, it will not depend
on the external targets, but may depend on targets for other steps.
``BYPRODUCTS <file>...``
.. versionadded:: 3.2
Files that will be generated by this custom step but which might or might
not have their modification time updated by subsequent builds.
This may also be required to explicitly declare dependencies
when using the :generator:`Ninja` generator. This list of
files will ultimately be passed through as the ``BYPRODUCTS`` option to the
:command:`add_custom_command` used to implement the custom step internally,
which has additional documentation.
``ALWAYS <bool>``
When enabled, this option specifies that the custom step should always be
run (i.e. that it is always considered out of date).
``JOB_SERVER_AWARE <bool>``
.. versionadded:: 3.28
Specifies that the custom step is aware of the GNU Make job server.
See the :command:`add_custom_command` documentation of its
``JOB_SERVER_AWARE`` option for details.
``EXCLUDE_FROM_MAIN <bool>``
When enabled, this option specifies that the external project's main target
does not depend on the custom step.
This may cause step targets to be created automatically for the steps on
which this step depends. See policy :policy:`CMP0114`.
``WORKING_DIRECTORY <dir>``
Specifies the working directory to set before running the custom step's
command. If this option is not specified, the directory will be the value
of the :variable:`CMAKE_CURRENT_BINARY_DIR` at the point where
``ExternalProject_Add_Step()`` was called.
``LOG <bool>``
If set, this causes the output from the custom step to be captured to files
in the external project's ``LOG_DIR`` if supplied or ``STAMP_DIR``.
``USES_TERMINAL <bool>``
If enabled, this gives the custom step direct access to the terminal if
possible.
The command line, comment, working directory and byproducts of every
standard and custom step are processed to replace the tokens
``<SOURCE_DIR>``, ``<SOURCE_SUBDIR>``, ``<BINARY_DIR>``, ``<INSTALL_DIR>``
``<TMP_DIR>``, ``<DOWNLOAD_DIR>`` and ``<DOWNLOADED_FILE>`` with their
corresponding property values defined in the original call to
:command:`ExternalProject_Add`.
.. versionadded:: 3.3
Token replacement is extended to byproducts.
.. versionadded:: 3.11
The ``<DOWNLOAD_DIR>`` substitution token.
.. command:: ExternalProject_Add_StepTargets
The ``ExternalProject_Add_StepTargets()`` function generates targets for the
steps listed. The name of each created target will be of the form
``<name>-<step>``:
.. code-block:: cmake
ExternalProject_Add_StepTargets(<name> <step1> [<step2>...])
Creating a target for a step allows it to be used as a dependency of another
target or to be triggered manually. Having targets for specific steps also
allows them to be driven independently of each other by specifying targets on
build command lines. For example, you may be submitting to a sub-project
based dashboard where you want to drive the configure portion of the build,
then submit to the dashboard, followed by the build portion, followed
by tests. If you invoke a custom target that depends on a step halfway
through the step dependency chain, then all the previous steps will also run
to ensure everything is up to date.
Internally, :command:`ExternalProject_Add` calls
:command:`ExternalProject_Add_Step` to create each step. If any
``STEP_TARGETS`` were specified, then ``ExternalProject_Add_StepTargets()``
will also be called after :command:`ExternalProject_Add_Step`. Even if a
step is not mentioned in the ``STEP_TARGETS`` option,
``ExternalProject_Add_StepTargets()`` can still be called later to manually
define a target for the step.
The ``STEP_TARGETS`` option for :command:`ExternalProject_Add` is generally
the easiest way to ensure targets are created for specific steps of interest.
For custom steps, ``ExternalProject_Add_StepTargets()`` must be called
explicitly if a target should also be created for that custom step.
An alternative to these two options is to populate the ``EP_STEP_TARGETS``
directory property. It acts as a default for the step target options and
can save having to repeatedly specify the same set of step targets when
multiple external projects are being defined.
.. versionadded:: 3.19
If :policy:`CMP0114` is set to ``NEW``, step targets are fully responsible
for holding the custom commands implementing their steps. The primary
target created by ``ExternalProject_Add`` depends on the step targets, and
the step targets depend on each other. The target-level dependencies match
the file-level dependencies used by the custom commands for each step.
The targets for steps created with :command:`ExternalProject_Add_Step`'s
``INDEPENDENT`` option do not depend on the external targets specified
by :command:`ExternalProject_Add`'s ``DEPENDS`` option. The predefined
steps ``mkdir``, ``download``, ``update``, and ``patch`` are independent.
If :policy:`CMP0114` is not ``NEW``, the following deprecated behavior
is available:
* A deprecated ``NO_DEPENDS`` option may be specified immediately after the
``<name>`` and before the first step.
If the ``NO_DEPENDS`` option is specified, the step target will not depend
on the dependencies of the external project (i.e. on any dependencies of the
``<name>`` custom target created by :command:`ExternalProject_Add`). This is
usually safe for the ``download``, ``update`` and ``patch`` steps, since
they do not typically require that the dependencies are updated and built.
Using ``NO_DEPENDS`` for any of the other pre-defined steps, however, may
break parallel builds. Only use ``NO_DEPENDS`` where it is certain that the
named steps genuinely do not have dependencies. For custom steps, consider
whether or not the custom commands require the dependencies to be
configured, built and installed.
* The ``INDEPENDENT_STEP_TARGETS`` option for :command:`ExternalProject_Add`,
or the ``EP_INDEPENDENT_STEP_TARGETS`` directory property, tells the
function to call ``ExternalProject_Add_StepTargets()`` internally
using the ``NO_DEPENDS`` option for the specified steps.
.. command:: ExternalProject_Add_StepDependencies
.. versionadded:: 3.2
The ``ExternalProject_Add_StepDependencies()`` function can be used to add
dependencies to a step. The dependencies added must be targets CMake already
knows about (these can be ordinary executable or library targets, custom
targets or even step targets of another external project):
.. code-block:: cmake
ExternalProject_Add_StepDependencies(<name> <step> <target1> [<target2>...])
This function takes care to set both target and file level dependencies and
will ensure that parallel builds will not break. It should be used instead of
:command:`add_dependencies` whenever adding a dependency for some of the step
targets generated by the ``ExternalProject`` module.
Examples
^^^^^^^^
The following example shows how to download and build a hypothetical project
called *FooBar* from github:
.. code-block:: cmake
include(ExternalProject)
ExternalProject_Add(foobar
GIT_REPOSITORY git@github.com:FooCo/FooBar.git
GIT_TAG origin/release/1.2.3
)
For the sake of the example, also define a second hypothetical external project
called *SecretSauce*, which is downloaded from a web server. Two URLs are given
to take advantage of a faster internal network if available, with a fallback to
a slower external server. The project is a typical ``Makefile`` project with no
configure step, so some of the default commands are overridden. The build is
only required to build the *sauce* target:
.. code-block:: cmake
find_program(MAKE_EXE NAMES gmake nmake make)
ExternalProject_Add(secretsauce
URL http://intranet.somecompany.com/artifacts/sauce-2.7.tgz
https://www.somecompany.com/downloads/sauce-2.7.zip
URL_HASH MD5=d41d8cd98f00b204e9800998ecf8427e
CONFIGURE_COMMAND ""
BUILD_COMMAND ${MAKE_EXE} sauce
)
Suppose the build step of ``secretsauce`` requires that ``foobar`` must already
be built. This could be enforced like so:
.. code-block:: cmake
ExternalProject_Add_StepDependencies(secretsauce build foobar)
Another alternative would be to create a custom target for ``foobar``'s build
step and make ``secretsauce`` depend on that rather than the whole ``foobar``
project. This would mean ``foobar`` only needs to be built, it doesn't need to
run its install or test steps before ``secretsauce`` can be built. The
dependency can also be defined along with the ``secretsauce`` project:
.. code-block:: cmake
ExternalProject_Add_StepTargets(foobar build)
ExternalProject_Add(secretsauce
URL http://intranet.somecompany.com/artifacts/sauce-2.7.tgz
https://www.somecompany.com/downloads/sauce-2.7.zip
URL_HASH MD5=d41d8cd98f00b204e9800998ecf8427e
CONFIGURE_COMMAND ""
BUILD_COMMAND ${MAKE_EXE} sauce
DEPENDS foobar-build
)
Instead of calling :command:`ExternalProject_Add_StepTargets`, the target could
be defined along with the ``foobar`` project itself:
.. code-block:: cmake
ExternalProject_Add(foobar
GIT_REPOSITORY git@github.com:FooCo/FooBar.git
GIT_TAG origin/release/1.2.3
STEP_TARGETS build
)
If many external projects should have the same set of step targets, setting a
directory property may be more convenient. The ``build`` step target could be
created automatically by setting the ``EP_STEP_TARGETS`` directory property
before creating the external projects with :command:`ExternalProject_Add`:
.. code-block:: cmake
set_property(DIRECTORY PROPERTY EP_STEP_TARGETS build)
Lastly, suppose that ``secretsauce`` provides a script called ``makedoc`` which
can be used to generate its own documentation. Further suppose that the script
expects the output directory to be provided as the only parameter and that it
should be run from the ``secretsauce`` source directory. A custom step and a
custom target to trigger the script can be defined like so:
.. code-block:: cmake
ExternalProject_Add_Step(secretsauce docs
COMMAND <SOURCE_DIR>/makedoc <BINARY_DIR>
WORKING_DIRECTORY <SOURCE_DIR>
COMMENT "Building secretsauce docs"
ALWAYS TRUE
EXCLUDE_FROM_MAIN TRUE
)
ExternalProject_Add_StepTargets(secretsauce docs)
The custom step could then be triggered from the main build like so::
cmake --build . --target secretsauce-docs
#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/ExternalProject/shared_internal_commands.cmake)
define_property(DIRECTORY PROPERTY "EP_BASE" INHERITED)
define_property(DIRECTORY PROPERTY "EP_PREFIX" INHERITED)
define_property(DIRECTORY PROPERTY "EP_STEP_TARGETS" INHERITED)
define_property(DIRECTORY PROPERTY "EP_INDEPENDENT_STEP_TARGETS" INHERITED)
define_property(DIRECTORY PROPERTY "EP_UPDATE_DISCONNECTED" INHERITED)
# file(TO_CMAKE_PATH) will interpret a platform-specific character as a path
# separator, and if its input contains that character, it will treat the input
# as a list. Sometimes we have a string that we know is always a single path,
# but it may contain the separator character. To prevent it being treated as a
# list of paths, this function masks the separator character while calling
# file(TO_CMAKE_PATH).
function(_ep_to_single_cmake_path out_var input)
if(WIN32)
set(unsafe_char ";")
else()
set(unsafe_char ":")
endif()
string(REPLACE "${unsafe_char}" "__EP_MARKER__" safe_input "${input}")
file(TO_CMAKE_PATH "${safe_input}" converted_input)
string(REPLACE "__EP_MARKER__" "${unsafe_char}" output "${converted_input}")
set(${out_var} "${output}" PARENT_SCOPE)
endfunction()
function(_ep_set_directories name)
get_property(prefix TARGET ${name} PROPERTY _EP_PREFIX)
if(NOT prefix)
get_property(prefix DIRECTORY PROPERTY EP_PREFIX)
if(NOT prefix)
get_property(base DIRECTORY PROPERTY EP_BASE)
if(NOT base)
set(prefix "${name}-prefix")
endif()
endif()
endif()
if(prefix)
_ep_to_single_cmake_path(prefix "${prefix}")
set(tmp_default "${prefix}/tmp")
set(download_default "${prefix}/src")
set(source_default "${prefix}/src/${name}")
set(binary_default "${prefix}/src/${name}-build")
set(stamp_default "${prefix}/src/${name}-stamp")
set(install_default "${prefix}")
else()
_ep_to_single_cmake_path(base "${base}")
set(tmp_default "${base}/tmp/${name}")
set(download_default "${base}/Download/${name}")
set(source_default "${base}/Source/${name}")
set(binary_default "${base}/Build/${name}")
set(stamp_default "${base}/Stamp/${name}")
set(install_default "${base}/Install/${name}")
endif()
get_property(build_in_source TARGET ${name} PROPERTY _EP_BUILD_IN_SOURCE)
if(build_in_source)
get_property(have_binary_dir TARGET ${name} PROPERTY _EP_BINARY_DIR SET)
if(have_binary_dir)
message(FATAL_ERROR
"External project ${name} has both BINARY_DIR and BUILD_IN_SOURCE!"
)
endif()
endif()
set(top "${CMAKE_CURRENT_BINARY_DIR}")
# Apply defaults and convert to absolute paths.
set(places stamp download source binary install tmp)
foreach(var IN LISTS places)
string(TOUPPER "${var}" VAR)
get_property(${var}_dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
if(NOT ${var}_dir)
set(${var}_dir "${${var}_default}")
endif()
if(NOT IS_ABSOLUTE "${${var}_dir}")
get_filename_component(${var}_dir "${top}/${${var}_dir}" ABSOLUTE)
endif()
_ep_to_single_cmake_path(${var}_dir "${${var}_dir}")
set_property(TARGET ${name} PROPERTY _EP_${VAR}_DIR "${${var}_dir}")
set(_EP_${VAR}_DIR "${${var}_dir}" PARENT_SCOPE)
endforeach()
# Special case for default log directory based on stamp directory.
get_property(log_dir TARGET ${name} PROPERTY _EP_LOG_DIR)
if(NOT log_dir)
get_property(log_dir TARGET ${name} PROPERTY _EP_STAMP_DIR)
endif()
if(NOT IS_ABSOLUTE "${log_dir}")
get_filename_component(log_dir "${top}/${log_dir}" ABSOLUTE)
endif()
_ep_to_single_cmake_path(log_dir "${log_dir}")
set_property(TARGET ${name} PROPERTY _EP_LOG_DIR "${log_dir}")
set(_EP_LOG_DIR "${log_dir}" PARENT_SCOPE)
get_property(source_subdir TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR)
if(NOT source_subdir)
set_property(TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR "")
set(_EP_SOURCE_SUBDIR "" PARENT_SCOPE)
elseif(IS_ABSOLUTE "${source_subdir}")
message(FATAL_ERROR
"External project ${name} has non-relative SOURCE_SUBDIR!"
)
else()
# Prefix with a slash so that when appended to the source directory, it
# behaves as expected.
_ep_to_single_cmake_path(source_subdir "${source_subdir}")
set_property(TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR "/${source_subdir}")
set(_EP_SOURCE_SUBDIR "/${source_subdir}" PARENT_SCOPE)
endif()
if(build_in_source)
get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
if(source_subdir)
set_property(TARGET ${name} PROPERTY
_EP_BINARY_DIR "${source_dir}/${source_subdir}"
)
set(_EP_BINARY_DIR "${source_dir}/${source_subdir}" PARENT_SCOPE)
else()
set_property(TARGET ${name} PROPERTY
_EP_BINARY_DIR "${source_dir}"
)
set(_EP_BINARY_DIR "${source_dir}" PARENT_SCOPE)
endif()
endif()
# This script will be used both here and by the mkdir step. We create the
# directories now at configure time and ensure they exist again at build
# time (since somebody might remove one of the required directories and try
# to rebuild without re-running cmake). They need to exist now at makefile
# generation time for Borland make and wmake so that CMake may generate
# makefiles with "cd C:\short\paths\with\no\spaces" commands in them.
set(script_filename "${tmp_dir}/${name}-mkdirs.cmake")
configure_file(
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject/mkdirs.cmake.in
${script_filename}
@ONLY
)
unset(cfgdir) # do not leak into mkdirs.cmake script
include(${script_filename})
endfunction()
# IMPORTANT: this MUST be a macro and not a function because of the
# in-place replacements that occur in each ${var}
#
macro(_ep_replace_location_tags target_name)
set(vars ${ARGN})
foreach(var IN LISTS vars)
if(var)
foreach(dir IN ITEMS
SOURCE_DIR
SOURCE_SUBDIR
BINARY_DIR
INSTALL_DIR
TMP_DIR
DOWNLOAD_DIR
DOWNLOADED_FILE
LOG_DIR
)
get_property(val TARGET ${target_name} PROPERTY _EP_${dir})
string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}")
endforeach()
endif()
endforeach()
endmacro()
function(_ep_command_line_to_initial_cache
var
args
force
)
set(script_initial_cache "")
set(regex "^([^:]+):([^=]+)=(.*)$")
set(setArg "")
set(forceArg "")
if(force)
set(forceArg "FORCE")
endif()
foreach(line IN LISTS args)
if("${line}" MATCHES "^-D(.*)")
set(line "${CMAKE_MATCH_1}")
if(NOT "${setArg}" STREQUAL "")
# This is required to build up lists in variables, or complete an entry
string(APPEND setArg
"${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})"
)
string(APPEND script_initial_cache "\n${setArg}")
set(accumulator "")
set(setArg "")
endif()
if("${line}" MATCHES "${regex}")
set(name "${CMAKE_MATCH_1}")
set(type "${CMAKE_MATCH_2}")
set(value "${CMAKE_MATCH_3}")
set(setArg "set(${name} \"${value}")
else()
message(WARNING "Line '${line}' does not match regex. Ignoring.")
endif()
else()
# Assume this is a list to append to the last var
string(APPEND accumulator ";${line}")
endif()
endforeach()
# Catch the final line of the args
if(NOT "${setArg}" STREQUAL "")
string(APPEND setArg
"${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})"
)
string(APPEND script_initial_cache "\n${setArg}")
endif()
set(${var} ${script_initial_cache} PARENT_SCOPE)
endfunction()
function(_ep_write_initial_cache
target_name
script_filename
script_initial_cache
)
# Write out values into an initial cache, that will be passed to CMake with -C
# Replace location tags.
_ep_replace_location_tags(${target_name} script_initial_cache)
_ep_replace_location_tags(${target_name} script_filename)
# Replace list separators.
get_property(sep TARGET ${target_name} PROPERTY _EP_LIST_SEPARATOR)
if(sep AND script_initial_cache)
string(REPLACE "${sep}" ";" script_initial_cache "${script_initial_cache}")
endif()
# Write out the initial cache file to the location specified.
file(GENERATE OUTPUT "${script_filename}" CONTENT "${script_initial_cache}")
endfunction()
function(ExternalProject_Get_Property name)
foreach(var IN LISTS ARGN)
string(TOUPPER "${var}" VAR)
get_property(is_set TARGET ${name} PROPERTY _EP_${VAR} SET)
if(NOT is_set)
message(FATAL_ERROR "External project \"${name}\" has no ${var}")
endif()
get_property(${var} TARGET ${name} PROPERTY _EP_${VAR})
set(${var} "${${var}}" PARENT_SCOPE)
endforeach()
endfunction()
function(_ep_get_configure_command_id
name
cfg_cmd_id_var
)
get_target_property(cmd ${name} _EP_CONFIGURE_COMMAND)
if(cmd STREQUAL "")
# Explicit empty string means no configure step for this project
set(${cfg_cmd_id_var} "none" PARENT_SCOPE)
else()
if(NOT cmd)
# Default is "use cmake":
set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
else()
# Otherwise we have to analyze the value:
if(cmd MATCHES "^[^;]*/configure")
set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
elseif(cmd MATCHES "^[^;]*/cmake" AND NOT cmd MATCHES ";-[PE];")
set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
elseif(cmd MATCHES "config")
set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
else()
set(${cfg_cmd_id_var} "unknown:${cmd}" PARENT_SCOPE)
endif()
endif()
endif()
endfunction()
function(_ep_get_build_command
name
step
cmd_var
)
set(cmd "")
set(args)
_ep_get_configure_command_id(${name} cfg_cmd_id)
if(cfg_cmd_id STREQUAL "cmake")
# Adding a CMake project as an External Project. Select command based on generator
get_property(cmake_generator TARGET ${name} PROPERTY _EP_CMAKE_GENERATOR)
# cmake_generator is the CMake generator of the ExternalProject target being added
# CMAKE_GENERATOR is the CMake generator of the Current Project
if("${CMAKE_GENERATOR}" MATCHES "Make" AND
("${cmake_generator}" MATCHES "Make" OR NOT cmake_generator))
# The project uses the same Makefile generator. Use recursive make.
set(cmd "$(MAKE)")
if(step STREQUAL "INSTALL")
set(args install)
endif()
if("x${step}x" STREQUAL "xTESTx")
set(args test)
endif()
else()
# Drive the project with "cmake --build".
if(NOT cmake_generator)
# If there is no CMake Generator defined on the ExternalProject,
# use the same Generator as the current project
set(cmake_generator "${CMAKE_GENERATOR}")
endif()
get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
if(cmake_command)
set(cmd "${cmake_command}")
else()
set(cmd "${CMAKE_COMMAND}")
endif()
set(args --build ".")
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
if (CMAKE_CFG_INTDIR AND
NOT CMAKE_CFG_INTDIR STREQUAL "." AND
NOT CMAKE_CFG_INTDIR MATCHES "\\$")
# CMake 3.4 and below used the CMAKE_CFG_INTDIR placeholder value
# provided by multi-configuration generators. Some projects were
# taking advantage of that undocumented implementation detail to
# specify a specific configuration here. They should use
# BUILD_COMMAND to change the default command instead, but for
# compatibility honor the value.
set(config ${CMAKE_CFG_INTDIR})
message(AUTHOR_WARNING
"CMAKE_CFG_INTDIR should not be set by project code.\n"
"To get a non-default build command, use the BUILD_COMMAND option."
)
else()
set(config $<CONFIG>)
endif()
list(APPEND args --config ${config})
endif()
if(step STREQUAL "INSTALL")
if("${cmake_generator}" MATCHES "Green Hills MULTI")
list(APPEND args --target INSTALL)
else()
list(APPEND args --target install)
endif()
endif()
# But for "TEST" drive the project with corresponding "ctest".
if("x${step}x" STREQUAL "xTESTx")
string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")
set(args "")
if(_isMultiConfig)
list(APPEND args -C ${config})
endif()
endif()
endif()
else()
# Non-CMake project. Guess "make" and "make install" and "make test".
if("${CMAKE_GENERATOR}" MATCHES "Makefiles")
# Try to get the parallel arguments
set(cmd "$(MAKE)")
else()
set(cmd "make")
endif()
if(step STREQUAL "INSTALL")
set(args install)
endif()
if("x${step}x" STREQUAL "xTESTx")
set(args test)
endif()
endif()
# Use user-specified arguments instead of default arguments, if any.
get_property(have_args TARGET ${name} PROPERTY _EP_${step}_ARGS SET)
if(have_args)
get_target_property(args ${name} _EP_${step}_ARGS)
endif()
if(NOT "${args}" STREQUAL "")
# args could have empty items, so we must quote it to prevent them
# from being silently removed
list(APPEND cmd "${args}")
endif()
set(${cmd_var} "${cmd}" PARENT_SCOPE)
endfunction()
function(_ep_write_log_script
name
step
cmd_var
)
ExternalProject_Get_Property(${name} log_dir)
ExternalProject_Get_Property(${name} stamp_dir)
set(command "${${cmd_var}}")
set(make "")
set(code_cygpath_make "")
if(command MATCHES "^\\$\\(MAKE\\)")
# GNU make recognizes the string "$(MAKE)" as recursive make, so
# ensure that it appears directly in the makefile.
string(REGEX REPLACE "^\\$\\(MAKE\\)" "\${make}" command "${command}")
set(make "-Dmake=$(MAKE)")
if(WIN32 AND NOT CYGWIN)
set(code_cygpath_make "
if(\${make} MATCHES \"^/\")
execute_process(
COMMAND cygpath -w \${make}
OUTPUT_VARIABLE cygpath_make
ERROR_VARIABLE cygpath_make
RESULT_VARIABLE cygpath_error
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT cygpath_error)
set(make \${cygpath_make})
endif()
endif()
")
endif()
endif()
set(config "")
if("${CMAKE_CFG_INTDIR}" MATCHES "^\\$")
string(REPLACE "${CMAKE_CFG_INTDIR}" "\${config}" command "${command}")
set(config "-Dconfig=${CMAKE_CFG_INTDIR}")
endif()
# Wrap multiple 'COMMAND' lines up into a second-level wrapper
# script so all output can be sent to one log file.
if(command MATCHES "(^|;)COMMAND;")
set(code_execute_process "
${code_cygpath_make}
execute_process(COMMAND \${command} RESULT_VARIABLE result)
if(result)
set(msg \"Command failed (\${result}):\\n\")
foreach(arg IN LISTS command)
set(msg \"\${msg} '\${arg}'\")
endforeach()
message(FATAL_ERROR \"\${msg}\")
endif()
")
set(code "")
set(cmd "")
set(sep "")
foreach(arg IN LISTS command)
if("x${arg}" STREQUAL "xCOMMAND")
if(NOT "x${cmd}" STREQUAL "x")
string(APPEND code "set(command \"${cmd}\")${code_execute_process}")
endif()
set(cmd "")
set(sep "")
else()
string(APPEND cmd "${sep}${arg}")
set(sep ";")
endif()
endforeach()
string(APPEND code "set(command \"${cmd}\")${code_execute_process}")
file(GENERATE
OUTPUT "${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake"
CONTENT "${code}"
)
set(command
${CMAKE_COMMAND}
"-Dmake=\${make}"
"-Dconfig=\${config}"
-P ${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake
)
endif()
# Wrap the command in a script to log output to files.
set(script ${stamp_dir}/${name}-${step}-$<CONFIG>.cmake)
set(logbase ${log_dir}/${name}-${step})
get_property(log_merged
TARGET ${name}
PROPERTY _EP_LOG_MERGED_STDOUTERR
)
get_property(log_output_on_failure
TARGET ${name}
PROPERTY _EP_LOG_OUTPUT_ON_FAILURE
)
if (log_merged)
set(stdout_log "${logbase}.log")
set(stderr_log "${logbase}.log")
else()
set(stdout_log "${logbase}-out.log")
set(stderr_log "${logbase}-err.log")
endif()
set(code "
cmake_minimum_required(VERSION \${CMAKE_VERSION}) # this file comes with cmake
${code_cygpath_make}
set(command \"${command}\")
set(log_merged \"${log_merged}\")
set(log_output_on_failure \"${log_output_on_failure}\")
set(stdout_log \"${stdout_log}\")
set(stderr_log \"${stderr_log}\")
execute_process(
COMMAND \${command}
RESULT_VARIABLE result
OUTPUT_FILE \"\${stdout_log}\"
ERROR_FILE \"\${stderr_log}\"
)
macro(read_up_to_max_size log_file output_var)
file(SIZE \${log_file} determined_size)
set(max_size 10240)
if (determined_size GREATER max_size)
math(EXPR seek_position \"\${determined_size} - \${max_size}\")
file(READ \${log_file} \${output_var} OFFSET \${seek_position})
set(\${output_var} \"...skipping to end...\\n\${\${output_var}}\")
else()
file(READ \${log_file} \${output_var})
endif()
endmacro()
if(result)
set(msg \"Command failed: \${result}\\n\")
foreach(arg IN LISTS command)
set(msg \"\${msg} '\${arg}'\")
endforeach()
if (\${log_merged})
set(msg \"\${msg}\\nSee also\\n \${stderr_log}\")
else()
set(msg \"\${msg}\\nSee also\\n ${logbase}-*.log\")
endif()
if (\${log_output_on_failure})
message(SEND_ERROR \"\${msg}\")
if (\${log_merged})
read_up_to_max_size(\"\${stderr_log}\" error_log_contents)
message(STATUS \"Log output is:\\n\${error_log_contents}\")
else()
read_up_to_max_size(\"\${stdout_log}\" out_log_contents)
read_up_to_max_size(\"\${stderr_log}\" err_log_contents)
message(STATUS \"stdout output is:\\n\${out_log_contents}\")
message(STATUS \"stderr output is:\\n\${err_log_contents}\")
endif()
message(FATAL_ERROR \"Stopping after outputting logs.\")
else()
message(FATAL_ERROR \"\${msg}\")
endif()
else()
if(NOT \"${CMAKE_GENERATOR}\" MATCHES \"Ninja\")
set(msg \"${name} ${step} command succeeded. See also ${logbase}-*.log\")
message(STATUS \"\${msg}\")
endif()
endif()
")
file(GENERATE OUTPUT "${script}" CONTENT "${code}")
set(command ${CMAKE_COMMAND} ${make} ${config} -P ${script})
set(${cmd_var} "${command}" PARENT_SCOPE)
endfunction()
# On multi-config generators, provide a placeholder for a per-config subdir.
# On single-config generators, this is empty.
function(_ep_get_configuration_subdir_genex suffix_var)
set(suffix "")
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
if(CMAKE_GENERATOR STREQUAL "Xcode")
# The Xcode generator does not support per-config sources,
# so use the underlying build system's placeholder instead.
# FIXME(#23652): We have no test for the use case requiring
# CMAKE_CFG_INTDIR for XCODE_EMIT_EFFECTIVE_PLATFORM_NAME,
# but $<CONFIG> does not work.
set(suffix "/${CMAKE_CFG_INTDIR}")
else()
set(suffix "/$<CONFIG>")
endif()
endif()
set(${suffix_var} "${suffix}" PARENT_SCOPE)
endfunction()
function(_ep_get_step_stampfile
name
step
stampfile_var
)
ExternalProject_Get_Property(${name} stamp_dir)
_ep_get_configuration_subdir_genex(cfgdir)
set(stampfile "${stamp_dir}${cfgdir}/${name}-${step}")
set(${stampfile_var} "${stampfile}" PARENT_SCOPE)
endfunction()
function(_ep_get_complete_stampfile
name
stampfile_var
)
set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
_ep_get_configuration_subdir_genex(cfgdir)
set(stampfile "${cmf_dir}${cfgdir}/${name}-complete")
set(${stampfile_var} ${stampfile} PARENT_SCOPE)
endfunction()
function(_ep_step_add_target
name
step
no_deps
)
if(TARGET ${name}-${step})
return()
endif()
get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114)
_ep_get_step_stampfile(${name} ${step} stamp_file)
cmake_policy(PUSH)
if(cmp0114 STREQUAL "NEW")
# To implement CMP0114 NEW behavior with Makefile generators,
# we need CMP0113 NEW behavior.
cmake_policy(SET CMP0113 NEW)
endif()
add_custom_target(${name}-${step} DEPENDS ${stamp_file})
cmake_policy(POP)
set_target_properties(${name}-${step} PROPERTIES
_EP_IS_EXTERNAL_PROJECT_STEP 1
LABELS "${name}"
FOLDER "ExternalProjectTargets/${name}"
)
if(cmp0114 STREQUAL "NEW")
# Add target-level dependencies for the step.
get_property(exclude_from_main
TARGET ${name}
PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN
)
if(NOT exclude_from_main)
add_dependencies(${name} ${name}-${step})
endif()
_ep_step_add_target_dependencies(${name} ${step} ${step})
_ep_step_add_target_dependents(${name} ${step} ${step})
get_property(independent TARGET ${name} PROPERTY _EP_${step}_INDEPENDENT)
else()
if(no_deps AND "${step}" MATCHES "^(configure|build|install|test)$")
message(AUTHOR_WARNING
"Using NO_DEPENDS for \"${step}\" step might break parallel builds"
)
endif()
set(independent ${no_deps})
endif()
# Depend on other external projects (target-level).
if(NOT independent)
get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
foreach(arg IN LISTS deps)
add_dependencies(${name}-${step} ${arg})
endforeach()
endif()
endfunction()
function(_ep_step_add_target_dependencies
name
step
node
)
get_property(dependees
TARGET ${name}
PROPERTY _EP_${node}_INTERNAL_DEPENDEES
)
list(REMOVE_DUPLICATES dependees)
foreach(dependee IN LISTS dependees)
get_property(exclude_from_main
TARGET ${name}
PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN
)
get_property(dependee_dependers
TARGET ${name}
PROPERTY _EP_${dependee}_INTERNAL_DEPENDERS
)
if(exclude_from_main OR dependee_dependers MATCHES ";")
# The step on which our step target depends itself has
# dependents in multiple targes. It needs a step target too
# so that there is a unique place for its custom command.
_ep_step_add_target("${name}" "${dependee}" "FALSE")
endif()
if(TARGET ${name}-${dependee})
add_dependencies(${name}-${step} ${name}-${dependee})
else()
_ep_step_add_target_dependencies(${name} ${step} ${dependee})
endif()
endforeach()
endfunction()
function(_ep_step_add_target_dependents
name
step
node
)
get_property(dependers
TARGET ${name}
PROPERTY _EP_${node}_INTERNAL_DEPENDERS
)
list(REMOVE_DUPLICATES dependers)
foreach(depender IN LISTS dependers)
if(TARGET ${name}-${depender})
add_dependencies(${name}-${depender} ${name}-${step})
else()
_ep_step_add_target_dependents(${name} ${step} ${depender})
endif()
endforeach()
endfunction()
function(ExternalProject_Add_StepTargets name)
get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114)
set(steps ${ARGN})
if(ARGC GREATER 1 AND "${ARGV1}" STREQUAL "NO_DEPENDS")
set(no_deps 1)
list(REMOVE_AT steps 0)
else()
set(no_deps 0)
endif()
if(cmp0114 STREQUAL "NEW")
if(no_deps)
message(FATAL_ERROR
"The 'NO_DEPENDS' option is no longer allowed. "
"It has been superseded by the per-step 'INDEPENDENT' option. "
"See policy CMP0114."
)
endif()
elseif(cmp0114 STREQUAL "")
cmake_policy(GET_WARNING CMP0114 _cmp0114_warning)
string(APPEND _cmp0114_warning "\n"
"ExternalProject target '${name}' would depend on the targets for "
"step(s) '${steps}' under policy CMP0114, but this is being left out "
"for compatibility since the policy is not set."
)
if(no_deps)
string(APPEND _cmp0114_warning " "
"Also, the NO_DEPENDS option is deprecated in favor of policy CMP0114."
)
endif()
message(AUTHOR_WARNING "${_cmp0114_warning}")
endif()
foreach(step IN LISTS steps)
_ep_step_add_target("${name}" "${step}" "${no_deps}")
endforeach()
endfunction()
# While this function is referenced in shared_internal_commands.cmake in a few
# places, all of those code paths will only be reached by calling one of the
# functions defined in this file. Keep it here, since it is part of the public
# interface of ExternalProject.
function(ExternalProject_Add_Step name step)
get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114)
_ep_get_complete_stampfile(${name} complete_stamp_file)
_ep_get_step_stampfile(${name} ${step} stamp_file)
set(keywords
COMMAND
COMMENT
DEPENDEES
DEPENDERS
DEPENDS
INDEPENDENT
BYPRODUCTS
ALWAYS
JOB_SERVER_AWARE
EXCLUDE_FROM_MAIN
WORKING_DIRECTORY
LOG
USES_TERMINAL
)
_ep_parse_arguments(
ExternalProject_Add_Step
"${keywords}"
${name}
_EP_${step}_
"${ARGN}"
)
get_property(independent
TARGET ${name}
PROPERTY _EP_${step}_INDEPENDENT
)
if(independent STREQUAL "")
set(independent FALSE)
set_property(TARGET ${name} PROPERTY
_EP_${step}_INDEPENDENT "${independent}"
)
endif()
get_property(exclude_from_main
TARGET ${name}
PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN
)
if(NOT exclude_from_main)
add_custom_command(APPEND
OUTPUT ${complete_stamp_file}
DEPENDS ${stamp_file}
)
endif()
# Steps depending on this step.
get_property(dependers TARGET ${name} PROPERTY _EP_${step}_DEPENDERS)
set_property(TARGET ${name} APPEND PROPERTY
_EP_${step}_INTERNAL_DEPENDERS ${dependers}
)
foreach(depender IN LISTS dependers)
set_property(TARGET ${name} APPEND PROPERTY
_EP_${depender}_INTERNAL_DEPENDEES ${step}
)
_ep_get_step_stampfile(${name} ${depender} depender_stamp_file)
add_custom_command(APPEND
OUTPUT ${depender_stamp_file}
DEPENDS ${stamp_file}
)
if(cmp0114 STREQUAL "NEW" AND NOT independent)
get_property(dep_independent
TARGET ${name}
PROPERTY _EP_${depender}_INDEPENDENT
)
if(dep_independent)
message(FATAL_ERROR
"ExternalProject '${name}' step '${depender}' is marked INDEPENDENT "
"but depends on step '${step}' that is not marked INDEPENDENT."
)
endif()
endif()
endforeach()
# Dependencies on files.
get_property(depends TARGET ${name} PROPERTY _EP_${step}_DEPENDS)
# Byproducts of the step.
get_property(byproducts TARGET ${name} PROPERTY _EP_${step}_BYPRODUCTS)
# Dependencies on steps.
get_property(dependees TARGET ${name} PROPERTY _EP_${step}_DEPENDEES)
set_property(TARGET ${name} APPEND PROPERTY
_EP_${step}_INTERNAL_DEPENDEES ${dependees}
)
foreach(dependee IN LISTS dependees)
set_property(TARGET ${name} APPEND PROPERTY
_EP_${dependee}_INTERNAL_DEPENDERS ${step}
)
_ep_get_step_stampfile(${name} ${dependee} dependee_stamp_file)
list(APPEND depends ${dependee_stamp_file})
if(cmp0114 STREQUAL "NEW" AND independent)
get_property(dep_independent
TARGET ${name}
PROPERTY _EP_${dependee}_INDEPENDENT
)
if(NOT dep_independent)
message(FATAL_ERROR
"ExternalProject '${name}' step '${step}' is marked INDEPENDENT "
"but depends on step '${dependee}' that is not marked INDEPENDENT."
)
endif()
endif()
endforeach()
# The command to run.
get_property(command TARGET ${name} PROPERTY _EP_${step}_COMMAND)
if(command)
set(comment "Performing ${step} step for '${name}'")
else()
set(comment "No ${step} step for '${name}'")
endif()
get_property(work_dir
TARGET ${name}
PROPERTY _EP_${step}_WORKING_DIRECTORY
)
# Replace list separators.
get_property(sep
TARGET ${name}
PROPERTY _EP_LIST_SEPARATOR
)
if(sep AND command)
string(REPLACE "${sep}" "\\;" command "${command}")
endif()
# Replace location tags.
_ep_replace_location_tags(
${name}
comment
command
work_dir
byproducts
)
if(NOT "x${work_dir}" STREQUAL "x")
set(maybe_WORKING_DIRECTORY "WORKING_DIRECTORY [==[${work_dir}]==]")
else()
set(maybe_WORKING_DIRECTORY "")
endif()
# Custom comment?
get_property(comment_set
TARGET ${name}
PROPERTY _EP_${step}_COMMENT
SET
)
if(comment_set)
get_property(comment
TARGET ${name}
PROPERTY _EP_${step}_COMMENT
)
endif()
# Uses terminal?
get_property(uses_terminal
TARGET ${name}
PROPERTY _EP_${step}_USES_TERMINAL
)
if(uses_terminal)
set(maybe_USES_TERMINAL USES_TERMINAL)
else()
set(maybe_USES_TERMINAL "")
endif()
# Run every time?
get_property(always
TARGET ${name}
PROPERTY _EP_${step}_ALWAYS
)
if(always)
set(maybe_COMMAND_touch "")
# Mark stamp files for all configs as SYMBOLIC since we do not create them.
# Remove any existing stamp in case the option changed in an existing tree.
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
_ep_get_configuration_subdir_genex(cfgdir)
foreach(cfg IN LISTS CMAKE_CONFIGURATION_TYPES)
string(REPLACE "${cfgdir}" "/${cfg}"
stamp_file_config "${stamp_file}"
)
set_property(SOURCE ${stamp_file_config} PROPERTY SYMBOLIC 1)
file(REMOVE ${stamp_file_config})
endforeach()
if(CMAKE_GENERATOR STREQUAL "Xcode")
# See Xcode case in _ep_get_configuration_subdir_genex.
set_property(SOURCE ${stamp_file} PROPERTY SYMBOLIC 1)
endif()
else()
set_property(SOURCE ${stamp_file} PROPERTY SYMBOLIC 1)
file(REMOVE ${stamp_file})
endif()
else()
set(maybe_COMMAND_touch "COMMAND \${CMAKE_COMMAND} -E touch \${stamp_file}")
endif()
get_property(job_server_aware
TARGET ${name}
PROPERTY _EP_${step}_JOB_SERVER_AWARE
)
if(job_server_aware)
set(maybe_JOB_SERVER_AWARE "JOB_SERVER_AWARE 1")
else()
set(maybe_JOB_SERVER_AWARE "")
endif()
# Wrap with log script?
get_property(log TARGET ${name} PROPERTY _EP_${step}_LOG)
if(command AND log)
_ep_write_log_script(${name} ${step} command)
endif()
if("${command}" STREQUAL "")
# Some generators (i.e. Xcode) will not generate a file level target
# if no command is set, and therefore the dependencies on this
# target will be broken.
# The empty command is replaced by an echo command here in order to
# avoid this issue.
set(command ${CMAKE_COMMAND} -E echo_append)
endif()
set(__cmdQuoted)
foreach(__item IN LISTS command)
string(APPEND __cmdQuoted " [==[${__item}]==]")
endforeach()
cmake_language(EVAL CODE "
add_custom_command(
OUTPUT \${stamp_file}
BYPRODUCTS \${byproducts}
COMMENT [===[${comment}]===]
COMMAND ${__cmdQuoted}
DEPENDS \${depends}
VERBATIM
${maybe_COMMAND_touch}
${maybe_JOB_SERVER_AWARE}
${maybe_WORKING_DIRECTORY}
${maybe_USES_TERMINAL}
)"
)
set_property(TARGET ${name} APPEND PROPERTY _EP_STEPS ${step})
# Add custom "step target"?
get_property(step_targets
TARGET ${name}
PROPERTY _EP_STEP_TARGETS
)
if(NOT step_targets)
get_property(step_targets
DIRECTORY
PROPERTY EP_STEP_TARGETS
)
endif()
foreach(st IN LISTS step_targets)
if("${st}" STREQUAL "${step}")
_ep_step_add_target("${name}" "${step}" "FALSE")
break()
endif()
endforeach()
get_property(independent_step_targets
TARGET ${name} PROPERTY
_EP_INDEPENDENT_STEP_TARGETS
)
if(NOT independent_step_targets)
get_property(independent_step_targets
DIRECTORY
PROPERTY EP_INDEPENDENT_STEP_TARGETS
)
endif()
if(cmp0114 STREQUAL "NEW")
if(independent_step_targets)
message(FATAL_ERROR
"ExternalProject '${name}' option 'INDEPENDENT_STEP_TARGETS' is set to"
"\n ${independent_step_targets}\n"
"but the option is no longer allowed. "
"It has been superseded by the per-step 'INDEPENDENT' option. "
"See policy CMP0114."
)
endif()
else()
if(independent_step_targets AND cmp0114 STREQUAL "")
get_property(warned
TARGET ${name}
PROPERTY _EP_CMP0114_WARNED_INDEPENDENT_STEP_TARGETS
)
if(NOT warned)
set_property(TARGET ${name} PROPERTY
_EP_CMP0114_WARNED_INDEPENDENT_STEP_TARGETS 1
)
cmake_policy(GET_WARNING CMP0114 _cmp0114_warning)
string(APPEND _cmp0114_warning
"\n"
"ExternalProject '${name}' option INDEPENDENT_STEP_TARGETS is set to"
"\n ${independent_step_targets}\n"
"but the option is deprecated in favor of policy CMP0114."
)
message(AUTHOR_WARNING "${_cmp0114_warning}")
endif()
endif()
foreach(st IN LISTS independent_step_targets)
if("${st}" STREQUAL "${step}")
_ep_step_add_target("${name}" "${step}" "TRUE")
break()
endif()
endforeach()
endif()
endfunction()
function(ExternalProject_Add_StepDependencies name step)
set(dependencies ${ARGN})
# Sanity checks on "name" and "step".
if(NOT TARGET ${name})
message(FATAL_ERROR
"Cannot find target \"${name}\". Perhaps it has not yet been created "
"using ExternalProject_Add."
)
endif()
get_property(type TARGET ${name} PROPERTY TYPE)
if(NOT type STREQUAL "UTILITY")
message(FATAL_ERROR
"Target \"${name}\" was not generated by ExternalProject_Add."
)
endif()
get_property(is_ep TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT)
if(NOT is_ep)
message(FATAL_ERROR
"Target \"${name}\" was not generated by ExternalProject_Add."
)
endif()
get_property(steps TARGET ${name} PROPERTY _EP_STEPS)
list(FIND steps ${step} is_step)
if(is_step LESS 0)
message(FATAL_ERROR
"External project \"${name}\" does not have a step \"${step}\"."
)
endif()
if(TARGET ${name}-${step})
get_property(type TARGET ${name}-${step} PROPERTY TYPE)
if(NOT type STREQUAL "UTILITY")
message(FATAL_ERROR
"Target \"${name}-${step}\" was not generated by "
"ExternalProject_Add_StepTargets."
)
endif()
get_property(is_ep_step
TARGET ${name}-${step}
PROPERTY _EP_IS_EXTERNAL_PROJECT_STEP
)
if(NOT is_ep_step)
message(FATAL_ERROR
"Target \"${name}-${step}\" was not generated by "
"ExternalProject_Add_StepTargets."
)
endif()
endif()
# Always add file-level dependency, but add target-level dependency
# only if the target exists for that step.
_ep_get_step_stampfile(${name} ${step} stamp_file)
foreach(dep IN LISTS dependencies)
add_custom_command(APPEND
OUTPUT ${stamp_file}
DEPENDS ${dep}
)
endforeach()
if(TARGET ${name}-${step})
add_dependencies(${name}-${step} ${dependencies})
endif()
endfunction()
function(_ep_add_mkdir_command name)
ExternalProject_Get_Property(${name} tmp_dir)
set(script_filename "${tmp_dir}/${name}-mkdirs.cmake")
_ep_get_configuration_subdir_genex(cfgdir)
ExternalProject_Add_Step(${name} mkdir
INDEPENDENT TRUE
COMMENT "Creating directories for '${name}'"
COMMAND ${CMAKE_COMMAND} -Dcfgdir=${cfgdir} -P ${script_filename}
)
endfunction()
function(_ep_get_file_deps var name)
set(file_deps)
get_property(deps
TARGET ${name}
PROPERTY _EP_DEPENDS
)
foreach(dep IN LISTS deps)
get_property(dep_type
TARGET ${dep}
PROPERTY TYPE
)
if(dep_type STREQUAL "UTILITY")
get_property(is_ep
TARGET ${dep}
PROPERTY _EP_IS_EXTERNAL_PROJECT
)
if(is_ep)
_ep_get_step_stampfile(${dep} "done" done_stamp_file)
list(APPEND file_deps ${done_stamp_file})
endif()
endif()
endforeach()
set("${var}" "${file_deps}" PARENT_SCOPE)
endfunction()
function(_ep_extract_configure_command var name)
get_property(cmd_set
TARGET ${name}
PROPERTY _EP_CONFIGURE_COMMAND
SET
)
if(cmd_set)
get_property(cmd
TARGET ${name}
PROPERTY _EP_CONFIGURE_COMMAND
)
else()
get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
if(cmake_command)
set(cmd "${cmake_command}")
else()
set(cmd "${CMAKE_COMMAND}")
endif()
get_property(cmake_args
TARGET ${name}
PROPERTY _EP_CMAKE_ARGS
)
list(APPEND cmd ${cmake_args})
# If there are any CMAKE_CACHE_ARGS or CMAKE_CACHE_DEFAULT_ARGS,
# write an initial cache and use it
get_property(cmake_cache_args
TARGET ${name}
PROPERTY _EP_CMAKE_CACHE_ARGS
)
get_property(cmake_cache_default_args
TARGET ${name}
PROPERTY _EP_CMAKE_CACHE_DEFAULT_ARGS
)
set(has_cmake_cache_args 0)
if(NOT "${cmake_cache_args}" STREQUAL "")
set(has_cmake_cache_args 1)
endif()
set(has_cmake_cache_default_args 0)
if(NOT "${cmake_cache_default_args}" STREQUAL "")
set(has_cmake_cache_default_args 1)
endif()
get_target_property(cmake_generator ${name}
_EP_CMAKE_GENERATOR
)
get_target_property(cmake_generator_instance ${name}
_EP_CMAKE_GENERATOR_INSTANCE
)
get_target_property(cmake_generator_platform ${name}
_EP_CMAKE_GENERATOR_PLATFORM
)
get_target_property(cmake_generator_toolset ${name}
_EP_CMAKE_GENERATOR_TOOLSET
)
if(cmake_generator)
list(APPEND cmd "-G${cmake_generator}")
if(cmake_generator_platform)
list(APPEND cmd "-A${cmake_generator_platform}")
endif()
if(cmake_generator_toolset)
list(APPEND cmd "-T${cmake_generator_toolset}")
endif()
if(cmake_generator_instance)
list(APPEND cmd
"-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${cmake_generator_instance}"
)
endif()
else()
if(CMAKE_EXTRA_GENERATOR)
list(APPEND cmd "-G${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
else()
list(APPEND cmd "-G${CMAKE_GENERATOR}")
# GreenHills needs to know about the compiler and toolset.
# Be sure to update the similar section in
# FetchContent.cmake:__FetchContent_directPopulate()
if("${CMAKE_GENERATOR}" MATCHES "Green Hills MULTI")
set(has_cmake_cache_default_args 1)
list(APPEND cmake_cache_default_args
"-DGHS_TARGET_PLATFORM:STRING=${GHS_TARGET_PLATFORM}"
"-DGHS_PRIMARY_TARGET:STRING=${GHS_PRIMARY_TARGET}"
"-DGHS_TOOLSET_ROOT:STRING=${GHS_TOOLSET_ROOT}"
"-DGHS_OS_ROOT:STRING=${GHS_OS_ROOT}"
"-DGHS_OS_DIR:STRING=${GHS_OS_DIR}"
"-DGHS_BSP_NAME:STRING=${GHS_BSP_NAME}"
)
endif()
endif()
if(cmake_generator_platform)
message(FATAL_ERROR
"Option CMAKE_GENERATOR_PLATFORM not allowed without "
"CMAKE_GENERATOR."
)
endif()
if(CMAKE_GENERATOR_PLATFORM)
list(APPEND cmd "-A${CMAKE_GENERATOR_PLATFORM}")
endif()
if(cmake_generator_toolset)
message(FATAL_ERROR
"Option CMAKE_GENERATOR_TOOLSET not allowed without CMAKE_GENERATOR."
)
endif()
if(CMAKE_GENERATOR_TOOLSET)
list(APPEND cmd "-T${CMAKE_GENERATOR_TOOLSET}")
endif()
if(cmake_generator_instance)
message(FATAL_ERROR
"Option CMAKE_GENERATOR_INSTANCE not allowed without CMAKE_GENERATOR."
)
endif()
if(CMAKE_GENERATOR_INSTANCE)
list(APPEND cmd
"-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}"
)
endif()
endif()
if(has_cmake_cache_args OR has_cmake_cache_default_args)
set(_ep_cache_args_script "<TMP_DIR>/${name}-cache-$<CONFIG>.cmake")
if(has_cmake_cache_args)
_ep_command_line_to_initial_cache(
script_initial_cache_force
"${cmake_cache_args}"
1
)
endif()
if(has_cmake_cache_default_args)
_ep_command_line_to_initial_cache(
script_initial_cache_default
"${cmake_cache_default_args}"
0
)
endif()
_ep_write_initial_cache(
${name}
"${_ep_cache_args_script}"
"${script_initial_cache_force}${script_initial_cache_default}"
)
list(APPEND cmd "-C${_ep_cache_args_script}")
_ep_replace_location_tags(${name} _ep_cache_args_script)
set(_ep_cache_args_script
"${_ep_cache_args_script}"
PARENT_SCOPE
)
endif()
list(APPEND cmd -S "<SOURCE_DIR><SOURCE_SUBDIR>" -B "<BINARY_DIR>")
endif()
set("${var}" "${cmd}" PARENT_SCOPE)
endfunction()
# TODO: Make sure external projects use the proper compiler
function(_ep_add_configure_command name)
ExternalProject_Get_Property(${name} binary_dir tmp_dir)
set(file_deps)
get_property(configure_handled_by_build
TARGET ${name}
PROPERTY _EP_CONFIGURE_HANDLED_BY_BUILD
)
if(NOT configure_handled_by_build)
# Depend on other external projects (file-level)
_ep_get_file_deps(file_deps ${name})
endif()
_ep_extract_configure_command(cmd ${name})
# If anything about the configure command changes, (command itself, cmake
# used, cmake args or cmake generator) then re-run the configure step.
# Fixes issue https://gitlab.kitware.com/cmake/cmake/-/issues/10258
#
configure_file(
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject/cfgcmd.txt.in
${tmp_dir}/${name}-cfgcmd.txt
@ONLY
)
list(APPEND file_deps ${tmp_dir}/${name}-cfgcmd.txt)
list(APPEND file_deps ${_ep_cache_args_script})
_ep_get_update_disconnected(update_disconnected ${name})
if(update_disconnected)
set(dependees patch_disconnected)
else()
set(dependees patch)
endif()
get_property(log
TARGET ${name}
PROPERTY _EP_LOG_CONFIGURE
)
if(log)
set(log LOG 1)
else()
set(log "")
endif()
get_property(uses_terminal
TARGET ${name}
PROPERTY _EP_USES_TERMINAL_CONFIGURE
)
if(uses_terminal)
set(uses_terminal USES_TERMINAL 1)
else()
set(uses_terminal "")
endif()
set(__cmdQuoted)
foreach(__item IN LISTS cmd)
string(APPEND __cmdQuoted " [==[${__item}]==]")
endforeach()
cmake_language(EVAL CODE "
ExternalProject_Add_Step(${name} configure
INDEPENDENT FALSE
COMMAND ${__cmdQuoted}
WORKING_DIRECTORY \${binary_dir}
DEPENDEES \${dependees}
DEPENDS \${file_deps}
${log}
${uses_terminal}
)"
)
endfunction()
function(_ep_add_build_command name)
ExternalProject_Get_Property(${name} binary_dir)
set(file_deps)
get_property(configure_handled_by_build
TARGET ${name}
PROPERTY _EP_CONFIGURE_HANDLED_BY_BUILD
)
if(configure_handled_by_build)
# Depend on other external projects (file-level)
_ep_get_file_deps(file_deps ${name})
endif()
get_property(cmd_set
TARGET ${name}
PROPERTY _EP_BUILD_COMMAND
SET
)
if(cmd_set)
get_property(cmd
TARGET ${name}
PROPERTY _EP_BUILD_COMMAND
)
else()
_ep_get_build_command(${name} BUILD cmd)
endif()
get_property(log
TARGET ${name}
PROPERTY _EP_LOG_BUILD
)
if(log)
set(log LOG 1)
else()
set(log "")
endif()
get_property(uses_terminal
TARGET ${name}
PROPERTY _EP_USES_TERMINAL_BUILD
)
if(uses_terminal)
set(uses_terminal USES_TERMINAL 1)
else()
set(uses_terminal "")
endif()
get_property(build_always
TARGET ${name}
PROPERTY _EP_BUILD_ALWAYS
)
if(build_always)
set(always 1)
else()
set(always 0)
endif()
get_property(build_byproducts
TARGET ${name}
PROPERTY _EP_BUILD_BYPRODUCTS
)
get_property(build_job_server_aware
TARGET ${name}
PROPERTY _EP_BUILD_JOB_SERVER_AWARE
)
if(build_job_server_aware)
set(maybe_JOB_SERVER_AWARE "JOB_SERVER_AWARE 1")
else()
set(maybe_JOB_SERVER_AWARE "")
endif()
set(__cmdQuoted)
foreach(__item IN LISTS cmd)
string(APPEND __cmdQuoted " [==[${__item}]==]")
endforeach()
cmake_language(EVAL CODE "
ExternalProject_Add_Step(${name} build
INDEPENDENT FALSE
COMMAND ${__cmdQuoted}
BYPRODUCTS \${build_byproducts}
WORKING_DIRECTORY \${binary_dir}
DEPENDEES configure
DEPENDS \${file_deps}
ALWAYS \${always}
${maybe_JOB_SERVER_AWARE}
${log}
${uses_terminal}
)"
)
endfunction()
function(_ep_add_install_command name)
ExternalProject_Get_Property(${name} binary_dir)
get_property(cmd_set
TARGET ${name}
PROPERTY _EP_INSTALL_COMMAND
SET
)
if(cmd_set)
get_property(cmd
TARGET ${name}
PROPERTY _EP_INSTALL_COMMAND
)
else()
_ep_get_build_command(${name} INSTALL cmd)
endif()
get_property(log
TARGET ${name}
PROPERTY _EP_LOG_INSTALL
)
if(log)
set(log LOG 1)
else()
set(log "")
endif()
get_property(uses_terminal
TARGET ${name}
PROPERTY _EP_USES_TERMINAL_INSTALL
)
if(uses_terminal)
set(uses_terminal USES_TERMINAL 1)
else()
set(uses_terminal "")
endif()
# With BUILD_ALWAYS+BUILD_BYPRODUCTS, Ninja restats the
# build step outputs and may not consider this step to
# be out-of-date. Explicitly mark it out-of-date too.
get_property(build_always
TARGET ${name}
PROPERTY _EP_BUILD_ALWAYS
)
if(build_always)
set(always 1)
else()
set(always 0)
endif()
get_property(install_byproducts
TARGET ${name}
PROPERTY _EP_INSTALL_BYPRODUCTS
)
get_property(install_job_server_aware
TARGET ${name}
PROPERTY _EP_INSTALL_JOB_SERVER_AWARE
)
if(install_job_server_aware)
set(maybe_JOB_SERVER_AWARE "JOB_SERVER_AWARE 1")
else()
set(maybe_JOB_SERVER_AWARE "")
endif()
set(__cmdQuoted)
foreach(__item IN LISTS cmd)
string(APPEND __cmdQuoted " [==[${__item}]==]")
endforeach()
cmake_language(EVAL CODE "
ExternalProject_Add_Step(${name} install
INDEPENDENT FALSE
COMMAND ${__cmdQuoted}
BYPRODUCTS \${install_byproducts}
WORKING_DIRECTORY \${binary_dir}
DEPENDEES build
ALWAYS \${always}
${maybe_JOB_SERVER_AWARE}
${log}
${uses_terminal}
)"
)
endfunction()
function(_ep_add_test_command name)
ExternalProject_Get_Property(${name} binary_dir)
get_property(before TARGET ${name} PROPERTY _EP_TEST_BEFORE_INSTALL)
get_property(after TARGET ${name} PROPERTY _EP_TEST_AFTER_INSTALL)
get_property(exclude TARGET ${name} PROPERTY _EP_TEST_EXCLUDE_FROM_MAIN)
get_property(cmd_set TARGET ${name} PROPERTY _EP_TEST_COMMAND SET)
# Only actually add the test step if one of the test related properties is
# explicitly set. (i.e. the test step is omitted unless requested...)
#
if(cmd_set OR before OR after OR exclude)
if(cmd_set)
get_property(cmd
TARGET ${name}
PROPERTY _EP_TEST_COMMAND
)
else()
_ep_get_build_command(${name} TEST cmd)
endif()
if(before)
set(dependees_args DEPENDEES build)
else()
set(dependees_args DEPENDEES install)
endif()
if(exclude)
set(dependers_args "")
set(exclude_args EXCLUDE_FROM_MAIN 1)
else()
if(before)
set(dependers_args DEPENDERS install)
else()
set(dependers_args "")
endif()
set(exclude_args "")
endif()
get_property(log
TARGET ${name}
PROPERTY _EP_LOG_TEST
)
if(log)
set(log LOG 1)
else()
set(log "")
endif()
get_property(uses_terminal
TARGET ${name}
PROPERTY _EP_USES_TERMINAL_TEST
)
if(uses_terminal)
set(uses_terminal USES_TERMINAL 1)
else()
set(uses_terminal "")
endif()
set(__cmdQuoted)
foreach(__item IN LISTS cmd)
string(APPEND __cmdQuoted " [==[${__item}]==]")
endforeach()
cmake_language(EVAL CODE "
ExternalProject_Add_Step(${name} test
INDEPENDENT FALSE
COMMAND ${__cmdQuoted}
WORKING_DIRECTORY \${binary_dir}
${dependees_args}
${dependers_args}
${exclude_args}
${log}
${uses_terminal}
)"
)
endif()
endfunction()
function(ExternalProject_Add name)
cmake_policy(GET CMP0097 _EP_CMP0097
PARENT_SCOPE # undocumented, do not use outside of CMake
)
cmake_policy(GET CMP0114 cmp0114
PARENT_SCOPE # undocumented, do not use outside of CMake
)
if(CMAKE_XCODE_BUILD_SYSTEM VERSION_GREATER_EQUAL 12 AND
NOT cmp0114 STREQUAL "NEW")
message(AUTHOR_WARNING
"Policy CMP0114 is not set to NEW. "
"In order to support the Xcode \"new build system\", "
"this project must be updated to set policy CMP0114 to NEW."
"\n"
"Since CMake is generating for the Xcode \"new build system\", "
"ExternalProject_Add will use policy CMP0114's NEW behavior anyway, "
"but the generated build system may not match what the project intends."
)
set(cmp0114 "NEW")
endif()
cmake_policy(GET CMP0135 _EP_CMP0135
PARENT_SCOPE # undocumented, do not use outside of CMake
)
_ep_get_configuration_subdir_genex(cfgdir)
# Add a custom target for the external project.
set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
_ep_get_complete_stampfile(${name} complete_stamp_file)
cmake_policy(PUSH)
if(cmp0114 STREQUAL "NEW")
# To implement CMP0114 NEW behavior with Makefile generators,
# we need CMP0113 NEW behavior.
cmake_policy(SET CMP0113 NEW)
endif()
# The "ALL" option to add_custom_target just tells it to not set the
# EXCLUDE_FROM_ALL target property. Later, if the EXCLUDE_FROM_ALL
# argument was passed, we explicitly set it for the target.
add_custom_target(${name} ALL DEPENDS ${complete_stamp_file})
cmake_policy(POP)
set_target_properties(${name} PROPERTIES
_EP_IS_EXTERNAL_PROJECT 1
LABELS ${name}
FOLDER "ExternalProjectTargets/${name}"
_EP_CMP0114 "${cmp0114}"
)
_ep_get_add_keywords(keywords)
_ep_parse_arguments(
ExternalProject_Add
"${keywords}"
${name}
_EP_
"${ARGN}"
)
_ep_set_directories(${name})
_ep_get_step_stampfile(${name} "done" done_stamp_file)
_ep_get_step_stampfile(${name} "install" install_stamp_file)
# Set the EXCLUDE_FROM_ALL target property if required.
get_property(exclude_from_all
TARGET ${name}
PROPERTY _EP_EXCLUDE_FROM_ALL
)
if(exclude_from_all)
set_property(TARGET ${name} PROPERTY EXCLUDE_FROM_ALL TRUE)
endif()
get_property(repo TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
if(NOT repo STREQUAL "")
cmake_policy(GET CMP0150 cmp0150
PARENT_SCOPE # undocumented, do not use outside of CMake
)
get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
get_filename_component(work_dir "${source_dir}" PATH)
_ep_resolve_git_remote(resolved_git_repository "${repo}" "${cmp0150}" "${work_dir}")
set_property(TARGET ${name} PROPERTY _EP_GIT_REPOSITORY ${resolved_git_repository})
set(_EP_GIT_REPOSITORY "${resolved_git_repository}")
endif()
# The 'complete' step depends on all other steps and creates a
# 'done' mark. A dependent external project's 'configure' step
# depends on the 'done' mark so that it rebuilds when this project
# rebuilds. It is important that 'done' is not the output of any
# custom command so that CMake does not propagate build rules to
# other external project targets, which may cause problems during
# parallel builds. However, the Ninja generator needs to see the entire
# dependency graph, and can cope with custom commands belonging to
# multiple targets, so we add the 'done' mark as an output for Ninja only.
set(complete_outputs ${complete_stamp_file})
if(${CMAKE_GENERATOR} MATCHES "Ninja")
set(complete_outputs ${complete_outputs} ${done_stamp_file})
endif()
add_custom_command(
OUTPUT ${complete_outputs}
COMMENT "Completed '${name}'"
COMMAND ${CMAKE_COMMAND} -E make_directory ${cmf_dir}${cfgdir}
COMMAND ${CMAKE_COMMAND} -E touch ${complete_stamp_file}
COMMAND ${CMAKE_COMMAND} -E touch ${done_stamp_file}
DEPENDS ${install_stamp_file}
VERBATIM
)
# Depend on other external projects (target-level).
get_property(deps
TARGET ${name}
PROPERTY _EP_DEPENDS
)
foreach(arg IN LISTS deps)
add_dependencies(${name} ${arg})
endforeach()
# Set up custom build steps based on the target properties.
# Each step depends on the previous one.
#
# The target depends on the output of the final step.
# (Already set up above in the DEPENDS of the add_custom_target command.)
#
_ep_add_mkdir_command(${name})
_ep_add_download_command(${name})
_ep_add_update_command(${name})
_ep_add_patch_command(${name})
_ep_add_configure_command(${name})
_ep_add_build_command(${name})
_ep_add_install_command(${name})
# Test is special in that it might depend on build, or it might depend
# on install.
#
_ep_add_test_command(${name})
endfunction()
|