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
|
project('glib', 'c', 'cpp',
version : '2.57.2',
meson_version : '>= 0.47.0',
default_options : [
'buildtype=debugoptimized',
'warning_level=1',
'c_std=gnu89'
]
)
cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp')
cc_can_run = not meson.is_cross_build() or meson.has_exe_wrapper()
if cc.get_id() == 'msvc'
# Ignore several spurious warnings for things glib does very commonly
# If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
# If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
# NOTE: Only add warnings here if you are sure they're spurious
add_project_arguments('/wd4035', '/wd4715', '/wd4116',
'/wd4046', '/wd4068', '/wo4090', '/FImsvc_recommended_pragmas.h',language : 'c')
# Disable SAFESEH with MSVC for plugins and libs that use external deps that
# are built with MinGW
noseh_link_args = ['/SAFESEH:NO']
# Set the input and exec encoding to utf-8, like is the default with GCC
add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c')
else
noseh_link_args = []
# -mms-bitfields vs -fnative-struct ?
endif
host_system = host_machine.system()
glib_version = meson.project_version()
glib_api_version = '2.0'
version_arr = glib_version.split('.')
major_version = version_arr[0].to_int()
minor_version = version_arr[1].to_int()
micro_version = version_arr[2].to_int()
interface_age = minor_version.is_odd() ? 0 : micro_version
binary_age = 100 * minor_version + micro_version
soversion = 0
# Maintain compatibility with previous libtool versioning
# current = minor * 100 + micro
library_version = '@0@.@1@.@2@'.format(soversion, binary_age - interface_age, interface_age)
configinc = include_directories('.')
glibinc = include_directories('glib')
gobjectinc = include_directories('gobject')
gmoduleinc = include_directories('gmodule')
gioinc = include_directories('gio')
glib_prefix = get_option('prefix')
glib_bindir = join_paths(glib_prefix, get_option('bindir'))
glib_libdir = join_paths(glib_prefix, get_option('libdir'))
glib_libexecdir = join_paths(glib_prefix, get_option('libexecdir'))
glib_datadir = join_paths(glib_prefix, get_option('datadir'))
glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
glib_includedir = join_paths(glib_prefix, get_option('includedir'))
glib_giomodulesdir = get_option('gio_module_dir')
if glib_giomodulesdir == ''
glib_giomodulesdir = join_paths(glib_libdir, 'gio', 'modules')
endif
glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
installed_tests_enabled = get_option('installed_tests')
installed_tests_template = files('template.test.in')
add_project_arguments('-D_GNU_SOURCE', language: 'c')
# Disable strict aliasing;
# see https://bugzilla.gnome.org/show_bug.cgi?id=791622
if cc.has_argument('-fno-strict-aliasing')
add_project_arguments('-fno-strict-aliasing', language: 'c')
endif
########################
# Configuration begins #
########################
glib_conf = configuration_data()
glibconfig_conf = configuration_data()
# accumulated list of defines as we check for them, so we can easily
# use them later in test programs (autoconf does this automatically)
glib_conf_prefix = ''
glib_conf.set('GLIB_MAJOR_VERSION', major_version)
glib_conf.set('GLIB_MINOR_VERSION', minor_version)
glib_conf.set('GLIB_MICRO_VERSION', micro_version)
glib_conf.set('GLIB_INTERFACE_AGE', interface_age)
glib_conf.set('GLIB_BINARY_AGE', binary_age)
glib_conf.set_quoted('GETTEXT_PACKAGE', 'glib20')
glib_conf.set_quoted('PACKAGE_BUGREPORT', 'https://gitlab.gnome.org/GNOME/glib/issues/new')
glib_conf.set_quoted('PACKAGE_NAME', 'glib')
glib_conf.set_quoted('PACKAGE_STRING', 'glib @0@'.format(meson.project_version()))
glib_conf.set_quoted('PACKAGE_TARNAME', 'glib')
glib_conf.set_quoted('PACKAGE_URL', '')
glib_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
glib_conf.set('ENABLE_NLS', 1)
# used by the .rc.in files
glibconfig_conf.set('LT_CURRENT_MINUS_AGE', soversion)
glib_conf.set('_GNU_SOURCE', 1)
if host_system == 'windows'
# Poll doesn't work on devices on Windows
glib_conf.set('BROKEN_POLL', true)
endif
# Check for GNU visibility attributes
g_have_gnuc_visibility = cc.compiles('''
void
__attribute__ ((visibility ("hidden")))
f_hidden (void)
{
}
void
__attribute__ ((visibility ("internal")))
f_internal (void)
{
}
void
__attribute__ ((visibility ("protected")))
f_protected (void)
{
}
void
__attribute__ ((visibility ("default")))
f_default (void)
{
}
int main (void)
{
f_hidden();
f_internal();
f_protected();
f_default();
return 0;
}
''',
# Not supported by MSVC, but MSVC also won't support visibility,
# so it's OK to pass -Werror explicitly. Replace with
# override_options : 'werror=true' once that is supported
args: ['-Werror'],
name : 'GNU C visibility attributes test')
if g_have_gnuc_visibility
glibconfig_conf.set('G_HAVE_GNUC_VISIBILITY', '1')
endif
# Detect and set symbol visibility
glib_hidden_visibility_args = []
if get_option('default_library') != 'static'
if host_system == 'windows'
glib_conf.set('DLL_EXPORT', true)
if cc.get_id() == 'msvc'
glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
elif cc.has_argument('-fvisibility=hidden')
glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
glib_hidden_visibility_args = ['-fvisibility=hidden']
endif
elif cc.has_argument('-fvisibility=hidden')
glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
glib_hidden_visibility_args = ['-fvisibility=hidden']
endif
endif
if host_system == 'windows' and get_option('default_library') == 'static'
glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
endif
# FIXME: what about Cygwin (G_WITH_CYGWIN)
if host_system == 'windows'
glib_os = '''#define G_OS_WIN32
#define G_PLATFORM_WIN32'''
else
glib_os = '#define G_OS_UNIX'
endif
glibconfig_conf.set('glib_os', glib_os)
# We need to know the build type to determine what .lib files we need on Visual Studio
# for dependencies that don't normally come with pkg-config files for Visual Studio builds
buildtype = get_option('buildtype')
glib_debug_cflags = []
if buildtype.startswith('debug')
glib_debug_cflags += ['-DG_ENABLE_DEBUG']
elif buildtype == 'release'
glib_debug_cflags += ['-DG_DISABLE_CAST_CHECKS']
endif
add_project_arguments(glib_debug_cflags, language: 'c')
# check for header files
headers = [
'alloca.h',
'crt_externs.h',
'dirent.h', # MSC does not come with this by default
'float.h',
'fstab.h',
'grp.h',
'inttypes.h',
'limits.h',
'linux/magic.h',
'locale.h',
'mach/mach_time.h',
'memory.h',
'mntent.h',
'poll.h',
'pwd.h',
'sched.h',
'stdint.h',
'stdlib.h',
'string.h',
'strings.h',
'sys/auxv.h',
'sys/event.h',
'sys/filio.h',
'sys/inotify.h',
'sys/mkdev.h',
'sys/mntctl.h',
'sys/mnttab.h',
'sys/mount.h',
'sys/param.h',
'sys/resource.h',
'sys/select.h',
'sys/statfs.h',
'sys/stat.h',
'sys/statvfs.h',
'sys/sysctl.h',
'sys/time.h', # MSC does not come with this by default
'sys/times.h',
'sys/types.h',
'sys/uio.h',
'sys/vfs.h',
'sys/vfstab.h',
'sys/vmount.h',
'sys/wait.h',
'termios.h',
'unistd.h',
'values.h',
'xlocale.h',
]
foreach h : headers
if cc.has_header(h)
define = 'HAVE_' + h.underscorify().to_upper()
glib_conf.set(define, 1)
glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
endif
endforeach
# FIXME: Use cc.check_header from Meson 0.47.
# FreeBSD includes a malloc.h which always throw compilation error.
if cc.compiles('#include <malloc.h>', name : 'malloc.h')
glib_conf.set('HAVE_MALLOC_H', 1)
glib_conf_prefix = glib_conf_prefix + '#define HAVE_MALLOC_H 1\n'
endif
if cc.has_header('linux/netlink.h')
glib_conf.set('HAVE_NETLINK', 1)
endif
if glib_conf.has('HAVE_LOCALE_H')
if cc.has_header_symbol('locale.h', 'LC_MESSAGES')
glib_conf.set('HAVE_LC_MESSAGES', 1)
endif
endif
struct_stat_blkprefix = '''
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
'''
struct_members = [
[ 'stat', 'st_mtimensec' ],
[ 'stat', 'st_mtim.tv_nsec' ],
[ 'stat', 'st_atimensec' ],
[ 'stat', 'st_atim.tv_nsec' ],
[ 'stat', 'st_ctimensec' ],
[ 'stat', 'st_ctim.tv_nsec' ],
[ 'stat', 'st_birthtime' ],
[ 'stat', 'st_birthtimensec' ],
[ 'stat', 'st_birthtim' ],
[ 'stat', 'st_birthtim.tv_nsec' ],
[ 'stat', 'st_blksize', struct_stat_blkprefix ],
[ 'stat', 'st_blocks', struct_stat_blkprefix ],
[ 'statfs', 'f_fstypename', struct_stat_blkprefix ],
[ 'statfs', 'f_bavail', struct_stat_blkprefix ],
[ 'dirent', 'd_type', '''#include <sys/types.h>
#include <dirent.h>''' ],
[ 'statvfs', 'f_basetype', '#include <sys/statvfs.h>' ],
[ 'statvfs', 'f_fstypename', '#include <sys/statvfs.h>' ],
[ 'tm', 'tm_gmtoff', '#include <time.h>' ],
[ 'tm', '__tm_gmtoff', '#include <time.h>' ],
]
foreach m : struct_members
header_check_prefix = glib_conf_prefix
if m.length() == 3
header_check_prefix = header_check_prefix + m[2]
else
header_check_prefix = header_check_prefix + '#include <sys/stat.h>'
endif
if cc.has_member('struct ' + m[0], m[1], prefix : header_check_prefix)
define = 'HAVE_STRUCT_@0@_@1@'.format(m[0].to_upper(), m[1].underscorify().to_upper())
glib_conf.set(define, 1)
glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
else
endif
endforeach
# Compiler flags
if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
test_c_args = [
'-Wall',
'-Wduplicated-branches',
'-Wmisleading-indentation',
'-Wstrict-prototypes',
'-Wunused',
# Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
# building with -Wbad-function-cast.
'-Wno-bad-function-cast',
'-Werror=declaration-after-statement',
'-Werror=format=2',
'-Werror=format-security',
'-Werror=implicit-function-declaration',
'-Werror=init-self',
'-Werror=missing-include-dirs',
'-Werror=missing-prototypes',
'-Werror=pointer-arith',
]
test_c_link_args = [
'-Wl,-z,nodelete',
]
if get_option('bsymbolic_functions')
test_c_link_args += ['-Wl,-Bsymbolic-functions']
endif
else
test_c_args = []
test_c_link_args = []
endif
add_project_arguments(cc.get_supported_arguments(test_c_args), language: 'c')
# FIXME: We cannot build some of the GResource tests with -z nodelete, which
# means we cannot use that flag in add_project_link_arguments(), and must add
# it to the relevant targets manually. We do the same with -Bsymbolic-functions
# because that is what the autotools build did.
# See https://github.com/mesonbuild/meson/pull/3520 for a way to eventually
# improve this.
glib_link_flags = cc.get_supported_link_arguments(test_c_link_args)
# Windows Support (7+)
if host_system == 'windows'
glib_conf.set('_WIN32_WINNT', '0x0601')
endif
functions = [
'alloca',
'endmntent',
'endservent',
'fallocate',
'fchmod',
'fchown',
'fdwalk',
'fsync',
'getc_unlocked',
'getfsstat',
'getgrgid_r',
'getmntent_r',
'getpwuid_r',
'getresuid',
'getvfsstat',
'gmtime_r',
'hasmntopt',
'inotify_init1',
'issetugid',
'kevent',
'kqueue',
'lchmod',
'lchown',
'link',
'localtime_r',
'lstat',
'mbrtowc',
'memalign',
'mmap',
'newlocale',
'pipe2',
'poll',
'prlimit',
'readlink',
'recvmmsg',
'sendmmsg',
'setenv',
'setmntent',
'strerror_r',
'strnlen',
'strsignal',
'strtod_l',
'strtoll_l',
'strtoull_l',
'symlink',
'timegm',
'unsetenv',
'uselocale',
'utimes',
'valloc',
'vasprintf',
'vsnprintf',
'wcrtomb',
'wcslen',
'wcsnlen',
'sysctlbyname',
'_NSGetEnviron',
]
if glib_conf.has('HAVE_SYS_STATVFS_H')
functions += ['statvfs']
else
have_func_statvfs = false
endif
if glib_conf.has('HAVE_SYS_STATFS_H') or glib_conf.has('HAVE_SYS_MOUNT_H')
functions += ['statfs']
else
have_func_statfs = false
endif
if host_system == 'windows'
iphlpapi_dep = cc.find_library('iphlpapi')
iphlpapi_funcs = ['if_nametoindex', 'if_indextoname']
foreach ifunc : iphlpapi_funcs
iphl_prefix = '''#define _WIN32_WINNT @0@
#include <winsock2.h>
#include <iphlpapi.h>'''.format(glib_conf.get('_WIN32_WINNT'))
if cc.has_function(ifunc,
prefix : iphl_prefix,
dependencies : iphlpapi_dep)
idefine = 'HAVE_' + ifunc.underscorify().to_upper()
glib_conf.set(idefine, 1)
glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(idefine)
set_variable('have_func_' + ifunc, true)
else
set_variable('have_func_' + ifunc, false)
endif
endforeach
else
functions += ['if_indextoname', 'if_nametoindex']
endif
# AIX splice is something else
if host_system != 'aix'
functions += ['splice']
endif
foreach f : functions
if cc.has_function(f)
define = 'HAVE_' + f.underscorify().to_upper()
glib_conf.set(define, 1)
glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format(define)
set_variable('have_func_' + f, true)
else
set_variable('have_func_' + f, false)
endif
endforeach
# Check that stpcpy() is usable; must use header
if cc.has_function('stpcpy', prefix : '#include <string.h>')
glib_conf.set('HAVE_STPCPY', 1)
endif
# Check that posix_memalign() is usable; must use header
if cc.has_function('posix_memalign', prefix : '#include <stdlib.h>')
glib_conf.set('HAVE_POSIX_MEMALIGN', 1)
endif
# Check that posix_spawn() is usable; must use header
if cc.has_function('posix_spawn', prefix : '#include <spawn.h>')
glib_conf.set('HAVE_POSIX_SPAWN', 1)
endif
# Check whether strerror_r returns char *
if have_func_strerror_r
if cc.compiles('''#define _GNU_SOURCE
#include <string.h>
int func (void) {
char error_string[256];
char *ptr = strerror_r (-2, error_string, 256);
char c = *strerror_r (-2, error_string, 256);
return c != 0 && ptr != (void*) 0L;
}
''',
name : 'strerror_r() returns char *')
glib_conf.set('STRERROR_R_CHAR_P', 1,
description: 'Defined if strerror_r returns char *')
endif
endif
# Special-case these functions that have alternative names on Windows/MSVC
if cc.has_function('snprintf') or cc.has_header_symbol('stdio.h', 'snprintf')
glib_conf.set('HAVE_SNPRINTF', 1)
glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF 1\n'
elif cc.has_function('_snprintf') or cc.has_header_symbol('stdio.h', '_snprintf')
hack_define = '1\n#define snprintf _snprintf'
glib_conf.set('HAVE_SNPRINTF', hack_define)
glib_conf_prefix = glib_conf_prefix + '#define HAVE_SNPRINTF ' + hack_define
endif
if cc.has_function('strcasecmp')
glib_conf.set('HAVE_STRCASECMP', 1)
glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP 1\n'
elif cc.has_function('_stricmp')
hack_define = '1\n#define strcasecmp _stricmp'
glib_conf.set('HAVE_STRCASECMP', hack_define)
glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRCASECMP ' + hack_define
endif
if cc.has_function('strncasecmp')
glib_conf.set('HAVE_STRNCASECMP', 1)
glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP 1\n'
elif cc.has_function('_strnicmp')
hack_define = '1\n#define strncasecmp _strnicmp'
glib_conf.set('HAVE_STRNCASECMP', hack_define)
glib_conf_prefix = glib_conf_prefix + '#define HAVE_STRNCASECMP ' + hack_define
endif
if cc.has_header_symbol('sys/sysmacros.h', 'major')
glib_conf.set('MAJOR_IN_SYSMACROS', 1)
elif cc.has_header_symbol('sys/mkdev.h', 'major')
glib_conf.set('MAJOR_IN_MKDEV', 1)
elif cc.has_header_symbol('sys/types.h', 'major')
glib_conf.set('MAJOR_IN_TYPES', 1)
endif
if cc.has_header_symbol('dlfcn.h', 'RTLD_LAZY')
glib_conf.set('HAVE_RTLD_LAZY', 1)
endif
if cc.has_header_symbol('dlfcn.h', 'RTLD_NOW')
glib_conf.set('HAVE_RTLD_NOW', 1)
endif
if cc.has_header_symbol('dlfcn.h', 'RTLD_GLOBAL')
glib_conf.set('HAVE_RTLD_GLOBAL', 1)
endif
# Check whether to use statfs or statvfs
# Some systems have both statfs and statvfs, pick the most "native" for these
if have_func_statfs and have_func_statvfs
# on solaris and irix, statfs doesn't even have the f_bavail field
if not glib_conf.has('HAVE_STRUCT_STATFS_F_BAVAIL')
have_func_statfs = false
else
# at least on linux, statfs is the actual syscall
have_func_statvfs = false
endif
endif
if have_func_statfs
glib_conf.set('USE_STATFS', 1)
stat_func_to_use = 'statfs'
elif have_func_statvfs
glib_conf.set('USE_STATVFS', 1)
stat_func_to_use = 'statvfs'
else
stat_func_to_use = 'neither'
endif
message('Checking whether to use statfs or statvfs .. ' + stat_func_to_use)
if host_system == 'linux'
if cc.has_function('mkostemp',
prefix: '''#define _GNU_SOURCE
#include <stdlib.h>''')
glib_conf.set('HAVE_MKOSTEMP', 1)
endif
endif
osx_ldflags = []
glib_have_os_x_9_or_later = false
glib_have_carbon = false
glib_have_cocoa = false
if host_system == 'darwin'
add_languages('objc')
objcc = meson.get_compiler('objc')
osx_ldflags += ['-Wl,-framework,CoreFoundation']
# Mac OS X Carbon support
glib_have_carbon = objcc.compiles('''#include <Carbon/Carbon.h>
#include <CoreServices/CoreServices.h>''',
name : 'Mac OS X Carbon support')
if glib_have_carbon
glib_conf.set('HAVE_CARBON', true)
osx_ldflags += '-Wl,-framework,Carbon'
glib_have_os_x_9_or_later = objcc.compiles('''#include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
#error Compiling for minimum OS X version before 10.9
#endif''',
name : 'OS X 9 or later')
endif
# Mac OS X Cocoa support
glib_have_cocoa = objcc.compiles('''#include <Cocoa/Cocoa.h>
#ifdef GNUSTEP_BASE_VERSION
#error "Detected GNUstep, not Cocoa"
#endif''',
name : 'Mac OS X Cocoa support')
if glib_have_cocoa
glib_conf.set('HAVE_COCOA', true)
osx_ldflags += ['-Wl,-framework,Foundation', '-Wl,-framework,AppKit']
endif
# FIXME: libgio mix C and objC source files and there is no way to reliably
# know which language flags it's going to use to link. Add to both languages
# for now. See https://github.com/mesonbuild/meson/issues/3585.
add_project_link_arguments(osx_ldflags, language : ['objc', 'c'])
endif
# Check for futex(2)
if cc.links('''#include <linux/futex.h>
#include <sys/syscall.h>
#include <unistd.h>
int main (int argc, char ** argv) {
syscall (__NR_futex, NULL, FUTEX_WAKE, FUTEX_WAIT);
return 0;
}''', name : 'futex(2) system call')
glib_conf.set('HAVE_FUTEX', 1)
endif
# Check for eventfd(2)
if cc.links('''#include <sys/eventfd.h>
#include <unistd.h>
int main (int argc, char ** argv) {
eventfd (0, EFD_CLOEXEC);
return 0;
}''', name : 'eventfd(2) system call')
glib_conf.set('HAVE_EVENTFD', 1)
endif
clock_gettime_test_code = '''
#include <time.h>
struct timespec t;
int main (int argc, char ** argv) {
return clock_gettime(CLOCK_REALTIME, &t);
}'''
librt = []
if cc.links(clock_gettime_test_code, name : 'clock_gettime')
glib_conf.set('HAVE_CLOCK_GETTIME', 1)
elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in librt')
glib_conf.set('HAVE_CLOCK_GETTIME', 1)
librt = cc.find_library('rt')
endif
# if statfs() takes 2 arguments (Posix) or 4 (Solaris)
if have_func_statfs
if cc.compiles(glib_conf_prefix + '''
#include <unistd.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
#endif
void some_func (void) {
struct statfs st;
statfs("/", &st);
}''', name : 'number of arguments to statfs() (n=2)')
glib_conf.set('STATFS_ARGS', 2)
elif cc.compiles(glib_conf_prefix + '''
#include <unistd.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
#endif
void some_func (void) {
struct statfs st;
statfs("/", &st, sizeof (st), 0);
}''', name : 'number of arguments to statfs() (n=4)')
glib_conf.set('STATFS_ARGS', 4)
else
error('Unable to determine number of arguments to statfs()')
endif
endif
# open takes O_DIRECTORY as an option
#AC_MSG_CHECKING([])
if cc.compiles('''#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>],
void some_func (void) {
open(0, O_DIRECTORY, 0);
}''', name : 'open() option O_DIRECTORY')
glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
endif
# Check whether there is a vsnprintf() function with C99 semantics installed.
# AC_FUNC_VSNPRINTF_C99
# Check whether there is a snprintf() function with C99 semantics installed.
# AC_FUNC_SNPRINTF_C99
have_good_vsnprintf = false
have_good_snprintf = false
if host_system == 'windows' and cc.get_id() == 'msvc'
# Unfortunately the Visual Studio 2015+ implementations of C99-style
# snprintf and vsnprintf don't seem to be quite good enough.
# (Sorry, I don't know exactly what is the problem,
# but it is related to floating point formatting and decimal point vs. comma.)
# The simple tests in AC_FUNC_VSNPRINTF_C99 and AC_FUNC_SNPRINTF_C99 aren't
# rigorous enough to notice, though.
glib_conf.set('HAVE_C99_SNPRINTF', false)
glib_conf.set('HAVE_C99_VSNPRINTF', false)
else
vsnprintf_c99_test_code = '''
#include <stdio.h>
#include <stdarg.h>
int
doit(char * s, ...)
{
char buffer[32];
va_list args;
int r;
va_start(args, s);
r = vsnprintf(buffer, 5, s, args);
va_end(args);
if (r != 7)
exit(1);
/* AIX 5.1 and Solaris seems to have a half-baked vsnprintf()
implementation. The above will return 7 but if you replace
the size of the buffer with 0, it borks! */
va_start(args, s);
r = vsnprintf(buffer, 0, s, args);
va_end(args);
if (r != 7)
exit(1);
exit(0);
}
int
main(void)
{
doit("1234567");
exit(1);
}'''
if cc_can_run
rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
if rres.compiled() and rres.returncode() == 0
glib_conf.set('HAVE_C99_VSNPRINTF', 1)
have_good_vsnprintf = true
endif
else
have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
endif
snprintf_c99_test_code = '''
#include <stdio.h>
#include <stdarg.h>
int
doit()
{
char buffer[32];
va_list args;
int r;
r = snprintf(buffer, 5, "1234567");
if (r != 7)
exit(1);
r = snprintf(buffer, 0, "1234567");
if (r != 7)
exit(1);
r = snprintf(NULL, 0, "1234567");
if (r != 7)
exit(1);
exit(0);
}
int
main(void)
{
doit();
exit(1);
}'''
if cc_can_run
rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
if rres.compiled() and rres.returncode() == 0
glib_conf.set('HAVE_C99_SNPRINTF', 1)
have_good_snprintf = true
endif
else
have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
endif
endif
if host_system == 'windows'
glib_conf.set_quoted('EXEEXT', '.exe')
else
glib_conf.set('EXEEXT', '')
endif
if have_good_vsnprintf and have_good_snprintf
# Our printf is 'good' only if vsnpintf()/snprintf() supports C99 well enough
glib_conf.set('HAVE_GOOD_PRINTF', 1) # FIXME: Check for HAVE_UNIX98_PRINTF?
else
glib_conf.set('HAVE_VASPRINTF', 1)
endif
# Check whether the printf() family supports Unix98 %n$ positional parameters
# AC_FUNC_PRINTF_UNIX98
# Nothing uses HAVE_UNIX98_PRINTF
# Check for nl_langinfo and CODESET
# FIXME: Check for HAVE_BIND_TEXTDOMAIN_CODESET
if cc.links('''#include <langinfo.h>
int main (int argc, char ** argv) {
char *codeset = nl_langinfo (CODESET);
return 0;
}''', name : 'nl_langinfo and CODESET')
glib_conf.set('HAVE_LANGINFO_CODESET', 1)
glib_conf.set('HAVE_CODESET', 1)
endif
# Check for nl_langinfo and LC_TIME parts that are needed in gdatetime.c
if cc.links('''#include <langinfo.h>
int main (int argc, char ** argv) {
char *str;
str = nl_langinfo (PM_STR);
str = nl_langinfo (D_T_FMT);
str = nl_langinfo (D_FMT);
str = nl_langinfo (T_FMT);
str = nl_langinfo (T_FMT_AMPM);
str = nl_langinfo (MON_1);
str = nl_langinfo (ABMON_12);
str = nl_langinfo (DAY_1);
str = nl_langinfo (ABDAY_7);
return 0;
}''', name : 'nl_langinfo (PM_STR)')
glib_conf.set('HAVE_LANGINFO_TIME', 1)
endif
if cc.links('''#include <langinfo.h>
int main (int argc, char ** argv) {
char *str;
str = nl_langinfo (_NL_CTYPE_OUTDIGIT0_MB);
str = nl_langinfo (_NL_CTYPE_OUTDIGIT1_MB);
str = nl_langinfo (_NL_CTYPE_OUTDIGIT2_MB);
str = nl_langinfo (_NL_CTYPE_OUTDIGIT3_MB);
str = nl_langinfo (_NL_CTYPE_OUTDIGIT4_MB);
str = nl_langinfo (_NL_CTYPE_OUTDIGIT5_MB);
str = nl_langinfo (_NL_CTYPE_OUTDIGIT6_MB);
str = nl_langinfo (_NL_CTYPE_OUTDIGIT7_MB);
str = nl_langinfo (_NL_CTYPE_OUTDIGIT8_MB);
str = nl_langinfo (_NL_CTYPE_OUTDIGIT9_MB);
return 0;
}''', name : 'nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)')
glib_conf.set('HAVE_LANGINFO_OUTDIGIT', 1)
endif
# Check for nl_langinfo and alternative month names
if cc.links('''#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <langinfo.h>
int main (int argc, char ** argv) {
char *str;
str = nl_langinfo (ALTMON_1);
str = nl_langinfo (ALTMON_2);
str = nl_langinfo (ALTMON_3);
str = nl_langinfo (ALTMON_4);
str = nl_langinfo (ALTMON_5);
str = nl_langinfo (ALTMON_6);
str = nl_langinfo (ALTMON_7);
str = nl_langinfo (ALTMON_8);
str = nl_langinfo (ALTMON_9);
str = nl_langinfo (ALTMON_10);
str = nl_langinfo (ALTMON_11);
str = nl_langinfo (ALTMON_12);
return 0;
}''', name : 'nl_langinfo (ALTMON_n)')
glib_conf.set('HAVE_LANGINFO_ALTMON', 1)
endif
# Check for nl_langinfo and abbreviated alternative month names
if cc.links('''#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <langinfo.h>
int main (int argc, char ** argv) {
char *str;
str = nl_langinfo (_NL_ALTMON_1);
str = nl_langinfo (_NL_ALTMON_2);
str = nl_langinfo (_NL_ALTMON_3);
str = nl_langinfo (_NL_ALTMON_4);
str = nl_langinfo (_NL_ALTMON_5);
str = nl_langinfo (_NL_ALTMON_6);
str = nl_langinfo (_NL_ALTMON_7);
str = nl_langinfo (_NL_ALTMON_8);
str = nl_langinfo (_NL_ALTMON_9);
str = nl_langinfo (_NL_ALTMON_10);
str = nl_langinfo (_NL_ALTMON_11);
str = nl_langinfo (_NL_ALTMON_12);
return 0;
}''', name : 'nl_langinfo (_NL_ALTMON_n)')
glib_conf.set('HAVE_LANGINFO_ABALTMON', 1)
endif
# Check if C compiler supports the 'signed' keyword
if not cc.compiles('''signed char x;''', name : 'signed')
glib_conf.set('signed', '/* NOOP */')
endif
# Check if the ptrdiff_t type exists
if cc.has_header_symbol('stddef.h', 'ptrdiff_t')
glib_conf.set('HAVE_PTRDIFF_T', 1)
endif
# Check for sig_atomic_t type
if cc.links('''#include <signal.h>
#include <sys/types.h>
sig_atomic_t val = 42;
int main (int argc, char ** argv) {
return val == 42 ? 0 : 1;
}''', name : 'sig_atomic_t')
glib_conf.set('HAVE_SIG_ATOMIC_T', 1)
endif
# Check if 'long long' works
# jm_AC_TYPE_LONG_LONG
if cc.compiles('''long long ll = 1LL;
int i = 63;
int some_func (void) {
long long llmax = (long long) -1;
return ll << i | ll >> i | llmax / ll | llmax % ll;
}''', name : 'long long')
glib_conf.set('HAVE_LONG_LONG', 1)
have_long_long = true
else
have_long_long = false
endif
# Test whether the compiler supports the 'long double' type.
if cc.compiles('''/* The Stardent Vistra knows sizeof(long double), but does not support it. */
long double foo = 0.0;
/* On Ultrix 4.3 cc, long double is 4 and double is 8. */
int array [2*(sizeof(long double) >= sizeof(double)) - 1];''',
name : 'long double')
glib_conf.set('HAVE_LONG_DOUBLE', 1)
endif
# Test whether <stddef.h> has the 'wchar_t' type.
if cc.has_header_symbol('stddef.h', 'wchar_t')
glib_conf.set('HAVE_WCHAR_T', 1)
endif
# Test whether <wchar.h> has the 'wint_t' type.
if cc.has_header_symbol('wchar.h', 'wint_t')
glib_conf.set('HAVE_WINT_T', 1)
endif
found_uintmax_t = false
# Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists,
# doesn't clash with <sys/types.h>, and declares uintmax_t.
# jm_AC_HEADER_INTTYPES_H
if cc.compiles('''#include <sys/types.h>
#include <inttypes.h>
void some_func (void) {
uintmax_t i = (uintmax_t) -1;
}''', name : 'uintmax_t in inttypes.h')
glib_conf.set('HAVE_INTTYPES_H_WITH_UINTMAX', 1)
found_uintmax_t = true
endif
# Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists,
# doesn't clash with <sys/types.h>, and declares uintmax_t.
# jm_AC_HEADER_STDINT_H
if cc.compiles('''#include <sys/types.h>
#include <stdint.h>
void some_func (void) {
uintmax_t i = (uintmax_t) -1;
}''', name : 'uintmax_t in stdint.h')
glib_conf.set('HAVE_STDINT_H_WITH_UINTMAX', 1)
found_uintmax_t = true
endif
# Define intmax_t to 'long' or 'long long'
# if it is not already defined in <stdint.h> or <inttypes.h>.
# For simplicity, we assume that a header file defines 'intmax_t' if and
# only if it defines 'uintmax_t'.
if found_uintmax_t
glib_conf.set('HAVE_INTMAX_T', 1)
elif have_long_long
glib_conf.set('intmax_t', 'long long')
else
glib_conf.set('intmax_t', 'long')
endif
char_size = cc.sizeof('char')
short_size = cc.sizeof('short')
int_size = cc.sizeof('int')
voidp_size = cc.sizeof('void*')
long_size = cc.sizeof('long')
if have_long_long
long_long_size = cc.sizeof('long long')
else
long_long_size = 0
endif
sizet_size = cc.sizeof('size_t')
if cc.get_id() == 'msvc'
ssizet_size = cc.sizeof('SSIZE_T', prefix : '#include <BaseTsd.h>')
else
ssizet_size = cc.sizeof('ssize_t')
endif
int64_m = 'll'
char_align = cc.alignment('char')
short_align = cc.alignment('short')
int_align = cc.alignment('int')
voidp_align = cc.alignment('void*')
long_align = cc.alignment('long')
long_long_align = cc.alignment('long long')
# NOTE: We don't check for size of __int64 because long long is guaranteed to
# be 64-bit in C99, and it is available on all supported compilers
sizet_align = cc.alignment('size_t')
glib_conf.set('ALIGNOF_UNSIGNED_LONG', long_align)
glib_conf.set('SIZEOF_CHAR', char_size)
glib_conf.set('SIZEOF_INT', int_size)
glib_conf.set('SIZEOF_SHORT', short_size)
glib_conf.set('SIZEOF_LONG', long_size)
glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
glib_conf.set('SIZEOF_SIZE_T', sizet_size)
glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
glib_conf.set('SIZEOF_VOID_P', voidp_size)
if short_size == 2
gint16 = 'short'
gint16_modifier='h'
gint16_format='hi'
guint16_format='hu'
elif int_size == 2
gint16 = 'int'
gint16_modifier=''
gint16_format='i'
guint16_format='u'
else
error('Compiler provides no native 16-bit integer type')
endif
glibconfig_conf.set('gint16', gint16)
glibconfig_conf.set_quoted('gint16_modifier', gint16_modifier)
glibconfig_conf.set_quoted('gint16_format', gint16_format)
glibconfig_conf.set_quoted('guint16_format', guint16_format)
if short_size == 4
gint32 = 'short'
gint32_modifier='h'
gint32_format='hi'
guint32_format='hu'
guint32_align = short_align
elif int_size == 4
gint32 = 'int'
gint32_modifier=''
gint32_format='i'
guint32_format='u'
guint32_align = int_align
elif long_size == 4
gint32 = 'long'
gint32_modifier='l'
gint32_format='li'
guint32_format='lu'
guint32_align = long_align
else
error('Compiler provides no native 32-bit integer type')
endif
glibconfig_conf.set('gint32', gint32)
glibconfig_conf.set_quoted('gint32_modifier', gint32_modifier)
glibconfig_conf.set_quoted('gint32_format', gint32_format)
glibconfig_conf.set_quoted('guint32_format', guint32_format)
glib_conf.set('ALIGNOF_GUINT32', guint32_align)
if int_size == 8
gint64 = 'int'
gint64_modifier=''
gint64_format='i'
guint64_format='u'
glib_extension=''
gint64_constant='(val)'
guint64_constant='(val)'
guint64_align = int_align
elif long_size == 8
gint64 = 'long'
glib_extension=''
gint64_modifier='l'
gint64_format='li'
guint64_format='lu'
gint64_constant='(val##L)'
guint64_constant='(val##UL)'
guint64_align = long_align
elif long_long_size == 8
gint64 = 'long long'
glib_extension='G_GNUC_EXTENSION '
gint64_modifier=int64_m
gint64_format=int64_m + 'i'
guint64_format=int64_m + 'u'
gint64_constant='(G_GNUC_EXTENSION (val##LL))'
guint64_constant='(G_GNUC_EXTENSION (val##ULL))'
guint64_align = long_long_align
else
error('Compiler provides no native 64-bit integer type')
endif
glibconfig_conf.set('glib_extension', glib_extension)
glibconfig_conf.set('gint64', gint64)
glibconfig_conf.set_quoted('gint64_modifier', gint64_modifier)
glibconfig_conf.set_quoted('gint64_format', gint64_format)
glibconfig_conf.set_quoted('guint64_format', guint64_format)
glibconfig_conf.set('gint64_constant', gint64_constant)
glibconfig_conf.set('guint64_constant', guint64_constant)
glib_conf.set('ALIGNOF_GUINT64', guint64_align)
if host_system == 'windows'
glibconfig_conf.set('g_pid_type', 'void*')
glibconfig_conf.set_quoted('g_pid_format', 'p')
if host_machine.cpu_family() == 'x86_64'
glibconfig_conf.set_quoted('g_pollfd_format', '%#' + int64_m + 'x')
else
glibconfig_conf.set_quoted('g_pollfd_format', '%#x')
endif
glibconfig_conf.set('g_dir_separator', '\\\\')
glibconfig_conf.set('g_searchpath_separator', ';')
else
glibconfig_conf.set('g_pid_type', 'int')
glibconfig_conf.set_quoted('g_pid_format', 'i')
glibconfig_conf.set_quoted('g_pollfd_format', '%d')
glibconfig_conf.set('g_dir_separator', '/')
glibconfig_conf.set('g_searchpath_separator', ':')
endif
if sizet_size == short_size
glibconfig_conf.set('glib_size_type_define', 'short')
glibconfig_conf.set_quoted('gsize_modifier', 'h')
glibconfig_conf.set_quoted('gssize_modifier', 'h')
glibconfig_conf.set_quoted('gsize_format', 'hu')
glibconfig_conf.set_quoted('gssize_format', 'hi')
glibconfig_conf.set('glib_msize_type', 'SHRT')
elif sizet_size == int_size
glibconfig_conf.set('glib_size_type_define', 'int')
glibconfig_conf.set_quoted('gsize_modifier', '')
glibconfig_conf.set_quoted('gssize_modifier', '')
glibconfig_conf.set_quoted('gsize_format', 'u')
glibconfig_conf.set_quoted('gssize_format', 'i')
glibconfig_conf.set('glib_msize_type', 'INT')
elif sizet_size == long_size
glibconfig_conf.set('glib_size_type_define', 'long')
glibconfig_conf.set_quoted('gsize_modifier', 'l')
glibconfig_conf.set_quoted('gssize_modifier', 'l')
glibconfig_conf.set_quoted('gsize_format', 'lu')
glibconfig_conf.set_quoted('gssize_format', 'li')
glibconfig_conf.set('glib_msize_type', 'LONG')
elif sizet_size == long_long_size
glibconfig_conf.set('glib_size_type_define', 'long long')
glibconfig_conf.set_quoted('gsize_modifier', int64_m)
glibconfig_conf.set_quoted('gssize_modifier', int64_m)
glibconfig_conf.set_quoted('gsize_format', int64_m + 'u')
glibconfig_conf.set_quoted('gssize_format', int64_m + 'i')
glibconfig_conf.set('glib_msize_type', 'INT64')
else
error('Could not determine size of size_t.')
endif
if voidp_size == int_size
glibconfig_conf.set('glib_intptr_type_define', 'int')
glibconfig_conf.set_quoted('gintptr_modifier', '')
glibconfig_conf.set_quoted('gintptr_format', 'i')
glibconfig_conf.set_quoted('guintptr_format', 'u')
glibconfig_conf.set('glib_gpi_cast', '(gint)')
glibconfig_conf.set('glib_gpui_cast', '(guint)')
elif voidp_size == long_size
glibconfig_conf.set('glib_intptr_type_define', 'long')
glibconfig_conf.set_quoted('gintptr_modifier', 'l')
glibconfig_conf.set_quoted('gintptr_format', 'li')
glibconfig_conf.set_quoted('guintptr_format', 'lu')
glibconfig_conf.set('glib_gpi_cast', '(glong)')
glibconfig_conf.set('glib_gpui_cast', '(gulong)')
elif voidp_size == long_long_size
glibconfig_conf.set('glib_intptr_type_define', 'long long')
glibconfig_conf.set_quoted('gintptr_modifier', int64_m)
glibconfig_conf.set_quoted('gintptr_format', int64_m + 'i')
glibconfig_conf.set_quoted('guintptr_format', int64_m + 'u')
glibconfig_conf.set('glib_gpi_cast', '(gint64)')
glibconfig_conf.set('glib_gpui_cast', '(guint64)')
else
error('Could not determine size of void *')
endif
if long_size != 8 and long_long_size != 8 and int_size != 8
error('GLib requires a 64-bit type. You might want to consider using the GNU C compiler.')
endif
glibconfig_conf.set('gintbits', int_size * 8)
glibconfig_conf.set('glongbits', long_size * 8)
glibconfig_conf.set('gsizebits', sizet_size * 8)
glibconfig_conf.set('gssizebits', ssizet_size * 8)
# FIXME: maybe meson should tell us the libsuffix?
if host_system == 'windows'
g_module_suffix = 'dll'
elif host_system == 'darwin'
g_module_suffix = 'dylib'
else
g_module_suffix = 'so'
endif
glibconfig_conf.set('g_module_suffix', g_module_suffix)
glibconfig_conf.set('GLIB_MAJOR_VERSION', major_version)
glibconfig_conf.set('GLIB_MINOR_VERSION', minor_version)
glibconfig_conf.set('GLIB_MICRO_VERSION', micro_version)
glibconfig_conf.set('GLIB_VERSION', glib_version)
glibconfig_conf.set('glib_void_p', voidp_size)
glibconfig_conf.set('glib_long', long_size)
glibconfig_conf.set('glib_size_t', sizet_size)
glibconfig_conf.set('glib_ssize_t', ssizet_size)
if host_machine.endian() == 'big'
glibconfig_conf.set('g_byte_order', 'G_BIG_ENDIAN')
glibconfig_conf.set('g_bs_native', 'BE')
glibconfig_conf.set('g_bs_alien', 'LE')
else
glibconfig_conf.set('g_byte_order', 'G_LITTLE_ENDIAN')
glibconfig_conf.set('g_bs_native', 'LE')
glibconfig_conf.set('g_bs_alien', 'BE')
endif
# === va_copy checks ===
# we currently check for all three va_copy possibilities, so we get
# all results in config.log for bug reports.
va_copy_func = ''
foreach try_func : [ '__va_copy', 'va_copy' ]
if cc.compiles('''#include <stdarg.h>
#include <stdlib.h>
#ifdef _MSC_VER
# include "msvc_recommended_pragmas.h"
#endif
void f (int i, ...) {
va_list args1, args2;
va_start (args1, i);
@0@ (args2, args1);
if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
exit (1);
va_end (args1); va_end (args2);
}
int main() {
f (0, 42);
return 0;
}'''.format(try_func),
name : try_func + ' check')
va_copy_func = try_func
endif
endforeach
if va_copy_func != ''
glib_conf.set('G_VA_COPY', va_copy_func)
glib_vacopy = '#define G_VA_COPY ' + va_copy_func
else
glib_vacopy = '/* #undef G_VA_COPY */'
endif
va_list_val_copy_prog = '''
#include <stdarg.h>
#include <stdlib.h>
void f (int i, ...) {
va_list args1, args2;
va_start (args1, i);
args2 = args1;
if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
exit (1);
va_end (args1); va_end (args2);
}
int main() {
f (0, 42);
return 0;
}'''
if cc_can_run
rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
glib_va_val_copy = rres.returncode() == 0
else
glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
endif
if not glib_va_val_copy
glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
endif
glibconfig_conf.set('glib_vacopy', glib_vacopy)
# check for flavours of varargs macros
g_have_iso_c_varargs = cc.compiles('''
void some_func (void) {
int a(int p1, int p2, int p3);
#define call_a(...) a(1,__VA_ARGS__)
call_a(2,3);
}''', name : 'ISO C99 varargs macros in C')
if g_have_iso_c_varargs
glibconfig_conf.set('g_have_iso_c_varargs', '''
#ifndef __cplusplus
# define G_HAVE_ISO_VARARGS 1
#endif''')
endif
g_have_iso_cxx_varargs = cxx.compiles('''
void some_func (void) {
int a(int p1, int p2, int p3);
#define call_a(...) a(1,__VA_ARGS__)
call_a(2,3);
}''', name : 'ISO C99 varargs macros in C++')
if g_have_iso_cxx_varargs
glibconfig_conf.set('g_have_iso_cxx_varargs', '''
#ifdef __cplusplus
# define G_HAVE_ISO_VARARGS 1
#endif''')
endif
g_have_gnuc_varargs = cc.compiles('''
void some_func (void) {
int a(int p1, int p2, int p3);
#define call_a(params...) a(1,params)
call_a(2,3);
}''', name : 'GNUC varargs macros')
if cc.has_header('alloca.h')
glibconfig_conf.set('GLIB_HAVE_ALLOCA_H', true)
endif
has_syspoll = cc.has_header('sys/poll.h')
has_systypes = cc.has_header('sys/types.h')
if has_syspoll
glibconfig_conf.set('GLIB_HAVE_SYS_POLL_H', true)
endif
has_winsock2 = cc.has_header('winsock2.h')
if has_syspoll and has_systypes
poll_includes = '''
#include<sys/poll.h>
#include<sys/types.h>'''
elif has_winsock2
poll_includes = '''
#define _WIN32_WINNT @0@
#include <winsock2.h>'''.format(glib_conf.get('_WIN32_WINNT'))
else
# FIXME?
error('FIX POLL* defines')
endif
poll_defines = [
[ 'POLLIN', 'g_pollin', 1 ],
[ 'POLLOUT', 'g_pollout', 4 ],
[ 'POLLPRI', 'g_pollpri', 2 ],
[ 'POLLERR', 'g_pollerr', 8 ],
[ 'POLLHUP', 'g_pollhup', 16 ],
[ 'POLLNVAL', 'g_pollnval', 32 ],
]
if has_syspoll and has_systypes
foreach d : poll_defines
val = cc.compute_int(d[0], prefix: poll_includes)
glibconfig_conf.set(d[1], val)
endforeach
elif has_winsock2
# Due to a missed bug in configure.ac the poll test
# never succeeded on Windows and used some pre-defined
# values as a fallback. Keep using them to maintain
# ABI compatibility with autotools builds of glibs
# and with *any* glib-using code compiled against them,
# since these values end up in a public header glibconfig.h.
foreach d : poll_defines
glibconfig_conf.set(d[1], d[2])
endforeach
endif
# Internet address families
# FIXME: what about Cygwin (G_WITH_CYGWIN)
if host_system == 'windows'
inet_includes = '''
#include <winsock2.h>'''
else
inet_includes = '''
#include <sys/types.h>
#include <sys/socket.h>'''
endif
inet_defines = [
[ 'AF_UNIX', 'g_af_unix' ],
[ 'AF_INET', 'g_af_inet' ],
[ 'AF_INET6', 'g_af_inet6' ],
[ 'MSG_OOB', 'g_msg_oob' ],
[ 'MSG_PEEK', 'g_msg_peek' ],
[ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
]
foreach d : inet_defines
val = cc.compute_int(d[0], prefix: inet_includes)
glibconfig_conf.set(d[1], val)
endforeach
glibconfig_conf.set('GLIB_USING_SYSTEM_PRINTF', true) # FIXME!
# We need a more robust approach here...
host_cpu_family = host_machine.cpu_family()
if host_cpu_family == 'x86' or host_cpu_family == 'x86_64' or host_cpu_family == 's390' or host_cpu_family == 's390x' or host_cpu_family.startswith('arm') or host_cpu_family.startswith('crisv32') or host_cpu_family.startswith('etrax')
glib_memory_barrier_needed = false
elif host_cpu_family.startswith('sparc') or host_cpu_family.startswith('alpha') or host_cpu_family.startswith('powerpc') or host_cpu_family == 'ia64'
glib_memory_barrier_needed = true
else
warning('Unknown host cpu: ' + host_cpu_family)
glib_memory_barrier_needed = true
endif
glibconfig_conf.set('G_ATOMIC_OP_MEMORY_BARRIER_NEEDED', glib_memory_barrier_needed)
# We need to decide at configure time if GLib will use real atomic
# operations ("lock free") or emulated ones with a mutex. This is
# because we must put this information in glibconfig.h so we know if
# it is safe or not to inline using compiler intrinsics directly from
# the header.
#
# We also publish the information via G_ATOMIC_LOCK_FREE in case the
# user is interested in knowing if they can use the atomic ops across
# processes.
#
# We can currently support the atomic ops natively when building GLib
# with recent versions of GCC or MSVC.
#
# Note that the atomic ops are only available with GCC on x86 when
# using -march=i486 or higher. If we detect that the atomic ops are
# not available but would be available given the right flags, we want
# to abort and advise the user to fix their CFLAGS. It's better to do
# that then to silently fall back on emulated atomic ops just because
# the user had the wrong build environment.
atomictest = '''int main() {
volatile int atomic = 2;
__sync_bool_compare_and_swap (&atomic, 2, 3);
return 0;
}
'''
atomicdefine = '''
#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
#error "compiler has atomic ops, but doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"
#endif
'''
# We know that we can always use real ("lock free") atomic operations with MSVC
if cc.get_id() == 'msvc' or cc.links(atomictest, name : 'atomic ops')
have_atomic_lock_free = true
if host_system == 'android' and not cc.compiles(atomicdefine, name : 'atomic ops define')
# When building for armv5 on Android, gcc 4.9 provides
# __sync_bool_compare_and_swap but doesn't define
# __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
glib_conf.set('__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4', true)
endif
else
have_atomic_lock_free = false
if host_machine.cpu_family() == 'x86' and cc.links(atomictest, args : '-march=i486')
error('GLib must be built with -march=i486 or later.')
endif
endif
glibconfig_conf.set('G_ATOMIC_LOCK_FREE', have_atomic_lock_free)
# === Threads ===
# Determination of thread implementation
if host_system == 'windows' and not get_option('force_posix_threads')
thread_dep = []
threads_implementation = 'win32'
glibconfig_conf.set('g_threads_impl_def', 'WIN32')
glib_conf.set('THREADS_WIN32', 1)
else
thread_dep = dependency('threads')
threads_implementation = 'posix'
pthread_prefix = '''
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <pthread.h>'''
glibconfig_conf.set('g_threads_impl_def', 'POSIX')
glib_conf.set('THREADS_POSIX', 1)
if cc.has_header_symbol('pthread.h', 'pthread_attr_setstacksize')
glib_conf.set('HAVE_PTHREAD_ATTR_SETSTACKSIZE', 1)
endif
if cc.has_header_symbol('pthread.h', 'pthread_condattr_setclock')
glib_conf.set('HAVE_PTHREAD_CONDATTR_SETCLOCK', 1)
endif
if cc.has_header_symbol('pthread.h', 'pthread_cond_timedwait_relative_np')
glib_conf.set('HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP', 1)
endif
if cc.has_header_symbol('pthread.h', 'pthread_getname_np', prefix : pthread_prefix)
glib_conf.set('HAVE_PTHREAD_GETNAME_NP', 1)
endif
# Assume that pthread_setname_np is available in some form; same as configure
if cc.links(pthread_prefix + '''
int main() {
pthread_setname_np("example");
return 0;
}''',
name : 'pthread_setname_np(const char*)',
dependencies : thread_dep)
# macOS and iOS
glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID', 1)
elif cc.links(pthread_prefix + '''
int main() {
pthread_setname_np(pthread_self(), "example");
return 0;
}''',
name : 'pthread_setname_np(pthread_t, const char*)',
dependencies : thread_dep)
# Linux, Solaris, etc.
glib_conf.set('HAVE_PTHREAD_SETNAME_NP_WITH_TID', 1)
endif
endif
# FIXME: we should make it print the result and always return 0, so that
# the output in meson shows up as green
stack_grows_check_prog = '''
volatile int *a = 0, *b = 0;
void f (int i) {
volatile int x = 5;
if (i == 0)
b = &x;
else
f (i - 1);
}
int main () {
volatile int y = 7;
a = &y;
f (100);
return b > a ? 0 : 1;
}'''
if cc_can_run
rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
growing_stack = rres.returncode() == 0
else
growing_stack = meson.get_cross_property('growing_stack', false)
endif
glibconfig_conf.set('G_HAVE_GROWING_STACK', growing_stack)
# Tests for iconv
#
# USE_LIBICONV_GNU: Using GNU libiconv
# USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library
#
# We should never use the MinGW C library's iconv. On Windows we use the
# GNU implementation that ships with MinGW.
# On Windows, just always use the built-in implementation
if host_system == 'windows'
libiconv = []
glib_conf.set('USE_LIBICONV_NATIVE', true)
else
found_iconv = false
iconv_opt = get_option('iconv')
if iconv_opt == 'libc'
if cc.has_function('iconv_open')
libiconv = []
found_iconv = true
endif
elif iconv_opt == 'gnu'
if cc.has_header_symbol('iconv.h', 'libiconv_open')
glib_conf.set('USE_LIBICONV_GNU', true)
libiconv = [cc.find_library('iconv')]
found_iconv = true
endif
elif iconv_opt == 'native'
if cc.has_header_symbol('iconv.h', 'iconv_open')
glib_conf.set('USE_LIBICONV_NATIVE', true)
libiconv = [cc.find_library('iconv')]
found_iconv = true
endif
endif
if not found_iconv
error('iconv implementation "@0@" not found'.format(iconv_opt))
endif
endif
if get_option('internal_pcre')
pcre = []
use_system_pcre = false
else
pcre = dependency('libpcre', version: '>= 8.31', required : false) # Should check for Unicode support, too. FIXME
if not pcre.found()
if cc.get_id() == 'msvc'
# MSVC: Search for the PCRE library by the configuration, which corresponds
# to the output of CMake builds of PCRE. Note that debugoptimized
# is really a Release build with .PDB files.
if buildtype == 'debug'
pcre = cc.find_library('pcred', required : false)
else
pcre = cc.find_library('pcre', required : false)
endif
endif
endif
use_system_pcre = pcre.found()
endif
glib_conf.set('USE_SYSTEM_PCRE', use_system_pcre)
use_pcre_static_flag = false
if host_system == 'windows'
if not use_system_pcre
use_pcre_static_flag = true
else
pcre_static = cc.links('''#define PCRE_STATIC
#include <pcre.h>
int main() {
void *p = NULL;
pcre_free(p);
return 0;
}''',
dependencies: pcre,
name : 'Windows system PCRE is a static build')
if pcre_static
use_pcre_static_flag = true
endif
endif
endif
libm = cc.find_library('m', required : false)
libffi_dep = dependency('libffi', version : '>= 3.0.0', fallback : ['libffi', 'ffi_dep'])
if cc.get_id() != 'msvc'
libz_dep = dependency('zlib', fallback : ['zlib', 'zlib_dep'])
else
# MSVC: Don't use the bundled ZLib sources until we are sure that we can't
# find the ZLib .lib
libz_dep = dependency('zlib', required : false)
# MSVC: Search for the ZLib .lib, which corresponds to the results of
# of using ZLib's win32/makefile.msc.
if not libz_dep.found()
libz_dep = cc.find_library('zlib1', required : false)
if not libz_dep.found()
libz_dep = cc.find_library('zlib', required : false)
if not libz_dep.found()
libz_dep = subproject('zlib').get_variable('zlib_dep')
endif
endif
endif
endif
# First check in libc, fallback to libintl, and as last chance build
# proxy-libintl subproject.
# FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
# implementations. This could be extended if issues are found in some platforms.
if cc.has_function('ngettext')
libintl = []
else
libintl = cc.find_library('intl', required : false)
if not libintl.found()
libintl = subproject('proxy-libintl').get_variable('intl_dep')
endif
endif
# We require gettext to always be present
glib_conf.set('HAVE_DCGETTEXT', 1)
glib_conf.set('HAVE_GETTEXT', 1)
glib_conf.set_quoted('GLIB_LOCALE_DIR', join_paths(glib_datadir, 'locale'))
# xgettext is optional (on Windows for instance)
xgettext = find_program('xgettext', required : false)
# libmount is only used by gio, but we need to fetch the libs to generate the
# pkg-config file below
libmount_dep = []
if host_system == 'linux' and get_option('libmount')
libmount_dep = [dependency('mount', version : '>=2.23', required : true)]
glib_conf.set('HAVE_LIBMOUNT', 1)
endif
if host_system == 'windows'
winsock2 = cc.find_library('ws2_32')
endif
selinux_dep = []
if host_system == 'linux' and get_option('selinux')
selinux_dep = [dependency('libselinux')]
glib_conf.set('HAVE_SELINUX', 1)
endif
xattr_dep = []
if host_system != 'windows' and get_option('xattr')
# either glibc or libattr can provide xattr support
# for both of them, we check for getxattr being in
# the library and a valid xattr header.
# try glibc
if cc.has_function('getxattr') and cc.has_header('sys/xattr.h')
glib_conf.set('HAVE_SYS_XATTR_H', 1)
glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_SYS_XATTR_H')
#failure. try libattr
elif cc.has_header_symbol('attr/xattr.h', 'getxattr')
glib_conf.set('HAVE_ATTR_XATTR_H', 1)
glib_conf_prefix = glib_conf_prefix + '#define @0@ 1\n'.format('HAVE_ATTR_XATTR_H')
xattr_dep = [cc.find_library('xattr')]
else
error('No getxattr implementation found in C library or libxattr')
endif
glib_conf.set('HAVE_XATTR', 1)
if cc.compiles(glib_conf_prefix + '''
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_XATTR_H
#include <sys/xattr.h>
#elif HAVE_ATTR_XATTR_H
#include <attr/xattr.h>
#endif
int main (void) {
ssize_t len = getxattr("", "", NULL, 0, 0, XATTR_NOFOLLOW);
return len;
}''',
name : 'XATTR_NOFOLLOW')
glib_conf.set('HAVE_XATTR_NOFOLLOW', 1)
endif
endif
# Test if we have strlcpy/strlcat with a compatible implementation:
# https://bugzilla.gnome.org/show_bug.cgi?id=53933
if cc_can_run
rres = cc.run('''#include <stdlib.h>
#include <string.h>
int main() {
char p[10];
(void) strlcpy (p, "hi", 10);
if (strlcat (p, "bye", 0) != 3)
return 1;
return 0;
}''',
name : 'OpenBSD strlcpy/strlcat')
if rres.compiled() and rres.returncode() == 0
glib_conf.set('HAVE_STRLCPY', 1)
endif
elif meson.get_cross_property('have_strlcpy', false)
glib_conf.set('HAVE_STRLCPY', 1)
endif
python = import('python').find_installation('python3')
# used for '#!/usr/bin/env <name>'
python_name = 'python3'
# Determine which user environment-dependent files that we want to install
have_bash = find_program('bash', required : false).found() # For completion scripts
have_m4 = find_program('m4', required : false).found() # For m4 macros
have_sh = find_program('sh', required : false).found() # For glib-gettextize
# FIXME: defines in config.h that are not actually used anywhere
# (we add them for now to minimise the diff)
glib_conf.set('HAVE_DLFCN_H', 1)
glib_conf.set('STDC_HEADERS', 1)
glib_conf.set('SIZEOF___INT64', 8)
# FIXME: How to detect Solaris? https://github.com/mesonbuild/meson/issues/1578
if host_system == 'sunos'
glib_conf.set('_XOPEN_SOURCE_EXTENDED', 1)
glib_conf.set('_XOPEN_SOURCE', 2)
glib_conf.set('__EXTENSIONS__',1)
endif
# Sadly Meson does not expose this value:
# https://github.com/mesonbuild/meson/pull/3460
if host_system == 'windows'
# Autotools explicitly removed --Wl,--export-all-symbols from windows builds,
# with no explanation. Do the same here for now but this could be revisited if
# if causes issues.
export_dynamic_ldflags = []
elif host_system == 'cygwin'
export_dynamic_ldflags = ['-Wl,--export-all-symbols']
elif host_system == 'darwin'
export_dynamic_ldflags = []
else
export_dynamic_ldflags = ['-Wl,--export-dynamic']
endif
win32_cflags = []
win32_ldflags = []
if host_system == 'windows' and cc.get_id() != 'msvc'
# Ensure MSVC-compatible struct packing convention is used when
# compiling for Win32 with gcc. It is used for the whole project and exposed
# in glib-2.0.pc.
win32_cflags = ['-mms-bitfields']
add_project_arguments(win32_cflags, language : 'c')
# Win32 API libs, used only by libglib and exposed in glib-2.0.pc
win32_ldflags = ['-lws2_32', '-lole32', '-lwinmm', '-lshlwapi']
elif host_system == 'cygwin'
win32_ldflags = ['-luser32', '-lkernel32']
endif
# Tracing: dtrace
want_dtrace = get_option('dtrace')
enable_dtrace = false
# Since dtrace support is opt-in we just error out if it was requested but
# is not available. We don't bother with autodetection yet.
if want_dtrace
if glib_have_carbon
error('GLib dtrace support not yet compatible with macOS dtrace')
endif
dtrace = find_program('dtrace', required : true) # error out if not found
if not cc.has_header('sys/sdt.h')
error('dtrace support needs sys/sdt.h header')
endif
# FIXME: autotools build also passes -fPIC -DPIC but is it needed in this case?
dtrace_obj_gen = generator(dtrace,
output : '@BASENAME@.o',
arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@'])
# FIXME: $(SED) -e "s,define STAP_HAS_SEMAPHORES 1,undef STAP_HAS_SEMAPHORES,"
# -e "s,define _SDT_HAS_SEMAPHORES 1,undef _SDT_HAS_SEMAPHORES,"
dtrace_hdr_gen = generator(dtrace,
output : '@BASENAME@.h',
arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@'])
glib_conf.set('HAVE_DTRACE', 1)
enable_dtrace = true
endif
# systemtap
want_systemtap = get_option('systemtap')
enable_systemtap = false
if want_systemtap and enable_dtrace
tapset_install_dir = get_option('tapset_install_dir')
if tapset_install_dir == ''
tapset_install_dir = join_paths(get_option('datadir'), 'systemtap/tapset', host_machine.cpu_family())
endif
stp_cdata = configuration_data()
stp_cdata.set('ABS_GLIB_RUNTIME_LIBDIR', glib_libdir)
stp_cdata.set('LT_CURRENT', minor_version * 100)
stp_cdata.set('LT_REVISION', micro_version)
enable_systemtap = true
endif
pkg = import('pkgconfig')
windows = import('windows')
subdir('glib')
subdir('gobject')
subdir('gthread')
subdir('gmodule')
subdir('gio')
if xgettext.found()
subdir('po')
endif
subdir('tests')
# Install glib-gettextize executable, if a UNIX-style shell is found
if have_sh
# These should not contain " quotes around the values
gettexize_conf = configuration_data()
gettexize_conf.set('PACKAGE', 'glib')
gettexize_conf.set('VERSION', meson.project_version())
gettexize_conf.set('prefix', glib_prefix)
gettexize_conf.set('datarootdir', glib_datadir)
gettexize_conf.set('datadir', glib_datadir)
configure_file(input : 'glib-gettextize.in',
install : true,
install_dir : 'bin',
output : 'glib-gettextize',
configuration : gettexize_conf)
endif
if have_m4
# Install m4 macros that other projects use
install_data('m4macros/glib-2.0.m4', 'm4macros/glib-gettext.m4', 'm4macros/gsettings.m4',
install_dir : join_paths(get_option('datadir'), 'aclocal'))
endif
if host_system != 'windows'
# Install Valgrind suppression file (except on Windows,
# as Valgrind is currently not supported on Windows)
install_data('glib.supp',
install_dir : join_paths(get_option('datadir'), 'glib-2.0', 'valgrind'))
endif
configure_file(output : 'config.h', configuration : glib_conf)
if host_system == 'windows'
install_headers([ 'msvc_recommended_pragmas.h' ], subdir : 'glib-2.0')
endif
if get_option('man')
xsltproc = find_program('xsltproc', required : true)
xsltproc_command = [
xsltproc,
'--nonet',
'--stringparam', 'man.output.quietly', '1',
'--stringparam', 'funcsynopsis.style', 'ansi',
'--stringparam', 'man.th.extra1.suppress', '1',
'--stringparam', 'man.authors.section.enabled', '0',
'--stringparam', 'man.copyright.section.enabled', '0',
'-o', '@OUTPUT@',
'http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl',
'@INPUT@',
]
man1_dir = get_option('mandir') + '/man1'
endif
gnome = import('gnome')
subdir('docs/reference/glib')
subdir('docs/reference/gobject')
subdir('docs/reference/gio')
|