@@ -37,6 +37,35 @@ absl_string_view_dep = dependency(
37
37
default_options : [' cpp_std=c++17' ],
38
38
)
39
39
40
+ # Make reasonable effort (volatile) to prevent the compiler from optimizing the atomic away without using tested
41
+ # functionality.
42
+ if cc.links(
43
+ '''
44
+ #include <atomic>
45
+ #include <cstdint>
46
+
47
+ int main() {
48
+ volatile std::atomic<std::uint64_t> testvar;
49
+ // The line below will lead to
50
+ // undefined reference to `__atomic_fetch_add_8'
51
+ // on armv6l to give an example.
52
+ volatile auto unused = testvar.fetch_add(0);
53
+ }
54
+ ''' ,
55
+ name : ' Check if libatomic is required' ,
56
+ )
57
+ if meson .version().version_compare(' >=1.7.0' )
58
+ atomic_dep = dependency (' atomic' )
59
+ else
60
+ atomic_dep = cc.find_library (
61
+ ' atomic' ,
62
+ required : true ,
63
+ )
64
+ endif
65
+ else
66
+ atomic_dep = []
67
+ endif
68
+
40
69
deps = [
41
70
dependency (' absl_base' ),
42
71
dependency (' absl_cord' ),
@@ -58,6 +87,7 @@ deps = [
58
87
' dbghelp' ,
59
88
required : host_machine .system() == ' windows' ,
60
89
),
90
+ atomic_dep,
61
91
]
62
92
63
93
incdir = include_directories (' src' )
@@ -136,6 +166,7 @@ protobuf_lite_dep = declare_dependency(
136
166
compile_args : imp,
137
167
link_with : libprotobuf_lite,
138
168
include_directories : incdir,
169
+ dependencies : atomic_dep,
139
170
)
140
171
141
172
libprotobuf_src = files (
@@ -218,8 +249,8 @@ libprotobuf_src = files(
218
249
' src/google/protobuf/wrappers.pb.cc' ,
219
250
)
220
251
libprotobuf_linker_args = (is_msvc ? [
221
- ' /export:??$MergeFrom@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@RepeatedPtrFieldBase@internal@protobuf@google@@QEAAXAEBV0123@@Z' ,
222
- ] : []
252
+ ' /export:??$MergeFrom@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@RepeatedPtrFieldBase@internal@protobuf@google@@QEAAXAEBV0123@@Z' ,
253
+ ] : []
223
254
)
224
255
libprotobuf = library (
225
256
' protobuf' ,
0 commit comments