Skip to content

Commit

Permalink
BLD Avoid misleading OpenMP warning with Apple Clang (scikit-learn#28839
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lesteve committed Apr 18, 2024
1 parent 6ffeabd commit 55378cb
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion sklearn/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ np_dep = declare_dependency(include_directories: inc_np)
openmp_dep = dependency('OpenMP', language: 'c', required: false)

if not openmp_dep.found()
warn_about_missing_openmp = true
# On Apple Clang avoid a misleading warning if compiler variables are set.
# See https://github.com/scikit-learn/scikit-learn/issues/28710 for more
# details. This may be removed if the OpenMP detection on Apple Clang improves,
# see https://github.com/mesonbuild/meson/issues/7435#issuecomment-2047585466.
if host_machine.system() == 'darwin' and cc.get_id() == 'clang'
compiler_env_vars_with_openmp = run_command(py,
[
'-c',
'''
import os
compiler_env_vars_to_check = ["CPPFLAGS", "CFLAGS", "CXXFLAGS"]
compiler_env_vars_with_openmp = [
var for var in compiler_env_vars_to_check if "-fopenmp" in os.getenv(var, "")]
print(compiler_env_vars_with_openmp)
'''], check: true).stdout().strip()
warn_about_missing_openmp = compiler_env_vars_with_openmp == '[]'
endif
if warn_about_missing_openmp
warning(
'''
***********
Expand All @@ -84,6 +105,13 @@ It seems that scikit-learn cannot be built with OpenMP.
***
''')
else
warning(
'''It looks like compiler environment variables were set to enable OpenMP support.
Check the output of "import sklearn; sklearn.show_versions()" after the build
to make sure that scikit-learn was actually built with OpenMP support.
''')
endif
endif

# For now, we keep supporting SKLEARN_ENABLE_DEBUG_CYTHON_DIRECTIVES variable
Expand Down Expand Up @@ -127,7 +155,6 @@ custom_target('write_built_with_meson_file',
install: true,
install_dir: py.get_install_dir() / 'sklearn'
)
# endif

extensions = ['_isotonic']

Expand Down

0 comments on commit 55378cb

Please sign in to comment.