@@ -37,6 +37,32 @@ 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+ #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+
4066deps = [
4167 dependency (' absl_base' ),
4268 dependency (' absl_cord' ),
@@ -58,6 +84,7 @@ deps = [
5884 ' dbghelp' ,
5985 required : host_machine .system() == ' windows' ,
6086 ),
87+ atomic_dep,
6188]
6289
6390incdir = include_directories (' src' )
@@ -136,6 +163,7 @@ protobuf_lite_dep = declare_dependency(
136163 compile_args : imp,
137164 link_with : libprotobuf_lite,
138165 include_directories : incdir,
166+ dependencies : atomic_dep,
139167)
140168
141169libprotobuf_src = files (
@@ -218,8 +246,8 @@ libprotobuf_src = files(
218246 ' src/google/protobuf/wrappers.pb.cc' ,
219247)
220248libprotobuf_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+ ] : []
223251)
224252libprotobuf = library (
225253 ' protobuf' ,
0 commit comments