@@ -37,6 +37,39 @@ absl_string_view_dep = dependency(
3737  default_options : [' cpp_std=c++17'  ],
3838)
3939
40+ if  meson .version().version_compare(' >=1.7.0'  )
41+   atomic_dep =  dependency (
42+     ' atomic'  ,
43+     required : false ,
44+   )
45+ else 
46+   atomic_dep =  cc.find_library (
47+     ' atomic'  ,
48+     required : false ,
49+   )
50+ endif 
51+ 
52+ # Make reasonable effort (volatile) to prevent the compiler from optimizing the atomic away without using tested 
53+ # functionality. 
54+ if  not  cc.links(
55+   ''' 
56+ #include <atomic> 
57+ #include <cstdint> 
58+ 
59+ int main() { 
60+     volatile std::atomic<std::uint64_t> testvar; 
61+     // The line below will lead to 
62+     // undefined reference to `__atomic_fetch_add_8' 
63+     // on armv6l to give an example. 
64+     volatile auto unused = testvar.fetch_add(0); 
65+ } 
66+   '''  ,
67+   name : ' Check if libatomic is required'  ,
68+   dependencies : atomic_dep,
69+ )
70+   error (' Host machine cannot handle atomics!'  )
71+ endif 
72+ 
4073deps =  [
4174  dependency (' absl_base'  ),
4275  dependency (' absl_cord'  ),
@@ -58,6 +91,7 @@ deps = [
5891    ' dbghelp'  ,
5992    required : host_machine .system() ==  ' windows'  ,
6093  ),
94+   atomic_dep,
6195]
6296
6397incdir =  include_directories (' src'  )
@@ -136,6 +170,7 @@ protobuf_lite_dep = declare_dependency(
136170  compile_args : imp,
137171  link_with : libprotobuf_lite,
138172  include_directories : incdir,
173+   dependencies : atomic_dep,
139174)
140175
141176libprotobuf_src =  files (
@@ -218,8 +253,8 @@ libprotobuf_src = files(
218253  ' src/google/protobuf/wrappers.pb.cc'  ,
219254)
220255libprotobuf_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- ] : []
256+      ' /export:??$MergeFrom@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@RepeatedPtrFieldBase@internal@protobuf@google@@QEAAXAEBV0123@@Z'  ,
257+    ] : []
223258)
224259libprotobuf =  library (
225260  ' protobuf'  ,
0 commit comments