cmake: Subprojects support CMAKE_PREFIX_PATH (fixes #7249)

0.54
Daniel Mensinger 5 years ago committed by Nirbheek Chauhan
parent d487924991
commit fd1b8b1971
  1. 22
      mesonbuild/cmake/executor.py
  2. 16
      mesonbuild/dependencies/base.py
  3. 5
      test cases/cmake/7 cmake options/subprojects/cmOpts/CMakeLists.txt
  4. 9
      test cases/cmake/7 cmake options/test.json

@ -28,6 +28,7 @@ import textwrap
from .. import mlog, mesonlib
from ..mesonlib import PerMachine, Popen_safe, version_compare, MachineChoice
from ..environment import Environment
from ..envconfig import get_env_var
if T.TYPE_CHECKING:
from ..dependencies.base import ExternalProgram
@ -48,6 +49,8 @@ class CMakeExecutor:
self.cmakebin, self.cmakevers = self.find_cmake_binary(self.environment, silent=silent)
self.always_capture_stderr = True
self.print_cmout = False
self.prefix_paths = [] # type: T.List[str]
self.extra_cmake_args = [] # type: T.List[str]
if self.cmakebin is False:
self.cmakebin = None
return
@ -60,6 +63,21 @@ class CMakeExecutor:
self.cmakebin = None
return
self.prefix_paths = self.environment.coredata.builtins_per_machine[self.for_machine]['cmake_prefix_path'].value
env_pref_path = get_env_var(
self.for_machine,
self.environment.is_cross_build(),
'CMAKE_PREFIX_PATH')
if env_pref_path is not None:
env_pref_path = env_pref_path.split(os.pathsep)
env_pref_path = [x for x in env_pref_path if x] # Filter out empty strings
if not self.prefix_paths:
self.prefix_paths = []
self.prefix_paths += env_pref_path
if self.prefix_paths:
self.extra_cmake_args += ['-DCMAKE_PREFIX_PATH={}'.format(';'.join(self.prefix_paths))]
def find_cmake_binary(self, environment: Environment, silent: bool = False) -> T.Tuple['ExternalProgram', str]:
from ..dependencies.base import ExternalProgram
@ -226,6 +244,7 @@ class CMakeExecutor:
if env is None:
env = os.environ
args = args + self.extra_cmake_args
if disable_cache:
return self._call_impl(args, build_dir, env)
@ -362,5 +381,8 @@ class CMakeExecutor:
def get_command(self) -> T.List[str]:
return self.cmakebin.get_command()
def get_cmake_prefix_paths(self) -> T.List[str]:
return self.prefix_paths
def machine_choice(self) -> MachineChoice:
return self.for_machine

@ -1102,21 +1102,7 @@ class CMakeDependency(ExternalDependency):
if cm_path:
cm_args.append('-DCMAKE_MODULE_PATH=' + ';'.join(cm_path))
pref_path = self.env.coredata.builtins_per_machine[self.for_machine]['cmake_prefix_path'].value
env_pref_path = get_env_var(
self.for_machine,
self.env.is_cross_build(),
'CMAKE_PREFIX_PATH')
if env_pref_path is not None:
env_pref_path = env_pref_path.split(os.pathsep)
env_pref_path = [x for x in env_pref_path if x] # Filter out empty strings
if not pref_path:
pref_path = []
pref_path += env_pref_path
if pref_path:
cm_args.append('-DCMAKE_PREFIX_PATH={}'.format(';'.join(pref_path)))
if not self._preliminary_find_check(name, cm_path, pref_path, environment.machines[self.for_machine]):
if not self._preliminary_find_check(name, cm_path, self.cmakebin.get_cmake_prefix_paths(), environment.machines[self.for_machine]):
mlog.debug('Preliminary CMake check failed. Aborting.')
return
self._detect_dep(name, modules, components, cm_args)

@ -1,5 +1,10 @@
cmake_minimum_required(VERSION 3.7)
project(testPro)
if(NOT "${SOME_CMAKE_VAR}" STREQUAL "something")
message(FATAL_ERROR "Setting the CMake var failed")
endif()
if(NOT "${CMAKE_PREFIX_PATH}" STREQUAL "val1;val2")
message(FATAL_ERROR "Setting the CMAKE_PREFIX_PATH failed '${CMAKE_PREFIX_PATH}'")
endif()

@ -0,0 +1,9 @@
{
"matrix": {
"options": {
"cmake_prefix_path": [
{ "val": ["val1", "val2"] }
]
}
}
}
Loading…
Cancel
Save