Split llvm-lib path discovery into its own function

This commit is contained in:
Thomas Nagy 2019-12-11 07:42:02 +01:00
parent 52a49960c1
commit 015a51a7cf
1 changed files with 63 additions and 59 deletions

View File

@ -16,9 +16,9 @@ Usage:
Or:
$ LLVM_PATH=C:\\Program Files\\LLVM\\bin waf configure
Or:
def configure(conf):
conf.env.LLVM_PATH = 'C:\\Program Files\\LLVM\\bin'
conf.load('clang_cl')
def configure(self):
self.env.LLVM_PATH = 'C:\\Program Files\\LLVM\\bin'
self.load('clang_cl')
"""
import sys, os
@ -31,86 +31,90 @@ def options(opt):
msvc.options(opt)
@conf
def find_clang_cl(conf):
"""
Find the program clang-cl.
"""
del(conf.env.CC)
del(conf.env.CXX)
llvm_path = None
def get_llvm_paths(self):
llvm_path = []
if Utils.is_win32:
try:
llvm_key = Utils.winreg.OpenKey(Utils.winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Wow6432Node\\LLVM\\LLVM')
except OSError:
llvm_key = Utils.winreg.OpenKey(Utils.winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\LLVM\\LLVM')
llvm_path,type = Utils.winreg.QueryValueEx(llvm_key, '')
llvm_path = os.path.join(llvm_path, 'bin')
llvm_dir, _ = Utils.winreg.QueryValueEx(llvm_key, '')
if llvm_dir:
llvm_path.append(os.path.join(llvm_dir, 'bin'))
llvm_path = conf.environ.get('LLVM_PATH') or conf.env.LLVM_PATH
if llvm_path and llvm_path != 'bin':
paths = [llvm_path] + conf.env.PATH
else:
paths = conf.env.PATH
cc = conf.find_program('clang-cl', var='CC', path_list=paths)
conf.env.CC = conf.env.CXX = cc
conf.env.CC_NAME_SECONDARY = conf.env.CXX_NAME_SECONDARY = 'clang'
if not Utils.is_win32:
conf.env.MSVC_COMPILER = 'msvc'
conf.env.MSVC_VERSION = 19
if not conf.env.LINK_CXX:
conf.find_program('lld-link', path_list=paths, errmsg='lld-link was not found (linker)', var='LINK_CXX')
if not conf.env.LINK_CC:
conf.env.LINK_CC = conf.env.LINK_CXX
tmp = self.environ.get('LLVM_PATH') or self.env.LLVM_PATH
if tmp:
llvm_path.append(tmp)
llvm_path.append(self.env.PATH)
return llvm_path
@conf
def find_llvm_tools(conf):
def find_clang_cl(self):
"""
Find the program clang-cl.
"""
del(self.env.CC)
del(self.env.CXX)
paths = self.get_llvm_paths()
cc = self.find_program('clang-cl', var='CC', path_list=paths)
self.env.CC = self.env.CXX = cc
self.env.CC_NAME_SECONDARY = self.env.CXX_NAME_SECONDARY = 'clang'
if not Utils.is_win32:
self.env.MSVC_COMPILER = 'msvc'
self.env.MSVC_VERSION = 19
if not self.env.LINK_CXX:
self.find_program('lld-link', path_list=paths, errmsg='lld-link was not found (linker)', var='LINK_CXX')
if not self.env.LINK_CC:
self.env.LINK_CC = self.env.LINK_CXX
@conf
def find_llvm_tools(self):
"""
Find the librarian, manifest tool, and resource compiler.
"""
conf.env.CC_NAME = conf.env.CXX_NAME = 'msvc'
self.env.CC_NAME = self.env.CXX_NAME = 'msvc'
llvm_path = conf.environ.get('LLVM_PATH') or conf.env.LLVM_PATH
if llvm_path and llvm_path != 'bin':
paths = [llvm_path] + conf.env.PATH
paths = self.get_llvm_paths()
llvm_path = self.environ.get('LLVM_PATH') or self.env.LLVM_PATH
if llvm_path:
paths = [llvm_path] + self.env.PATH
else:
paths = conf.env.PATH
paths = self.env.PATH
if not conf.env.AR:
stliblink = conf.find_program('llvm-lib', path_list=paths, var='AR')
if not self.env.AR:
stliblink = self.find_program('llvm-lib', path_list=paths, var='AR')
if not stliblink:
conf.fatal('Unable to find required program "llvm-lib"')
self.fatal('Unable to find required program "llvm-lib"')
conf.env.ARFLAGS = ['/nologo']
self.env.ARFLAGS = ['/nologo']
# We assume clang_cl to only be used with relatively new MSVC installations.
conf.env.MSVC_MANIFEST = True
conf.find_program('llvm-mt', path_list=paths, var='MT')
conf.env.MTFLAGS = ['/nologo']
self.env.MSVC_MANIFEST = True
self.find_program('llvm-mt', path_list=paths, var='MT')
self.env.MTFLAGS = ['/nologo']
try:
conf.load('winres')
self.load('winres')
except Errors.ConfigurationError:
Logs.warn('Resource compiler not found. Compiling resource file is disabled')
def configure(conf):
def configure(self):
if sys.platform == 'win32':
conf.autodetect(True)
conf.find_msvc()
self.autodetect(True)
self.find_msvc()
else:
conf.find_llvm_tools()
self.find_llvm_tools()
conf.find_clang_cl()
conf.msvc_common_flags()
conf.cc_load_tools()
conf.cxx_load_tools()
conf.cc_add_flags()
conf.cxx_add_flags()
conf.link_add_flags()
conf.visual_studio_add_flags()
self.find_clang_cl()
self.msvc_common_flags()
self.cc_load_tools()
self.cxx_load_tools()
self.cc_add_flags()
self.cxx_add_flags()
self.link_add_flags()
self.visual_studio_add_flags()