From 661a1f6f4bfb0c9a5ae6c6d02e7b2e8c88281bd8 Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Wed, 21 Apr 2021 16:47:14 +0800 Subject: [PATCH] [CustomOP]Support find include/c++/v1 include dirs automatically (#32404) --- .../utils/cpp_extension/extension_utils.py | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/python/paddle/utils/cpp_extension/extension_utils.py b/python/paddle/utils/cpp_extension/extension_utils.py index 30ff3f81ca7..aa5a7ab533a 100644 --- a/python/paddle/utils/cpp_extension/extension_utils.py +++ b/python/paddle/utils/cpp_extension/extension_utils.py @@ -612,12 +612,34 @@ def find_paddle_includes(use_cuda=False): if OS_NAME.startswith('darwin'): # NOTE(Aurelius84): Ensure to find std v1 headers correctly. - std_v1_includes = '/Library/Developer/CommandLineTools/usr/include/c++/v1/' - include_dirs.append(std_v1_includes) + std_v1_includes = find_clang_cpp_include() + if std_v1_includes is not None and os.path.exists(std_v1_includes): + include_dirs.append(std_v1_includes) return include_dirs +def find_clang_cpp_include(compiler='clang'): + std_v1_includes = None + try: + compiler_version = subprocess.check_output([compiler, "--version"]) + if six.PY3: + compiler_version = compiler_version.decode() + infos = compiler_version.split("\n") + for info in infos: + if "InstalledDir" in info: + v1_path = info.split(':')[-1].strip() + if v1_path and os.path.exists(v1_path): + std_v1_includes = os.path.join( + os.path.dirname(v1_path), 'include/c++/v1') + except Exception: + # Just raise warnings because the include dir is not required. + warnings.warn( + "Failed to search `include/c++/v1/` include dirs. Don't worry because it's not required." + ) + return std_v1_includes + + def find_cuda_libraries(): """ Use heuristic method to find cuda static lib path -- GitLab