in python/tvm/_ffi/libinfo.py [0:0]
def find_include_path(name=None, search_path=None, optional=False):
"""Find header files for C compilation.
Parameters
----------
name : list of str
List of directory names to be searched.
Returns
-------
include_path : list(string)
List of all found paths to header files.
"""
if os.environ.get("TVM_HOME", None):
source_dir = os.environ["TVM_HOME"]
else:
ffi_dir = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
for source_dir in ["..", "../..", "../../.."]:
source_dir = os.path.join(ffi_dir, source_dir)
if os.path.isdir(os.path.join(source_dir, "include")):
break
else:
raise AssertionError("Cannot find the source directory given ffi_dir: {ffi_dir}")
third_party_dir = os.path.join(source_dir, "3rdparty")
header_path = []
if os.environ.get("TVM_INCLUDE_PATH", None):
header_path.append(os.environ["TVM_INCLUDE_PATH"])
header_path.append(source_dir)
header_path.append(third_party_dir)
header_path = [os.path.abspath(x) for x in header_path]
if search_path is not None:
if isinstance(search_path, list):
header_path = header_path + search_path
else:
header_path.append(search_path)
if name is not None:
if isinstance(name, list):
tvm_include_path = []
for n in name:
tvm_include_path += [os.path.join(p, n) for p in header_path]
else:
tvm_include_path = [os.path.join(p, name) for p in header_path]
dlpack_include_path = []
dmlc_include_path = []
else:
tvm_include_path = [os.path.join(p, "include") for p in header_path]
tvm_ffi_include_path = [os.path.join(p, "ffi/include") for p in header_path]
dlpack_include_path = [os.path.join(p, "dlpack/include") for p in header_path]
dmlc_include_path = [os.path.join(p, "dmlc-core/include") for p in header_path]
# try to find include path
include_found = [p for p in tvm_include_path if os.path.exists(p) and os.path.isdir(p)]
include_found += [p for p in tvm_ffi_include_path if os.path.exists(p) and os.path.isdir(p)]
include_found += [p for p in dlpack_include_path if os.path.exists(p) and os.path.isdir(p)]
include_found += [p for p in dmlc_include_path if os.path.exists(p) and os.path.isdir(p)]
if not include_found:
message = (
"Cannot find the files.\n"
+ "List of candidates:\n"
+ str("\n".join(tvm_include_path + dlpack_include_path))
)
if not optional:
raise RuntimeError(message)
return None
return include_found