From 271915f641e87019fc5a3590340094822276342c Mon Sep 17 00:00:00 2001 From: Peter Urban Date: Wed, 10 Jan 2024 00:32:29 +0100 Subject: [PATCH] fix openmp dependency for clang-cl - see https://github.com/mesonbuild/meson/issues/5298 --- mesonbuild/dependencies/misc.py | 14 ++++++++++++-- test cases/common/184 openmp/meson.build | 10 +++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index bec1466e9053..87d927bfca21 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -103,6 +103,7 @@ def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> No self.is_found = True self.compile_args = self.link_args = self.clib_compiler.openmp_flags() return + try: openmp_date = self.clib_compiler.get_define( '_OPENMP', '', self.env, self.clib_compiler.openmp_flags(), [self], disable_cache=True)[0] @@ -119,13 +120,22 @@ def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]) -> No if openmp_date == '_OPENMP': mlog.debug('This can be caused by flags such as gcc\'s `-fdirectives-only`, which affect preprocessor behavior.') return + + if self.clib_compiler.get_id() == 'clang-cl': + try: + # this is necessary for clang-cl, see https://github.com/mesonbuild/meson/issues/5298 + self.link_args.extend(self.clib_compiler.find_library("libomp", self.env, [])) + except: + mlog.log(mlog.yellow('WARNING:'), 'OpenMP found could not find libomp necessary for clang-cl.') + return + # Flang has omp_lib.h header_names = ('omp.h', 'omp_lib.h') for name in header_names: if self.clib_compiler.has_header(name, '', self.env, dependencies=[self], disable_cache=True)[0]: self.is_found = True - self.compile_args = self.clib_compiler.openmp_flags() - self.link_args = self.clib_compiler.openmp_link_flags() + self.compile_args.extend(self.clib_compiler.openmp_flags()) + self.link_args.extend(self.clib_compiler.openmp_link_flags()) break if not self.is_found: mlog.log(mlog.yellow('WARNING:'), 'OpenMP found but omp.h missing.') diff --git a/test cases/common/184 openmp/meson.build b/test cases/common/184 openmp/meson.build index a1154c22c0c4..0bfaa0e76026 100644 --- a/test cases/common/184 openmp/meson.build +++ b/test cases/common/184 openmp/meson.build @@ -10,15 +10,15 @@ endif if cc.get_id() == 'msvc' and cc.version().version_compare('<17') error('MESON_SKIP_TEST msvc is too old to support OpenMP.') endif -if cc.get_id() == 'clang-cl' - error('MESON_SKIP_TEST clang-cl does not support OpenMP.') +if cc.get_id() == 'clang-cl' and cc.version().version_compare('<10.0.0') + error('MESON_SKIP_TEST clang-cl is too old to support OpenMP.') endif if cc.get_id() == 'clang' and host_machine.system() == 'windows' error('MESON_SKIP_TEST Windows clang does not support OpenMP.') endif -if host_machine.system() == 'darwin' - error('MESON_SKIP_TEST macOS does not support OpenMP.') -endif +# if host_machine.system() == 'darwin' +# error('MESON_SKIP_TEST macOS does not support OpenMP.') +# endif openmp = dependency('openmp') env = environment()