Skip to content

Commit

Permalink
protobuf: default to static, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
klokik committed Jan 22, 2024
1 parent 64a6e07 commit c5d4ddc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 39 deletions.
53 changes: 16 additions & 37 deletions subprojects/packagefiles/protobuf/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ project(
license: 'protobuf',
default_options: [
'warning_level=0',
# I was unable to get libprotoc linking as shared library on MINGW, for whatever reason
# abseil-cpp symbols are sticking out of libprotobuf and are reported as multiple definitions
# Linux, Mac and MSVC should work perfectly fine as shared libs
# If you have time and inspiration, please fix.
'default_library=static',
'cpp_std=c++17',
],
meson_version: '>=0.63.0',
)

is_shared = (get_option('default_library') != 'static')

cc = meson.get_compiler('cpp')
if cc.get_argument_syntax() == 'msvc'
add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', cc.get_supported_arguments('-Wno-deprecated-declarations'), language: 'cpp')
Expand Down Expand Up @@ -86,28 +93,19 @@ libprotobuf_lite_src = files(
'src/google/protobuf/stubs/common.cc',
'src/google/protobuf/wire_format_lite.cc',
)
api = []
if host_machine.system() == 'windows'
api += '-DLIBPROTOBUF_EXPORTS'
if get_option('default_library') != 'static'
api += '-DPROTOBUF_USE_DLLS'
endif
endif
api = is_shared ? ['-DPROTOBUF_USE_DLLS'] : []
libprotobuf_lite = library(
'protobuf-lite',
libprotobuf_lite_src,
cpp_args: api,
cpp_args: ['-DLIBPROTOBUF_EXPORTS', api],
dependencies: deps,
gnu_symbol_visibility: 'hidden',
version: meson.project_version(),
soversion: 25,
install: true,
include_directories: incdir,
)
imp = []
if host_machine.system() == 'windows' and get_option('default_library') != 'static'
imp += '-DPROTOBUF_USE_DLLS'
endif
imp = is_shared ? ['-DPROTOBUF_USE_DLLS'] : []
protobuf_lite_dep = declare_dependency(
compile_args: imp,
link_with: libprotobuf_lite,
Expand Down Expand Up @@ -193,28 +191,17 @@ libprotobuf_src = files(
'src/google/protobuf/wire_format.cc',
'src/google/protobuf/wire_format_lite.cc',
)
api = []
if host_machine.system() == 'windows'
api += '-DLIBPROTOBUF_EXPORTS'
if get_option('default_library') != 'static'
api += '-DPROTOBUF_USE_DLLS'
endif
endif
libprotobuf = library(
'protobuf',
libprotobuf_src,
cpp_args: api,
sources: libprotobuf_src,
cpp_args: ['-DLIBPROTOBUF_EXPORTS', api],
dependencies: [deps],
gnu_symbol_visibility: 'hidden',
version: meson.project_version(),
soversion: 25,
install: true,
include_directories: incdir,
)
imp = []
if host_machine.system() == 'windows' and get_option('default_library') != 'static'
imp += '-DPROTOBUF_USE_DLLS'
endif
protobuf_dep = declare_dependency(
compile_args: imp,
link_with: libprotobuf,
Expand Down Expand Up @@ -334,25 +321,17 @@ libprotoc_src = files(
'src/google/protobuf/compiler/subprocess.cc',
'src/google/protobuf/compiler/zip_writer.cc',
)
api = []
if host_machine.system() == 'windows'
api += '-DLIBPROTOC_EXPORTS'
if get_option('default_library') != 'static'
api += '-DPROTOBUF_USE_DLLS'
endif
endif
libprotoc = library(
'protoc',
libprotoc_src,
libprotobuf_src,
cpp_args: api,
dependencies: [protobuf_dep.partial_dependency(includes: true), deps],
gnu_symbol_visibility: 'hidden',
sources: libprotoc_src,
cpp_args: ['-DLIBPROTOC_EXPORTS', api],
dependencies: [protobuf_dep, deps],
version: meson.project_version(),
soversion: 25,
install: true,
)
protoc_dep = declare_dependency(
compile_args: imp,
dependencies: protobuf_dep,
link_with: libprotoc,
)
Expand Down
4 changes: 2 additions & 2 deletions subprojects/packagefiles/protobuf/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ absl_log_initialize_dep = dependency('absl_log_initialize')
protoc_src = ['google/protobuf/compiler/main.cc']
protoc = executable(
'protoc',
protoc_src,
sources: protoc_src,
include_directories: incdir,
dependencies: [
dependency('threads'),
Expand All @@ -26,7 +26,7 @@ protoc = executable(
if meson.is_cross_build()
protoc_native = executable(
'protoc-native',
[libprotobuf_lite_src, libprotobuf_src, libprotoc_src, protoc_src],
sources: [libprotobuf_lite_src, libprotobuf_src, libprotoc_src, protoc_src],
native: true,
include_directories: incdir,
dependencies: [
Expand Down

0 comments on commit c5d4ddc

Please sign in to comment.