@@ -37,6 +37,32 @@ 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
+ #include <atomic>
44
+ #include <cstdint>
45
+
46
+ int main() {
47
+ volatile std::atomic<std::uint64_t> testvar;
48
+ // The line below will lead to
49
+ // undefined reference to `__atomic_fetch_add_8'
50
+ // on armv6l to give an example.
51
+ volatile auto unused = testvar.fetch_add(0);
52
+ }
53
+ ''' , name : ' Check if libatomic is required' )
54
+ if meson .version().version_compare(' >=1.7.0' )
55
+ atomic_dep = dependency (' atomic' )
56
+ else
57
+ atomic_dep = cc.find_library (
58
+ ' atomic' ,
59
+ required : true ,
60
+ )
61
+ endif
62
+ else
63
+ atomic_dep = []
64
+ endif
65
+
40
66
deps = [
41
67
dependency (' absl_base' ),
42
68
dependency (' absl_cord' ),
@@ -58,6 +84,7 @@ deps = [
58
84
' dbghelp' ,
59
85
required : host_machine .system() == ' windows' ,
60
86
),
87
+ atomic_dep,
61
88
]
62
89
63
90
incdir = include_directories (' src' )
@@ -136,6 +163,7 @@ protobuf_lite_dep = declare_dependency(
136
163
compile_args : imp,
137
164
link_with : libprotobuf_lite,
138
165
include_directories : incdir,
166
+ dependencies : atomic_dep,
139
167
)
140
168
141
169
libprotobuf_src = files (
@@ -218,8 +246,8 @@ libprotobuf_src = files(
218
246
' src/google/protobuf/wrappers.pb.cc' ,
219
247
)
220
248
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
- ] : []
249
+ ' /export:??$MergeFrom@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@RepeatedPtrFieldBase@internal@protobuf@google@@QEAAXAEBV0123@@Z' ,
250
+ ] : []
223
251
)
224
252
libprotobuf = library (
225
253
' protobuf' ,
0 commit comments