Skip to content

Commit

Permalink
fix openmp dependency for clang-cl
Browse files Browse the repository at this point in the history
- see #5298
  • Loading branch information
peter-urban committed Jan 10, 2024
1 parent a5fdd37 commit 271915f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 12 additions & 2 deletions mesonbuild/dependencies/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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:

Check notice

Code scanning / CodeQL

Except block handles 'BaseException' Note

Except block directly handles BaseException.
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.')
Expand Down
10 changes: 5 additions & 5 deletions test cases/common/184 openmp/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 271915f

Please sign in to comment.