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 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506
|
#[==[
@defgroup module Module CMake APIs
@defgroup module-internal Module Internal CMake APIs
@defgroup module-impl Module Implementation CMake APIs
@defgroup module-support Module Support CMake APIs
#]==]
#[==[
@ingroup module
@page module-api-overview Module API
This module includes functions to find and build VTK modules. A module is a set
of related functionality. These are then compiled together into libraries at
the "kit" level. Each module may be enabled or disabled individually and its
dependencies will be built as needed.
All functions strictly check their arguments. Any unrecognized or invalid
values for a function cause errors to be raised.
#]==]
#[==[
@ingroup module-internal
@page module-internal-api Internal API
The VTK module system provides some API functions for use by other code which
consumes VTK modules (primarily language wrappers). This file documents these
APIs. They may start with `_vtk_module`, but they are intended for use in cases
of language wrappers or dealing with trickier third party packages.
#]==]
#[==[
@ingroup module-impl
@page module-impl-api Implementation API
These functions are purely internal implementation details. No guarantees are
made for them and they may change at any time (including wrapping code calls).
Note that these functions are usually very lax in their argument parsing.
#]==]
#[==[
@ingroup module-internal
@brief Conditionally output debug statements
The @ref _vtk_module_debug function is provided to assist in debugging. It is
controlled by the `_vtk_module_log` variable which contains a list of "domains"
to debug.
~~~
_vtk_module_debug(<domain> <format>)
~~~
If the `domain` is enabled for debugging, the `format` argument is configured
and printed. It should contain `@` variable expansions to replace rather than
it being done outside. This helps to avoid the cost of generating large strings
when debugging is disabled.
#]==]
function (_vtk_module_debug domain format)
if (NOT _vtk_module_log STREQUAL "ALL" AND
NOT domain IN_LIST _vtk_module_log)
return ()
endif ()
string(CONFIGURE "${format}" _vtk_module_debug_msg)
if (_vtk_module_debug_msg)
message(STATUS
"VTK module debug ${domain}: ${_vtk_module_debug_msg}")
endif ()
endfunction ()
# TODO: Support finding `vtk.module` and `vtk.kit` contents in the
# `CMakeLists.txt` files for the module via a comment header.
#[==[
@ingroup module
@brief Find `vtk.kit` files in a set of directories
~~~
vtk_module_find_kits(<output> [<directory>...])
~~~
This scans the given directories recursively for `vtk.kit` files and put the
paths into the output variable.
#]==]
function (vtk_module_find_kits output)
set(_vtk_find_kits_all)
foreach (_vtk_find_kits_directory IN LISTS ARGN)
file(GLOB_RECURSE _vtk_find_kits_kits
"${_vtk_find_kits_directory}/vtk.kit")
list(APPEND _vtk_find_kits_all
${_vtk_find_kits_kits})
endforeach ()
set("${output}" ${_vtk_find_kits_all} PARENT_SCOPE)
endfunction ()
#[==[
@ingroup module
@brief Find `vtk.module` files in a set of directories
~~~
vtk_module_find_modules(<output> [<directory>...])
~~~
This scans the given directories recursively for `vtk.module` files and put the
paths into the output variable. Note that module files are assumed to live next
to the `CMakeLists.txt` file which will build the module.
#]==]
function (vtk_module_find_modules output)
set(_vtk_find_modules_all)
foreach (_vtk_find_modules_directory IN LISTS ARGN)
file(GLOB_RECURSE _vtk_find_modules_modules
"${_vtk_find_modules_directory}/vtk.module")
list(APPEND _vtk_find_modules_all
${_vtk_find_modules_modules})
endforeach ()
set("${output}" ${_vtk_find_modules_all} PARENT_SCOPE)
endfunction ()
#[==[
@ingroup module-internal
@brief Split a module name into a namespace and target component
Module names may include a namespace. This function splits the name into a
namespace and target name part.
~~~
_vtk_module_split_module_name(<name> <prefix>)
~~~
The `<prefix>_NAMESPACE` and `<prefix>_TARGET_NAME` variables will be set in
the calling scope.
#]==]
function (_vtk_module_split_module_name name prefix)
string(FIND "${name}" "::" namespace_pos)
if (namespace_pos EQUAL -1)
set(namespace "")
set(target_name "${name}")
else ()
string(SUBSTRING "${name}" 0 "${namespace_pos}" namespace)
math(EXPR name_pos "${namespace_pos} + 2")
string(SUBSTRING "${name}" "${name_pos}" -1 target_name)
endif ()
set("${prefix}_NAMESPACE"
"${namespace}"
PARENT_SCOPE)
set("${prefix}_TARGET_NAME"
"${target_name}"
PARENT_SCOPE)
endfunction ()
#[==[
@ingroup module
@page module-overview Module overview
@section module-parse-module vtk.module file contents
The `vtk.module` file is parsed and used as arguments to a CMake function which
stores information about the module for use when building it. Note that no
variable expansion is allowed and it is not CMake code, so no control flow is
allowed. Comments are supported and any content after a `#` on a line is
treated as a comment. Due to the breakdown of the content, quotes are not
meaningful within the files.
Example:
~~~
NAME
VTK::CommonCore
LIBRARY_NAME
vtkCommonCore
DESCRIPTION
The base VTK library.
LICENSE_FILES
Copyright.txt
GROUPS
StandAlone
DEPENDS
VTK::kwiml
PRIVATE_DEPENDS
VTK::vtksys
VTK::utf8
~~~
All values are optional unless otherwise noted. The following arguments are
supported:
* `NAME`: (Required) The name of the module.
* `LIBRARY_NAME`: The base name of the library file. It defaults to the
module name, but any namespaces are removed. For example, a `NS::Foo`
module will have a default `LIBRARY_NAME` of `Foo`.
* `DESCRIPTION`: (Recommended) Short text describing what the module is for.
* `KIT`: The name of the kit the module belongs to (see `Kits files` for more
information).
* `IMPLEMENTABLE`: If present, the module contains logic which supports the
autoinit functionality.
* `GROUPS`: Modules may belong to "groups" which is exposed as a build
option. This allows for enabling a set of modules with a single build
option.
* `CONDITION`: Arguments to CMake's `if` command which may be used to hide
the module for certain platforms or other reasons. If the expression is
false, the module is completely ignored.
* `DEPENDS`: A list of modules which are required by this module and modules
using this module.
* `PRIVATE_DEPENDS`: A list of modules which are required by this module, but
not by those using this module.
* `OPTIONAL_DEPENDS`: A list of modules which are used by this module if
enabled; these are treated as `PRIVATE_DEPENDS` if they exist.
* `ORDER_DEPENDS`: Dependencies which only matter for ordering. This does not
mean that the module will be enabled, just guaranteed to build before this
module.
* `IMPLEMENTS`: A list of modules for which this module needs to register
with.
* `TEST_DEPENDS`: Modules required by the test suite for this module.
* `TEST_OPTIONAL_DEPENDS`: Modules used by the test suite for this module if
available.
* `TEST_LABELS`: Labels to apply to the tests of this module. By default, the
module name is applied as a label.
* `EXCLUDE_WRAP`: If present, this module should not be wrapped in any
language.
* `THIRD_PARTY`: If present, this module is a third party module.
* `LICENSE_FILES`: A list of license files to install for the module.
Optional.
#]==]
#[==[
@ingroup module-impl
@brief Parse `vtk.module` file contents
This macro places all `vtk.module` keyword "arguments" into the caller's scope
prefixed with the value of `name_output` which is set to the `NAME` of the
module.
~~~
_vtk_module_parse_module_args(name_output <vtk.module args...>)
~~~
For example, this `vtk.module` file:
~~~
NAME
Namespace::Target
LIBRARY_NAME
nsTarget
~~~
called with `_vtk_module_parse_module_args(name ...)` will set the following
variables in the calling scope:
- `name`: `Namespace::Target`
- `Namespace::Target_LIBRARY_NAME`: `nsTarget`
With namespace support for module names, the variable should instead be
referenced via `${${name}_LIBRARY_NAME}` instead.
#]==]
macro (_vtk_module_parse_module_args name_output)
cmake_parse_arguments("_name"
""
"NAME"
""
${ARGN})
if (NOT _name_NAME)
message(FATAL_ERROR
"A VTK module requires a name (from ${_vtk_scan_module_file}).")
endif ()
set("${name_output}" "${_name_NAME}")
cmake_parse_arguments("${_name_NAME}"
"IMPLEMENTABLE;EXCLUDE_WRAP;THIRD_PARTY"
"LIBRARY_NAME;NAME;KIT"
"GROUPS;DEPENDS;PRIVATE_DEPENDS;OPTIONAL_DEPENDS;ORDER_DEPENDS;TEST_DEPENDS;TEST_OPTIONAL_DEPENDS;TEST_LABELS;DESCRIPTION;CONDITION;IMPLEMENTS;LICENSE_FILES"
${ARGN})
if (${_name_NAME}_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for ${_name_NAME}: "
"${${_name_NAME}_UNPARSED_ARGUMENTS}")
endif ()
if (NOT ${_name_NAME}_DESCRIPTION AND _vtk_module_warnings)
message(WARNING "The ${_name_NAME} module should have a description")
endif ()
string(REPLACE ";" " " "${_name_NAME}_DESCRIPTION" "${${_name_NAME}_DESCRIPTION}")
_vtk_module_split_module_name("${_name_NAME}" "${_name_NAME}")
if (NOT DEFINED "${_name_NAME}_LIBRARY_NAME")
set("${_name_NAME}_LIBRARY_NAME" "${${_name_NAME}_TARGET_NAME}")
endif ()
if (NOT ${_name_NAME}_LIBRARY_NAME)
message(FATAL_ERROR "The ${_name_NAME} module must have a non-empty `LIBRARY_NAME`.")
endif ()
list(APPEND "${_name_NAME}_TEST_LABELS"
"${${_name_NAME}_NAME}"
"${${_name_NAME}_LIBRARY_NAME}")
endmacro ()
#[==[
@page module-overview
@section module-parse-kit vtk.kit file contents
The `vtk.kit` file is parsed similarly to `vtk.module` files. Kits are intended
to bring together related modules into a single library in order to reduce the
number of objects that linkers need to deal with.
Example:
~~~
NAME
VTK::Common
LIBRARY_NAME
vtkCommon
DESCRIPTION
Core utilities for VTK.
~~~
All values are optional unless otherwise noted. The following arguments are
supported:
* `NAME`: (Required) The name of the kit.
* `LIBRARY_NAME`: The base name of the library file. It defaults to the
module name, but any namespaces are removed. For example, a `NS::Foo`
module will have a default `LIBRARY_NAME` of `Foo`.
* `DESCRIPTION`: (Recommended) Short text describing what the kit contains.
#]==]
#[==[
@ingroup module-impl
@brief Parse `vtk.kit` file contents
Just like @ref _vtk_module_parse_module_args, but for kits.
#]==]
macro (_vtk_module_parse_kit_args name_output)
cmake_parse_arguments("_name"
""
"NAME"
""
${ARGN})
if (NOT _name_NAME)
message(FATAL_ERROR
"A VTK kit requires a name (from ${_vtk_scan_kit_file}).")
endif ()
set("${name_output}" "${_name_NAME}")
cmake_parse_arguments("${_name_NAME}"
""
"NAME;LIBRARY_NAME"
"DESCRIPTION"
${ARGN})
if (${_name_NAME}_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for ${_name_NAME}: "
"${${_name_NAME}_UNPARSED_ARGUMENTS}")
endif ()
_vtk_module_split_module_name("${_name_NAME}" "${_name_NAME}")
if (NOT DEFINED "${_name_NAME}_LIBRARY_NAME")
set("${_name_NAME}_LIBRARY_NAME" "${${_name_NAME}_TARGET_NAME}")
endif ()
if (NOT ${_name_NAME}_LIBRARY_NAME)
message(FATAL_ERROR "The ${_name_NAME} module must have a non-empty `LIBRARY_NAME`.")
endif ()
if (NOT ${_name_NAME}_DESCRIPTION AND _vtk_module_warnings)
message(WARNING "The ${_name_NAME} kit should have a description")
endif ()
string(REPLACE ";" " " "${_name_NAME}_DESCRIPTION" "${${_name_NAME}_DESCRIPTION}")
endmacro ()
#[==[
@page module-overview
@ingroup module
@section module-enable-status Enable status values
Modules and groups are enable and disable preferences are specified using a
5-way flag setting:
- `YES`: The module or group must be built.
- `NO`: The module or group must not be built.
- `WANT`: The module or group should be built if possible.
- `DONT_WANT`: The module or group should only be built if required (e.g.,
via a dependency).
- `DEFAULT`: Acts as either `WANT` or `DONT_WANT` based on the group settings
for the module or `WANT_BY_DEFAULT` option to @ref vtk_module_scan if no
other preference is specified. This is usually handled via another setting
in the main project.
If a `YES` module preference requires a module with a `NO` preference, an error
is raised.
A module with a setting of `DEFAULT` will look for its first non-`DEFAULT`
group setting and only if all of those are set to `DEFAULT` is the
`WANT_BY_DEFAULT` setting used.
#]==]
#[==[
@ingroup module-impl
@brief Verify enable values
Verifies that the variable named as the first parameter is a valid `enable
status` value.
~~~
_vtk_module_verify_enable_value(var)
~~~
#]==]
function (_vtk_module_verify_enable_value var)
if (NOT (${var} STREQUAL "YES" OR
${var} STREQUAL "WANT" OR
${var} STREQUAL "DONT_WANT" OR
${var} STREQUAL "NO" OR
${var} STREQUAL "DEFAULT"))
message(FATAL_ERROR
"The `${var}` variable must be one of `YES`, `WANT`, `DONT_WANT`, `NO`, "
"or `DEFAULT`. Found `${${var}}`.")
endif ()
endfunction ()
include("${CMAKE_CURRENT_LIST_DIR}/vtkTopologicalSort.cmake")
#[==[
@ingroup module
@brief Scan modules and kits
Once all of the modules and kits files have been found, they are "scanned" to
determine what modules are enabled or required.
~~~
vtk_module_scan(
MODULE_FILES <file>...
[KIT_FILES <file>...]
PROVIDES_MODULES <variable>
[PROVIDES_KITS <variable>]
[REQUIRES_MODULES <variable>]
[REQUEST_MODULES <module>...]
[REJECT_MODULES <module>...]
[UNRECOGNIZED_MODULES <variable>]
[WANT_BY_DEFAULT <ON|OFF>]
[HIDE_MODULES_FROM_CACHE <ON|OFF>]
[ENABLE_TESTS <ON|OFF|WANT|DEFAULT>])
~~~
The `MODULE_FILES` and `PROVIDES_MODULES` arguments are required. Modules which
refer to kits must be scanned at the same time as their kits. This is so that
modules may not add themselves to kits declared prior. The arguments are as follows:
* `MODULE_FILES`: (Required) The list of module files to scan.
* `KIT_FILES`: The list of kit files to scan.
* `PROVIDES_MODULES`: (Required) This variable will contain the list of
modules which are enabled due to this scan.
* `PROVIDES_KITS`: (Required if `KIT_FILES` are provided) This variable will
contain the list of kits which are enabled due to this scan.
* `REQUIRES_MODULES`: This variable will contain the list of modules required
by the enabled modules that were not scanned.
* `REQUEST_MODULES`: The list of modules required by previous scans.
* `REJECT_MODULES`: The list of modules to exclude from the scan. If any of
these modules are required, an error will be raised.
* `UNRECOGNIZED_MODULES`: This variable will contain the list of requested
modules that were not scanned.
* `WANT_BY_DEFAULT`: (Defaults to `OFF`) Whether modules should default to
being built or not.
* `HIDE_MODULES_FROM_CACHE`: (Defaults to `OFF`) Whether or not to hide the
control variables from the cache or not. If enabled, modules will not be
built unless they are required elsewhere.
* `ENABLE_TESTS`: (Defaults to `DEFAULT`) Whether or not modules required by
the tests for the scanned modules should be enabled or not.
- `ON`: Modules listed as `TEST_DEPENDS` will be required.
- `OFF`: Test modules will not be considered.
- `WANT`: Test dependencies will enable modules if possible. Note that this
has known issues where modules required only via testing may not have
their dependencies enabled.
- `DEFAULT`: Test modules will be enabled if their required dependencies
are satisfied and skipped otherwise.
To make error messages clearer, modules passed to `REQUIRES_MODULES` and
`REJECT_MODULES` may have a `_vtk_module_reason_<MODULE>` variable set to the
reason for the module appearing in either argument. For example, if the
`Package::Frobnitz` module is required due to a `ENABLE_FROBNITZ` cache
variable:
~~~{.cmake}
set("_vtk_module_reason_Package::Frobnitz"
"via the `ENABLE_FROBNITZ` setting")
~~~
Additionally, the reason for the `WANT_BY_DEFAULT` value may be provided via
the `_vtk_module_reason_WANT_BY_DEFAULT` variable.
@section module-scanning-multiple Scanning multiple groups of modules
When scanning complicated projects, multiple scans may be required to get
defaults set properly. The `REQUIRES_MODULES`, `REQUEST_MODULES`, and
`UNRECOGNIZED_MODULES` arguments are meant to deal with this case. As an
example, imagine a project with its source code, third party dependencies, as
well as some utility modules which should only be built as necessary. Here, the
project would perform three scans, one for each "grouping" of modules:
~~~{.cmake}
# Scan our modules first because we need to know what of the other groups we
# need.
vtk_module_find_modules(our_modules "${CMAKE_CURRENT_SOURCE_DIR}/src")
vtk_module_scan(
MODULE_FILES ${our_modules}
PROVIDES_MODULES our_enabled_modules
REQUIRES_MODULES required_modules)
# Scan the third party modules, requesting only those that are necessary, but
# allowing them to be toggled during the build.
vtk_module_find_modules(third_party_modules "${CMAKE_CURRENT_SOURCE_DIR}/third-party")
vtk_module_scan(
MODULE_FILES ${third_party_modules}
PROVIDES_MODULES third_party_enabled_modules
# These modules were requested by an earlier scan.
REQUEST_MODULES ${required_modules}
REQUIRES_MODULES required_modules
UNRECOGNIZED_MODULES unrecognized_modules)
# These modules are internal and should only be built if necessary. There is no
# need to support them being enabled independently, so hide them from the
# cache.
vtk_module_find_modules(utility_modules "${CMAKE_CURRENT_SOURCE_DIR}/utilities")
vtk_module_scan(
MODULE_FILES ${utility_modules}
PROVIDES_MODULES utility_enabled_modules
# These modules were either requested or unrecognized by an earlier scan.
REQUEST_MODULES ${required_modules}
${unrecognized_modules}
REQUIRES_MODULES required_modules
UNRECOGNIZED_MODULES unrecognized_modules
HIDE_MODULES_FROM_CACHE ON)
if (required_modules OR unrecognized_modules)
# Not all of the modules we required were found. This should probably error out.
endif ()
~~~
#]==]
function (vtk_module_scan)
cmake_parse_arguments(PARSE_ARGV 0 _vtk_scan
""
"WANT_BY_DEFAULT;HIDE_MODULES_FROM_CACHE;PROVIDES_MODULES;REQUIRES_MODULES;UNRECOGNIZED_MODULES;ENABLE_TESTS;PROVIDES_KITS"
"MODULE_FILES;KIT_FILES;REQUEST_MODULES;REJECT_MODULES")
if (_vtk_scan_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_scan: "
"${_vtk_scan_UNPARSED_ARGUMENTS}")
endif ()
if (NOT DEFINED _vtk_scan_WANT_BY_DEFAULT)
set(_vtk_scan_WANT_BY_DEFAULT OFF)
endif ()
if (NOT DEFINED _vtk_scan_HIDE_MODULES_FROM_CACHE)
set(_vtk_scan_HIDE_MODULES_FROM_CACHE OFF)
endif ()
if (NOT DEFINED _vtk_scan_PROVIDES_MODULES)
message(FATAL_ERROR
"The `PROVIDES_MODULES` argument is required.")
endif ()
if (NOT DEFINED _vtk_scan_PROVIDES_KITS AND _vtk_scan_KIT_FILES)
message(FATAL_ERROR
"The `PROVIDES_KITS` argument is required.")
endif ()
if (NOT DEFINED _vtk_scan_ENABLE_TESTS)
set(_vtk_scan_ENABLE_TESTS "DEFAULT")
endif ()
if (NOT (_vtk_scan_ENABLE_TESTS STREQUAL "ON" OR
_vtk_scan_ENABLE_TESTS STREQUAL "OFF" OR
_vtk_scan_ENABLE_TESTS STREQUAL "WANT" OR
_vtk_scan_ENABLE_TESTS STREQUAL "DEFAULT"))
message(FATAL_ERROR
"The `ENABLE_TESTS` argument must be one of `ON`, `OFF`, `WANT`, or "
"`DEFAULT`. " "Received `${_vtk_scan_ENABLE_TESTS}`.")
endif ()
if (NOT _vtk_scan_MODULE_FILES)
message(FATAL_ERROR
"No module files given to scan.")
endif ()
set(_vtk_scan_option_default_type STRING)
if (_vtk_scan_HIDE_MODULES_FROM_CACHE)
set(_vtk_scan_option_default_type INTERNAL)
endif ()
set(_vtk_scan_all_kits)
foreach (_vtk_scan_kit_file IN LISTS _vtk_scan_KIT_FILES)
if (NOT IS_ABSOLUTE "${_vtk_scan_kit_file}")
string(PREPEND _vtk_scan_kit_file "${CMAKE_CURRENT_SOURCE_DIR}/")
endif ()
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND
PROPERTY
CMAKE_CONFIGURE_DEPENDS "${_vtk_scan_kit_file}")
file(READ "${_vtk_scan_kit_file}" _vtk_scan_kit_args)
# Replace comments.
string(REGEX REPLACE "#[^\n]*\n" "\n" _vtk_scan_kit_args "${_vtk_scan_kit_args}")
# Use argument splitting.
string(REGEX REPLACE "( |\n)+" ";" _vtk_scan_kit_args "${_vtk_scan_kit_args}")
_vtk_module_parse_kit_args(_vtk_scan_kit_name ${_vtk_scan_kit_args})
_vtk_module_debug(kit "@_vtk_scan_kit_name@ declared by @_vtk_scan_kit_file@")
list(APPEND _vtk_scan_all_kits
"${_vtk_scan_kit_name}")
# Set properties for building.
set_property(GLOBAL
PROPERTY
"_vtk_kit_${_vtk_scan_kit_name}_namespace" "${${_vtk_scan_kit_name}_NAMESPACE}")
set_property(GLOBAL
PROPERTY
"_vtk_kit_${_vtk_scan_kit_name}_target_name" "${${_vtk_scan_kit_name}_TARGET_NAME}")
set_property(GLOBAL
PROPERTY
"_vtk_kit_${_vtk_scan_kit_name}_library_name" "${${_vtk_scan_kit_name}_LIBRARY_NAME}")
endforeach ()
set(_vtk_scan_all_modules)
set(_vtk_scan_all_groups)
set(_vtk_scan_rejected_modules)
# Read all of the module files passed in.
foreach (_vtk_scan_module_file IN LISTS _vtk_scan_MODULE_FILES)
if (NOT IS_ABSOLUTE "${_vtk_scan_module_file}")
string(PREPEND _vtk_scan_module_file "${CMAKE_CURRENT_SOURCE_DIR}/")
endif ()
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND
PROPERTY
CMAKE_CONFIGURE_DEPENDS "${_vtk_scan_module_file}")
file(READ "${_vtk_scan_module_file}" _vtk_scan_module_args)
# Replace comments.
string(REGEX REPLACE "#[^\n]*\n" "\n" _vtk_scan_module_args "${_vtk_scan_module_args}")
# Use argument splitting.
string(REGEX REPLACE "( |\n)+" ";" _vtk_scan_module_args "${_vtk_scan_module_args}")
_vtk_module_parse_module_args(_vtk_scan_module_name ${_vtk_scan_module_args})
_vtk_module_debug(module "@_vtk_scan_module_name@ declared by @_vtk_scan_module_file@")
string(REPLACE "::" "_" _vtk_scan_module_name_safe "${_vtk_scan_module_name}")
if (${_vtk_scan_module_name}_THIRD_PARTY)
if (_vtk_module_warnings)
if (${_vtk_scan_module_name}_EXCLUDE_WRAP)
message(WARNING
"The third party ${_vtk_scan_module_name} module does not need to "
"declare `EXCLUDE_WRAP` also.")
endif ()
endif ()
if (${_vtk_scan_module_name}_IMPLEMENTABLE)
message(FATAL_ERROR
"The third party ${_vtk_scan_module_name} module may not be "
"`IMPLEMENTABLE`.")
endif ()
if (${_vtk_scan_module_name}_IMPLEMENTS)
message(FATAL_ERROR
"The third party ${_vtk_scan_module_name} module may not "
"`IMPLEMENTS` another module.")
endif ()
if (${_vtk_scan_module_name}_KIT)
message(FATAL_ERROR
"The third party ${_vtk_scan_module_name} module may not be part of "
"a kit (${${_vtk_scan_module_name}_KIT}).")
endif ()
endif ()
if (${_vtk_scan_module_name}_KIT)
if (NOT ${_vtk_scan_module_name}_KIT IN_LIST _vtk_scan_all_kits)
message(FATAL_ERROR
"The ${_vtk_scan_module_name} belongs to the "
"${${_vtk_scan_module_name}_KIT} kit, but it has not been scanned.")
endif ()
endif ()
# Check if the module is visible. Modules which have a failing condition
# are basically invisible.
if (DEFINED ${_vtk_scan_module_name}_CONDITION)
if (NOT (${${_vtk_scan_module_name}_CONDITION}))
if (DEFINED "VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}")
set_property(CACHE "VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}"
PROPERTY
TYPE INTERNAL)
endif ()
_vtk_module_debug(module "@_vtk_scan_module_name@ hidden by its `CONDITION`")
continue ()
endif ()
endif ()
# Determine whether we should provide a user-visible option for this
# module.
set(_vtk_build_use_option 1)
if (DEFINED _vtk_scan_REQUEST_MODULE)
if (_vtk_scan_module_name IN_LIST _vtk_scan_REQUEST_MODULE)
set("_vtk_scan_enable_${_vtk_scan_module_name}" YES)
set(_vtk_build_use_option 0)
endif ()
endif ()
if (DEFINED _vtk_scan_REJECT_MODULES)
if (_vtk_scan_module_name IN_LIST _vtk_scan_REJECT_MODULES)
if (NOT _vtk_build_use_option)
message(FATAL_ERROR
"The ${_vtk_scan_module_name} module has been requested and rejected.")
endif ()
# Rejected modules should not have a build option.
set(_vtk_build_use_option 0)
list(APPEND _vtk_scan_rejected_modules
"${_vtk_scan_module_name}")
endif ()
endif ()
# Handle cache entries and determine the enabled state of the module from
# the relevant cache variables.
if (_vtk_build_use_option)
set("VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}" "DEFAULT"
CACHE STRING "Enable the ${_vtk_scan_module_name} module. ${${_vtk_scan_module_name}_DESCRIPTION}")
mark_as_advanced("VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}")
set_property(CACHE "VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}"
PROPERTY
STRINGS "YES;WANT;DONT_WANT;NO;DEFAULT")
_vtk_module_verify_enable_value("VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}")
if (NOT VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe} STREQUAL "DEFAULT")
set("_vtk_scan_enable_${_vtk_scan_module_name}" "${VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}}")
set("_vtk_scan_enable_reason_${_vtk_scan_module_name}"
"via `VTK_MDDULE_ENABLE_${_vtk_scan_module_name_safe}`")
_vtk_module_debug(enable "@_vtk_scan_module_name@ is `${_vtk_scan_enable_${_vtk_scan_module_name}}` by cache value")
endif ()
# Check the state of any groups the module belongs to.
foreach (_vtk_scan_group IN LISTS "${_vtk_scan_module_name}_GROUPS")
if (NOT DEFINED "VTK_GROUP_ENABLE_${_vtk_scan_group}")
set(_vtk_scan_group_default "DEFAULT")
if (DEFINED "_vtk_module_group_default_${_vtk_scan_group}")
set(_vtk_scan_group_default "${_vtk_module_group_default_${_vtk_scan_group}}")
endif ()
set("VTK_GROUP_ENABLE_${_vtk_scan_group}" "${_vtk_scan_group_default}"
CACHE STRING "Enable the ${_vtk_scan_group} group modules.")
set_property(CACHE "VTK_GROUP_ENABLE_${_vtk_scan_group}"
PROPERTY
STRINGS "YES;WANT;DONT_WANT;NO;DEFAULT")
set_property(CACHE "VTK_GROUP_ENABLE_${_vtk_scan_group}"
PROPERTY
TYPE "${_vtk_scan_option_default_type}")
endif ()
_vtk_module_verify_enable_value("VTK_GROUP_ENABLE_${_vtk_scan_group}")
if (NOT VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe} STREQUAL "DEFAULT")
continue ()
endif ()
# Determine the state of the group.
set(_vtk_scan_group_enable "${VTK_GROUP_ENABLE_${_vtk_scan_group}}")
if (NOT _vtk_scan_group_enable STREQUAL "DEFAULT")
set("_vtk_scan_enable_${_vtk_scan_module_name}" "${_vtk_scan_group_enable}")
set("_vtk_scan_enable_reason_${_vtk_scan_module_name}"
"via `VTK_GROUP_ENABLE_${_vtk_scan_group}`")
_vtk_module_debug(enable "@_vtk_scan_module_name@ is DEFAULT, using group `@_vtk_scan_group@` setting: @_vtk_scan_group_enable@")
endif ()
endforeach ()
set_property(CACHE "VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe}"
PROPERTY
TYPE "${_vtk_scan_option_default_type}")
endif ()
if (NOT DEFINED "_vtk_scan_enable_${_vtk_scan_module_name}" AND
VTK_MODULE_ENABLE_${_vtk_scan_module_name_safe} STREQUAL "DEFAULT")
if (_vtk_scan_WANT_BY_DEFAULT)
set("_vtk_scan_enable_${_vtk_scan_module_name}" "WANT")
else ()
set("_vtk_scan_enable_${_vtk_scan_module_name}" "DONT_WANT")
endif ()
if (DEFINED _vtk_module_reason_WANT_BY_DEFAULT)
set("_vtk_scan_enable_reason_${_vtk_scan_module_name}"
"${_vtk_module_reason_WANT_BY_DEFAULT}")
else ()
set("_vtk_scan_enable_reason_${_vtk_scan_module_name}"
"via `WANT_BY_DEFAULT=${_vtk_scan_WANT_BY_DEFAULT}`")
endif ()
_vtk_module_debug(enable "@_vtk_scan_module_name@ is DEFAULT, using `WANT_BY_DEFAULT`: ${_vtk_scan_enable_reason_${_vtk_scan_module_name}}")
endif ()
list(APPEND _vtk_scan_all_modules
"${_vtk_scan_module_name}")
set("_vtk_scan_${_vtk_scan_module_name}_all_depends"
${${_vtk_scan_module_name}_DEPENDS}
${${_vtk_scan_module_name}_PRIVATE_DEPENDS})
if (${_vtk_scan_module_name}_THIRD_PARTY)
set("${_vtk_scan_module_name}_EXCLUDE_WRAP" TRUE)
set("${_vtk_scan_module_name}_IMPLEMENTABLE" FALSE)
set("${_vtk_scan_module_name}_IMPLEMENTS")
endif ()
if (${_vtk_scan_module_name}_KIT)
_vtk_module_debug(kit "@_vtk_scan_module_name@ belongs to the ${${_vtk_scan_module_name}_KIT} kit")
endif ()
# Set properties for building.
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_file" "${_vtk_scan_module_file}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_namespace" "${${_vtk_scan_module_name}_NAMESPACE}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_target_name" "${${_vtk_scan_module_name}_TARGET_NAME}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_library_name" "${${_vtk_scan_module_name}_LIBRARY_NAME}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_third_party" "${${_vtk_scan_module_name}_THIRD_PARTY}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_exclude_wrap" "${${_vtk_scan_module_name}_EXCLUDE_WRAP}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_kit" "${${_vtk_scan_module_name}_KIT}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_depends" "${${_vtk_scan_module_name}_DEPENDS}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_order_depends" "${${_vtk_scan_module_name}_ORDER_DEPENDS}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_private_depends" "${${_vtk_scan_module_name}_PRIVATE_DEPENDS}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_optional_depends" "${${_vtk_scan_module_name}_OPTIONAL_DEPENDS}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_test_depends" "${${_vtk_scan_module_name}_TEST_DEPENDS}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_test_optional_depends" "${${_vtk_scan_module_name}_TEST_OPTIONAL_DEPENDS}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_test_labels" "${${_vtk_scan_module_name}_TEST_LABELS}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_implements" "${${_vtk_scan_module_name}_IMPLEMENTS}")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_implementable" "${${_vtk_scan_module_name}_IMPLEMENTABLE}")
# create absolute path for license files
set(_license_files)
foreach (_license_file IN LISTS ${_vtk_scan_module_name}_LICENSE_FILES)
if (NOT IS_ABSOLUTE "${_license_file}")
get_filename_component(_vtk_scan_module_dir "${_vtk_scan_module_file}" DIRECTORY)
string(PREPEND _license_file "${_vtk_scan_module_dir}/")
endif ()
list(APPEND _license_files "${_license_file}")
endforeach ()
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_license_files" "${_license_files}")
if (_vtk_scan_ENABLE_TESTS STREQUAL "WANT")
set_property(GLOBAL
PROPERTY
"_vtk_module_${_vtk_scan_module_name}_enable_tests_by_want" "1")
endif ()
endforeach ()
set(_vtk_scan_current_modules "${_vtk_scan_all_modules}")
vtk_topological_sort(_vtk_scan_all_modules "_vtk_scan_" "_all_depends")
set(_vtk_scan_provided_modules)
set(_vtk_scan_required_modules)
set(_vtk_scan_disabled_modules)
# Seed the `_vtk_scan_provide_` variables with modules requested and rejected
# as arguments.
foreach (_vtk_scan_request_module IN LISTS _vtk_scan_REQUEST_MODULES)
set("_vtk_scan_provide_${_vtk_scan_request_module}" ON)
if (DEFINED "_vtk_module_reason_${_vtk_scan_request_module}")
set("_vtk_scan_provide_reason_${_vtk_scan_request_module}"
"${_vtk_module_reason_${_vtk_scan_request_module}}")
else ()
set("_vtk_scan_provide_reason_${_vtk_scan_request_module}"
"via `REQUEST_MODULES`")
endif ()
_vtk_module_debug(provide "@_vtk_scan_request_module@ is provided ${_vtk_scan_provide_reason_${_vtk_scan_request_module}}")
endforeach ()
foreach (_vtk_scan_reject_module IN LISTS _vtk_scan_REJECT_MODULES)
set("_vtk_scan_provide_${_vtk_scan_reject_module}" OFF)
if (DEFINED "_vtk_module_reason_${_vtk_scan_reject_module}")
set("_vtk_scan_provide_reason_${_vtk_scan_reject_module}"
"${_vtk_module_reason_${_vtk_scan_reject_module}}")
else ()
set("_vtk_scan_provide_reason_${_vtk_scan_reject_module}"
"via `REJECT_MODULES`")
endif ()
_vtk_module_debug(provide "@_vtk_scan_reject_module@ is not provided ${_vtk_scan_provide_reason_${_vtk_scan_reject_module}}")
endforeach ()
# Traverse the graph classifying the quad-state for enabling modules into a
# boolean stored in the `_vtk_scan_provide_` variables.
foreach (_vtk_scan_module IN LISTS _vtk_scan_all_modules)
if (NOT _vtk_scan_module IN_LIST _vtk_scan_current_modules)
_vtk_module_debug(provide "@_vtk_scan_module@ is ignored because it is not in the current scan set")
continue ()
endif ()
if (DEFINED "_vtk_scan_provide_${_vtk_scan_module}")
# Already done.
elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "YES")
# Mark enabled modules as to-be-provided. Any errors with requiring a
# disabled module will be dealt with later.
set("_vtk_scan_provide_${_vtk_scan_module}" ON)
set("_vtk_scan_provide_reason_${_vtk_scan_module}"
"via a `YES` setting (${_vtk_scan_enable_reason_${_vtk_scan_module}})")
_vtk_module_debug(provide "@_vtk_scan_module@ is provided due to `YES` setting")
elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "WANT")
# Check to see if we can provide this module by checking of any of its
# dependencies have been disabled.
set(_vtk_scan_test_depends)
if (NOT ${_vtk_scan_module}_THIRD_PARTY AND _vtk_scan_ENABLE_TESTS STREQUAL "ON")
# If the tests have to be on, we also need the test dependencies.
set(_vtk_scan_test_depends "${${_vtk_scan_module}_TEST_DEPENDS}")
endif ()
set("_vtk_scan_provide_${_vtk_scan_module}" ON)
set("_vtk_scan_provide_reason_${_vtk_scan_module}"
"via a `WANT` setting (${_vtk_scan_enable_reason_${_vtk_scan_module}})")
_vtk_module_debug(provide "@_vtk_scan_module@ is provided due to `WANT` setting")
foreach (_vtk_scan_module_depend IN LISTS "${_vtk_scan_module}_DEPENDS" "${_vtk_scan_module}_PRIVATE_DEPENDS" _vtk_scan_test_depends)
if (DEFINED "_vtk_scan_provide_${_vtk_scan_module_depend}" AND NOT _vtk_scan_provide_${_vtk_scan_module_depend})
set("_vtk_scan_provide_${_vtk_scan_module}" OFF)
set("_vtk_scan_provide_reason_${_vtk_scan_module}"
"due to the ${_vtk_scan_module_depend} module not being available")
if (DEFINED "_vtk_scan_provide_reason_${_vtk_scan_module_depend}")
string(APPEND "_vtk_scan_provide_reason_${_vtk_scan_module}"
" (${_vtk_scan_provide_reason_${_vtk_scan_module_depend}})")
endif ()
_vtk_module_debug(provide "@_vtk_scan_module@ is not provided due to not provided dependency @_vtk_scan_module_depend@")
break ()
endif ()
endforeach ()
elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "DONT_WANT")
# Check for disabled dependencies and disable if so.
foreach (_vtk_scan_module_depend IN LISTS "${_vtk_scan_module}_DEPENDS" "${_vtk_scan_module}_PRIVATE_DEPENDS" _vtk_scan_test_depends)
if (DEFINED "_vtk_scan_provide_${_vtk_scan_module_depend}" AND NOT _vtk_scan_provide_${_vtk_scan_module_depend})
set("_vtk_scan_provide_${_vtk_scan_module}" OFF)
set("_vtk_scan_provide_reason_${_vtk_scan_module}"
"due to the ${_vtk_scan_module_depend} module not being available")
if (DEFINED "_vtk_scan_provide_reason_${_vtk_scan_module_depend}")
string(APPEND "_vtk_scan_provide_reason_${_vtk_scan_module}"
" (${_vtk_scan_provide_reason_${_vtk_scan_module_depend}})")
endif ()
_vtk_module_debug(provide "@_vtk_scan_module@ is not provided due to not provided dependency @_vtk_scan_module_depend@")
break ()
endif ()
endforeach ()
elseif (_vtk_scan_enable_${_vtk_scan_module} STREQUAL "NO")
# Disable the module.
set("_vtk_scan_provide_${_vtk_scan_module}" OFF)
set("_vtk_scan_provide_reason_${_vtk_scan_module}"
"via a `NO` setting (${_vtk_scan_enable_reason_${_vtk_scan_module}})")
_vtk_module_debug(provide "@_vtk_scan_module@ is not provided due to `NO` setting")
endif ()
# Collect disabled modules into a list.
if (DEFINED "_vtk_scan_provide_${_vtk_scan_module}" AND NOT _vtk_scan_provide_${_vtk_scan_module})
list(APPEND _vtk_scan_disabled_modules
"${_vtk_scan_module}")
endif ()
if (NOT DEFINED "_vtk_scan_provide_${_vtk_scan_module}")
_vtk_module_debug(provide "@_vtk_scan_module@ is indeterminate (${_vtk_scan_enable_${_vtk_scan_module}})")
endif ()
endforeach ()
# Scan all modules from the top of tree to the bottom.
list(REVERSE _vtk_scan_all_modules)
foreach (_vtk_scan_module IN LISTS _vtk_scan_all_modules)
if (NOT _vtk_scan_module IN_LIST _vtk_scan_current_modules)
continue ()
endif ()
# If we're providing this module...
if (_vtk_scan_provide_${_vtk_scan_module})
list(APPEND _vtk_scan_provided_modules
"${_vtk_scan_module}")
# Grab any test dependencies that are required.
set(_vtk_scan_test_depends)
set(_vtk_scan_test_wants)
if (NOT ${_vtk_scan_module}_THIRD_PARTY)
if (_vtk_scan_ENABLE_TESTS STREQUAL "ON")
set_property(GLOBAL APPEND
PROPERTY
"_vtk_module_test_modules" "${_vtk_scan_module}")
set(_vtk_scan_test_depends "${${_vtk_scan_module}_TEST_DEPENDS}")
elseif (_vtk_scan_ENABLE_TESTS STREQUAL "WANT")
set_property(GLOBAL APPEND
PROPERTY
"_vtk_module_test_modules" "${_vtk_scan_module}")
set(_vtk_scan_test_wants _vtk_scan_wants_marker ${${_vtk_scan_module}_TEST_DEPENDS})
elseif (_vtk_scan_ENABLE_TESTS STREQUAL "DEFAULT")
set_property(GLOBAL APPEND
PROPERTY
"_vtk_module_test_modules" "${_vtk_scan_module}")
elseif (_vtk_scan_ENABLE_TESTS STREQUAL "OFF")
# Nothing to do.
else ()
message(FATAL_ERROR
"Unrecognized option for ENABLE_TESTS: ${_vtk_module_ENABLE_TESTS}.")
endif ()
endif ()
# Add all dependent modules to the list of required or provided modules.
set(_vtk_scan_is_wanting 0)
foreach (_vtk_scan_module_depend IN LISTS "${_vtk_scan_module}_DEPENDS" "${_vtk_scan_module}_PRIVATE_DEPENDS" _vtk_scan_test_depends _vtk_scan_test_wants)
if (_vtk_scan_module_depend STREQUAL "_vtk_scan_wants_marker")
set(_vtk_scan_is_wanting 1)
continue ()
endif ()
# Though we need to error if this would cause a disabled module to be
# provided.
if (_vtk_scan_module_depend IN_LIST _vtk_scan_disabled_modules)
if (_vtk_scan_is_wanting)
continue ()
else ()
message(FATAL_ERROR
"The ${_vtk_scan_module} module (enabled "
"${_vtk_scan_provide_reason_${_vtk_scan_module}}) requires the "
"disabled module ${_vtk_scan_module_depend} (disabled "
"${_vtk_scan_provide_reason_${_vtk_scan_module_depend}}).")
endif ()
endif ()
if (DEFINED "_vtk_scan_provide_${_vtk_scan_module_depend}")
if (NOT _vtk_scan_provide_${_vtk_scan_module_depend})
message(FATAL_ERROR
"The ${_vtk_scan_module_depend} module (disabled "
"${_vtk_scan_provide_reason_${_vtk_scan_module_depend}}) should "
"be provided because it is required by ${_vtk_scan_module} "
"(${_vtk_scan_provide_reason_${_vtk_scan_module}})")
endif ()
continue ()
endif ()
set("_vtk_scan_provide_reason_${_vtk_scan_module_depend}"
"via dependency from ${_vtk_scan_module}")
if (DEFINED "_vtk_scan_provide_reason_${_vtk_scan_module}")
string(APPEND "_vtk_scan_provide_reason_${_vtk_scan_module_depend}"
" (${_vtk_scan_provide_reason_${_vtk_scan_module}})")
endif ()
set("_vtk_scan_provide_${_vtk_scan_module_depend}" ON)
if (NOT _vtk_scan_module_depend IN_LIST _vtk_scan_current_modules)
if (NOT TARGET "${_vtk_scan_module_depend}")
_vtk_module_debug(provide "@_vtk_scan_module_depend@ is external and required due to dependency from @_vtk_scan_module@")
endif ()
list(APPEND _vtk_scan_required_modules
"${_vtk_scan_module_depend}")
else ()
_vtk_module_debug(provide "@_vtk_scan_module_depend@ is provided due to dependency from @_vtk_scan_module@")
list(APPEND _vtk_scan_provided_modules
"${_vtk_scan_module_depend}")
endif ()
endforeach ()
endif ()
endforeach ()
if (_vtk_scan_provided_modules)
list(REMOVE_DUPLICATES _vtk_scan_provided_modules)
endif ()
set(_vtk_scan_provided_kits)
# Build a list of kits which contain the provided modules.
foreach (_vtk_scan_provided_module IN LISTS _vtk_scan_provided_modules)
if (${_vtk_scan_provided_module}_KIT)
list(APPEND _vtk_scan_provided_kits
"${${_vtk_scan_provided_module}_KIT}")
set_property(GLOBAL APPEND
PROPERTY
"_vtk_kit_${${_vtk_scan_provided_module}_KIT}_kit_modules" "${_vtk_scan_provided_module}")
endif ()
endforeach ()
if (_vtk_scan_provided_kits)
list(REMOVE_DUPLICATES _vtk_scan_provided_kits)
endif ()
if (_vtk_scan_required_modules)
list(REMOVE_DUPLICATES _vtk_scan_required_modules)
endif ()
set(_vtk_scan_unrecognized_modules
${_vtk_scan_REQUEST_MODULES}
${_vtk_scan_REJECT_MODULES})
if (_vtk_scan_unrecognized_modules AND (_vtk_scan_provided_modules OR _vtk_scan_rejected_modules))
list(REMOVE_ITEM _vtk_scan_unrecognized_modules
${_vtk_scan_provided_modules}
${_vtk_scan_rejected_modules})
endif ()
set("${_vtk_scan_PROVIDES_MODULES}"
${_vtk_scan_provided_modules}
PARENT_SCOPE)
if (DEFINED _vtk_scan_REQUIRES_MODULES)
set("${_vtk_scan_REQUIRES_MODULES}"
${_vtk_scan_required_modules}
PARENT_SCOPE)
endif ()
if (DEFINED _vtk_scan_UNRECOGNIZED_MODULES)
set("${_vtk_scan_UNRECOGNIZED_MODULES}"
${_vtk_scan_unrecognized_modules}
PARENT_SCOPE)
endif ()
if (DEFINED _vtk_scan_PROVIDES_KITS)
set("${_vtk_scan_PROVIDES_KITS}"
${_vtk_scan_provided_kits}
PARENT_SCOPE)
endif ()
endfunction ()
#[==[
@page module-overview
@section module-target-functions Module-as-target functions
Due to the nature of VTK modules supporting being built as kits, the module
name might not be usable as a target to CMake's `target_` family of commands.
Instead, there are various wrappers around them which take the module name as
an argument. These handle the forwarding of relevant information to the kit
library as well where necessary.
- @ref vtk_module_set_properties
- @ref vtk_module_set_property
- @ref vtk_module_get_property
- @ref vtk_module_depend
- @ref vtk_module_include
- @ref vtk_module_definitions
- @ref vtk_module_compile_options
- @ref vtk_module_compile_features
- @ref vtk_module_link
- @ref vtk_module_link_options
#]==]
#[==[
@page module-internal-api
@section module-target-internals Module target internals
When manipulating modules as targets, there are a few functions provided for
use in wrapping code to more easily access them.
- @ref _vtk_module_real_target
- @ref _vtk_module_real_target_kit
#]==]
#[==[
@ingroup module-internal
@brief The real target for a module
~~~
_vtk_module_real_target(<var> <module>)
~~~
Sometimes the actual, core target for a module is required (e.g., setting
CMake-level target properties or install rules). This function returns the real
target for a module.
#]==]
function (_vtk_module_real_target var module)
if (ARGN)
message(FATAL_ERROR
"Unparsed arguments for _vtk_module_real_target: ${ARGN}.")
endif ()
set(_vtk_real_target_res "")
if (TARGET "${module}")
get_property(_vtk_real_target_imported
TARGET "${module}"
PROPERTY IMPORTED)
if (_vtk_real_target_imported)
set(_vtk_real_target_res "${module}")
endif ()
endif ()
if (NOT _vtk_real_target_res)
get_property(_vtk_real_target_res GLOBAL
PROPERTY "_vtk_module_${module}_target_name")
# Querying during the build.
if (DEFINED _vtk_build_BUILD_WITH_KITS AND _vtk_build_BUILD_WITH_KITS)
get_property(_vtk_real_target_kit GLOBAL
PROPERTY "_vtk_module_${module}_kit")
if (_vtk_real_target_kit)
string(APPEND _vtk_real_target_res "-objects")
endif ()
# A query for after the module is built.
elseif (TARGET "${_vtk_real_target_res}-objects")
string(APPEND _vtk_real_target_res "-objects")
endif ()
endif ()
if (NOT _vtk_real_target_res)
set(_vtk_real_target_msg "")
if (NOT TARGET "${module}")
if (DEFINED _vtk_build_module)
set(_vtk_real_target_msg
" Is a module dependency missing?")
elseif (TARGET "${module}")
set(_vtk_real_target_msg
" It's a target, but is it a VTK module?")
else ()
set(_vtk_real_target_msg
" The module name is not a CMake target. Is there a typo? Is it missing a `Package::` prefix? Is a `find_package` missing a required component?")
endif ()
endif ()
message(FATAL_ERROR
"Failed to determine the real target for the `${module}` "
"module.${_vtk_real_target_msg}")
endif ()
set("${var}"
"${_vtk_real_target_res}"
PARENT_SCOPE)
endfunction ()
#[==[
@ingroup module-internal
@brief The real target for a kit
~~~
_vtk_module_real_target_kit(<var> <kit>)
~~~
Sometimes the actual, core target for a module is required (e.g., setting
CMake-level target properties or install rules). This function returns the real
target for a kit.
#]==]
function (_vtk_module_real_target_kit var kit)
if (ARGN)
message(FATAL_ERROR
"Unparsed arguments for _vtk_module_real_target_kit: ${ARGN}.")
endif ()
set(_vtk_real_target_res "")
if (TARGET "${kit}")
get_property(_vtk_real_target_imported
TARGET "${kit}"
PROPERTY IMPORTED)
if (_vtk_real_target_imported)
set(_vtk_real_target_res "${kit}")
endif ()
endif ()
if (NOT _vtk_real_target_res)
get_property(_vtk_real_target_res GLOBAL
PROPERTY "_vtk_kit_${kit}_target_name")
endif ()
if (NOT _vtk_real_target_res)
message(FATAL_ERROR
"Failed to determine the real target for the `${kit}` kit.")
endif ()
set("${var}"
"${_vtk_real_target_res}"
PARENT_SCOPE)
endfunction ()
#[==[
@ingroup module
@brief Set multiple properties on a module
A wrapper around `set_target_properties` that works for modules.
~~~
vtk_module_set_properties(<module>
[<property> <value>]...)
~~~
#]==]
function (vtk_module_set_properties module)
_vtk_module_real_target(_vtk_set_properties_target "${module}")
set_target_properties("${_vtk_set_properties_target}"
PROPERTIES
${ARGN})
endfunction ()
#[==[
@ingroup module
@brief Set a property on a module
A wrapper around `set_property(TARGET)` that works for modules.
~~~
vtk_module_set_property(<module>
[APPEND] [APPEND_STRING]
PROPERTY <property>
VALUE <value>...)
~~~
#]==]
function (vtk_module_set_property module)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_property
"APPEND;APPEND_STRING"
"PROPERTY"
"VALUE")
if (_vtk_property_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_set_property: "
"${_vtk_property_UNPARSED_ARGUMENTS}.")
endif ()
if (NOT DEFINED _vtk_property_PROPERTY)
message(FATAL_ERROR
"The `PROPERTY` argument is required.")
endif ()
if (NOT DEFINED _vtk_property_VALUE)
message(FATAL_ERROR
"The `VALUE` argument is required.")
endif ()
if (_vtk_property_APPEND AND _vtk_property_APPEND_STRING)
message(FATAL_ERROR
"`APPEND` and `APPEND_STRING` may not be used at the same time.")
endif ()
set(_vtk_property_args)
if (_vtk_property_APPEND)
list(APPEND _vtk_property_args
APPEND)
endif ()
if (_vtk_property_APPEND_STRING)
list(APPEND _vtk_property_args
APPEND_STRING)
endif ()
_vtk_module_real_target(_vtk_property_target "${module}")
set_property(TARGET "${_vtk_property_target}"
${_vtk_property_args}
PROPERTY
"${_vtk_property_PROPERTY}" "${_vtk_property_VALUE}")
endfunction ()
#[==[
@ingroup module
@brief Get a property from a module
A wrapper around `get_property(TARGET)` that works for modules.
~~~
vtk_module_get_property(<module>
PROPERTY <property>
VARIABLE <variable>)
~~~
The variable name passed to the `VARIABLE` argument will be unset if the
property is not set (rather than the empty string).
#]==]
function (vtk_module_get_property module)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_property
""
"PROPERTY;VARIABLE"
"")
if (_vtk_property_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_get_property: "
"${_vtk_property_UNPARSED_ARGUMENTS}.")
endif ()
if (NOT DEFINED _vtk_property_PROPERTY)
message(FATAL_ERROR
"The `PROPERTY` argument is required.")
endif ()
if (NOT DEFINED _vtk_property_VARIABLE)
message(FATAL_ERROR
"The `VARIABLE` argument is required.")
endif ()
_vtk_module_real_target(_vtk_property_target "${module}")
get_property(_vtk_property_is_set
TARGET "${_vtk_property_target}"
PROPERTY "${_vtk_property_PROPERTY}"
SET)
if (_vtk_property_is_set)
get_property(_vtk_property_value
TARGET "${_vtk_property_target}"
PROPERTY "${_vtk_property_PROPERTY}")
set("${_vtk_property_VARIABLE}"
"${_vtk_property_value}"
PARENT_SCOPE)
else ()
unset("${_vtk_property_VARIABLE}"
PARENT_SCOPE)
endif ()
endfunction ()
#[==[
@ingroup module-impl
@brief Generate arguments for target function wrappers
Create the `INTERFACE`, `PUBLIC`, and `PRIVATE` arguments for a function
wrapping CMake's `target_` functions to call the wrapped function.
This is necessary because not all of the functions support empty lists given a
keyword.
#]==]
function (_vtk_module_target_function prefix)
foreach (visibility IN ITEMS INTERFACE PUBLIC PRIVATE)
if (${prefix}_${visibility})
set("${prefix}_${visibility}_args"
"${visibility}"
${${prefix}_${visibility}}
PARENT_SCOPE)
endif ()
endforeach ()
endfunction ()
#[==[
@ingroup module
@brief Add dependencies to a module
A wrapper around `add_dependencies` that works for modules.
~~~
vtk_module_depend(<module> <depend>...)
~~~
#]==]
function (vtk_module_depend module)
_vtk_module_real_target(_vtk_depend_target "${module}")
add_dependencies("${_vtk_depend_target}"
${ARGN})
endfunction ()
#[==[
@ingroup module
@brief Add source files to a module
A wrapper around `target_sources` that works for modules.
~~~
vtk_module_sources(<module>
[PUBLIC <source>...]
[PRIVATE <source>...]
[INTERFACE <source>...])
~~~
#]==]
function (vtk_module_sources module)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_sources
""
""
"INTERFACE;PUBLIC;PRIVATE")
if (_vtk_sources_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_sources: "
"${_vtk_sources_UNPARSED_ARGUMENTS}.")
endif ()
_vtk_module_real_target(_vtk_sources_target "${module}")
_vtk_module_target_function(_vtk_sources)
if (NOT _vtk_sources_INTERFACE_args AND
NOT _vtk_sources_PUBLIC_args AND
NOT _vtk_sources_PRIVATE_args)
return ()
endif ()
target_sources("${_vtk_sources_target}"
${_vtk_sources_INTERFACE_args}
${_vtk_sources_PUBLIC_args}
${_vtk_sources_PRIVATE_args})
endfunction ()
#[==[
@ingroup module
@brief Add include directories to a module
A wrapper around `target_include_directories` that works for modules.
~~~
vtk_module_include(<module>
[SYSTEM]
[PUBLIC <directory>...]
[PRIVATE <directory>...]
[INTERFACE <directory>...])
~~~
#]==]
function (vtk_module_include module)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_include
"SYSTEM"
""
"INTERFACE;PUBLIC;PRIVATE")
if (_vtk_include_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_include: "
"${_vtk_include_UNPARSED_ARGUMENTS}.")
endif ()
_vtk_module_real_target(_vtk_include_target "${module}")
_vtk_module_target_function(_vtk_include)
set(_vtk_include_system_arg)
if (_vtk_include_SYSTEM)
set(_vtk_include_system_arg SYSTEM)
endif ()
if (NOT _vtk_include_INTERFACE_args AND
NOT _vtk_include_PUBLIC_args AND
NOT _vtk_include_PRIVATE_args)
return ()
endif ()
target_include_directories("${_vtk_include_target}"
${_vtk_include_system_arg}
${_vtk_include_INTERFACE_args}
${_vtk_include_PUBLIC_args}
${_vtk_include_PRIVATE_args})
endfunction ()
#[==[
@ingroup module
@brief Add compile definitions to a module
A wrapper around `target_compile_definitions` that works for modules.
~~~
vtk_module_definitions(<module>
[PUBLIC <define>...]
[PRIVATE <define>...]
[INTERFACE <define>...])
~~~
#]==]
function (vtk_module_definitions module)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_definitions
""
""
"INTERFACE;PUBLIC;PRIVATE")
if (_vtk_definitions_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_definitions: "
"${_vtk_definitions_UNPARSED_ARGUMENTS}.")
endif ()
_vtk_module_real_target(_vtk_definitions_target "${module}")
_vtk_module_target_function(_vtk_definitions)
if (NOT _vtk_definitions_INTERFACE_args AND
NOT _vtk_definitions_PUBLIC_args AND
NOT _vtk_definitions_PRIVATE_args)
return ()
endif ()
target_compile_definitions("${_vtk_definitions_target}"
${_vtk_definitions_INTERFACE_args}
${_vtk_definitions_PUBLIC_args}
${_vtk_definitions_PRIVATE_args})
endfunction ()
#[==[
@ingroup module
@brief Add compile options to a module
A wrapper around `target_compile_options` that works for modules.
~~~
vtk_module_compile_options(<module>
[PUBLIC <option>...]
[PRIVATE <option>...]
[INTERFACE <option>...])
~~~
#]==]
function (vtk_module_compile_options module)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_compile_options
""
""
"INTERFACE;PUBLIC;PRIVATE")
if (_vtk_compile_options_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_compile_options: "
"${_vtk_compile_options_UNPARSED_ARGUMENTS}.")
endif ()
_vtk_module_real_target(_vtk_compile_options_target "${module}")
_vtk_module_target_function(_vtk_compile_options)
if (NOT _vtk_compile_options_INTERFACE_args AND
NOT _vtk_compile_options_PUBLIC_args AND
NOT _vtk_compile_options_PRIVATE_args)
return ()
endif ()
target_compile_options("${_vtk_compile_options_target}"
${_vtk_compile_options_INTERFACE_args}
${_vtk_compile_options_PUBLIC_args}
${_vtk_compile_options_PRIVATE_args})
endfunction ()
#[==[
@ingroup module
@brief Add compile features to a module
A wrapper around `target_compile_features` that works for modules.
~~~
vtk_module_compile_features(<module>
[PUBLIC <feature>...]
[PRIVATE <feature>...]
[INTERFACE <feature>...])
~~~
#]==]
function (vtk_module_compile_features module)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_compile_features
""
""
"INTERFACE;PUBLIC;PRIVATE")
if (_vtk_compile_features_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_compile_features: "
"${_vtk_compile_features_UNPARSED_ARGUMENTS}.")
endif ()
_vtk_module_real_target(_vtk_compile_features_target "${module}")
_vtk_module_target_function(_vtk_compile_features)
if (NOT _vtk_compile_features_INTERFACE_args AND
NOT _vtk_compile_features_PUBLIC_args AND
NOT _vtk_compile_features_PRIVATE_args)
return ()
endif ()
target_compile_features("${_vtk_compile_features_target}"
${_vtk_compile_features_INTERFACE_args}
${_vtk_compile_features_PUBLIC_args}
${_vtk_compile_features_PRIVATE_args})
endfunction ()
#[==[
@ingroup module-impl
@brief Manage the private link target for a module
This function manages the private link target for a module.
~~~
_vtk_private_kit_link_target(<module>
[CREATE_IF_NEEDED]
[SETUP_TARGET_NAME <var>]
[USAGE_TARGET_NAME <var>])
~~~
#]==]
function (_vtk_private_kit_link_target module)
cmake_parse_arguments(_vtk_private_kit_link_target
"CREATE_IF_NEEDED"
"SETUP_TARGET_NAME;USAGE_TARGET_NAME"
""
${ARGN})
if (_vtk_private_kit_link_target_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for _vtk_private_kit_link_target: "
"${_vtk_private_kit_link_target_UNPARSED_ARGUMENTS}.")
endif ()
# Compute the target name.
get_property(_vtk_private_kit_link_base_target_name GLOBAL
PROPERTY "_vtk_module_${module}_target_name")
if (NOT _vtk_private_kit_link_base_target_name)
message(FATAL_ERROR
"_vtk_private_kit_link_target only works for modules built in the "
"current project.")
endif ()
set(_vtk_private_kit_link_target_setup_name
"${_vtk_private_kit_link_base_target_name}-private-kit-links")
get_property(_vtk_private_kit_link_namespace GLOBAL
PROPERTY "_vtk_module_${module}_namespace")
if (_vtk_private_kit_link_namespace)
set(_vtk_private_kit_link_target_usage_name
"${_vtk_private_kit_link_namespace}::${_vtk_private_kit_link_target_setup_name}")
else ()
set(_vtk_private_kit_link_target_usage_name
":${_vtk_private_kit_link_target_setup_name}")
endif ()
# Create the target if requested.
if (_vtk_private_kit_link_target_CREATE_IF_NEEDED AND
NOT TARGET "${_vtk_private_kit_link_target_setup_name}")
add_library("${_vtk_private_kit_link_target_setup_name}" INTERFACE)
if (NOT _vtk_private_kit_link_target_setup_name STREQUAL _vtk_private_kit_link_target_usage_name)
add_library("${_vtk_private_kit_link_target_usage_name}" ALIAS
"${_vtk_private_kit_link_target_setup_name}")
endif ()
_vtk_module_install("${_vtk_private_kit_link_target_setup_name}")
endif ()
if (_vtk_private_kit_link_target_SETUP_TARGET_NAME)
set("${_vtk_private_kit_link_target_SETUP_TARGET_NAME}"
"${_vtk_private_kit_link_target_setup_name}"
PARENT_SCOPE)
endif ()
if (_vtk_private_kit_link_target_USAGE_TARGET_NAME)
set("${_vtk_private_kit_link_target_USAGE_TARGET_NAME}"
"${_vtk_private_kit_link_target_usage_name}"
PARENT_SCOPE)
endif ()
endfunction ()
#[==[
@ingroup module
@brief Add link libraries to a module
A wrapper around `target_link_libraries` that works for modules. Note that this
function does extra work in kit builds, so circumventing it may break in kit
builds.
~~~
vtk_module_link(<module>
[PUBLIC <link item>...]
[PRIVATE <link item>...]
[INTERFACE <link item>...])
~~~
#]==]
function (vtk_module_link module)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_link
""
""
"INTERFACE;PUBLIC;PRIVATE")
if (_vtk_link_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_link: "
"${_vtk_link_UNPARSED_ARGUMENTS}.")
endif ()
_vtk_module_real_target(_vtk_link_target "${module}")
_vtk_module_target_function(_vtk_link)
get_property(_vtk_link_kit GLOBAL
PROPERTY "_vtk_module_${module}_kit")
if (_vtk_link_kit)
if (_vtk_link_PRIVATE)
_vtk_private_kit_link_target("${module}"
CREATE_IF_NEEDED
SETUP_TARGET_NAME _vtk_link_private_kit_link_target)
foreach (_vtk_link_private IN LISTS _vtk_link_PRIVATE)
target_link_libraries("${_vtk_link_private_kit_link_target}"
INTERFACE
"$<LINK_ONLY:${_vtk_link_private}>")
endforeach ()
endif ()
endif ()
if (NOT _vtk_link_INTERFACE_args AND
NOT _vtk_link_PUBLIC_args AND
NOT _vtk_link_PRIVATE_args)
return ()
endif ()
target_link_libraries("${_vtk_link_target}"
${_vtk_link_INTERFACE_args}
${_vtk_link_PUBLIC_args}
${_vtk_link_PRIVATE_args})
endfunction ()
#[==[
@ingroup module
@brief Add link options to a module
A wrapper around `target_link_options` that works for modules.
~~~
vtk_module_link_options(<module>
[PUBLIC <option>...]
[PRIVATE <option>...]
[INTERFACE <option>...])
~~~
#]==]
function (vtk_module_link_options module)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_link_options
""
""
"INTERFACE;PUBLIC;PRIVATE")
if (_vtk_link_options_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_link_options: "
"${_vtk_link_options_UNPARSED_ARGUMENTS}.")
endif ()
_vtk_module_real_target(_vtk_link_options_target "${module}")
_vtk_module_target_function(_vtk_link_options)
if (NOT _vtk_link_options_INTERFACE_args AND
NOT _vtk_link_options_PUBLIC_args AND
NOT _vtk_link_options_PRIVATE_args)
return ()
endif ()
target_link_options("${_vtk_link_options_target}"
${_vtk_link_options_INTERFACE_args}
${_vtk_link_options_PUBLIC_args}
${_vtk_link_options_PRIVATE_args})
endfunction ()
#[==[
@page module-internal-api
@ingroup module-internal
@section module-properties Module properties
The VTK module system leverages CMake's target propagation and storage. As
such, there are a number of properties added to the targets representing
modules. These properties are intended for use by the module system and
associated functionality. In particular, more properties may be available by
language wrappers.
@subsection module-properties-naming Naming properties
When creating properties for use with the module system, they should be
prefixed with `INTERFACE_vtk_module_`. The `INTERFACE_` portion is required in
order to work with interface libraries. The `vtk_module_` portion is to avoid
colliding with any other properties. This function assumes this naming scheme
for some of its convenience features as well.
Properties should be the same in the local build as well as when imported to
ease use.
@subsection module-properties-system VTK module system properties
There are a number of properties that are used and expected by the core of the
module system. These are generally module metadata (module dependencies,
whether to wrap or not, etc.). The properties all have the
`INTERFACE_vtk_module_` prefix mentioned in the previous section.
* `third_party`: If set, the module represents a third party
dependency and should be treated specially. Third party modules are very
restricted and generally do not have any other properties set on them.
* `exclude_wrap`: If set, the module should not be wrapped by an external
language.
* `depends`: The list of dependent modules. Language wrappers will generally
require this to satisfy references to parent classes of the classes in the
module.
* `private_depends`: The list of privately dependent modules. Language
wrappers may require this to satisfy references to parent classes of the
classes in the module.
* `optional_depends`: The list of optionally dependent modules. Language
wrappers may require this to satisfy references to parent classes of the
classes in the module.
* `kit`: The kit the module is a member of. Only set if the module is
actually a member of the kit (i.e., the module was built with
`BUILD_WITH_KITS ON`).
* `implements`: The list of modules for which this module registers to. This
is used by the autoinit subsystem and generally is not required.
* `implementable`: If set, this module provides registries which may be
populated by dependent modules. It is used to check the `implements`
property to help minimize unnecessary work from the autoinit subsystem.
* `needs_autoinit`: If set, linking to this module requires the autoinit
subsystem to ensure that registries in modules are fully populated.
* `headers`: Paths to the public headers from the module. These are the
headers which should be handled by language wrappers.
* `hierarchy`: The path to the hierarchy file describing inheritance of the
classes for use in language wrappers.
* `forward_link`: Usage requirements that must be forwarded even though the
module is linked to privately.
Kits have the following properties available (but only if kits are enabled):
* `kit_modules`: Modules which are compiled into the kit.
#]==]
#[==[
@ingroup module-internal
@brief Set a module property
This function sets a [module property](@ref module-properties) on a module. The
required prefix will automatically be added to the passed name.
~~~
_vtk_module_set_module_property(<module>
[APPEND] [APPEND_STRING]
PROPERTY <property>
VALUE <value>...)
~~~
#]==]
function (_vtk_module_set_module_property module)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_property
"APPEND;APPEND_STRING"
"PROPERTY"
"VALUE")
if (_vtk_property_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_set_module_property: "
"${_vtk_property_UNPARSED_ARGUMENTS}.")
endif ()
if (NOT DEFINED _vtk_property_PROPERTY)
message(FATAL_ERROR
"The `PROPERTY` argument is required.")
endif ()
if (NOT DEFINED _vtk_property_VALUE)
message(FATAL_ERROR
"The `VALUE` argument is required.")
endif ()
if (_vtk_property_APPEND AND _vtk_property_APPEND_STRING)
message(FATAL_ERROR
"`APPEND` and `APPEND_STRING` may not be used at the same time.")
endif ()
set(_vtk_property_args)
if (_vtk_property_APPEND)
list(APPEND _vtk_property_args
APPEND)
endif ()
if (_vtk_property_APPEND_STRING)
list(APPEND _vtk_property_args
APPEND_STRING)
endif ()
get_property(_vtk_property_is_alias
TARGET "${module}"
PROPERTY ALIASED_TARGET
SET)
if (_vtk_property_is_alias)
_vtk_module_real_target(_vtk_property_target "${module}")
else ()
set(_vtk_property_target "${module}")
endif ()
set_property(TARGET "${_vtk_property_target}"
${_vtk_property_args}
PROPERTY
"INTERFACE_vtk_module_${_vtk_property_PROPERTY}" "${_vtk_property_VALUE}")
endfunction ()
#[==[
@ingroup module-internal
@brief Get a module property
Get a [module property](@ref module-properties) from a module.
~~~
_vtk_module_get_module_property(<module>
PROPERTY <property>
VARIABLE <variable>)
~~~
As with @ref vtk_module_get_property, the output variable will be unset if the
property is not set. The property name is automatically prepended with the
required prefix.
#]==]
function (_vtk_module_get_module_property module)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_property
""
"PROPERTY;VARIABLE"
"")
if (_vtk_property_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_get_module_property: "
"${_vtk_property_UNPARSED_ARGUMENTS}.")
endif ()
if (NOT DEFINED _vtk_property_PROPERTY)
message(FATAL_ERROR
"The `PROPERTY` argument is required.")
endif ()
if (NOT DEFINED _vtk_property_VARIABLE)
message(FATAL_ERROR
"The `VARIABLE` argument is required.")
endif ()
get_property(_vtk_property_is_alias
TARGET "${module}"
PROPERTY ALIASED_TARGET
SET)
if (_vtk_property_is_alias)
_vtk_module_real_target(_vtk_property_target "${module}")
else ()
set(_vtk_property_target "${module}")
endif ()
get_property(_vtk_property_is_set
TARGET "${_vtk_property_target}"
PROPERTY "INTERFACE_vtk_module_${_vtk_property_PROPERTY}"
SET)
if (_vtk_property_is_set)
get_property(_vtk_property_value
TARGET "${_vtk_property_target}"
PROPERTY "INTERFACE_vtk_module_${_vtk_property_PROPERTY}")
set("${_vtk_property_VARIABLE}"
"${_vtk_property_value}"
PARENT_SCOPE)
else ()
unset("${_vtk_property_VARIABLE}"
PARENT_SCOPE)
endif ()
endfunction ()
#[==[
@ingroup module-internal
@brief Check that destinations are valid
All installation destinations are expected to be relative so that
`CMAKE_INSTALL_PREFIX` can be relied upon in all code paths. This function may
be used to verify that destinations are relative.
~~~
_vtk_module_check_destinations(<prefix> [<suffix>...])
~~~
For each `suffix`, `prefix` is prefixed to it and the resulting variable name
is checked for validity as an install prefix. Raises an error if any is
invalid.
#]==]
function (_vtk_module_check_destinations prefix)
foreach (suffix IN LISTS ARGN)
if (IS_ABSOLUTE "${${prefix}${suffix}}")
message(FATAL_ERROR
"The `${suffix}` must not be an absolute path. Use "
"`CMAKE_INSTALL_PREFIX` to keep everything in a single installation "
"prefix.")
endif ()
endforeach ()
endfunction ()
#[==[
@ingroup module-internal
@brief Write an import prefix statement
CMake files, once installed, may need to construct paths to other locations
within the install prefix. This function writes a prefix computation for file
given its install destination.
~~~
_vtk_module_write_import_prefix(<file> <destination>)
~~~
The passed file is cleared so that it occurs at the top of the file. The prefix
is available in the file as the `_vtk_module_import_prefix` variable. It is
recommended to unset the variable at the end of the file.
#]==]
function (_vtk_module_write_import_prefix file destination)
if (IS_ABSOLUTE "${destination}")
message(FATAL_ERROR
"An import prefix cannot be determined from an absolute installation "
"destination. Use `CMAKE_INSTALL_PREFIX` to keep everything in a single "
"installation prefix.")
endif ()
file(WRITE "${file}"
"set(_vtk_module_import_prefix \"\${CMAKE_CURRENT_LIST_DIR}\")\n")
while (destination)
get_filename_component(destination "${destination}" DIRECTORY)
file(APPEND "${file}"
"get_filename_component(_vtk_module_import_prefix \"\${_vtk_module_import_prefix}\" DIRECTORY)\n")
endwhile ()
endfunction ()
#[==[
@ingroup module-internal
@brief Export properties on modules and targets
This function is intended for use in support functions which leverage the
module system, not by general system users. This function supports exporting
properties from the build into dependencies via target properties which are
loaded from a project's config file which is loaded via CMake's `find_package`
function.
~~~
_vtk_module_export_properties(
[MODULE <module>]
[KIT <kit>]
BUILD_FILE <path>
INSTALL_FILE <path>
[PROPERTIES <property>...]
[FROM_GLOBAL_PROPERTIES <property fragment>...]
[SPLIT_INSTALL_PROPERTIES <property fragment>...])
~~~
The `BUILD_FILE` and `INSTALL_FILE` arguments are required. Exactly one of
`MODULE` and `KIT` is also required. The `MODULE` or `KIT` argument holds the
name of the module or kit that will have properties exported. The `BUILD_FILE`
and `INSTALL_FILE` paths are *appended to*. As such, when setting up these
files, it should be preceded with:
~~~{.cmake}
file(WRITE "${build_file}")
file(WRITE "${install_file}")
~~~
To avoid accidental usage of the install file from the build tree, it is
recommended to store it under a `CMakeFiles/` directory in the build tree with
an additional `.install` suffix and use `install(RENAME)` to rename it at
install time.
The set of properties exported is computed as follows:
* `PROPERTIES` queries the module target for the given property and exports
its value as-is to both the build and install files. In addition, these
properties are set on the target directly as the same name.
* `FROM_GLOBAL_PROPERTIES` queries the global
`_vtk_module_<MODULE>_<fragment>` property and exports it to both the build
and install files as `INTERFACE_vtk_module_<fragment>`.
* `SPLIT_INSTALL_PROPERTIES` queries the target for
`INTERFACE_vtk_module_<fragment>` and exports its value to the build file
and `INTERFACE_vtk_module_<fragment>_install` to the install file as the
non-install property name. This is generally useful for properties which
change between the build and installation.
#]==]
function (_vtk_module_export_properties)
cmake_parse_arguments(PARSE_ARGV 0 _vtk_export_properties
""
"BUILD_FILE;INSTALL_FILE;MODULE;KIT"
"FROM_GLOBAL_PROPERTIES;PROPERTIES;SPLIT_INSTALL_PROPERTIES")
if (_vtk_export_properties_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for _vtk_export_properties: "
"${_vtk_export_properties_UNPARSED_ARGUMENTS}.")
endif ()
if (DEFINED _vtk_export_properties_MODULE)
if (DEFINED _vtk_export_properties_KIT)
message(FATAL_ERROR
"Only one of `MODULE` or `KIT` is required to export properties.")
endif ()
set(_vtk_export_properties_type "module")
set(_vtk_export_properties_name "${_vtk_export_properties_MODULE}")
elseif (_vtk_export_properties_KIT)
set(_vtk_export_properties_type "kit")
set(_vtk_export_properties_name "${_vtk_export_properties_KIT}")
else ()
message(FATAL_ERROR
"A module or kit is required to export properties.")
endif ()
if (NOT _vtk_export_properties_BUILD_FILE)
message(FATAL_ERROR
"Exporting properties requires a build file to write to.")
endif ()
if (NOT _vtk_export_properties_INSTALL_FILE)
message(FATAL_ERROR
"Exporting properties requires an install file to write to.")
endif ()
if (_vtk_export_properties_type STREQUAL "module")
_vtk_module_real_target(_vtk_export_properties_target_name "${_vtk_export_properties_name}")
elseif (_vtk_export_properties_type STREQUAL "kit")
_vtk_module_real_target_kit(_vtk_export_properties_target_name "${_vtk_export_properties_name}")
endif ()
foreach (_vtk_export_properties_global IN LISTS _vtk_export_properties_FROM_GLOBAL_PROPERTIES)
get_property(_vtk_export_properties_is_set GLOBAL
PROPERTY "_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_name}_${_vtk_export_properties_global}"
SET)
if (NOT _vtk_export_properties_is_set)
continue ()
endif ()
get_property(_vtk_export_properties_value GLOBAL
PROPERTY "_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_name}_${_vtk_export_properties_global}")
set(_vtk_export_properties_set_property
"set_property(TARGET \"${_vtk_export_properties_name}\" PROPERTY \"INTERFACE_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_global}\" \"${_vtk_export_properties_value}\")\n")
set_property(TARGET "${_vtk_export_properties_target_name}"
PROPERTY
"INTERFACE_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_global}" "${_vtk_export_properties_value}")
file(APPEND "${_vtk_export_properties_BUILD_FILE}"
"${_vtk_export_properties_set_property}")
file(APPEND "${_vtk_export_properties_INSTALL_FILE}"
"${_vtk_export_properties_set_property}")
endforeach ()
foreach (_vtk_export_properties_target IN LISTS _vtk_export_properties_PROPERTIES)
get_property(_vtk_export_properties_is_set
TARGET "${_vtk_export_properties_target_name}"
PROPERTY "${_vtk_export_properties_target}"
SET)
if (NOT _vtk_export_properties_is_set)
continue ()
endif ()
get_property(_vtk_export_properties_value
TARGET "${_vtk_export_properties_target_name}"
PROPERTY "${_vtk_export_properties_target}")
set(_vtk_export_properties_set_property
"set_property(TARGET \"${_vtk_export_properties_name}\" PROPERTY \"${_vtk_export_properties_target}\" \"${_vtk_export_properties_value}\")\n")
file(APPEND "${_vtk_export_properties_BUILD_FILE}"
"${_vtk_export_properties_set_property}")
file(APPEND "${_vtk_export_properties_INSTALL_FILE}"
"${_vtk_export_properties_set_property}")
endforeach ()
foreach (_vtk_export_properties_split IN LISTS _vtk_export_properties_SPLIT_INSTALL_PROPERTIES)
get_property(_vtk_export_properties_is_set
TARGET "${_vtk_export_properties_target_name}"
PROPERTY "INTERFACE_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_split}"
SET)
if (NOT _vtk_export_properties_is_set)
continue ()
endif ()
get_property(_vtk_export_properties_value
TARGET "${_vtk_export_properties_target_name}"
PROPERTY "INTERFACE_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_split}")
set(_vtk_export_properties_set_property
"set_property(TARGET \"${_vtk_export_properties_name}\" PROPERTY \"INTERFACE_vtk_module_${_vtk_export_properties_split}\" \"${_vtk_export_properties_value}\")\n")
file(APPEND "${_vtk_export_properties_BUILD_FILE}"
"${_vtk_export_properties_set_property}")
get_property(_vtk_export_properties_value
TARGET "${_vtk_export_properties_target_name}"
PROPERTY "INTERFACE_vtk_${_vtk_export_properties_type}_${_vtk_export_properties_split}_install")
set(_vtk_export_properties_set_property
"set_property(TARGET \"${_vtk_export_properties_name}\" PROPERTY \"INTERFACE_vtk_module_${_vtk_export_properties_split}\" \"${_vtk_export_properties_value}\")\n")
file(APPEND "${_vtk_export_properties_INSTALL_FILE}"
"${_vtk_export_properties_set_property}")
endforeach ()
endfunction ()
include("${CMAKE_CURRENT_LIST_DIR}/vtkModuleTesting.cmake")
#[==[
@ingroup module
@brief Build modules and kits
Once all of the modules have been scanned, they need to be built. Generally,
there will be just one build necessary for a set of scans, though they may be
built distinctly as well. If there are multiple calls to this function, they
should generally in reverse order of their scans.
~~~
vtk_module_build(
MODULES <module>...
[KITS <kit>...]
[LIBRARY_NAME_SUFFIX <suffix>]
[VERSION <version>]
[SOVERSION <soversion>]
[PACKAGE <package>]
[BUILD_WITH_KITS <ON|OFF>]
[ENABLE_WRAPPING <ON|OFF>]
[USE_EXTERNAL <ON|OFF>]
[INSTALL_HEADERS <ON|OFF>]
[HEADERS_COMPONENT <component>]
[TARGETS_COMPONENT <component>]
[INSTALL_EXPORT <export>]
[TARGET_SPECIFIC_COMPONENTS <ON|OFF>]
[LICENSE_COMPONENT <component>]
[UTILITY_TARGET <target>]
[TEST_DIRECTORY_NAME <name>]
[TEST_DATA_TARGET <target>]
[TEST_INPUT_DATA_DIRECTORY <directory>]
[TEST_OUTPUT_DATA_DIRECTORY <directory>]
[TEST_OUTPUT_DIRECTORY <directory>]
[ARCHIVE_DESTINATION <destination>]
[HEADERS_DESTINATION <destination>]
[LIBRARY_DESTINATION <destination>]
[RUNTIME_DESTINATION <destination>]
[CMAKE_DESTINATION <destination>]
[LICENSE_DESTINATION <destination>]
[HIERARCHY_DESTINATION <destination>])
~~~
The only requirement of the function is the list of modules to build, the rest
have reasonable defaults if not specified.
* `MODULES`: (Required) The list of modules to build.
* `KITS`: (Required if `BUILD_WITH_KITS` is `ON`) The list of kits to build.
* `LIBRARY_NAME_SUFFIX`: (Defaults to `""`) A suffix to add to library names.
If it is not empty, it is prefixed with `-` to separate it from the kit
name.
* `VERSION`: If specified, the `VERSION` property on built libraries will be
set to this value.
* `SOVERSION`: If specified, the `SOVERSION` property on built libraries will
be set to this value.
* `PACKAGE`: (Defaults to `${CMAKE_PROJECT_NAME}`) The name the build is
meant to be found as when using `find_package`. Note that separate builds
will require distinct `PACKAGE` values.
* `BUILD_WITH_KITS`: (Defaults to `OFF`) If enabled, kit libraries will be
built.
* `ENABLE_WRAPPING`: (Default depends on the existence of
`VTK::WrapHierarchy` or `VTKCompileTools::WrapHierarchy` targets) If
enabled, wrapping will be available to the modules built in this call.
* `USE_EXTERNAL`: (Defaults to `OFF`) Whether third party modules should find
external copies rather than building their own copy.
* `INSTALL_HEADERS`: (Defaults to `ON`) Whether or not to install public headers.
* `HEADERS_COMPONENT`: (Defaults to `development`) The install component to
use for header installation. Note that other SDK-related bits use the same
component (e.g., CMake module files).
* `TARGETS_COMPONENT`: `Defaults to `runtime`) The install component to use
for the libraries built.
* `TARGET_SPECIFIC_COMPONENTS`: (Defaults to `OFF`) If `ON`, place artifacts
into target-specific install components (`<TARGET>-<COMPONENT>`).
* `LICENSE_COMPONENT`: (Defaults to `licenses`) The install component to use
for licenses.
* `UTILITY_TARGET`: If specified, all libraries and executables made by the
VTK Module API will privately link to this target. This may be used to
provide things such as project-wide compilation flags or similar.
* `TARGET_NAMESPACE`: `Defaults to `\<AUTO\>`) The namespace for installed
targets. All targets must have the same namespace. If set to `\<AUTO\>`,
the namespace will be detected automatically.
* `INSTALL_EXPORT`: (Defaults to `""`) If non-empty, targets will be added to
the given export. The export will also be installed as part of this build
command.
* `TEST_DIRECTORY_NAME`: (Defaults to `Testing`) The name of the testing
directory to look for in each module. Set to `NONE` to disable automatic
test management.
* `TEST_DATA_TARGET`: (Defaults to `<PACKAGE>-data`) The target to add
testing data download commands to.
* `TEST_INPUT_DATA_DIRECTORY`: (Defaults to
`${CMAKE_CURRENT_SOURCE_DIR}/Data`) The directory which will contain data
for use by tests.
* `TEST_OUTPUT_DATA_DIRECTORY`: (Defaults to
`${CMAKE_CURRENT_BINARY_DIR}/Data`) The directory which will contain data
for use by tests.
* `TEST_OUTPUT_DIRECTORY`: (Defaults to
`${CMAKE_BINARY_DIR}/<TEST_DIRECTORY_NAME>/Temporary`) The directory which
tests may write any output files to.
The remaining arguments control where to install files related to the build.
See CMake documentation for the difference between `ARCHIVE`, `LIBRARY`, and
`RUNTIME`.
* `ARCHIVE_DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) The install
destination for archive files.
* `HEADERS_DESTINATION`: (Defaults to `${CMAKE_INSTALL_INCLUDEDIR}`) The
install destination for header files.
* `LIBRARY_DESTINATION`: (Defaults to `${CMAKE_INSTALL_LIBDIR}`) The install
destination for library files.
* `RUNTIME_DESTINATION`: (Defaults to `${CMAKE_INSTALL_BINDIR}`) The install
destination for runtime files.
* `CMAKE_DESTINATION`: (Defaults to `<LIBRARY_DESTINATION>/cmake/<PACKAGE>`)
The install destination for CMake files.
* `LICENSE_DESTINATION`: (Defaults to `${CMAKE_INSTALL_DATAROOTDIR}/licenses/${CMAKE_PROJECT_NAME}`)
The install destination for license files.
* `HIERARCHY_DESTINATION`: (Defaults to
`<LIBRARY_DESTINATION>/vtk/hierarchy/<PACKAGE>`) The install destination
for hierarchy files (used for language wrapping).
#]==]
function (vtk_module_build)
set(_vtk_build_install_arguments
# Headers
INSTALL_HEADERS
HEADERS_COMPONENT
# Targets
INSTALL_EXPORT
TARGETS_COMPONENT
LICENSE_COMPONENT
TARGET_NAMESPACE
UTILITY_TARGET
# Destinations
ARCHIVE_DESTINATION
HEADERS_DESTINATION
LIBRARY_DESTINATION
RUNTIME_DESTINATION
CMAKE_DESTINATION
LICENSE_DESTINATION
HIERARCHY_DESTINATION)
set(_vtk_build_test_arguments
# Testing
TEST_DIRECTORY_NAME
TEST_DATA_TARGET
TEST_INPUT_DATA_DIRECTORY
TEST_OUTPUT_DATA_DIRECTORY
TEST_OUTPUT_DIRECTORY)
# TODO: Add an option to build statically? Currently, `BUILD_SHARED_LIBS` is
# used.
cmake_parse_arguments(PARSE_ARGV 0 _vtk_build
""
"BUILD_WITH_KITS;USE_EXTERNAL;TARGET_SPECIFIC_COMPONENTS;LIBRARY_NAME_SUFFIX;VERSION;SOVERSION;PACKAGE;ENABLE_WRAPPING;${_vtk_build_install_arguments};${_vtk_build_test_arguments}"
"MODULES;KITS")
if (_vtk_build_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_build: "
"${_vtk_build_UNPARSED_ARGUMENTS}")
endif ()
if (NOT DEFINED _vtk_build_USE_EXTERNAL)
set(_vtk_build_USE_EXTERNAL OFF)
endif ()
if (NOT DEFINED _vtk_build_TARGET_SPECIFIC_COMPONENTS)
set(_vtk_build_TARGET_SPECIFIC_COMPONENTS OFF)
endif ()
if (NOT DEFINED _vtk_build_PACKAGE)
set(_vtk_build_PACKAGE "${CMAKE_PROJECT_NAME}")
endif ()
get_property(_vtk_build_package_exists GLOBAL
PROPERTY "_vtk_module_package_${_vtk_build_PACKAGE}"
SET)
if (_vtk_build_package_exists)
message(FATAL_ERROR
"A set of modules have already been built using the "
"`${_vtk_build_PACKAGE}` package.")
else ()
set_property(GLOBAL
PROPERTY
"_vtk_module_package_${_vtk_build_PACKAGE}" "ON")
endif ()
if (NOT DEFINED _vtk_build_INSTALL_HEADERS)
set(_vtk_build_INSTALL_HEADERS ON)
endif ()
if (NOT DEFINED _vtk_build_ENABLE_WRAPPING)
if (TARGET "VTKCompileTools::WrapHierarchy" OR
TARGET "VTK::WrapHierarchy")
set(_vtk_build_ENABLE_WRAPPING ON)
else ()
set(_vtk_build_ENABLE_WRAPPING OFF)
endif ()
endif ()
if (NOT DEFINED _vtk_build_TARGET_NAMESPACE)
set(_vtk_build_TARGET_NAMESPACE "<AUTO>")
endif ()
if (NOT DEFINED _vtk_build_BUILD_WITH_KITS)
set(_vtk_build_BUILD_WITH_KITS OFF)
endif ()
if (_vtk_build_BUILD_WITH_KITS AND NOT BUILD_SHARED_LIBS)
message(AUTHOR_WARNING
"Static builds with kits are not well-tested and doesn't make much "
"sense. It is recommended to only build with kits in shared builds.")
endif ()
if (_vtk_build_BUILD_WITH_KITS AND NOT DEFINED _vtk_build_KITS)
message(FATAL_ERROR
"Building with kits was requested, but no kits were specified.")
endif ()
if (NOT DEFINED _vtk_build_TEST_DIRECTORY_NAME)
set(_vtk_build_TEST_DIRECTORY_NAME "Testing")
endif ()
if (NOT DEFINED _vtk_build_TEST_DATA_TARGET)
set(_vtk_build_TEST_DATA_TARGET "${_vtk_build_PACKAGE}-data")
endif ()
if (NOT DEFINED _vtk_build_TEST_INPUT_DATA_DIRECTORY)
set(_vtk_build_TEST_INPUT_DATA_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Data")
endif ()
if (NOT DEFINED _vtk_build_TEST_OUTPUT_DATA_DIRECTORY)
set(_vtk_build_TEST_OUTPUT_DATA_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Data")
endif ()
if (NOT DEFINED _vtk_build_TEST_OUTPUT_DIRECTORY)
set(_vtk_build_TEST_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_build_TEST_DIRECTORY_NAME}/Temporary")
endif ()
if (NOT DEFINED _vtk_build_HEADERS_COMPONENT)
set(_vtk_build_HEADERS_COMPONENT "development")
endif ()
if (NOT DEFINED _vtk_build_LICENSE_COMPONENT)
set(_vtk_build_LICENSE_COMPONENT "licenses")
endif ()
if (NOT DEFINED _vtk_build_ARCHIVE_DESTINATION)
set(_vtk_build_ARCHIVE_DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif ()
if (NOT DEFINED _vtk_build_HEADERS_DESTINATION)
set(_vtk_build_HEADERS_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
endif ()
if (NOT DEFINED _vtk_build_LIBRARY_DESTINATION)
set(_vtk_build_LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif ()
if (NOT DEFINED _vtk_build_RUNTIME_DESTINATION)
set(_vtk_build_RUNTIME_DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif ()
if (NOT DEFINED _vtk_build_CMAKE_DESTINATION)
set(_vtk_build_CMAKE_DESTINATION "${_vtk_build_LIBRARY_DESTINATION}/cmake/${_vtk_build_PACKAGE}")
endif ()
if (NOT DEFINED _vtk_build_LICENSE_DESTINATION)
set(_vtk_build_LICENSE_DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${CMAKE_PROJECT_NAME}")
endif ()
if (NOT DEFINED _vtk_build_HIERARCHY_DESTINATION)
set(_vtk_build_HIERARCHY_DESTINATION "${_vtk_build_LIBRARY_DESTINATION}/vtk/hierarchy/${_vtk_build_PACKAGE}")
endif ()
if (NOT DEFINED _vtk_build_TARGETS_COMPONENT)
set(_vtk_build_TARGETS_COMPONENT "runtime")
endif ()
if (NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_build_ARCHIVE_DESTINATION}")
endif ()
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_build_LIBRARY_DESTINATION}")
endif ()
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_build_RUNTIME_DESTINATION}")
endif ()
if (NOT _vtk_build_MODULES)
message(FATAL_ERROR
"No modules given to build.")
endif ()
_vtk_module_check_destinations(_vtk_build_
ARCHIVE_DESTINATION
HEADERS_DESTINATION
RUNTIME_DESTINATION
CMAKE_DESTINATION
LICENSE_DESTINATION
HIERARCHY_DESTINATION)
foreach (_vtk_build_module IN LISTS _vtk_build_MODULES)
get_property("_vtk_build_${_vtk_build_module}_depends" GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_depends")
get_property("_vtk_build_${_vtk_build_module}_private_depends" GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_private_depends")
get_property("_vtk_build_${_vtk_build_module}_optional_depends" GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_optional_depends")
get_property("_vtk_build_${_vtk_build_module}_order_depends" GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_order_depends")
set("_vtk_build_${_vtk_build_module}_all_depends"
${_vtk_build_${_vtk_build_module}_depends}
${_vtk_build_${_vtk_build_module}_private_depends}
${_vtk_build_${_vtk_build_module}_optional_depends}
${_vtk_build_${_vtk_build_module}_order_depends})
endforeach ()
set(_vtk_build_sorted_modules "${_vtk_build_MODULES}")
vtk_topological_sort(_vtk_build_sorted_modules "_vtk_build_" "_all_depends")
foreach (_vtk_build_module IN LISTS _vtk_build_sorted_modules)
if (NOT _vtk_build_module IN_LIST _vtk_build_MODULES)
continue ()
endif ()
if (TARGET "${_vtk_build_module}")
get_property(_vtk_build_is_imported
TARGET "${_vtk_build_module}"
PROPERTY IMPORTED)
# TODO: Is this right?
if (NOT _vtk_build_is_imported)
message(FATAL_ERROR
"The ${_vtk_build_module} module has been requested to be built, but "
"it is already built by this project.")
endif ()
continue ()
endif ()
foreach (_vtk_build_depend IN LISTS "_vtk_build_${_vtk_build_module}_depends" "_vtk_build_${_vtk_build_module}_private_depends")
if (NOT TARGET "${_vtk_build_depend}")
get_property(_vtk_build_enable_tests_by_want GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_enable_tests_by_want")
set(_vtk_build_explain "")
if (_vtk_build_enable_tests_by_want)
string(APPEND _vtk_build_explain
" The `vtk_module_scan` for this module used `ENABLE_TESTS WANT`. "
"This is a known issue, but the fix is not trivial. You may "
"either change the flag used to control testing for this scan or "
"explicitly enable the ${_vtk_build_depend} module.")
endif ()
message(FATAL_ERROR
"The ${_vtk_build_depend} dependency is missing for "
"${_vtk_build_module}.${_vtk_build_explain}")
endif ()
endforeach ()
get_property(_vtk_build_module_file GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_file")
if (NOT _vtk_build_module_file)
message(FATAL_ERROR
"The requested ${_vtk_build_module} module is not a VTK module.")
endif ()
_vtk_module_debug(building "@_vtk_build_module@ is being built")
get_filename_component(_vtk_build_module_dir "${_vtk_build_module_file}" DIRECTORY)
if (COMMAND cmake_path) # XXX(cmake-3.20)
cmake_path(NORMAL_PATH _vtk_build_module_dir)
else ()
get_filename_component(_vtk_build_module_dir "${_vtk_build_module_dir}" ABSOLUTE)
endif ()
file(RELATIVE_PATH _vtk_build_module_subdir "${CMAKE_SOURCE_DIR}" "${_vtk_build_module_dir}")
set(_vtk_build_module_subdir_build "${_vtk_build_module_subdir}")
# Check if the source for this module is outside of `CMAKE_SOURCE_DIR`.
# Place it under `CMAKE_BINARY_DIR` more meaningfully if so.
if (_vtk_build_module_subdir MATCHES "\\.\\./")
file(RELATIVE_PATH _vtk_build_module_subdir_build "${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
get_property(_vtk_build_module_library_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
string(APPEND _vtk_build_module_subdir_build "/${_vtk_build_module_library_name}")
endif ()
add_subdirectory(
"${CMAKE_SOURCE_DIR}/${_vtk_build_module_subdir}"
"${CMAKE_BINARY_DIR}/${_vtk_build_module_subdir_build}")
if (NOT TARGET "${_vtk_build_module}")
message(FATAL_ERROR
"The ${_vtk_build_module} is being built, but a matching target was "
"not created.")
endif ()
endforeach ()
if (_vtk_build_BUILD_WITH_KITS)
foreach (_vtk_build_kit IN LISTS _vtk_build_KITS)
get_property(_vtk_build_target_name GLOBAL
PROPERTY "_vtk_kit_${_vtk_build_kit}_target_name")
set(_vtk_kit_source_file
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/vtk_module_kit_${_vtk_build_target_name}.c")
file(GENERATE
OUTPUT "${_vtk_kit_source_file}"
CONTENT "void vtk_module_kit_${_vtk_build_target_name}(void);\nvoid vtk_module_kit_${_vtk_build_target_name}(void) {}\n")
add_library("${_vtk_build_target_name}"
"${_vtk_kit_source_file}")
get_property(_vtk_build_namespace GLOBAL
PROPERTY "_vtk_kit_${_vtk_build_kit}_namespace")
if (_vtk_build_TARGET_NAMESPACE STREQUAL "<AUTO>")
set(_vtk_build_TARGET_NAMESPACE "${_vtk_build_namespace}")
endif ()
if (NOT _vtk_build_namespace STREQUAL _vtk_build_TARGET_NAMESPACE)
message(FATAL_ERROR
"The `TARGET_NAMESPACE` (${_vtk_build_TARGET_NAMESPACE}) is not the "
"same as the ${_vtk_build_kit} kit namespace "
"(${_vtk_build_namespace}).")
endif ()
if (NOT _vtk_build_kit STREQUAL _vtk_build_target_name)
add_library("${_vtk_build_kit}" ALIAS
"${_vtk_build_target_name}")
endif ()
_vtk_module_apply_properties("${_vtk_build_target_name}")
_vtk_module_install("${_vtk_build_target_name}")
set(_vtk_build_kit_modules_object_libraries)
set(_vtk_build_kit_modules_private_depends)
get_property(_vtk_build_kit_modules GLOBAL
PROPERTY "_vtk_kit_${_vtk_build_kit}_kit_modules")
foreach (_vtk_build_kit_module IN LISTS _vtk_build_kit_modules)
get_property(_vtk_build_kit_module_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_kit_module}_target_name")
list(APPEND _vtk_build_kit_modules_object_libraries
"${_vtk_build_kit_module_target_name}-objects")
_vtk_private_kit_link_target("${_vtk_build_kit_module}"
USAGE_TARGET_NAME _vtk_build_kit_module_usage_name)
if (TARGET "${_vtk_build_kit_module_usage_name}")
list(APPEND _vtk_build_kit_modules_private_depends
"${_vtk_build_kit_module_usage_name}")
endif ()
# Since there is no link step for modules, we need to copy the private
# dependencies of the constituent modules into the kit so that their
# private dependencies are actually linked.
get_property(_vtk_build_kit_module_private_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_kit_module}_private_depends")
# Also grab optional dependencies since they end up being private
# links.
get_property(_vtk_build_kit_module_optional_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_kit_module}_optional_depends")
foreach (_vtk_build_kit_module_private_depend IN LISTS _vtk_build_kit_module_private_depends _vtk_build_kit_module_optional_depends)
if (NOT TARGET "${_vtk_build_kit_module_private_depend}")
continue ()
endif ()
# But we don't need to link to modules that are part of the kit we are
# building.
if (NOT _vtk_build_kit_module_private_depend IN_LIST _vtk_build_kit_modules)
list(APPEND _vtk_build_kit_modules_private_depends
"$<LINK_ONLY:${_vtk_build_kit_module_private_depend}>")
endif ()
endforeach ()
endforeach ()
if (_vtk_build_kit_modules_private_depends)
list(REMOVE_DUPLICATES _vtk_build_kit_modules_private_depends)
endif ()
if (_vtk_build_kit_modules_private_links)
list(REMOVE_DUPLICATES _vtk_build_kit_modules_private_links)
endif ()
target_link_libraries("${_vtk_build_target_name}"
PRIVATE
${_vtk_build_kit_modules_object_libraries}
${_vtk_build_kit_modules_private_depends})
if (_vtk_build_UTILITY_TARGET)
target_link_libraries("${_vtk_build_target_name}"
PRIVATE
"${_vtk_build_UTILITY_TARGET}")
endif ()
get_property(_vtk_build_kit_library_name GLOBAL
PROPERTY "_vtk_kit_${_vtk_build_kit}_library_name")
if (_vtk_build_LIBRARY_NAME_SUFFIX)
string(APPEND _vtk_build_kit_library_name "-${_vtk_build_LIBRARY_NAME_SUFFIX}")
endif ()
set_target_properties("${_vtk_build_target_name}"
PROPERTIES
OUTPUT_NAME "${_vtk_build_kit_library_name}")
endforeach ()
endif ()
set(_vtk_build_properties_filename "${_vtk_build_PACKAGE}-vtk-module-properties.cmake")
set(_vtk_build_properties_install_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_build_properties_filename}.install")
set(_vtk_build_properties_build_file "${CMAKE_BINARY_DIR}/${_vtk_build_CMAKE_DESTINATION}/${_vtk_build_properties_filename}")
file(WRITE "${_vtk_build_properties_build_file}")
_vtk_module_write_import_prefix(
"${_vtk_build_properties_install_file}"
"${_vtk_build_CMAKE_DESTINATION}")
foreach (_vtk_build_module IN LISTS _vtk_build_MODULES)
get_property(_vtk_build_namespace GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_namespace")
if (_vtk_build_TARGET_NAMESPACE STREQUAL "<AUTO>")
set(_vtk_build_TARGET_NAMESPACE "${_vtk_build_namespace}")
endif ()
if (NOT _vtk_build_namespace STREQUAL _vtk_build_TARGET_NAMESPACE)
message(FATAL_ERROR
"The `TARGET_NAMESPACE` (${_vtk_build_TARGET_NAMESPACE}) is not the "
"same as the ${_vtk_build_module} module namespace "
"(${_vtk_build_namespace}).")
endif ()
get_property(_vtk_build_is_third_party
TARGET "${_vtk_build_module}"
PROPERTY "INTERFACE_vtk_module_third_party")
if (_vtk_build_is_third_party)
_vtk_module_export_properties(
BUILD_FILE "${_vtk_build_properties_build_file}"
INSTALL_FILE "${_vtk_build_properties_install_file}"
MODULE "${_vtk_build_module}"
FROM_GLOBAL_PROPERTIES
# Export the dependencies of a module.
depends
private_depends
optional_depends
# The library name of the module.
library_name
PROPERTIES
# Export whether a module is third party or not.
INTERFACE_vtk_module_third_party
INTERFACE_vtk_module_exclude_wrap)
continue ()
endif ()
set(_vtk_build_split_properties)
get_property(_vtk_build_exclude_wrap
TARGET "${_vtk_build_module}"
PROPERTY "INTERFACE_vtk_module_${_vtk_build_module}_exclude_wrap")
if (NOT _vtk_build_exclude_wrap)
list(APPEND _vtk_build_split_properties
headers)
if (_vtk_build_ENABLE_WRAPPING)
list(APPEND _vtk_build_split_properties
hierarchy)
endif ()
endif ()
set(_vtk_build_properties_kit_properties)
if (_vtk_build_BUILD_WITH_KITS)
list(APPEND _vtk_build_properties_kit_properties
# Export the kit membership of a module.
kit)
endif ()
_vtk_module_export_properties(
BUILD_FILE "${_vtk_build_properties_build_file}"
INSTALL_FILE "${_vtk_build_properties_install_file}"
MODULE "${_vtk_build_module}"
FROM_GLOBAL_PROPERTIES
# Export whether the module should be excluded from wrapping or not.
exclude_wrap
# Export the dependencies of a module.
depends
private_depends
optional_depends
# Export what modules are implemented by the module.
implements
# Export whether the module contains autoinit logic.
implementable
# The library name of the module.
library_name
${_vtk_build_properties_kit_properties}
PROPERTIES
# Export whether the module needs autoinit logic handled.
INTERFACE_vtk_module_needs_autoinit
# Forward private usage requirements with global effects.
INTERFACE_vtk_module_forward_link
SPLIT_INSTALL_PROPERTIES
# Set the properties which differ between build and install trees.
${_vtk_build_split_properties})
endforeach ()
if (_vtk_build_BUILD_WITH_KITS)
foreach (_vtk_build_kit IN LISTS _vtk_build_KITS)
_vtk_module_export_properties(
BUILD_FILE "${_vtk_build_properties_build_file}"
INSTALL_FILE "${_vtk_build_properties_install_file}"
KIT "${_vtk_build_kit}"
FROM_GLOBAL_PROPERTIES
# Export the list of modules in the kit.
kit_modules)
endforeach ()
endif ()
if (_vtk_build_INSTALL_EXPORT AND _vtk_build_INSTALL_HEADERS)
set(_vtk_build_namespace)
if (_vtk_build_TARGET_NAMESPACE)
set(_vtk_build_namespace
NAMESPACE "${_vtk_build_TARGET_NAMESPACE}::")
endif ()
export(
EXPORT "${_vtk_build_INSTALL_EXPORT}"
${_vtk_build_namespace}
FILE "${CMAKE_BINARY_DIR}/${_vtk_build_CMAKE_DESTINATION}/${_vtk_build_PACKAGE}-targets.cmake")
install(
EXPORT "${_vtk_build_INSTALL_EXPORT}"
DESTINATION "${_vtk_build_CMAKE_DESTINATION}"
${_vtk_build_namespace}
FILE "${_vtk_build_PACKAGE}-targets.cmake"
COMPONENT "${_vtk_build_HEADERS_COMPONENT}")
if (_vtk_build_INSTALL_HEADERS)
file(APPEND "${_vtk_build_properties_install_file}"
"unset(_vtk_module_import_prefix)\n")
install(
FILES "${_vtk_build_properties_install_file}"
DESTINATION "${_vtk_build_CMAKE_DESTINATION}"
RENAME "${_vtk_build_properties_filename}"
COMPONENT "${_vtk_build_HEADERS_COMPONENT}")
endif ()
endif ()
get_property(_vtk_build_test_modules GLOBAL
PROPERTY "_vtk_module_test_modules")
set(_vtk_build_tests_handled)
foreach (_vtk_build_test IN LISTS _vtk_build_test_modules)
if (NOT _vtk_build_test IN_LIST _vtk_build_MODULES)
continue ()
endif ()
list(APPEND _vtk_build_tests_handled
"${_vtk_build_test}")
get_property(_vtk_build_test_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_test}_test_depends")
set(_vtk_build_test_has_depends TRUE)
foreach (_vtk_build_test_depend IN LISTS _vtk_build_test_depends)
if (NOT TARGET "${_vtk_build_test_depend}")
set(_vtk_build_test_has_depends FALSE)
_vtk_module_debug(testing "@_vtk_build_test@ testing disabled due to missing @_vtk_build_test_depend@")
endif ()
endforeach ()
if (NOT _vtk_build_test_has_depends)
continue ()
endif ()
get_property(_vtk_build_module_file GLOBAL
PROPERTY "_vtk_module_${_vtk_build_test}_file")
if (NOT _vtk_build_TEST_DIRECTORY_NAME STREQUAL "NONE")
get_filename_component(_vtk_build_module_dir "${_vtk_build_module_file}" DIRECTORY)
if (COMMAND cmake_path) # XXX(cmake-3.20)
cmake_path(NORMAL_PATH _vtk_build_module_dir)
else ()
get_filename_component(_vtk_build_module_dir "${_vtk_build_module_dir}" ABSOLUTE)
endif ()
file(RELATIVE_PATH _vtk_build_module_subdir "${CMAKE_SOURCE_DIR}" "${_vtk_build_module_dir}")
set(_vtk_build_module_subdir_build "${_vtk_build_module_subdir}")
if (EXISTS "${CMAKE_SOURCE_DIR}/${_vtk_build_module_subdir}/${_vtk_build_TEST_DIRECTORY_NAME}")
# Check if the source for this module is outside of `CMAKE_SOURCE_DIR`.
# Place it under `CMAKE_BINARY_DIR` more meaningfully if so.
if (_vtk_build_module_subdir MATCHES "\\.\\./")
file(RELATIVE_PATH _vtk_build_module_subdir_build "${CMAKE_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
get_property(_vtk_build_module_library_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_test}_library_name")
string(APPEND _vtk_build_module_subdir_build "/${_vtk_build_module_library_name}")
endif ()
get_property(_vtk_build_test_labels GLOBAL
PROPERTY "_vtk_module_${_vtk_build_test}_test_labels")
add_subdirectory(
"${CMAKE_SOURCE_DIR}/${_vtk_build_module_subdir}/${_vtk_build_TEST_DIRECTORY_NAME}"
"${CMAKE_BINARY_DIR}/${_vtk_build_module_subdir_build}/${_vtk_build_TEST_DIRECTORY_NAME}")
endif ()
endif ()
endforeach ()
if (_vtk_build_test_modules AND _vtk_build_tests_handled)
list(REMOVE_ITEM _vtk_build_test_modules
${_vtk_build_tests_handled})
set_property(GLOBAL
PROPERTY
_vtk_module_test_modules "${_vtk_build_test_modules}")
endif ()
endfunction ()
#[==[
@ingroup module-impl
@brief Add "standard" include directories to a module
Add the "standard" includes for a module to its interface. These are the source
and build directories for the module itself. They are always either `PUBLIC` or
`INTERFACE` (depending on the module's target type).
~~~
_vtk_module_standard_includes(
[SYSTEM]
[INTERFACE]
TARGET <target>
[HEADERS_DESTINATION <destination>])
~~~
#]==]
function (_vtk_module_standard_includes)
cmake_parse_arguments(PARSE_ARGV 0 _vtk_standard_includes
"SYSTEM;INTERFACE"
"TARGET;HEADERS_DESTINATION"
"")
if (NOT _vtk_standard_includes_TARGET)
message(FATAL_ERROR
"The `TARGET` argument is required.")
endif ()
if (NOT TARGET "${_vtk_standard_includes_TARGET}")
message(FATAL_ERROR
"The `TARGET` argument is not a target.")
endif ()
if (_vtk_standard_includes_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_standard_includes: "
"${_vtk_standard_includes_UNPARSED_ARGUMENTS}")
endif ()
set(_vtk_standard_includes_system)
if (_vtk_standard_includes_SYSTEM)
set(_vtk_standard_includes_system SYSTEM)
endif ()
set(_vtk_standard_includes_visibility PUBLIC)
if (_vtk_standard_includes_INTERFACE)
set(_vtk_standard_includes_visibility INTERFACE)
endif ()
target_include_directories("${_vtk_standard_includes_TARGET}"
${_vtk_standard_includes_system}
"${_vtk_standard_includes_visibility}"
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
if (_vtk_build_INSTALL_HEADERS AND _vtk_standard_includes_HEADERS_DESTINATION AND NOT _vtk_add_module_NO_INSTALL)
target_include_directories("${_vtk_standard_includes_TARGET}"
${_vtk_standard_includes_system}
"${_vtk_standard_includes_visibility}"
$<INSTALL_INTERFACE:${_vtk_standard_includes_HEADERS_DESTINATION}>)
endif ()
endfunction ()
#[==[
@ingroup module-impl
@brief Determine the default export macro for a module
Determines the export macro to be used for a module from its metadata. Assumes
it is called from within a @ref vtk_module_build call.
~~~
_vtk_module_default_library_name(<varname>)
~~~
#]==]
function (_vtk_module_default_export_macro_prefix varname)
get_property(_vtk_module_default_library_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
string(TOUPPER "${_vtk_module_default_library_name}" _vtk_default_export_macro_upper)
set("${varname}"
"${_vtk_default_export_macro_upper}"
PARENT_SCOPE)
endfunction ()
# TODO: It would be nice to support `USE_LINK_PROPERTIES` instead of listing
# the modules again here. However, the format of the `LINK_LIBRARIES` property
# value may not be easy to handle.
#[==[
@page module-overview
@ingroup module
@section module-autoinit Autoinit
When a module contains a factory which may be populated by other modules, these
factories need to be populated when the modules are loaded by the dynamic linker
(for shared builds) or program load time (for static builds). To provide for
this, the module system contains an autoinit "subsystem".
@subsection module-autoinit-leverage Leveraging the autoinit subsystem
The subsystem provides the following hooks for use by projects:
* In modules which `IMPLEMENTS` other modules, in the generated
`<module>Module.h` header (which provides export symbols as well) will
include the modules which are implemented.
* In modules which are `IMPLEMENTABLE` or `IMPLEMENTS` another module, the
generated `<module>Module.h` file will include the following block:
~~~{.c}
#ifdef <module>_AUTOINIT_INCLUDE
#include <module>_AUTOINIT_INCLUDE
#endif
#ifdef <module>_AUTOINIT
#include <header>
VTK_MODULE_AUTOINIT(<module>)
#endif
~~~
The @ref vtk_module_autoinit function will generate an include file and provide
its path via the `<module>_AUTOINIT_INCLUDE` define. once it has been included,
if the `<module>_AUTOINIT` symbol is defined, a header is included which is
intended to provide the `VTK_MODULE_AUTOINIT` macro. This macro is given the
module name and should use `<module>_AUTOINIT` to fill in the factories in the
module with those from the `IMPLEMENTS` modules listed in that symbol.
The `<module>_AUTOINIT` symbol's value is:
~~~
<count>(<module1>,<module2>,<module3>)
~~~
where `<count>` is the number of modules in the parentheses and each module
listed need to register something to `<module>`.
If not provided via the `AUTOINIT_INCLUDE` argument to the
@ref vtk_module_add_module function, the header to use is fetched from the
`_vtk_module_autoinit_include` global property. This only needs to be managed
in modules that `IMPLEMENTS` or are `IMPLEMENTABLE`. This should be provided by
projects using the module system at its lowest level. Projects not implementing
the `VTK_MODULE_AUTOINIT` macro should have its value provided by
`find_package` dependencies in some way.
#]==]
#[==[
@ingroup module
@brief Linking to autoinit-using modules
When linking to modules, in order for the autoinit system to work, modules need
to declare their registration. In order to do this, defines may need to be
provided to targets in order to trigger registration. These defines may be
added to targets by using this function.
~~~
vtk_module_autoinit(
TARGETS <target>...
MODULES <module>...)
~~~
After this call, the targets given to the `TARGETS` argument will gain the
preprocessor definitions to trigger registrations properly.
#]==]
function (vtk_module_autoinit)
cmake_parse_arguments(PARSE_ARGV 0 _vtk_autoinit
""
""
"TARGETS;MODULES")
if (_vtk_autoinit_UNRECOGNIZED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_autoinit: "
"${_vtk_autoinit_UNRECOGNIZED_ARGUMENTS}.")
endif ()
if (NOT _vtk_autoinit_TARGETS)
message(FATAL_ERROR
"The `TARGETS` argument is required.")
endif ()
if (NOT _vtk_autoinit_MODULES)
message(AUTHOR_WARNING
"No `MODULES` passed to `vtk_modules_autoinit`.")
endif ()
set(_vtk_autoinit_module_stack
${_vtk_autoinit_MODULES})
set(_vtk_autoinit_needs_implements)
set(_vtk_autoinit_seen)
while (_vtk_autoinit_module_stack)
list(GET _vtk_autoinit_module_stack 0 _vtk_autoinit_current_module)
list(REMOVE_AT _vtk_autoinit_module_stack 0)
if (_vtk_autoinit_current_module IN_LIST _vtk_autoinit_seen)
continue ()
endif ()
list(APPEND _vtk_autoinit_seen
"${_vtk_autoinit_current_module}")
_vtk_module_real_target(_vtk_autoinit_current_target "${_vtk_autoinit_current_module}")
get_property(_vtk_autoinit_implements
TARGET "${_vtk_autoinit_current_target}"
PROPERTY "INTERFACE_vtk_module_implements")
list(APPEND _vtk_autoinit_needs_implements
${_vtk_autoinit_implements})
foreach (_vtk_autoinit_implement IN LISTS _vtk_autoinit_implements)
_vtk_module_real_target(_vtk_autoinit_implements_target "${_vtk_autoinit_implement}")
get_property(_vtk_autoinit_implementable
TARGET "${_vtk_autoinit_implements_target}"
PROPERTY "INTERFACE_vtk_module_implementable")
if (NOT _vtk_autoinit_implementable)
message(FATAL_ERROR
"The `${_vtk_autoinit_current_module}` module says that it "
"implements the `${_vtk_autoinit_implement}` module, but it is not "
"implementable.")
endif ()
list(APPEND "_vtk_autoinit_implements_${_vtk_autoinit_implement}"
"${_vtk_autoinit_current_module}")
endforeach ()
endwhile ()
if (NOT _vtk_autoinit_needs_implements)
return ()
endif ()
list(REMOVE_DUPLICATES _vtk_autoinit_needs_implements)
list(SORT _vtk_autoinit_needs_implements)
set(_vtk_autoinit_hash_content)
foreach (_vtk_autoinit_need_implements IN LISTS _vtk_autoinit_needs_implements)
if (NOT _vtk_autoinit_implements_${_vtk_autoinit_need_implements})
continue ()
endif ()
list(SORT "_vtk_autoinit_implements_${_vtk_autoinit_need_implements}")
string(APPEND _vtk_autoinit_hash_content
"${_vtk_autoinit_need_implements}: ${_vtk_autoinit_implements_${_vtk_autoinit_need_implements}}\n")
endforeach ()
string(MD5 _vtk_autoinit_header_tag "${_vtk_autoinit_hash_content}")
set(_vtk_autoinit_header
"${CMAKE_BINARY_DIR}/CMakeFiles/vtkModuleAutoInit_${_vtk_autoinit_header_tag}.h")
get_property(_vtk_autoinit_header_generated GLOBAL
PROPERTY "_vtk_autoinit_generated_${_vtk_autoinit_header_tag}")
set(_vtk_autoinit_defines)
set(_vtk_autoinit_header_content)
foreach (_vtk_autoinit_need_implements IN LISTS _vtk_autoinit_needs_implements)
if (NOT _vtk_autoinit_implements_${_vtk_autoinit_need_implements})
continue ()
endif ()
get_property(_vtk_autoinit_implements_library_name
TARGET "${_vtk_autoinit_need_implements}"
PROPERTY "INTERFACE_vtk_module_library_name")
if (NOT _vtk_autoinit_header_generated)
list(LENGTH "_vtk_autoinit_implements_${_vtk_autoinit_need_implements}"
_vtk_autoinit_length)
set(_vtk_autoinit_args)
foreach (_vtk_autoinit_arg IN LISTS "_vtk_autoinit_implements_${_vtk_autoinit_need_implements}")
get_property(_vtk_autoinit_arg_library_name
TARGET "${_vtk_autoinit_arg}"
PROPERTY "INTERFACE_vtk_module_library_name")
list(APPEND _vtk_autoinit_args
"${_vtk_autoinit_arg_library_name}")
endforeach ()
string(REPLACE ";" "," _vtk_autoinit_args "${_vtk_autoinit_args}")
string(APPEND _vtk_autoinit_header_content
"#define ${_vtk_autoinit_implements_library_name}_AUTOINIT ${_vtk_autoinit_length}(${_vtk_autoinit_args})\n")
endif ()
list(APPEND _vtk_autoinit_defines
"${_vtk_autoinit_implements_library_name}_AUTOINIT_INCLUDE=\"${_vtk_autoinit_header}\"")
endforeach ()
if (NOT _vtk_autoinit_header_generated)
file(GENERATE
OUTPUT "${_vtk_autoinit_header}"
CONTENT "${_vtk_autoinit_header_content}")
set_property(GLOBAL
PROPERTY
"_vtk_autoinit_generated_${_vtk_autoinit_header_tag}" TRUE)
endif ()
foreach (_vtk_autoinit_target IN LISTS _vtk_autoinit_TARGETS)
get_property(_vtk_autoinit_target_type
TARGET "${_vtk_autoinit_target}"
PROPERTY TYPE)
if (_vtk_autoinit_target_type STREQUAL "INTERFACE_LIBRARY")
continue ()
endif ()
target_compile_definitions("${_vtk_autoinit_target}"
PRIVATE
${_vtk_autoinit_defines})
endforeach ()
endfunction ()
#[==[
@ingroup module-impl
@brief Generate the hierarchy for a module
Write wrap hierarchy files for the module currently being built. This also
installs the hierarchy file for use by dependent projects if `INSTALL_HEADERS`
is set.
~~~
_vtk_module_write_wrap_hierarchy()
~~~
#]==]
function (_vtk_module_write_wrap_hierarchy)
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${_vtk_build_HIERARCHY_DESTINATION}")
get_property(_vtk_hierarchy_library_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
set(_vtk_hierarchy_filename "${_vtk_hierarchy_library_name}-hierarchy.txt")
set(_vtk_hierarchy_file "${CMAKE_BINARY_DIR}/${_vtk_build_HIERARCHY_DESTINATION}/${_vtk_hierarchy_filename}")
set(_vtk_hierarchy_args_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_hierarchy_library_name}-hierarchy.$<CONFIGURATION>.args")
set(_vtk_hierarchy_data_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_hierarchy_library_name}-hierarchy.data")
set(_vtk_hierarchy_depends_args_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_hierarchy_library_name}-hierarchy.depends.args")
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_hierarchy" "${_vtk_hierarchy_file}")
set(_vtk_add_module_target_name_iface "${_vtk_add_module_target_name}")
if (_vtk_add_module_build_with_kit)
string(APPEND _vtk_add_module_target_name_iface "-objects")
endif ()
set(_vtk_hierarchy_genex_compile_definitions
"$<TARGET_PROPERTY:${_vtk_add_module_target_name_iface},COMPILE_DEFINITIONS>")
set(_vtk_hierarchy_genex_include_directories
"$<TARGET_PROPERTY:${_vtk_add_module_target_name_iface},INCLUDE_DIRECTORIES>")
file(GENERATE
OUTPUT "${_vtk_hierarchy_args_file}"
CONTENT "$<$<BOOL:${_vtk_hierarchy_genex_compile_definitions}>:\n-D\'$<JOIN:${_vtk_hierarchy_genex_compile_definitions},\'\n-D\'>\'>\n
$<$<BOOL:${_vtk_hierarchy_genex_include_directories}>:\n-I\'$<JOIN:${_vtk_hierarchy_genex_include_directories},\'\n-I\'>\'>\n")
get_property(_vtk_hierarchy_depends_is_global GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_depends"
SET)
if (_vtk_hierarchy_depends_is_global)
get_property(_vtk_hierarchy_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_depends")
else ()
get_property(_vtk_hierarchy_depends GLOBAL
TARGET "${_vtk_add_module_real_target}"
PROPERTY "INTERFACE_vtk_module_depends")
endif ()
set(_vtk_hierarchy_depends_files)
set(_vtk_hierarchy_depends_targets)
foreach (_vtk_hierarchy_depend IN LISTS _vtk_hierarchy_depends)
_vtk_module_get_module_property("${_vtk_hierarchy_depend}"
PROPERTY "hierarchy"
VARIABLE _vtk_hierarchy_depend_hierarchy)
if (NOT DEFINED _vtk_hierarchy_depend_hierarchy)
continue ()
endif ()
list(APPEND _vtk_hierarchy_depends_files
"${_vtk_hierarchy_depend_hierarchy}")
# Find the hierarchy target of the module.
get_property(_vtk_hierarchy_module_is_imported
TARGET "${_vtk_hierarchy_depend}"
PROPERTY IMPORTED)
# Imported target modules are external and should already have their file
# generated.
if (_vtk_hierarchy_module_is_imported)
continue ()
endif ()
get_property(_vtk_hierarchy_depend_library_name GLOBAL
PROPERTY "_vtk_module_${_vtk_hierarchy_depend}_library_name")
if (TARGET "${_vtk_hierarchy_depend_library_name}-hierarchy")
list(APPEND _vtk_hierarchy_depends_targets
"${_vtk_hierarchy_depend_library_name}-hierarchy")
endif ()
endforeach ()
set(_vtk_hierarchy_depends_files_arg)
if (_vtk_hierarchy_depends_files)
file(GENERATE
OUTPUT "${_vtk_hierarchy_depends_args_file}"
CONTENT "\"$<JOIN:${_vtk_hierarchy_depends_files},\"\n\">\"\n")
else ()
file(GENERATE
OUTPUT "${_vtk_hierarchy_depends_args_file}"
CONTENT "")
endif ()
_vtk_module_get_module_property("${_vtk_build_module}"
PROPERTY "headers"
VARIABLE _vtk_hierarchy_headers)
set(_vtk_hierarchy_data_content "")
foreach (_vtk_hierarchy_header IN LISTS _vtk_hierarchy_headers)
string(APPEND _vtk_hierarchy_data_content
"${_vtk_hierarchy_header};${_vtk_hierarchy_library_name}\n")
endforeach ()
file(GENERATE
OUTPUT "${_vtk_hierarchy_data_file}"
CONTENT "${_vtk_hierarchy_data_content}")
if (CMAKE_GENERATOR MATCHES "Ninja")
set(_vtk_hierarchy_command_depends ${_vtk_hierarchy_depends_files})
else ()
set(_vtk_hierarchy_command_depends ${_vtk_hierarchy_depends_targets})
endif ()
set(_vtk_hierarchy_tool_target "VTK::WrapHierarchy")
set(_vtk_hierarchy_macros_args)
if (TARGET VTKCompileTools::WrapHierarchy)
set(_vtk_hierarchy_tool_target "VTKCompileTools::WrapHierarchy")
if (TARGET VTKCompileTools_macros)
list(APPEND _vtk_hierarchy_command_depends
"VTKCompileTools_macros")
list(APPEND _vtk_hierarchy_macros_args
-undef
-imacros "${_VTKCompileTools_macros_file}")
endif ()
endif ()
add_custom_command(
OUTPUT "${_vtk_hierarchy_file}"
COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR}
"$<TARGET_FILE:${_vtk_hierarchy_tool_target}>"
"@${_vtk_hierarchy_args_file}"
-o "${_vtk_hierarchy_file}"
"${_vtk_hierarchy_data_file}"
"@${_vtk_hierarchy_depends_args_file}"
${_vtk_hierarchy_macros_args}
COMMENT "Generating the wrap hierarchy for ${_vtk_build_module}"
DEPENDS
${_vtk_hierarchy_headers}
"${_vtk_hierarchy_args_file}"
"${_vtk_hierarchy_data_file}"
"${_vtk_hierarchy_depends_args_file}"
${_vtk_hierarchy_command_depends})
add_custom_target("${_vtk_add_module_library_name}-hierarchy" ALL
DEPENDS
"${_vtk_hierarchy_file}"
"$<TARGET_FILE:${_vtk_hierarchy_tool_target}>")
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_hierarchy" "${_vtk_hierarchy_file}")
if (_vtk_build_INSTALL_HEADERS)
set(_vtk_hierarchy_headers_component "${_vtk_build_HEADERS_COMPONENT}")
if (_vtk_build_TARGET_SPECIFIC_COMPONENTS)
string(PREPEND _vtk_hierarchy_headers_component "${_vtk_build_module}-")
if (_vtk_build_BUILD_WITH_KITS)
get_property(_vtk_hierarchy_build_with_kit GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_kit")
if (_vtk_hierarchy_build_with_kit)
set(_vtk_hierarchy_headers_component "${_vtk_hierarchy_build_with_kit}-${_vtk_build_HEADERS_COMPONENT}")
endif ()
endif ()
endif ()
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_hierarchy_install" "\${_vtk_module_import_prefix}/${_vtk_build_HIERARCHY_DESTINATION}/${_vtk_hierarchy_filename}")
install(
FILES "${_vtk_hierarchy_file}"
DESTINATION "${_vtk_build_HIERARCHY_DESTINATION}"
RENAME "${_vtk_hierarchy_filename}"
COMPONENT "${_vtk_hierarchy_headers_component}")
endif ()
endfunction ()
include(GenerateExportHeader)
#[==[
@ingroup module
@brief Create a module library
~~~
vtk_module_add_module(<name>
[NO_INSTALL] [FORCE_STATIC] [HEADER_ONLY] [HEADER_DIRECTORIES]
[EXPORT_MACRO_PREFIX <prefix>]
[HEADERS_SUBDIR <subdir>]
[LIBRARY_NAME_SUFFIX <suffix>]
[CLASSES <class>...]
[TEMPLATE_CLASSES <template class>...]
[NOWRAP_CLASSES <nowrap class>...]
[NOWRAP_TEMPLATE_CLASSES <nowrap template class>...]
[SOURCES <source>...]
[HEADERS <header>...]
[NOWRAP_HEADERS <header>...]
[TEMPLATES <template>...]
[PRIVATE_CLASSES <class>...]
[PRIVATE_TEMPLATE_CLASSES <template class>...]
[PRIVATE_HEADERS <header>...]
[PRIVATE_TEMPLATES <template>...])
~~~
The `PRIVATE_` arguments are analogous to their non-`PRIVATE_` arguments, but
the associated files are not installed or available for wrapping (`SOURCES` are
always private, so there is no `PRIVATE_` variant for that argument).
* `NO_INSTALL`: Skip installation of the module and all its installation
artifacts. Note that if this target is used by any other target that is
exported, this option may not be used because CMake (in addition to VTK
module APIs such as `vtk_module_export_find_packages` and `) will generate
references to the target that are expected to be satisfied. It is highly
recommended to test that the build and install exports (as used) be tested
to make sure that the module is not actually referenced.
* `FORCE_STATIC`: For a static library to be created. If not provided,
`BUILD_SHARED_LIBS` will control the library type.
* `HEADER_ONLY`: The module only contains headers (or templates) and contains
no compilation steps. Mutually exclusive with `FORCE_STATIC`.
* `HEADER_DIRECTORIES`: The headers for this module are in a directory
structure which should be preserved in the install tree.
* `EXPORT_MACRO_PREFIX`: The prefix for the export macro definitions.
Defaults to the library name of the module in all uppercase.
* `HEADERS_SUBDIR`: The subdirectory to install headers into in the install
tree.
* `LIBRARY_NAME_SUFFIX`: The suffix to the module's library name if
additional information is required.
* `CLASSES`: A list of classes in the module. This is a shortcut for adding
`<class>.cxx` to `SOURCES` and `<class>.h` to `HEADERS`.
* `TEMPLATE_CLASSES`: A list of template classes in the module. This is a
shortcut for adding `<class>.txx` to `TEMPLATES` and `<class>.h` to
`HEADERS`.
* `SOURCES`: A list of source files which require compilation.
* `HEADERS`: A list of header files which will be available for wrapping and
installed.
* `NOWRAP_CLASSES`: A list of classes which will not be available for
wrapping but installed. This is a shortcut for adding `<class>.cxx` to
`SOURCES` and `<class>.h` to `NOWRAP_HEADERS`.
* `NOWRAP_TEMPLATE_CLASSES`: A list of template classes which will not be
* available for
wrapping but installed. This is a shortcut for adding `<class>.txx` to
`TEMPLATES` and `<class>.h` to `NOWRAP_HEADERS`.
* `NOWRAP_HEADERS`: A list of header files which will not be available for
wrapping but installed.
* `TEMPLATES`: A list of template files which will be installed.
#]==]
function (vtk_module_add_module name)
if (NOT name STREQUAL _vtk_build_module)
message(FATAL_ERROR
"The ${_vtk_build_module}'s CMakeLists.txt may not add the ${name} module.")
endif ()
set(_vtk_add_module_source_keywords)
foreach (_vtk_add_module_kind IN ITEMS CLASSES TEMPLATE_CLASSES HEADERS TEMPLATES)
list(APPEND _vtk_add_module_source_keywords
"${_vtk_add_module_kind}"
"PRIVATE_${_vtk_add_module_kind}")
endforeach ()
cmake_parse_arguments(PARSE_ARGV 1 _vtk_add_module
"NO_INSTALL;FORCE_STATIC;HEADER_ONLY;HEADER_DIRECTORIES;EXCLUDE_HEADER_TEST"
"EXPORT_MACRO_PREFIX;HEADERS_SUBDIR;LIBRARY_NAME_SUFFIX"
"${_vtk_add_module_source_keywords};SOURCES;NOWRAP_CLASSES;NOWRAP_TEMPLATE_CLASSES;NOWRAP_HEADERS")
if (_vtk_add_module_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_add_module: "
"${_vtk_add_module_UNPARSED_ARGUMENTS}")
endif ()
if (NOT DEFINED _vtk_add_module_EXPORT_MACRO_PREFIX)
_vtk_module_default_export_macro_prefix(_vtk_add_module_EXPORT_MACRO_PREFIX)
endif ()
if (_vtk_add_module_HEADER_ONLY AND _vtk_add_module_FORCE_STATIC)
message(FATAL_ERROR
"The ${_vtk_build_module} module cannot be header only yet forced "
"static.")
endif ()
foreach (_vtk_add_module_class IN LISTS _vtk_add_module_CLASSES)
list(APPEND _vtk_add_module_SOURCES
"${_vtk_add_module_class}.cxx")
list(APPEND _vtk_add_module_HEADERS
"${_vtk_add_module_class}.h")
endforeach ()
foreach (_vtk_add_module_template_class IN LISTS _vtk_add_module_TEMPLATE_CLASSES)
list(APPEND _vtk_add_module_TEMPLATES
"${_vtk_add_module_template_class}.txx")
list(APPEND _vtk_add_module_HEADERS
"${_vtk_add_module_template_class}.h")
endforeach ()
foreach (_vtk_add_module_class IN LISTS _vtk_add_module_NOWRAP_CLASSES)
list(APPEND _vtk_add_module_SOURCES
"${_vtk_add_module_class}.cxx")
list(APPEND _vtk_add_module_NOWRAP_HEADERS
"${_vtk_add_module_class}.h")
endforeach ()
foreach (_vtk_add_module_class IN LISTS _vtk_add_module_NOWRAP_TEMPLATE_CLASSES)
list(APPEND _vtk_add_module_TEMPLATES
"${_vtk_add_module_class}.txx")
list(APPEND _vtk_add_module_NOWRAP_HEADERS
"${_vtk_add_module_class}.h")
endforeach ()
foreach (_vtk_add_module_class IN LISTS _vtk_add_module_PRIVATE_CLASSES)
list(APPEND _vtk_add_module_SOURCES
"${_vtk_add_module_class}.cxx")
list(APPEND _vtk_add_module_PRIVATE_HEADERS
"${_vtk_add_module_class}.h")
endforeach ()
foreach (_vtk_add_module_template_class IN LISTS _vtk_add_module_PRIVATE_TEMPLATE_CLASSES)
list(APPEND _vtk_add_module_PRIVATE_TEMPLATES
"${_vtk_add_module_template_class}.txx")
list(APPEND _vtk_add_module_PRIVATE_HEADERS
"${_vtk_add_module_template_class}.h")
endforeach ()
if (NOT _vtk_add_module_SOURCES AND NOT _vtk_add_module_HEADER_ONLY)
message(AUTHOR_WARNING
"The ${_vtk_build_module} module has no source files. Did you mean to "
"pass the `HEADER_ONLY` flag?")
endif ()
get_property(_vtk_add_module_third_party GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_third_party")
get_property(_vtk_add_module_library_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
set(_vtk_add_module_module_header_name
"${_vtk_add_module_library_name}Module.h")
if (NOT _vtk_add_module_HEADER_ONLY AND NOT _vtk_add_module_third_party)
set(_vtk_add_module_generated_header
"${CMAKE_CURRENT_BINARY_DIR}/${_vtk_add_module_module_header_name}")
list(APPEND _vtk_add_module_HEADERS
"${_vtk_add_module_generated_header}")
endif ()
set(_vtk_add_module_use_relative_paths)
if (_vtk_add_module_HEADER_DIRECTORIES)
set(_vtk_add_module_use_relative_paths
USE_RELATIVE_PATHS)
endif ()
if (NOT _vtk_add_module_NO_INSTALL)
vtk_module_install_headers(
${_vtk_add_module_use_relative_paths}
FILES ${_vtk_add_module_HEADERS}
${_vtk_add_module_NOWRAP_HEADERS}
${_vtk_add_module_TEMPLATES}
SUBDIR "${_vtk_add_module_HEADERS_SUBDIR}")
endif ()
set(_vtk_add_module_type)
if (_vtk_add_module_FORCE_STATIC)
set(_vtk_add_module_type STATIC)
endif ()
set(_vtk_add_module_build_with_kit)
if (_vtk_build_BUILD_WITH_KITS)
get_property(_vtk_add_module_build_with_kit GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_kit")
endif ()
get_property(_vtk_add_module_namespace GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_namespace")
get_property(_vtk_add_module_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_target_name")
set(_vtk_add_module_real_target "${_vtk_add_module_target_name}")
if (_vtk_add_module_HEADER_ONLY)
if (_vtk_add_module_build_with_kit)
message(FATAL_ERROR
"The module ${_vtk_build_module} is header-only, but is part of the "
"${_vtk_add_module_build_with_kit} kit. Header-only modules do not "
"belong in kits.")
endif ()
add_library("${_vtk_add_module_real_target}" INTERFACE)
if (NOT _vtk_build_module STREQUAL _vtk_add_module_real_target)
add_library("${_vtk_build_module}" ALIAS
"${_vtk_add_module_real_target}")
endif ()
else ()
if (_vtk_add_module_build_with_kit)
add_library("${_vtk_add_module_real_target}" INTERFACE)
target_link_libraries("${_vtk_add_module_real_target}"
INTERFACE
# For usage requirements.
"${_vtk_add_module_real_target}-objects"
# For the implementation.
"$<LINK_ONLY:${_vtk_add_module_build_with_kit}>")
if (NOT _vtk_build_module STREQUAL _vtk_add_module_real_target)
add_library("${_vtk_build_module}" ALIAS
"${_vtk_add_module_real_target}")
endif ()
# Set up properties necessary for other infrastructure.
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_library_name" "${_vtk_add_module_library_name}")
add_library("${_vtk_add_module_real_target}-objects" OBJECT
${_vtk_add_module_SOURCES}
${_vtk_add_module_TEMPLATES}
${_vtk_add_module_PRIVATE_TEMPLATES}
${_vtk_add_module_HEADERS}
${_vtk_add_module_NOWRAP_HEADERS}
${_vtk_add_module_PRIVATE_HEADERS})
if (_vtk_build_UTILITY_TARGET)
target_link_libraries("${_vtk_add_module_real_target}-objects"
PRIVATE
"${_vtk_build_UTILITY_TARGET}")
endif ()
set_target_properties("${_vtk_add_module_real_target}-objects"
PROPERTIES
# Emulate the regular library as much as possible.
DEFINE_SYMBOL "${_vtk_add_module_real_target}_EXPORT"
POSITION_INDEPENDENT_CODE ON)
target_compile_definitions("${_vtk_add_module_real_target}-objects"
PRIVATE
"${_vtk_add_module_real_target}_EXPORT")
string(APPEND _vtk_add_module_real_target "-objects")
else ()
add_library("${_vtk_add_module_real_target}" ${_vtk_add_module_type}
${_vtk_add_module_SOURCES}
${_vtk_add_module_TEMPLATES}
${_vtk_add_module_HEADERS}
${_vtk_add_module_PRIVATE_HEADERS})
if (_vtk_build_UTILITY_TARGET)
target_link_libraries("${_vtk_add_module_real_target}"
PRIVATE
"${_vtk_build_UTILITY_TARGET}")
endif ()
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
POSITION_INDEPENDENT_CODE ON)
if (NOT _vtk_build_module STREQUAL _vtk_add_module_real_target)
add_library("${_vtk_build_module}" ALIAS
"${_vtk_add_module_real_target}")
endif ()
endif ()
endif ()
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_library_name" "${_vtk_add_module_library_name}")
get_property(_vtk_add_module_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_depends")
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_depends" "${_vtk_add_module_depends}")
set(_vtk_add_module_includes_interface)
if (_vtk_add_module_HEADER_ONLY)
target_link_libraries("${_vtk_add_module_real_target}"
INTERFACE
${_vtk_add_module_depends})
set(_vtk_add_module_includes_interface INTERFACE)
else ()
get_property(_vtk_add_module_private_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_private_depends")
# XXX(cmake#18484): Linking dependencies directly currently creates
# circular dependencies. This logic should be removed once the minimum for
# kits contains a fix for the mentioned issue.
#
# When two modules are part of the same kit, we can get this problem:
#
# A - iface -> A-objects <- tll - K
# ^ |
# | |
# B - iface -> B-objects <- tll -/
#
# If B depends on A, it ends up with a circular dependency since A has a
# `$<LINK_ONLY:K>` link. instead, munge up dependencies of intra-kit
# dependencies to link to the `-objects` target instead.
if (_vtk_add_module_build_with_kit)
set(_vtk_add_module_depends_link)
set(_vtk_add_module_private_depends_link)
foreach (_vtk_add_module_depend IN LISTS _vtk_add_module_depends)
get_property(_vtk_add_module_depend_kit GLOBAL
PROPERTY "_vtk_module_${_vtk_add_module_depend}_kit")
if (_vtk_add_module_depend_kit STREQUAL _vtk_add_module_build_with_kit)
# We're in the same kit; depend on the `-objects` library of the
# module.
get_property(_vtk_add_module_depend_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_add_module_depend}_target_name")
list(APPEND _vtk_add_module_depends_link
"${_vtk_add_module_depend_target_name}-objects")
else ()
# Different kit, just use as normal.
list(APPEND _vtk_add_module_depends_link
"${_vtk_add_module_depend}")
endif ()
endforeach ()
foreach (_vtk_add_module_private_depend IN LISTS _vtk_add_module_private_depends)
get_property(_vtk_add_module_private_depend_kit GLOBAL
PROPERTY "_vtk_module_${_vtk_add_module_private_depend}_kit")
if (_vtk_add_module_private_depend_kit STREQUAL _vtk_add_module_build_with_kit)
# We're in the same kit; depend on the `-objects` library of the
# module.
get_property(_vtk_add_module_private_depend_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_add_module_private_depend}_target_name")
list(APPEND _vtk_add_module_private_depends_link
"${_vtk_add_module_private_depend_target_name}-objects")
else ()
# Different kit, just use as normal.
list(APPEND _vtk_add_module_private_depends_link
"${_vtk_add_module_private_depend}")
endif ()
endforeach ()
# Add the `DEFINE_SYMBOL` for all other modules within the same kit which
# have already been processed because the direct dependencies are not
# sufficient: export symbols from any included header needs to be
# correct. Since modules are built in topological order, a module can
# only possibly include modules in the kit which have already been built.
get_property(_vtk_add_module_kit_modules GLOBAL
PROPERTY "_vtk_kit_${_vtk_add_module_build_with_kit}_kit_modules")
list(REMOVE_ITEM _vtk_add_module_kit_modules "${_vtk_build_module}")
foreach (_vtk_add_module_kit_module IN LISTS _vtk_add_module_kit_modules)
get_property(_vtk_add_module_kit_module_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_add_module_kit_module}_target_name")
if (TARGET "${_vtk_add_module_kit_module_target_name}-objects")
get_property(_vtk_add_module_kit_module_define_symbol
TARGET "${_vtk_add_module_kit_module_target_name}-objects"
PROPERTY DEFINE_SYMBOL)
target_compile_definitions("${_vtk_add_module_real_target}"
PRIVATE
"${_vtk_add_module_kit_module_define_symbol}")
endif ()
endforeach ()
else ()
set(_vtk_add_module_depends_link ${_vtk_add_module_depends})
set(_vtk_add_module_private_depends_link ${_vtk_add_module_private_depends})
endif ()
target_link_libraries("${_vtk_add_module_real_target}"
PUBLIC
${_vtk_add_module_depends_link}
PRIVATE
${_vtk_add_module_private_depends_link})
set(_vtk_add_module_private_depends_forward_link)
foreach (_vtk_add_module_private_depend IN LISTS _vtk_add_module_depends_link _vtk_add_module_private_depends)
_vtk_module_get_module_property("${_vtk_add_module_private_depend}"
PROPERTY "forward_link"
VARIABLE _vtk_add_module_forward_link)
list(APPEND _vtk_add_module_private_depends_forward_link
${_vtk_add_module_forward_link})
endforeach ()
get_property(_vtk_add_module_optional_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_optional_depends")
foreach (_vtk_add_module_optional_depend IN LISTS _vtk_add_module_optional_depends)
if (TARGET "${_vtk_add_module_optional_depend}")
set(_vtk_add_module_optional_depend_link "${_vtk_add_module_optional_depend}")
if (_vtk_add_module_build_with_kit)
get_property(_vtk_add_module_optional_depend_kit GLOBAL
PROPERTY "_vtk_module_${_vtk_add_module_optional_depend}_kit")
if (_vtk_add_module_optional_depend_kit STREQUAL _vtk_add_module_build_with_kit)
# We're in the same kit; depend on the `-objects` library of the
# module to avoid circular dependency (see explanation earlier)
get_property(_vtk_add_module_optional_depend_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_add_module_optional_depend}_target_name")
set(_vtk_add_module_optional_depend_link "${_vtk_add_module_optional_depend_target_name}-objects")
endif ()
endif ()
_vtk_module_get_module_property("${_vtk_add_module_optional_depend_link}"
PROPERTY "forward_link"
VARIABLE _vtk_add_module_forward_link)
list(APPEND _vtk_add_module_private_depends_forward_link
${_vtk_add_module_forward_link})
target_link_libraries("${_vtk_add_module_real_target}"
PRIVATE
"${_vtk_add_module_optional_depend_link}")
endif ()
string(REPLACE "::" "_" _vtk_add_module_optional_depend_safe "${_vtk_add_module_optional_depend}")
target_compile_definitions("${_vtk_add_module_real_target}"
PRIVATE
"VTK_MODULE_ENABLE_${_vtk_add_module_optional_depend_safe}=$<TARGET_EXISTS:${_vtk_add_module_optional_depend}>")
endforeach ()
if (_vtk_add_module_private_depends_forward_link)
list(REMOVE_DUPLICATES _vtk_add_module_private_depends_forward_link)
_vtk_module_set_module_property("${_vtk_build_module}" APPEND
PROPERTY "forward_link"
VALUE "${_vtk_add_module_private_depends_forward_link}")
target_link_libraries("${_vtk_add_module_real_target}"
PUBLIC
"${_vtk_add_module_private_depends_forward_link}")
endif ()
endif ()
_vtk_module_standard_includes(
TARGET "${_vtk_add_module_real_target}"
${_vtk_add_module_includes_interface}
HEADERS_DESTINATION "${_vtk_build_HEADERS_DESTINATION}")
vtk_module_autoinit(
MODULES ${_vtk_add_module_depends}
${_vtk_add_module_private_depends}
"${_vtk_build_module}"
TARGETS "${_vtk_add_module_real_target}")
set(_vtk_add_module_headers_build)
set(_vtk_add_module_headers_install)
# TODO: Perform this in `vtk_module_install_headers` so that manually
# installed headers may participate in wrapping as well.
foreach (_vtk_add_module_header IN LISTS _vtk_add_module_HEADERS)
if (IS_ABSOLUTE "${_vtk_add_module_header}")
list(APPEND _vtk_add_module_headers_build
"${_vtk_add_module_header}")
else ()
list(APPEND _vtk_add_module_headers_build
"${CMAKE_CURRENT_SOURCE_DIR}/${_vtk_add_module_header}")
endif ()
get_filename_component(_vtk_add_module_header_name "${_vtk_add_module_header}" NAME)
list(APPEND _vtk_add_module_headers_install
"\${_vtk_module_import_prefix}/${_vtk_build_HEADERS_DESTINATION}/${_vtk_add_module_header_name}")
endforeach ()
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_headers" "${_vtk_add_module_headers_build}")
if (_vtk_build_INSTALL_HEADERS AND NOT _vtk_add_module_NO_INSTALL)
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_headers_install" "${_vtk_add_module_headers_install}")
endif ()
get_property(_vtk_add_module_exclude_wrap GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_exclude_wrap")
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_exclude_wrap" "${_vtk_add_module_exclude_wrap}")
if (NOT _vtk_add_module_exclude_wrap AND _vtk_build_ENABLE_WRAPPING)
_vtk_module_write_wrap_hierarchy()
endif ()
# Make sure this file is excluded from the header tests
set(_vtk_add_module_module_content "
/* VTK-HeaderTest-Exclude: ${_vtk_add_module_library_name}Module.h */
")
if (NOT _vtk_add_module_AUTOINIT_INCLUDE)
get_property(_vtk_add_module_AUTOINIT_INCLUDE GLOBAL
PROPERTY "_vtk_module_autoinit_include")
endif ()
set(_vtk_add_module_autoinit_include_header)
if (_vtk_add_module_AUTOINIT_INCLUDE)
set(_vtk_add_module_autoinit_include_header
"#include ${_vtk_add_module_AUTOINIT_INCLUDE}")
endif ()
set(_vtk_add_module_autoinit_depends_includes)
foreach (_vtk_add_module_autoinit_dependency IN LISTS _vtk_add_module_depends)
get_property(_vtk_add_module_autoinit_dependency_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_add_module_autoinit_dependency}_target_name")
if (_vtk_add_module_autoinit_dependency_target_name)
get_property(_vtk_add_module_depends_needs_autoinit
TARGET "${_vtk_add_module_autoinit_dependency_target_name}"
PROPERTY "INTERFACE_vtk_module_needs_autoinit")
else ()
set(_vtk_add_module_autoinit_dependency_target_name
"${_vtk_add_module_autoinit_dependency}")
get_property(_vtk_add_module_depends_needs_autoinit
TARGET "${_vtk_add_module_autoinit_dependency}"
PROPERTY "INTERFACE_vtk_module_needs_autoinit")
endif ()
if (NOT _vtk_add_module_depends_needs_autoinit)
continue ()
endif ()
get_property(_vtk_add_module_depends_library_name
TARGET "${_vtk_add_module_autoinit_dependency_target_name}"
PROPERTY "INTERFACE_vtk_module_library_name")
string(APPEND _vtk_add_module_autoinit_depends_includes
"#include \"${_vtk_add_module_depends_library_name}Module.h\"\n")
endforeach ()
set(_vtk_add_module_autoinit_content)
if (_vtk_add_module_autoinit_depends_includes)
string(APPEND _vtk_add_module_autoinit_content
"/* AutoInit dependencies. */\n${_vtk_add_module_autoinit_depends_includes}\n")
endif ()
get_property(_vtk_add_module_implementable GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_implementable")
get_property(_vtk_add_module_implements GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_implements")
if (_vtk_add_module_implementable)
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_implementable" 1)
endif ()
# TODO: Make this a proper argument to be parsed.
if (NOT _vtk_module_no_namespace_abi_mangling)
# Include the ABI Namespace macros header
string(APPEND _vtk_add_module_module_content
"
/* Include ABI Namespace */
#include \"vtkABINamespace.h\"
")
endif ()
if (_vtk_add_module_implementable OR _vtk_add_module_implements)
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_implements" "${_vtk_add_module_implements}")
set_property(TARGET "${_vtk_add_module_real_target}"
PROPERTY
"INTERFACE_vtk_module_needs_autoinit" 1)
string(APPEND _vtk_add_module_autoinit_content
"
/* AutoInit implementations. */
#ifdef ${_vtk_add_module_library_name}_AUTOINIT_INCLUDE
#include ${_vtk_add_module_library_name}_AUTOINIT_INCLUDE
#endif
#ifdef ${_vtk_add_module_library_name}_AUTOINIT
${_vtk_add_module_autoinit_include_header}
VTK_MODULE_AUTOINIT(${_vtk_add_module_library_name})
#endif
")
string(APPEND _vtk_add_module_module_content
"${_vtk_add_module_autoinit_content}")
endif ()
if (NOT _vtk_add_module_HEADER_ONLY AND NOT _vtk_add_module_third_party)
generate_export_header("${_vtk_add_module_real_target}"
EXPORT_MACRO_NAME "${_vtk_add_module_EXPORT_MACRO_PREFIX}_EXPORT"
NO_EXPORT_MACRO_NAME "${_vtk_add_module_EXPORT_MACRO_PREFIX}_NO_EXPORT"
DEPRECATED_MACRO_NAME "${_vtk_add_module_EXPORT_MACRO_PREFIX}_DEPRECATED"
NO_DEPRECATED_MACRO_NAME "${_vtk_add_module_EXPORT_MACRO_PREFIX}_NO_DEPRECATED"
STATIC_DEFINE "${_vtk_add_module_EXPORT_MACRO_PREFIX}_STATIC_DEFINE"
EXPORT_FILE_NAME "${_vtk_add_module_module_header_name}"
CUSTOM_CONTENT_FROM_VARIABLE _vtk_add_module_module_content)
endif ()
_vtk_module_apply_properties("${_vtk_add_module_target_name}")
_vtk_module_add_header_tests()
if (NOT _vtk_add_module_NO_INSTALL)
_vtk_module_install("${_vtk_add_module_target_name}")
if (_vtk_add_module_build_with_kit)
_vtk_module_install("${_vtk_add_module_target_name}-objects")
endif ()
endif ()
get_property(_vtk_add_module_LICENSE_FILES GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_license_files")
if (_vtk_add_module_LICENSE_FILES)
if (_vtk_build_TARGET_SPECIFIC_COMPONENTS)
string(PREPEND _vtk_build_LICENSE_COMPONENT "${_vtk_build_module}-")
endif ()
if (NOT _vtk_add_module_NO_INSTALL)
install(
FILES ${_vtk_add_module_LICENSE_FILES}
DESTINATION "${_vtk_build_LICENSE_DESTINATION}/${_vtk_add_module_library_name}/"
COMPONENT "${_vtk_build_LICENSE_COMPONENT}")
endif ()
endif ()
endfunction ()
#[==[
@ingroup module-impl
@brief Add header tests for a module
@todo Move this function out to be VTK-specific, probably into
`vtkModuleTesting.cmake`. Each module would then need to manually call this
function. It currently assumes it is in VTK itself.
~~~
_vtk_module_add_header_tests()
~~~
#]==]
function (_vtk_module_add_header_tests)
if (NOT BUILD_TESTING)
return ()
endif ()
get_property(_vtk_add_header_tests_is_third_party GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_third_party")
if (_vtk_add_header_tests_is_third_party)
return ()
endif ()
# TODO: Add test compiles which include each header file to ensure that
# public headers have their includes satisfied by a public dependency.
# Bad...
if (NOT Python${VTK_PYTHON_VERSION}_EXECUTABLE)
return ()
endif ()
# Worse...
if (NOT VTK_SOURCE_DIR)
return ()
endif ()
if (NOT _vtk_add_module_EXCLUDE_HEADER_TEST)
add_test(
NAME "${_vtk_build_module}-HeaderTest"
COMMAND "${Python${VTK_PYTHON_VERSION}_EXECUTABLE}"
# TODO: What to do when using this from a VTK install?
"${VTK_SOURCE_DIR}/Testing/Core/HeaderTesting.py"
"${CMAKE_CURRENT_SOURCE_DIR}"
"--export-macro"
"${_vtk_add_module_EXPORT_MACRO}"
"--headers"
"${_vtk_add_module_HEADERS}"
"${_vtk_add_module_NOWRAP_HEADERS}"
"${_vtk_add_module_TEMPLATES}")
endif ()
endfunction ()
#[==[
@ingroup module
@brief Install headers
Installing headers is done for normal modules by the @ref vtk_module_add_module
function already. However, sometimes header structures are more complicated and
need to be installed manually. This is common for third party modules or
projects which use more than a single directory of headers for a module.
To facilitate the installation of headers in various ways, the this function is
available. This function honors the `INSTALL_HEADERS`, `HEADERS_DESTINATION`,
and `HEADERS_COMPONENT` arguments to @ref vtk_module_build.
~~~
vtk_module_install_headers(
[USE_RELATIVE_PATHS]
[DIRECTORIES <directory>...]
[FILES <file>...]
[SUBDIR <subdir>])
~~~
Installation of header directories follows CMake's `install` function semantics
with respect to trailing slashes.
If `USE_RELATIVE_PATHS` is given, the directory part of any listed files will
be added to the destination. Absolute paths will be computed relative to
`${CMAKE_CURRENT_BINARY_DIR}`.
#]==]
function (vtk_module_install_headers)
cmake_parse_arguments(PARSE_ARGV 0 _vtk_install_headers
"USE_RELATIVE_PATHS"
"SUBDIR"
"FILES;DIRECTORIES")
if (_vtk_install_headers_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_install_headers: "
"${_vtk_install_headers_UNPARSED_ARGUMENTS}")
endif ()
if (NOT _vtk_build_INSTALL_HEADERS)
return ()
endif ()
if (NOT _vtk_install_headers_FILES AND NOT _vtk_install_headers_DIRECTORIES)
return ()
endif ()
set(_vtk_install_headers_destination
"${_vtk_build_HEADERS_DESTINATION}/${_vtk_install_headers_SUBDIR}")
set(_vtk_install_headers_headers_component "${_vtk_build_HEADERS_COMPONENT}")
if (_vtk_build_TARGET_SPECIFIC_COMPONENTS)
string(PREPEND _vtk_install_headers_headers_component "${_vtk_build_module}-")
if (_vtk_build_BUILD_WITH_KITS)
get_property(_vtk_install_headers_build_with_kit GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_kit")
if (_vtk_install_headers_build_with_kit)
set(_vtk_install_headers_headers_component "${_vtk_install_headers_build_with_kit}-${_vtk_build_HEADERS_COMPONENT}")
endif ()
endif ()
endif ()
if (_vtk_install_headers_USE_RELATIVE_PATHS)
set(_vtk_install_headers_destination_file_subdir "")
foreach (_vtk_install_headers_file IN LISTS _vtk_install_headers_FILES)
if (IS_ABSOLUTE "${_vtk_install_headers_file}")
file(RELATIVE_PATH _vtk_install_headers_destination_file_from_binary_dir
"${CMAKE_CURRENT_BINARY_DIR}"
"${_vtk_install_headers_file}")
get_filename_component(_vtk_install_headers_destination_file_subdir "${_vtk_install_headers_destination_file_from_binary_dir}" DIRECTORY)
else ()
get_filename_component(_vtk_install_headers_destination_file_subdir "${_vtk_install_headers_file}" DIRECTORY)
endif ()
install(
FILES ${_vtk_install_headers_file}
DESTINATION "${_vtk_install_headers_destination}/${_vtk_install_headers_destination_file_subdir}"
COMPONENT "${_vtk_install_headers_headers_component}")
endforeach ()
elseif (_vtk_install_headers_FILES)
install(
FILES ${_vtk_install_headers_FILES}
DESTINATION "${_vtk_install_headers_destination}"
COMPONENT "${_vtk_install_headers_headers_component}")
endif ()
set(_vtk_install_headers_destination_directory_subdir "")
foreach (_vtk_install_headers_directory IN LISTS _vtk_install_headers_DIRECTORIES)
if (_vtk_install_headers_USE_RELATIVE_PATHS)
if (IS_ABSOLUTE "${_vtk_install_headers_directory}")
file(RELATIVE_PATH _vtk_install_headers_destination_directory_from_binary_dir
"${CMAKE_CURRENT_BINARY_DIR}"
"${_vtk_install_headers_directory}")
get_filename_component(_vtk_install_headers_destination_directory_subdir "${_vtk_install_headers_destination_directory_from_binary_dir}" DIRECTORY)
else ()
get_filename_component(_vtk_install_headers_destination_directory_subdir "${_vtk_install_headers_directory}" DIRECTORY)
endif ()
endif ()
install(
DIRECTORY "${_vtk_install_headers_directory}"
DESTINATION "${_vtk_install_headers_destination}/${_vtk_install_headers_destination_directory_subdir}"
COMPONENT "${_vtk_install_headers_headers_component}")
endforeach ()
endfunction ()
#[==[
@ingroup module-internal
@brief Apply properties to a module
Apply build properties to a target. Generally only useful to wrapping code or
other modules that cannot use @ref vtk_module_add_module for some reason.
~~~
_vtk_module_apply_properties(<target>
[BASENAME <basename>])
~~~
If `BASENAME` is given, it will be used instead of the target name as the basis
for `OUTPUT_NAME`. Full modules (as opposed to third party or other non-module
libraries) always use the module's `LIBRARY_NAME` setting.
The following target properties are set based on the arguments to the calling
@ref vtk_module_build call:
- `OUTPUT_NAME` (based on the module's `LIBRARY_NAME` and
`vtk_module_build(LIBRARY_NAME_SUFFIX)`)
- `VERSION` (based on `vtk_module_build(VERSION)`)
- `SOVERSION` (based on `vtk_module_build(SOVERSION)`)
- `DEBUG_POSTFIX` (on Windows unless already set via `CMAKE_DEBUG_POSTFIX`)
#]==]
function (_vtk_module_apply_properties target)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_apply_properties
""
"BASENAME"
"")
if (_vtk_apply_properties_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for _vtk_module_apply_properties: "
"${_vtk_apply_properties_UNPARSED_ARGUMENTS}.")
endif ()
if (NOT DEFINED _vtk_apply_properties_BASENAME)
set(_vtk_apply_properties_BASENAME "${target}")
endif ()
get_property(_vtk_add_module_type
TARGET "${target}"
PROPERTY TYPE)
if (_vtk_add_module_type STREQUAL "OBJECT_LIBRARY" OR
_vtk_add_module_type STREQUAL "INTERFACE_LIBRARY")
return ()
endif ()
set(_vtk_add_module_library_name "${_vtk_apply_properties_BASENAME}")
get_property(_vtk_add_module_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_target_name")
if (_vtk_add_module_target_name STREQUAL "${target}")
get_property(_vtk_add_module_library_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
endif ()
set(_vtk_add_module_output_name "${_vtk_add_module_library_name}${_vtk_add_module_LIBRARY_NAME_SUFFIX}")
if (_vtk_build_LIBRARY_NAME_SUFFIX)
string(APPEND _vtk_add_module_output_name "-${_vtk_build_LIBRARY_NAME_SUFFIX}")
endif ()
set_target_properties("${target}"
PROPERTIES
OUTPUT_NAME "${_vtk_add_module_output_name}")
if (_vtk_build_VERSION AND NOT _vtk_add_module_type STREQUAL "EXECUTABLE")
set_target_properties("${target}"
PROPERTIES
VERSION "${_vtk_build_VERSION}")
endif ()
if (_vtk_build_SOVERSION)
set_target_properties("${target}"
PROPERTIES
SOVERSION "${_vtk_build_SOVERSION}")
endif ()
if (WIN32 AND NOT DEFINED CMAKE_DEBUG_POSTFIX)
set_target_properties("${target}"
PROPERTIES
DEBUG_POSTFIX "d")
endif ()
# rpath settings
if (NOT _vtk_add_module_type STREQUAL "EXECUTABLE")
set_property(TARGET "${target}"
PROPERTY
BUILD_RPATH_USE_ORIGIN 1)
if (UNIX)
if (APPLE)
set(_vtk_build_origin_rpath_prefix
"@loader_path")
else ()
set(_vtk_build_origin_rpath_prefix
"$ORIGIN")
endif ()
set_property(TARGET "${target}" APPEND
PROPERTY
INSTALL_RPATH "${_vtk_build_origin_rpath_prefix}")
endif ()
endif ()
endfunction ()
#[==[
@ingroup module-internal
@brief Install a module target
Install a target within the module context. Generally only useful to wrapping
code, modules that cannot use @ref vtk_module_add_module for some reason, or
modules which create utility targets that need installed.
~~~
_vtk_module_install(<target>)
~~~
This function uses the various installation options to @ref vtk_module_build
function to keep the install uniform.
#]==]
function (_vtk_module_install target)
set(_vtk_install_export)
if (_vtk_build_INSTALL_EXPORT)
list(APPEND _vtk_install_export
EXPORT "${_vtk_build_INSTALL_EXPORT}")
endif ()
set(_vtk_install_headers_component "${_vtk_build_HEADERS_COMPONENT}")
set(_vtk_install_targets_component "${_vtk_build_TARGETS_COMPONENT}")
if (_vtk_build_TARGET_SPECIFIC_COMPONENTS)
if (_vtk_build_kit)
string(PREPEND _vtk_install_headers_component "${_vtk_build_kit}-")
string(PREPEND _vtk_install_targets_component "${_vtk_build_kit}-")
else ()
string(PREPEND _vtk_install_headers_component "${_vtk_build_module}-")
string(PREPEND _vtk_install_targets_component "${_vtk_build_module}-")
if (_vtk_build_BUILD_WITH_KITS)
get_property(_vtk_install_kit GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_kit")
if (_vtk_install_kit)
set(_vtk_install_headers_component "${_vtk_install_kit}-${_vtk_build_HEADERS_COMPONENT}")
set(_vtk_install_targets_component "${_vtk_install_kit}-${_vtk_build_TARGETS_COMPONENT}")
endif ()
endif ()
endif ()
endif ()
install(
TARGETS "${target}"
${_vtk_install_export}
${ARGN}
ARCHIVE
DESTINATION "${_vtk_build_ARCHIVE_DESTINATION}"
COMPONENT "${_vtk_install_targets_component}"
LIBRARY
DESTINATION "${_vtk_build_LIBRARY_DESTINATION}"
COMPONENT "${_vtk_install_targets_component}"
NAMELINK_COMPONENT "${_vtk_build_HEADERS_COMPONENT}"
RUNTIME
DESTINATION "${_vtk_build_RUNTIME_DESTINATION}"
COMPONENT "${_vtk_install_targets_component}")
endfunction ()
#[==[
@ingroup module
@brief Create a module executable
Some modules may have associated executables with them. By using this function,
the target will be installed following the options given to the associated
@ref vtk_module_build command. Its name will also be changed according to the
`LIBRARY_NAME_SUFFIX` option.
~~~
vtk_module_add_executable(<name>
[NO_INSTALL]
[DEVELOPMENT]
[BASENAME <basename>]
<source>...)
~~~
If `NO_INSTALL` is specified, the executable will not be installed. If
`BASENAME` is given, it will be used as the name of the executable rather than
the target name.
If `DEVELOPMENT` is given, it marks the executable as a development tool and
will not be installed if `INSTALL_HEADERS` is not set for the associated
@ref vtk_module_build command.
If the executable being built is the module, its module properties are used
rather than `BASENAME`. In addition, the dependencies of the module will be
linked.
#]==]
function (vtk_module_add_executable name)
cmake_parse_arguments(PARSE_ARGV 1 _vtk_add_executable
"NO_INSTALL;DEVELOPMENT"
"BASENAME"
"")
if (NOT _vtk_add_executable_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"The ${name} executable must have at least one source file.")
endif ()
if (_vtk_add_executable_NO_INSTALL AND _vtk_add_executable_DEVELOPMENT)
message(FATAL_ERROR
"Both `NO_INSTALL` and `DEVELOPMENT` may not be specified.")
endif ()
set(_vtk_add_executable_target_name "${name}")
set(_vtk_add_executable_library_name "${name}")
if (name STREQUAL _vtk_build_module)
if (_vtk_add_executable_NO_INSTALL)
message(FATAL_ERROR
"The executable ${_vtk_build_module} module may not use `NO_INSTALL`.")
endif ()
if (DEFINED _vtk_add_executable_BASENAME)
message(FATAL_ERROR
"The executable ${_vtk_build_module} module may not pass `BASENAME` "
"when adding the executable; it is controlled via `LIBRARY_NAME` in "
"the associated `vtk.module` file.")
endif ()
get_property(_vtk_add_executable_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_target_name")
get_property(_vtk_add_executable_library_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
endif ()
if (_vtk_add_executable_DEVELOPMENT AND NOT _vtk_build_INSTALL_HEADERS)
set(_vtk_add_executable_NO_INSTALL ON)
endif ()
# Set up rpaths
set(CMAKE_BUILD_RPATH_USE_ORIGIN 1)
if (UNIX)
file(RELATIVE_PATH _vtk_add_executable_relpath
"/prefix/${_vtk_build_RUNTIME_DESTINATION}"
"/prefix/${_vtk_build_LIBRARY_DESTINATION}")
if (APPLE)
set(_vtk_add_executable_origin_rpath_prefix
"@executable_path")
else ()
set(_vtk_add_executable_origin_rpath_prefix
"$ORIGIN")
endif ()
list(APPEND CMAKE_INSTALL_RPATH
"${_vtk_add_executable_origin_rpath_prefix}/${_vtk_add_executable_relpath}")
endif ()
add_executable("${_vtk_add_executable_target_name}"
${_vtk_add_executable_UNPARSED_ARGUMENTS})
if (name STREQUAL _vtk_build_module AND NOT _vtk_add_executable_target_name STREQUAL _vtk_build_module)
add_executable("${_vtk_build_module}" ALIAS
"${_vtk_add_executable_target_name}")
endif ()
if (name STREQUAL _vtk_build_module)
get_property(_vtk_real_target_kit GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_kit")
if (_vtk_real_target_kit)
message(FATAL_ERROR
"Executable module ${_vtk_build_module} is declared to be part of a "
"kit; this is not possible.")
endif ()
get_property(_vtk_add_executable_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_depends")
get_property(_vtk_add_executable_private_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_private_depends")
target_link_libraries("${_vtk_add_executable_target_name}"
PUBLIC
${_vtk_add_executable_depends}
PRIVATE
${_vtk_add_executable_private_depends})
get_property(_vtk_add_executable_optional_depends GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_optional_depends")
foreach (_vtk_add_executable_optional_depend IN LISTS _vtk_add_executable_optional_depends)
string(REPLACE "::" "_" _vtk_add_executable_optional_depend_safe "${_vtk_add_executable_optional_depend}")
target_compile_definitions("${_vtk_add_executable_target_name}"
PRIVATE
"VTK_MODULE_ENABLE_${_vtk_add_executable_optional_depend_safe}=$<TARGET_EXISTS:{_vtk_add_executable_optional_depend}>")
endforeach ()
if (_vtk_module_warnings)
if (_vtk_add_executable_depends)
message(WARNING
"Executable module ${_vtk_build_module} has public dependencies; this "
"shouldn't be necessary.")
endif ()
endif ()
endif ()
if (_vtk_build_UTILITY_TARGET)
target_link_libraries("${_vtk_add_executable_target_name}"
PRIVATE
"${_vtk_build_UTILITY_TARGET}")
endif ()
set(_vtk_add_executable_property_args)
if (DEFINED _vtk_add_executable_BASENAME)
list(APPEND _vtk_add_executable_property_args
BASENAME "${_vtk_add_executable_BASENAME}")
endif ()
_vtk_module_apply_properties("${_vtk_add_executable_target_name}"
${_vtk_add_executable_property_args})
_vtk_module_standard_includes(TARGET "${_vtk_add_executable_target_name}")
if (NOT _vtk_add_executable_NO_INSTALL)
_vtk_module_install("${_vtk_add_executable_target_name}")
endif ()
endfunction ()
#[==[
@ingroup module
@brief Find a package
A wrapper around `find_package` that records information for use so that the
same targets may be found when finding this package.
Modules may need to find external dependencies. CMake often provides modules to
find these dependencies, but when imported targets are involved, these.need to
also be found from dependencies of the current project. Since the benefits of
imported targets greatly outweighs not using them, it is preferred to use them.
The module system provides the @ref vtk_module_find_package function in order
to extend `find_package` support to include finding the dependencies from an
install of the project.
~~~
vtk_module_find_package(
[PRIVATE] [CONFIG_MODE]
PACKAGE <package>
[VERSION <version>]
[COMPONENTS <component>...]
[OPTIONAL_COMPONENTS <component>...]
[FORWARD_VERSION_REQ <MAJOR|MINOR|PATCH|EXACT>]
[VERSION_VAR <variable>])
~~~
* `PACKAGE`: The name of the package to find.
* `VERSION`: The minimum version of the package that is required.
* `COMPONENTS`: Components of the package which are required.
* `OPTIONAL_COMPONENTS`: Components of the package which may be missing.
* `FORWARD_VERSION_REQ`: If provided, the found version will be promoted to
the minimum version required matching the given version scheme.
* `VERSION_VAR`: The variable to use as the provided version (defaults to
`<PACKAGE>_VERSION`). It may contain `@` in which case it will be
configured. This is useful for modules which only provide components of the
actual version number.
* `CONFIG_MODE`: If present, pass `CONFIG` to the underlying `find_package`
call.
* `PRIVATE`: The dependency should not be exported to the install.
The `PACKAGE` argument is the only required argument. The rest are optional.
Note that `PRIVATE` is *only* applicable for private dependencies on interface
targets (basically, header libraries) because some platforms require private
shared libraries dependencies to be present when linking dependent libraries
and executables as well. Such usages should additionally be used only via a
`$<BUILD_INTERFACE>` generator expression to avoid putting the target name into
the install tree at all.
#]==]
macro (vtk_module_find_package)
# This needs to be a macro because find modules typically set variables which
# may need to be available in the calling scope. If we declare that it only
# works with imported targets (which is the primary motivating factor behind
# this function), we can instead make it a function at the cost of any
# non-target variables a module might want to set being available. It is
# unlikely that this will be the case for all callers.
if (NOT _vtk_build_module)
message(FATAL_ERROR
"`vtk_module_find_package` may only be called when building a VTK "
"module.")
endif ()
# Note: when adding arguments here, add them to the `unset` block at the end
# of the function.
cmake_parse_arguments(_vtk_find_package
"PRIVATE;CONFIG_MODE"
"PACKAGE;VERSION;FORWARD_VERSION_REQ;VERSION_VAR"
"COMPONENTS;OPTIONAL_COMPONENTS"
${ARGN})
if (_vtk_find_package_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_find_package: "
"${_vtk_find_package_UNPARSED_ARGUMENTS}")
endif ()
if (NOT DEFINED _vtk_find_package_PACKAGE)
message(FATAL_ERROR
"The `PACKAGE` argument is required.")
endif ()
if (DEFINED _vtk_find_package_FORWARD_VERSION_REQ)
if (_vtk_find_package_PRIVATE)
message(FATAL_ERROR
"The `FORWARD_VERSION_REQ` argument is incompatible with the "
"`PRIVATE` flag.")
endif ()
if (NOT _vtk_find_package_FORWARD_VERSION_REQ STREQUAL "MAJOR" AND
NOT _vtk_find_package_FORWARD_VERSION_REQ STREQUAL "MINOR" AND
NOT _vtk_find_package_FORWARD_VERSION_REQ STREQUAL "PATCH" AND
NOT _vtk_find_package_FORWARD_VERSION_REQ STREQUAL "EXACT")
message(FATAL_ERROR
"The `FORWARD_VERSION_REQ` argument must be one of `MAJOR`, `MINOR`, "
"`PATCH`, or `EXACT`.")
endif ()
endif ()
if (NOT DEFINED _vtk_find_package_VERSION_VAR)
set(_vtk_find_package_VERSION_VAR
"${_vtk_find_package_PACKAGE}_VERSION")
endif ()
set(_vtk_find_package_config)
if (_vtk_find_package_CONFIG_MODE)
set(_vtk_find_package_config "CONFIG")
endif ()
find_package("${_vtk_find_package_PACKAGE}"
${_vtk_find_package_VERSION}
${_vtk_find_package_config}
COMPONENTS ${_vtk_find_package_COMPONENTS}
OPTIONAL_COMPONENTS ${_vtk_find_package_OPTIONAL_COMPONENTS})
if (NOT ${_vtk_find_package_PACKAGE}_FOUND)
message(FATAL_ERROR
"Could not find the ${_vtk_find_package_PACKAGE} external dependency.")
return ()
endif ()
set(_vtk_find_package_optional_components_found)
foreach (_vtk_find_package_optional_component IN LISTS _vtk_find_package_OPTIONAL_COMPONENTS)
if (${_vtk_find_package_PACKAGE}_${_vtk_find_package_optional_component}_FOUND)
list(APPEND _vtk_find_package_optional_components_found
"${_vtk_find_package_optional_component}")
endif ()
endforeach ()
set_property(GLOBAL APPEND
PROPERTY
"_vtk_module_find_packages_${_vtk_build_PACKAGE}" "${_vtk_find_package_PACKAGE}")
set(_vtk_find_package_base "_vtk_module_find_package_${_vtk_build_module}")
set_property(GLOBAL APPEND
PROPERTY
"${_vtk_find_package_base}" "${_vtk_find_package_PACKAGE}")
set(_vtk_find_package_base_package "${_vtk_find_package_base}_${_vtk_find_package_PACKAGE}")
set_property(GLOBAL
PROPERTY
"${_vtk_find_package_base_package}_private" "${_vtk_find_package_PRIVATE}")
set_property(GLOBAL
PROPERTY
"${_vtk_find_package_base_package}_version" "${_vtk_find_package_VERSION}")
set_property(GLOBAL
PROPERTY
"${_vtk_find_package_base_package}_config" "${_vtk_find_package_CONFIG_MODE}")
set_property(GLOBAL APPEND
PROPERTY
"${_vtk_find_package_base_package}_components" "${_vtk_find_package_COMPONENTS}")
set_property(GLOBAL APPEND
PROPERTY
"${_vtk_find_package_base_package}_optional_components" "${_vtk_find_package_OPTIONAL_COMPONENTS}")
set_property(GLOBAL APPEND
PROPERTY
"${_vtk_find_package_base_package}_optional_components_found" "${_vtk_find_package_optional_components_found}")
set_property(GLOBAL
PROPERTY
"${_vtk_find_package_base_package}_exact" "0")
if (DEFINED _vtk_find_package_FORWARD_VERSION_REQ)
string(FIND "${_vtk_find_package_VERSION_VAR}" "@" _vtk_find_package_idx)
if (_vtk_find_package_idx EQUAL -1)
if (NOT DEFINED "${_vtk_find_package_VERSION_VAR}")
message(FATAL_ERROR
"The `${_vtk_find_package_VERSION_VAR}` variable is not defined.")
endif ()
set(_vtk_find_package_version "${${_vtk_find_package_VERSION_VAR}}")
else ()
string(CONFIGURE "${_vtk_find_package_VERSION_VAR}" _vtk_find_package_version)
endif ()
unset(_vtk_find_package_idx)
if ("${_vtk_find_package_version}" STREQUAL "")
message(FATAL_ERROR
"The `${_vtk_find_package_PACKAGE}` version is empty.")
endif ()
if (_vtk_find_package_FORWARD_VERSION_REQ STREQUAL "MAJOR")
set(_vtk_find_package_version_regex "^\([^.]*\).*")
elseif (_vtk_find_package_FORWARD_VERSION_REQ STREQUAL "MINOR")
set(_vtk_find_package_version_regex "^\([^.]*.[^.]*\).*")
elseif (_vtk_find_package_FORWARD_VERSION_REQ STREQUAL "PATCH")
set(_vtk_find_package_version_regex "^\([^.]*.[^.]*.[^.]*\).*")
elseif (_vtk_find_package_FORWARD_VERSION_REQ STREQUAL "EXACT")
set(_vtk_find_package_version_regex "^\\(.*\\)$")
set_property(GLOBAL
PROPERTY
"${_vtk_find_package_base_package}_exact" "1")
endif ()
string(REGEX REPLACE "${_vtk_find_package_version_regex}" "\\1"
_vtk_find_package_found_version "${_vtk_find_package_version}")
unset(_vtk_find_package_version_regex)
unset(_vtk_find_package_version)
set_property(GLOBAL
PROPERTY
"${_vtk_find_package_base_package}_version" "${_vtk_find_package_found_version}")
unset(_vtk_find_package_found_version)
endif ()
unset(_vtk_find_package_base)
unset(_vtk_find_package_base_package)
unset(_vtk_find_package_COMPONENTS)
unset(_vtk_find_package_FORWARD_VERSION_REQ)
unset(_vtk_find_package_OPTIONAL_COMPONENTS)
unset(_vtk_find_package_PACKAGE)
unset(_vtk_find_package_PRIVATE)
unset(_vtk_find_package_UNPARSED_ARGUMENTS)
unset(_vtk_find_package_VERSION)
unset(_vtk_find_package_VERSION_VAR)
endmacro ()
#[==[
@ingroup module
@brief Export find_package calls for dependencies
When installing a project that is meant to be found via `find_package` from
CMake, using imported targets in the build means that imported targets need to
be created during the `find_package` as well. This function writes a file
suitable for inclusion from a `<package>-config.cmake` file to satisfy
dependencies. It assumes that the exported targets are named
`${CMAKE_FIND_PACKAGE_NAME}::${component}`. Dependent packages will only be
found if a requested component requires the package to be found either directly
or transitively.
~~~
vtk_module_export_find_packages(
CMAKE_DESTINATION <directory>
FILE_NAME <filename>
[COMPONENT <component>]
MODULES <module>...)
~~~
The file will be named according to the `FILE_NAME` argument will be installed
into `CMAKE_DESTINATION` in the build and install trees with the given
filename. If not provided, the `development` component will be used.
The `vtk_module_find_package` calls made by the modules listed in `MODULES`
will be exported to this file.
#]==]
function (vtk_module_export_find_packages)
cmake_parse_arguments(PARSE_ARGV 0 _vtk_export
""
"CMAKE_DESTINATION;FILE_NAME;COMPONENT"
"MODULES")
if (_vtk_export_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_export_find_packages: "
"${_vtk_export_UNPARSED_ARGUMENTS}")
endif ()
if (NOT DEFINED _vtk_export_CMAKE_DESTINATION)
message(FATAL_ERROR
"The `CMAKE_DESTINATION` is required.")
endif ()
if (NOT DEFINED _vtk_export_FILE_NAME)
message(FATAL_ERROR
"The `FILE_NAME` is required.")
endif ()
if (NOT DEFINED _vtk_export_COMPONENT)
set(_vtk_export_COMPONENT "development")
endif ()
set(_vtk_export_prelude
"set(_vtk_module_find_package_quiet)
if (\${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
set(_vtk_module_find_package_quiet QUIET)
endif ()
set(_vtk_module_find_package_components_checked)
set(_vtk_module_find_package_components_to_check
\${\${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS})
set(_vtk_module_find_package_components)
set(_vtk_module_find_package_components_required)
while (_vtk_module_find_package_components_to_check)
list(GET _vtk_module_find_package_components_to_check 0 _vtk_module_component)
list(REMOVE_AT _vtk_module_find_package_components_to_check 0)
if (_vtk_module_component IN_LIST _vtk_module_find_package_components_checked)
continue ()
endif ()
list(APPEND _vtk_module_find_package_components_checked
\"\${_vtk_module_component}\")
list(APPEND _vtk_module_find_package_components
\"\${_vtk_module_component}\")
if (\${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_\${_vtk_module_component})
list(APPEND _vtk_module_find_package_components_required
\"\${_vtk_module_component}\")
endif ()
if (TARGET \"\${CMAKE_FIND_PACKAGE_NAME}::\${_vtk_module_component}\")
set(_vtk_module_find_package_component_target \"\${CMAKE_FIND_PACKAGE_NAME}::\${_vtk_module_component}\")
elseif (TARGET \"\${_vtk_module_component}\")
set(_vtk_module_find_package_component_target \"\${_vtk_module_component}\")
else ()
# No such target for the component; skip.
continue ()
endif ()
get_property(_vtk_module_find_package_depends
TARGET \"\${_vtk_module_find_package_component_target}\"
PROPERTY \"INTERFACE_vtk_module_depends\")
string(REPLACE \"\${CMAKE_FIND_PACKAGE_NAME}::\" \"\" _vtk_module_find_package_depends \"\${_vtk_module_find_package_depends}\")
list(APPEND _vtk_module_find_package_components_to_check
\${_vtk_module_find_package_depends})
get_property(_vtk_module_find_package_depends
TARGET \"\${_vtk_module_find_package_component_target}\"
PROPERTY \"INTERFACE_vtk_module_private_depends\")
string(REPLACE \"\${CMAKE_FIND_PACKAGE_NAME}::\" \"\" _vtk_module_find_package_depends \"\${_vtk_module_find_package_depends}\")
list(APPEND _vtk_module_find_package_components_to_check
\${_vtk_module_find_package_depends})
get_property(_vtk_module_find_package_depends
TARGET \"\${_vtk_module_find_package_component_target}\"
PROPERTY \"INTERFACE_vtk_module_optional_depends\")
foreach (_vtk_module_find_package_depend IN LISTS _vtk_module_find_package_depends)
if (TARGET \"\${_vtk_module_find_package_depend}\")
string(REPLACE \"\${CMAKE_FIND_PACKAGE_NAME}::\" \"\" _vtk_module_find_package_depend \"\${_vtk_module_find_package_depend}\")
list(APPEND _vtk_module_find_package_components_to_check
\"\${_vtk_module_find_package_depend}\")
endif ()
endforeach ()
get_property(_vtk_module_find_package_depends
TARGET \"\${_vtk_module_find_package_component_target}\"
PROPERTY \"INTERFACE_vtk_module_forward_link\")
string(REPLACE \"\${CMAKE_FIND_PACKAGE_NAME}::\" \"\" _vtk_module_find_package_depends \"\${_vtk_module_find_package_depends}\")
list(APPEND _vtk_module_find_package_components_to_check
\${_vtk_module_find_package_depends})
get_property(_vtk_module_find_package_kit
TARGET \"\${_vtk_module_find_package_component_target}\"
PROPERTY \"INTERFACE_vtk_module_kit\")
if (_vtk_module_find_package_kit)
get_property(_vtk_module_find_package_kit_modules
TARGET \"\${_vtk_module_find_package_kit}\"
PROPERTY \"INTERFACE_vtk_kit_kit_modules\")
string(REPLACE \"\${CMAKE_FIND_PACKAGE_NAME}::\" \"\" _vtk_module_find_package_kit_modules \"\${_vtk_module_find_package_kit_modules}\")
list(APPEND _vtk_module_find_package_components_to_check
\${_vtk_module_find_package_kit_modules})
endif ()
endwhile ()
unset(_vtk_module_find_package_component_target)
unset(_vtk_module_find_package_components_to_check)
unset(_vtk_module_find_package_components_checked)
unset(_vtk_module_component)
unset(_vtk_module_find_package_depend)
unset(_vtk_module_find_package_depends)
unset(_vtk_module_find_package_kit)
unset(_vtk_module_find_package_kit_modules)
if (_vtk_module_find_package_components)
list(REMOVE_DUPLICATES _vtk_module_find_package_components)
endif ()
if (_vtk_module_find_package_components_required)
list(REMOVE_DUPLICATES _vtk_module_find_package_components_required)
endif ()\n\n")
set(_vtk_export_build_content)
set(_vtk_export_install_content)
foreach (_vtk_export_module IN LISTS _vtk_export_MODULES)
get_property(_vtk_export_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_export_module}_target_name")
# Use the export name of the target if it has one set.
get_property(_vtk_export_target_has_export_name
TARGET "${_vtk_export_target_name}"
PROPERTY EXPORT_NAME SET)
if (_vtk_export_target_has_export_name)
get_property(_vtk_export_target_name
TARGET "${_vtk_export_target_name}"
PROPERTY EXPORT_NAME)
endif ()
set(_vtk_export_base "_vtk_module_find_package_${_vtk_export_module}")
get_property(_vtk_export_packages GLOBAL
PROPERTY "${_vtk_export_base}")
if (NOT _vtk_export_packages)
continue ()
endif ()
set(_vtk_export_module_prelude
"set(_vtk_module_find_package_enabled OFF)
set(_vtk_module_find_package_is_required OFF)
set(_vtk_module_find_package_fail_if_not_found OFF)
if (_vtk_module_find_package_components)
if (\"${_vtk_export_target_name}\" IN_LIST _vtk_module_find_package_components)
set(_vtk_module_find_package_enabled ON)
if (\"${_vtk_export_target_name}\" IN_LIST _vtk_module_find_package_components_required)
set(_vtk_module_find_package_is_required \"\${\${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED}\")
set(_vtk_module_find_package_fail_if_not_found ON)
endif ()
endif ()
else ()
set(_vtk_module_find_package_enabled ON)
set(_vtk_module_find_package_is_required \"\${\${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED}\")
set(_vtk_module_find_package_fail_if_not_found ON)
endif ()
if (_vtk_module_find_package_enabled)
set(_vtk_module_find_package_required)
if (_vtk_module_find_package_is_required)
set(_vtk_module_find_package_required REQUIRED)
endif ()\n\n")
list(REMOVE_DUPLICATES _vtk_export_packages)
set(_vtk_export_module_build_content)
set(_vtk_export_module_install_content)
foreach (_vtk_export_package IN LISTS _vtk_export_packages)
set(_vtk_export_base_package "${_vtk_export_base}_${_vtk_export_package}")
get_property(_vtk_export_private GLOBAL
PROPERTY "${_vtk_export_base_package}_private")
get_property(_vtk_export_version GLOBAL
PROPERTY "${_vtk_export_base_package}_version")
get_property(_vtk_export_config GLOBAL
PROPERTY "${_vtk_export_base_package}_config")
get_property(_vtk_export_exact GLOBAL
PROPERTY "${_vtk_export_base_package}_exact")
get_property(_vtk_export_components GLOBAL
PROPERTY "${_vtk_export_base_package}_components")
get_property(_vtk_export_optional_components GLOBAL
PROPERTY "${_vtk_export_base_package}_optional_components")
get_property(_vtk_export_optional_components_found GLOBAL
PROPERTY "${_vtk_export_base_package}_optional_components_found")
# Assume that any found optional components end up being required.
if (${_vtk_export_base_package}_optional_components_found)
list(REMOVE_ITEM _vtk_export_optional_components
${_vtk_export_optional_components_found})
list(APPEND _vtk_export_components
${_vtk_export_optional_components_found})
endif ()
set(_vtk_export_config_arg)
if (_vtk_export_config)
set(_vtk_export_config_arg CONFIG)
endif ()
set(_vtk_export_exact_arg)
if (_vtk_export_exact)
set(_vtk_export_exact_arg EXACT)
endif ()
set(_vtk_export_module_content
" find_package(${_vtk_export_package}
${_vtk_export_version}
${_vtk_export_exact_arg}
${_vtk_export_config_arg}
\${_vtk_module_find_package_quiet}
\${_vtk_module_find_package_required}
COMPONENTS ${_vtk_export_components}
OPTIONAL_COMPONENTS ${_vtk_export_optional_components})
if (NOT ${_vtk_export_package}_FOUND AND _vtk_module_find_package_fail_if_not_found)
if (NOT \${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
message(STATUS
\"Could not find the \${CMAKE_FIND_PACKAGE_NAME} package due to a \"
\"missing dependency: ${_vtk_export_package}\")
endif ()
set(\"\${CMAKE_FIND_PACKAGE_NAME}_${_vtk_export_target_name}_FOUND\" 0)
list(APPEND \"\${CMAKE_FIND_PACKAGE_NAME}_${_vtk_export_target_name}_NOT_FOUND_MESSAGE\"
\"Failed to find the ${_vtk_export_package} package.\")
endif ()\n")
string(APPEND _vtk_export_module_build_content "${_vtk_export_module_content}")
# Private usages should be guarded by `$<BUILD_INTERFACE>` and can be
# skipped for the install tree regardless of the build mode.
if (NOT _vtk_export_private)
string(APPEND _vtk_export_module_install_content "${_vtk_export_module_content}")
endif ()
endforeach ()
set(_vtk_export_module_trailer
"endif ()
unset(_vtk_module_find_package_fail_if_not_found)
unset(_vtk_module_find_package_enabled)
unset(_vtk_module_find_package_required)\n\n")
if (_vtk_export_module_build_content)
string(APPEND _vtk_export_build_content
"${_vtk_export_module_prelude}${_vtk_export_module_build_content}${_vtk_export_module_trailer}")
endif ()
if (_vtk_export_module_install_content)
string(APPEND _vtk_export_install_content
"${_vtk_export_module_prelude}${_vtk_export_module_install_content}${_vtk_export_module_trailer}")
endif ()
endforeach ()
set(_vtk_export_trailer
"unset(_vtk_module_find_package_components)
unset(_vtk_module_find_package_components_required)
unset(_vtk_module_find_package_quiet)\n")
set(_vtk_export_build_file
"${CMAKE_BINARY_DIR}/${_vtk_export_CMAKE_DESTINATION}/${_vtk_export_FILE_NAME}")
set(_vtk_export_install_file
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_vtk_export_FILE_NAME}.install")
if (_vtk_export_build_content)
file(WRITE "${_vtk_export_build_file}"
"${_vtk_export_prelude}${_vtk_export_build_content}${_vtk_export_trailer}")
else ()
file(WRITE "${_vtk_export_build_file}" "")
endif ()
if (_vtk_export_install_content)
file(WRITE "${_vtk_export_install_file}"
"${_vtk_export_prelude}${_vtk_export_install_content}${_vtk_export_trailer}")
else ()
file(WRITE "${_vtk_export_install_file}" "")
endif ()
install(
FILES "${_vtk_export_install_file}"
DESTINATION "${_vtk_export_CMAKE_DESTINATION}"
RENAME "${_vtk_export_FILE_NAME}"
COMPONENT "${_vtk_export_COMPONENT}")
endfunction ()
#[==[
@page module-overview
@ingroup module
@section module-third-party Third party support
The module system acknowledges that third party support is a pain and offers
APIs to help wrangle them. Sometimes third party code needs a shim introduced
to make it behave better, so an `INTERFACE` library to add that in is very
useful. Other times, third party code is hard to ensure that it exists
everywhere, so it is bundled. When that happens, the ability to select between
the bundled copy and an external copy is useful. All three (and more) of these
are possible.
The following functions are used to handle third party modules:
- @ref vtk_module_third_party
- @ref vtk_module_third_party_external
- @ref vtk_module_third_party_internal
#]==]
#[==[
@ingroup module
@brief Third party module
When a project has modules which represent third party packages, there are some
convenience functions to help deal with them. First, there is the meta-wrapper:
~~~
vtk_module_third_party(
[INTERNAL <internal arguments>...]
[EXTERNAL <external arguments>...])
~~~
This offers a cache variable named `VTK_MODULE_USE_EXTERNAL_<module name>` that
may be set to trigger between the internal copy and an externally provided
copy. This is available as a local variable named
`VTK_MODULE_USE_EXTERNAL_<library name>`. See the
@ref vtk_module_third_party_external and @ref vtk_module_third_party_internal
functions for the arguments supported by the `EXTERNAL` and `INTERNAL`
arguments, respectively.
#]==]
function (vtk_module_third_party)
cmake_parse_arguments(PARSE_ARGV 0 _vtk_third_party
""
""
"INTERNAL;EXTERNAL")
if (_vtk_third_party_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_third_party: "
"${_vtk_third_party_UNPARSED_ARGUMENTS}")
endif ()
string(REPLACE "::" "_" _vtk_build_module_safe "${_vtk_build_module}")
option("VTK_MODULE_USE_EXTERNAL_${_vtk_build_module_safe}"
"Use externally provided ${_vtk_build_module}"
"${_vtk_build_USE_EXTERNAL}")
mark_as_advanced("VTK_MODULE_USE_EXTERNAL_${_vtk_build_module_safe}")
get_property(_vtk_third_party_library_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
set("VTK_MODULE_USE_EXTERNAL_${_vtk_third_party_library_name}"
"${VTK_MODULE_USE_EXTERNAL_${_vtk_build_module_safe}}"
PARENT_SCOPE)
if (VTK_MODULE_USE_EXTERNAL_${_vtk_build_module_safe})
vtk_module_third_party_external(${_vtk_third_party_EXTERNAL})
# Bubble up variables again.
foreach (_vtk_third_party_variable IN LISTS _vtk_third_party_variables)
set("${_vtk_third_party_variable}"
"${${_vtk_third_party_variable}}"
PARENT_SCOPE)
endforeach ()
else ()
set(_vtk_third_party_has_external_support 1)
vtk_module_third_party_internal(${_vtk_third_party_INTERNAL})
endif ()
endfunction ()
#[==[
@ingroup module-impl
@brief Mark a module as being third party
Mark a module as being a third party module.
~~~
_vtk_module_mark_third_party(<target>)
~~~
#]==]
function (_vtk_module_mark_third_party target)
# TODO: `_vtk_module_set_module_property` instead.
set_target_properties("${target}"
PROPERTIES
"INTERFACE_vtk_module_exclude_wrap" 1
"INTERFACE_vtk_module_third_party" 1)
endfunction ()
#[==[
@ingroup module
@brief External third party package
A third party dependency may be expressed as a module using this function.
Third party packages are found using CMake's `find_package` function. It is
highly recommended that imported targets are used to make usage easier. The
module itself will be created as an `INTERFACE` library which exposes the
package.
~~~
vtk_module_third_party_external(
PACKAGE <package>
[VERSION <version>]
[COMPONENTS <component>...]
[OPTIONAL_COMPONENTS <component>...]
[TARGETS <target>...]
[INCLUDE_DIRS <path-or-variable>...]
[LIBRARIES <target-or-variable>...]
[DEFINITIONS <variable>...]
[FORWARD_VERSION_REQ <MAJOR|MINOR|PATCH|EXACT>]
[VERSION_VAR <version-spec>]
[USE_VARIABLES <variable>...]
[CONFIG_MODE]
[STANDARD_INCLUDE_DIRS])
~~~
Only the `PACKAGE` argument is required. The arguments are as follows:
* `PACKAGE`: (Required) The name of the package to find.
* `VERSION`: If specified, the minimum version of the dependency that must be
found.
* `COMPONENTS`: The list of components to request from the package.
* `OPTIONAL_COMPONENTS`: The list of optional components to request from the
package.
* `TARGETS`: The list of targets to search for when using this package.
Targets which do not exist will be ignored to support different versions of
a package using different target names.
* `STANDARD_INCLUDE_DIRS`: If present, standard include directories will be
added to the module target. This is usually only required if both internal
and external are supported for a given dependency.
* `INCLUDE_DIRS`: If specified, this is added as a `SYSTEM INTERFACE` include
directory for the target. If a variable name is given, it will be
dereferenced.
* `LIBRARIES`: The libraries to link from the package. If a variable name is
given, it will be dereferenced, however a warning that imported targets are
not being used will be emitted.
* `DEFINITIONS`: If specified, the given variables will be added to the
target compile definitions interface.
* `CONFIG_MODE`: Force `CONFIG` mode.
* `FORWARD_VERSION_REQ` and `VERSION_VAR`: See documentation for
@ref vtk_module_find_package.
* `USE_VARIABLES`: List of variables from the `find_package` to make
available to the caller.
#]==]
function (vtk_module_third_party_external)
cmake_parse_arguments(PARSE_ARGV 0 _vtk_third_party_external
"STANDARD_INCLUDE_DIRS;CONFIG_MODE"
"VERSION;PACKAGE;FORWARD_VERSION_REQ;VERSION_VAR"
"COMPONENTS;OPTIONAL_COMPONENTS;LIBRARIES;INCLUDE_DIRS;DEFINITIONS;TARGETS;USE_VARIABLES")
if (_vtk_third_party_external_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_third_party_external: "
"${_vtk_third_party_external_UNPARSED_ARGUMENTS}")
endif ()
get_property(_vtk_third_party_external_is_third_party GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_third_party")
if (NOT _vtk_third_party_external_is_third_party)
message(FATAL_ERROR
"The ${_vtk_build_module} has not been declared as a third party "
"module.")
endif ()
if (NOT DEFINED _vtk_third_party_external_PACKAGE)
message(FATAL_ERROR
"The `PACKAGE` argument is required.")
endif ()
set(_vtk_third_party_external_args)
if (DEFINED _vtk_third_party_external_FORWARD_VERSION_REQ)
list(APPEND _vtk_third_party_external_args
FORWARD_VERSION_REQ "${_vtk_third_party_external_FORWARD_VERSION_REQ}")
endif ()
if (DEFINED _vtk_third_party_external_VERSION_VAR)
list(APPEND _vtk_third_party_external_args
VERSION_VAR "${_vtk_third_party_external_VERSION_VAR}")
endif ()
if (_vtk_third_party_external_TARGETS)
set(_vtk_third_party_external_config_mode)
if (_vtk_third_party_external_CONFIG_MODE)
set(_vtk_third_party_external_config_mode "CONFIG_MODE")
endif ()
# If we have targets, they must be exported to the install as well.
vtk_module_find_package(
PACKAGE "${_vtk_third_party_external_PACKAGE}"
VERSION "${_vtk_third_party_external_VERSION}"
COMPONENTS ${_vtk_third_party_external_COMPONENTS}
OPTIONAL_COMPONENTS ${_vtk_third_party_external_OPTIONAL_COMPONENTS}
${_vtk_third_party_external_config_mode}
${_vtk_third_party_external_args})
else ()
set(_vtk_third_party_external_config)
if (_vtk_third_party_external_CONFIG_MODE)
set(_vtk_third_party_external_config "CONFIG")
endif ()
# If there are no targets, the install uses strings and therefore does not
# need to find the dependency again.
find_package("${_vtk_third_party_external_PACKAGE}"
${_vtk_third_party_external_VERSION}
${_vtk_third_party_external_config}
COMPONENTS ${_vtk_third_party_external_COMPONENTS}
OPTIONAL_COMPONENTS ${_vtk_third_party_external_OPTIONAL_COMPONENTS})
endif ()
get_property(_vtk_third_party_external_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_target_name")
# Check if an imported target of the same name already exists.
set(_vtk_third_party_external_real_target_name
"${_vtk_third_party_external_target_name}")
set(_vtk_third_party_external_using_mangled_name OFF)
if (TARGET "${_vtk_third_party_external_target_name}")
# Ensure that the target collision comes from an imported target.
get_property(_vtk_third_party_external_is_imported
TARGET "${_vtk_third_party_external_target_name}"
PROPERTY IMPORTED)
if (NOT _vtk_third_party_external_is_imported)
message(FATAL_ERROR
"It appears as though there is a conflicting target named "
"`${_vtk_third_party_external_target_name}` expected to be used by "
"the `${_vtk_build_module}` module already added to the build. This "
"conflicts with the target name expected to be used by an external "
"third party dependency.")
endif ()
# If it does, we need to have a module name that is not the same as this
# one. Error out if this is detected.
if (_vtk_build_module STREQUAL _vtk_third_party_external_target_name)
message(FATAL_ERROR
"An imported target has the same name used by the module system for "
"the facade of the external dependency for `${_vtk_build_module}`. "
"This module must be either renamed or placed into a namespace.")
endif ()
# Mangle the internal name. The alias is the expected use case anyways and
# since this is an INTERFACE target, there's nothing to break with respect
# to `make $target` anyways.
string(APPEND _vtk_third_party_external_real_target_name
"_vtk_module_mangle")
set_property(GLOBAL APPEND_STRING
PROPERTY "_vtk_module_${_vtk_build_module}_target_name"
"_vtk_module_mangle")
set(_vtk_third_party_external_using_mangled_name ON)
endif ()
add_library("${_vtk_third_party_external_real_target_name}" INTERFACE)
if (_vtk_third_party_external_using_mangled_name)
set_property(TARGET "${_vtk_third_party_external_real_target_name}"
PROPERTY
EXPORT_NAME "${_vtk_third_party_external_target_name}")
endif ()
if (NOT _vtk_build_module STREQUAL _vtk_third_party_external_target_name)
add_library("${_vtk_build_module}" ALIAS
"${_vtk_third_party_external_real_target_name}")
endif ()
if (_vtk_third_party_external_STANDARD_INCLUDE_DIRS)
_vtk_module_standard_includes(TARGET "${_vtk_third_party_external_real_target_name}"
SYSTEM INTERFACE)
endif ()
# Try to use targets if they're specified and available.
set(_vtk_third_party_external_have_targets FALSE)
set(_vtk_third_party_external_used_targets FALSE)
if (_vtk_third_party_external_TARGETS)
set(_vtk_third_party_external_have_targets TRUE)
foreach (_vtk_third_party_external_target IN LISTS _vtk_third_party_external_TARGETS)
if (TARGET "${_vtk_third_party_external_target}")
target_link_libraries("${_vtk_third_party_external_real_target_name}"
INTERFACE
"${_vtk_third_party_external_target}")
set(_vtk_third_party_external_used_targets TRUE)
endif ()
endforeach ()
endif ()
if (NOT _vtk_third_party_external_used_targets)
if (NOT _vtk_third_party_external_have_targets)
message(WARNING
"A third party dependency for ${_vtk_build_module} was found externally "
"using paths rather than targets; it is recommended to use imported "
"targets rather than find_library and such.")
endif ()
set(_vtk_third_party_external_have_includes FALSE)
foreach (_vtk_third_party_external_include_dir IN LISTS _vtk_third_party_external_INCLUDE_DIRS)
if (DEFINED "${_vtk_third_party_external_include_dir}")
if (${_vtk_third_party_external_include_dir})
set(_vtk_third_party_external_have_includes TRUE)
endif ()
target_include_directories("${_vtk_third_party_external_real_target_name}" SYSTEM
INTERFACE "${${_vtk_third_party_external_include_dir}}")
endif ()
endforeach ()
if (_vtk_third_party_external_have_targets AND
NOT _vtk_third_party_external_have_includes)
message(WARNING
"A third party dependency for ${_vtk_build_module} has external targets "
"which were not found and no `INCLUDE_DIRS` were found either. "
"Including this module may not work.")
endif ()
foreach (_vtk_third_party_external_define IN LISTS _vtk_third_party_external_DEFINITIONS)
if (DEFINED "${_vtk_third_party_external_define}")
target_compile_definitions("${_vtk_third_party_external_real_target_name}"
INTERFACE "${${_vtk_third_party_external_define}}")
endif ()
endforeach ()
set(_vtk_third_party_external_have_libraries FALSE)
foreach (_vtk_third_party_external_library IN LISTS _vtk_third_party_external_LIBRARIES)
if (DEFINED "${_vtk_third_party_external_library}")
if (${_vtk_third_party_external_library})
set(_vtk_third_party_external_have_libraries TRUE)
endif ()
target_link_libraries("${_vtk_third_party_external_real_target_name}"
INTERFACE "${${_vtk_third_party_external_library}}")
endif ()
endforeach ()
if (_vtk_third_party_external_have_targets AND
NOT _vtk_third_party_external_have_libraries)
message(WARNING
"A third party dependency for ${_vtk_build_module} has external targets "
"which were not found and no `LIBRARIES` were found either. Linking to "
"this this module may not work.")
endif ()
endif ()
if (DEFINED _vtk_third_party_external_USE_VARIABLES)
# If we're called from `vtk_module_third_party`, the variables need bubbled
# up again.
if (DEFINED _vtk_third_party_EXTERNAL)
set(_vtk_third_party_variables
"${_vtk_third_party_external_USE_VARIABLES}"
PARENT_SCOPE)
endif ()
foreach (_vtk_third_party_external_variable IN LISTS _vtk_third_party_external_USE_VARIABLES)
if (NOT DEFINED "${_vtk_third_party_external_variable}")
message(FATAL_ERROR
"The variable `${_vtk_third_party_external_variable}` was expected "
"to have been available, but was not defined.")
endif ()
set("${_vtk_third_party_external_variable}"
"${${_vtk_third_party_external_variable}}"
PARENT_SCOPE)
endforeach ()
endif ()
_vtk_module_mark_third_party("${_vtk_third_party_external_real_target_name}")
_vtk_module_install("${_vtk_third_party_external_real_target_name}")
endfunction ()
#[==[
@ingroup module
@brief Internal third party package
Third party modules may also be bundled with the project itself. In this case,
it is an internal third party dependency. The dependency is assumed to be in a
subdirectory that will be used via `add_subdirectory`. Unless it is marked as
`HEADERS_ONLY`, it is assumed that it will create a target with the name of the
module.
~~~
vtk_module_third_party_internal(
[SUBDIRECTORY <path>]
[HEADERS_SUBDIR <subdir>]
[LICENSE_FILES <file>...]
[VERSION <version>]
[HEADER_ONLY]
[INTERFACE]
[STANDARD_INCLUDE_DIRS])
~~~
All arguments are optional, however warnings are emitted if `LICENSE_FILES` or
`VERSION` is not specified. They are as follows:
* `SUBDIRECTORY`: (Defaults to the library name of the module) The
subdirectory containing the `CMakeLists.txt` for the dependency.
* `HEADERS_SUBDIR`: If non-empty, the subdirectory to use for installing
headers.
* `LICENSE_FILES`: A list of license files to install for the dependency. If
not given, a warning will be emitted.
* `VERSION`: The version of the library that is included.
* `HEADER_ONLY`: The dependency is header only and will not create a target.
* `INTERFACE`: The dependency is an `INTERFACE` library.
* `STANDARD_INCLUDE_DIRS`: If present, module-standard include directories
will be added to the module target.
#]==]
function (vtk_module_third_party_internal)
# TODO: Support scanning for third-party modules which don't support an
# external copy.
cmake_parse_arguments(PARSE_ARGV 0 _vtk_third_party_internal
"INTERFACE;HEADER_ONLY;STANDARD_INCLUDE_DIRS"
"SUBDIRECTORY;HEADERS_SUBDIR;VERSION"
"LICENSE_FILES")
if (_vtk_third_party_internal_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for vtk_module_third_party_internal: "
"${_vtk_third_party_internal_UNPARSED_ARGUMENTS}")
endif ()
get_property(_vtk_third_party_internal_is_third_party GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_third_party")
if (NOT _vtk_third_party_internal_is_third_party)
message(FATAL_ERROR
"The ${_vtk_build_module} has not been declared as a third party "
"module.")
endif ()
get_property(_vtk_third_party_internal_library_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_library_name")
if (NOT DEFINED _vtk_third_party_internal_SUBDIRECTORY)
set(_vtk_third_party_internal_SUBDIRECTORY "${_vtk_third_party_internal_library_name}")
endif ()
if (NOT DEFINED _vtk_third_party_internal_LICENSE_FILES)
message(WARNING
"The ${_vtk_build_module} third party package is embedded, but does not "
"specify any license files.")
endif ()
if (NOT DEFINED _vtk_third_party_internal_VERSION)
message(WARNING
"The ${_vtk_build_module} third party package is embedded, but does not "
"specify the version it is based on.")
endif ()
get_property(_vtk_third_party_internal_target_name GLOBAL
PROPERTY "_vtk_module_${_vtk_build_module}_target_name")
set(_vtk_third_party_internal_include_type)
if (_vtk_third_party_internal_INTERFACE)
set(_vtk_third_party_internal_include_type INTERFACE)
elseif (_vtk_third_party_internal_HEADER_ONLY)
add_library("${_vtk_third_party_internal_target_name}" INTERFACE)
if (NOT _vtk_build_module STREQUAL _vtk_third_party_internal_target_name)
add_library("${_vtk_build_module}" ALIAS
"${_vtk_third_party_internal_target_name}")
endif ()
set(_vtk_third_party_internal_include_type INTERFACE)
set(_vtk_third_party_internal_STANDARD_INCLUDE_DIRS 1)
endif ()
add_subdirectory("${_vtk_third_party_internal_SUBDIRECTORY}")
if (NOT TARGET "${_vtk_build_module}")
message(FATAL_ERROR
"The ${_vtk_build_module} is being built as an internal third party "
"library, but a matching target was not created.")
endif ()
if (_vtk_third_party_internal_STANDARD_INCLUDE_DIRS)
_vtk_module_standard_includes(
TARGET "${_vtk_third_party_internal_target_name}"
SYSTEM ${_vtk_third_party_internal_include_type}
HEADERS_DESTINATION "${_vtk_build_HEADERS_DESTINATION}/${_vtk_third_party_internal_HEADERS_SUBDIR}")
endif ()
_vtk_module_apply_properties("${_vtk_third_party_internal_target_name}")
if (_vtk_third_party_internal_INTERFACE)
# Nothing.
elseif (_vtk_third_party_internal_HEADER_ONLY)
_vtk_module_install("${_vtk_third_party_internal_target_name}")
endif ()
if (_vtk_third_party_internal_LICENSE_FILES)
set(_vtk_third_party_internal_license_component "license")
if (_vtk_build_TARGET_SPECIFIC_COMPONENTS)
string(PREPEND _vtk_third_party_internal_license_component "${_vtk_build_module}-")
endif ()
install(
FILES ${_vtk_third_party_internal_LICENSE_FILES}
DESTINATION "${_vtk_build_LICENSE_DESTINATION}/${_vtk_third_party_internal_library_name}/"
COMPONENT "${_vtk_third_party_internal_license_component}")
endif ()
_vtk_module_mark_third_party("${_vtk_third_party_internal_target_name}")
endfunction ()
|