@@ -37,6 +37,35 @@ absl_string_view_dep = dependency(
3737 default_options : [' cpp_std=c++17' ],
3838)
3939
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+
4069deps = [
4170 dependency (' absl_base' ),
4271 dependency (' absl_cord' ),
@@ -58,6 +87,7 @@ deps = [
5887 ' dbghelp' ,
5988 required : host_machine .system() == ' windows' ,
6089 ),
90+ atomic_dep,
6191]
6292
6393incdir = include_directories (' src' )
@@ -136,6 +166,7 @@ protobuf_lite_dep = declare_dependency(
136166 compile_args : imp,
137167 link_with : libprotobuf_lite,
138168 include_directories : incdir,
169+ dependencies : atomic_dep,
139170)
140171
141172libprotobuf_src = files (
@@ -218,8 +249,8 @@ libprotobuf_src = files(
218249 ' src/google/protobuf/wrappers.pb.cc' ,
219250)
220251libprotobuf_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+ ] : []
223254)
224255libprotobuf = library (
225256 ' protobuf' ,
0 commit comments