From 2b44b4be9f0e3896ca7f7a24c92a841939332596 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sat, 23 Feb 2019 11:50:32 +0100 Subject: [PATCH] cmake: Fixed install prefix --- mesonbuild/cmake/interpreter.py | 14 ++++++++++---- mesonbuild/interpreter.py | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py index b296ed463..e070a684d 100644 --- a/mesonbuild/cmake/interpreter.py +++ b/mesonbuild/cmake/interpreter.py @@ -107,7 +107,7 @@ class ConverterTarget: std_regex = re.compile(r'([-]{1,2}std=|/std:v?)(.*)') - def postprocess(self, output_target_map: dict, root_src_dir: str) -> None: + def postprocess(self, output_target_map: dict, root_src_dir: str, install_prefix: str) -> None: # Detect setting the C and C++ standard for i in ['c', 'cpp']: if not i in self.compile_opts: @@ -154,6 +154,11 @@ class ConverterTarget: if '.' not in self.includes: self.includes += ['.'] + # make install dir relative to the install prefix + if self.install_dir and os.path.isabs(self.install_dir): + if os.path.commonpath([self.install_dir, install_prefix]) == install_prefix: + self.install_dir = os.path.relpath(self.install_dir, install_prefix) + def meson_func(self) -> str: return CMAKE_TGT_TYPE_MAP.get(self.type.upper()) @@ -177,12 +182,13 @@ class ConverterTarget: mlog.log(' -', key, '=', mlog.bold(str(val))) class CMakeInterpreter: - def __init__(self, build: Build, subdir: str, src_dir: str, build_dir: str, env: Environment, backend: Backend): + def __init__(self, build: Build, subdir: str, src_dir: str, build_dir: str, install_prefix: str, env: Environment, backend: Backend): assert(hasattr(backend, 'name')) self.build = build self.subdir = subdir self.src_dir = src_dir self.build_dir = build_dir + self.install_prefix = install_prefix self.env = env self.backend_name = backend.name self.client = CMakeClient(self.env) @@ -219,7 +225,7 @@ class CMakeInterpreter: elif len(exelist) == 2: cmake_args += ['-DCMAKE_{}_COMPILER_LAUNCHER={}'.format(cmake_lang, exelist[0]), '-DCMAKE_{}_COMPILER={}'.format(cmake_lang, exelist[1])] - cmake_args += ['-G', generator] + cmake_args += ['-G', generator, '-DCMAKE_INSTALL_PREFIX={}'.format(self.install_prefix)] # Run CMake mlog.log() @@ -292,7 +298,7 @@ class CMakeInterpreter: output_target_map = {x.full_name: x for x in self.targets} for i in self.targets: - i.postprocess(output_target_map, self.src_dir) + i.postprocess(output_target_map, self.src_dir, self.install_prefix) self.languages += [x for x in i.languages if x not in self.languages] mlog.log('CMake project', mlog.bold(self.project_name), 'has', mlog.bold(str(len(self.targets))), 'build targets.') diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index bee990a8c..182326e88 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2548,7 +2548,8 @@ external dependencies (including libraries) must go to "dependencies".''') with mlog.nested(): build_dir = os.path.join(self.environment.get_scratch_dir(), 'cmake_subp_{}'.format(dirname)) new_build = self.build.copy() - cm_int = CMakeInterpreter(new_build, subdir, subdir_abs, build_dir, new_build.environment, self.backend) + prefix = self.coredata.builtins['prefix'].value + cm_int = CMakeInterpreter(new_build, subdir, subdir_abs, build_dir, prefix, new_build.environment, self.backend) cm_int.initialise() cm_int.analyse()