Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions mesonbuild/cmake/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ def __init__(self, target: CMakeTarget, env: 'Environment', for_machine: Machine
self.compile_opts: T.Dict[str, T.List[str]] = {}
self.public_compile_opts: T.List[str] = []
self.pie = False
self.version: T.Optional[str] = None
self.soversion: T.Optional[str] = None

# Project default override options (c_std, cpp_std, etc.)
self.override_options: T.List[str] = []
Expand Down Expand Up @@ -357,6 +359,8 @@ def postprocess(self, output_target_map: OutputTargetMap, root_src_dir: Path, su
tgt = trace.targets.get(self.cmake_name)
if tgt:
self.depends_raw = trace.targets[self.cmake_name].depends
self.version = trace.targets[self.cmake_name].properties.get('VERSION', [None])[0]
self.soversion = trace.targets[self.cmake_name].properties.get('SOVERSION', [None])[0]

rtgt = resolve_cmake_trace_targets(self.cmake_name, trace, self.env, clib_compiler=self.clib_compiler)
self.includes += [Path(x) for x in rtgt.include_directories]
Expand Down Expand Up @@ -1172,6 +1176,12 @@ def process_target(tgt: ConverterTarget) -> None:
'objects': [method(x, 'extract_all_objects') for x in objec_libs],
}

# Only set version if we know it
if tgt.version:
tgt_kwargs['version'] = tgt.version
if tgt.soversion:
tgt_kwargs['soversion'] = tgt.soversion

# Only set if installed and only override if it is set
if install_tgt and tgt.install_dir:
tgt_kwargs['install_dir'] = tgt.install_dir
Expand Down
18 changes: 18 additions & 0 deletions test cases/cmake/2 advanced/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,21 @@ test('test3', sub_pro.target('testEXE'))
# Test that we can add a new target with the same name as the CMake subproject
exe4 = executable('testEXE', ['main.cpp'], dependencies: [sub_sta])
test('test4', exe4)

# Test if libraries are named correctly
assert(sub_pro.target_type('cmModLib') == 'shared_library', 'Type should be shared_library')
expected_soversion_str = '1'
expected_version_str = '1.0.1'
lib_file_name = import('fs').name(sub_pro.target('cmModLib').full_path())
if host_machine.system() == 'linux'
# Linux shared libraries end with their version: libcmModLib.so.1.0.1
lib_version_ok = lib_file_name.endswith(expected_version_str)
elif host_machine.system() == 'darwin'
# MacOS shared libraries are suffixed with their soversion: libcmModLib.1.dylib
lib_version_ok = lib_file_name.split('.')[1] == expected_soversion_str
else
# Don't try to assert anything about the library version, either unknown host
# system or host system doesn't support versioning of shared libraries
lib_version_ok = true
endif
assert(lib_version_ok, f'Shared library version @lib_file_name@ not picked up correctly')
Loading