Merge pull request #5992 from mensinda/cmakeFixSoVersion

cmake: fix detection of libraries with .so version
pull/5998/head
Jussi Pakkanen 5 years ago committed by GitHub
commit 5bbea6be05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      mesonbuild/cmake/interpreter.py
  2. 2
      mesonbuild/compilers/compilers.py
  3. 2
      test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt
  4. 2
      test cases/cmake/3 advanced no dep/subprojects/cmMod/CMakeLists.txt

@ -22,7 +22,7 @@ from .traceparser import CMakeTraceParser, CMakeGeneratorTarget
from .. import mlog
from ..environment import Environment
from ..mesonlib import MachineChoice
from ..compilers.compilers import lang_suffixes, header_suffixes, obj_suffixes, is_header
from ..compilers.compilers import lang_suffixes, header_suffixes, obj_suffixes, lib_suffixes, is_header
from subprocess import Popen, PIPE
from typing import Any, List, Dict, Optional, TYPE_CHECKING
from threading import Thread
@ -117,6 +117,7 @@ def _generated_file_key(fname: str) -> str:
class ConverterTarget:
lang_cmake_to_meson = {val.lower(): key for key, val in language_map.items()}
rm_so_version = re.compile(r'(\.[0-9]+)+$')
def __init__(self, target: CMakeTarget, env: Environment):
self.env = env
@ -211,15 +212,30 @@ class ConverterTarget:
mlog.warning('CMake: Target', mlog.bold(self.name), 'not found in CMake trace. This can lead to build errors')
# Fix link libraries
def try_resolve_link_with(path: str) -> Optional[str]:
basename = os.path.basename(path)
candidates = [basename, ConverterTarget.rm_so_version.sub('', basename)]
for i in lib_suffixes:
if not basename.endswith('.' + i):
continue
new_basename = basename[:-len(i) - 1]
new_basename = ConverterTarget.rm_so_version.sub('', new_basename)
new_basename = '{}.{}'.format(new_basename, i)
candidates += [new_basename]
for i in candidates:
if i in output_target_map:
return output_target_map[i]
return None
temp = []
for i in self.link_libraries:
# Let meson handle this arcane magic
if ',-rpath,' in i:
continue
if not os.path.isabs(i):
basename = os.path.basename(i)
if basename in output_target_map:
self.link_with += [output_target_map[basename]]
link_with = try_resolve_link_with(i)
if link_with:
self.link_with += [link_with]
continue
temp += [i]
@ -586,14 +602,9 @@ class CMakeInterpreter:
# generate the output_target_map
output_target_map = {}
output_target_map.update({x.full_name: x for x in self.targets})
output_target_map.update({_target_key(x.name): x for x in self.targets})
for i in self.targets:
output_target_map[i.full_name] = i
output_target_map[_target_key(i.name)] = i
ttarget = self.trace.targets.get(i.name)
soversion = ttarget.properties.get('SOVERSION') if ttarget else None
if soversion:
k = '{}.{}'.format(i.full_name, soversion[0])
output_target_map[k] = i
for j in i.artifacts:
output_target_map[os.path.basename(j)] = i
for i in self.custom_targets:

@ -39,7 +39,7 @@ Also add corresponding autodetection code in environment.py."""
header_suffixes = ('h', 'hh', 'hpp', 'hxx', 'H', 'ipp', 'moc', 'vapi', 'di')
obj_suffixes = ('o', 'obj', 'res')
lib_suffixes = ('a', 'lib', 'dll', 'dylib', 'so')
lib_suffixes = ('a', 'lib', 'dll', 'dll.a', 'dylib', 'so')
# Mapping of language to suffixes of files that should always be in that language
# This means we can't include .h headers here since they could be C, C++, ObjC, etc.
lang_suffixes = {

@ -14,6 +14,8 @@ add_library(cmModLib SHARED lib/cmMod.cpp)
include(GenerateExportHeader)
generate_export_header(cmModLib)
set_target_properties(cmModLib PROPERTIES VERSION 1.0.1)
add_executable(testEXE main.cpp)
target_link_libraries(cmModLib ZLIB::ZLIB)

@ -12,6 +12,8 @@ add_library(cmModLib SHARED lib/cmMod.cpp)
include(GenerateExportHeader)
generate_export_header(cmModLib)
set_target_properties(cmModLib PROPERTIES VERSION 1.0.1)
add_executable(testEXE main.cpp)
target_link_libraries(testEXE cmModLib)

Loading…
Cancel
Save