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: Or:
$ LLVM_PATH=C:\\Program Files\\LLVM\\bin waf configure $ LLVM_PATH=C:\\Program Files\\LLVM\\bin waf configure
Or: Or:
def configure(conf): def configure(self):
conf.env.LLVM_PATH = 'C:\\Program Files\\LLVM\\bin' self.env.LLVM_PATH = 'C:\\Program Files\\LLVM\\bin'
conf.load('clang_cl') self.load('clang_cl')
""" """
import sys, os import sys, os
@ -31,86 +31,90 @@ def options(opt):
msvc.options(opt) msvc.options(opt)
@conf @conf
def find_clang_cl(conf): def get_llvm_paths(self):
""" llvm_path = []
Find the program clang-cl.
"""
del(conf.env.CC)
del(conf.env.CXX)
llvm_path = None
if Utils.is_win32: if Utils.is_win32:
try: try:
llvm_key = Utils.winreg.OpenKey(Utils.winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Wow6432Node\\LLVM\\LLVM') llvm_key = Utils.winreg.OpenKey(Utils.winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Wow6432Node\\LLVM\\LLVM')
except OSError: except OSError:
llvm_key = Utils.winreg.OpenKey(Utils.winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\LLVM\\LLVM') llvm_key = Utils.winreg.OpenKey(Utils.winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\LLVM\\LLVM')
llvm_path,type = Utils.winreg.QueryValueEx(llvm_key, '') llvm_dir, _ = Utils.winreg.QueryValueEx(llvm_key, '')
llvm_path = os.path.join(llvm_path, 'bin') if llvm_dir:
llvm_path.append(os.path.join(llvm_dir, 'bin'))
llvm_path = conf.environ.get('LLVM_PATH') or conf.env.LLVM_PATH tmp = self.environ.get('LLVM_PATH') or self.env.LLVM_PATH
if llvm_path and llvm_path != 'bin': if tmp:
paths = [llvm_path] + conf.env.PATH llvm_path.append(tmp)
else: llvm_path.append(self.env.PATH)
paths = conf.env.PATH return llvm_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
@conf @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. 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 paths = self.get_llvm_paths()
if llvm_path and llvm_path != 'bin': llvm_path = self.environ.get('LLVM_PATH') or self.env.LLVM_PATH
paths = [llvm_path] + conf.env.PATH if llvm_path:
paths = [llvm_path] + self.env.PATH
else: else:
paths = conf.env.PATH paths = self.env.PATH
if not conf.env.AR: if not self.env.AR:
stliblink = conf.find_program('llvm-lib', path_list=paths, var='AR') stliblink = self.find_program('llvm-lib', path_list=paths, var='AR')
if not stliblink: 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. # We assume clang_cl to only be used with relatively new MSVC installations.
conf.env.MSVC_MANIFEST = True self.env.MSVC_MANIFEST = True
conf.find_program('llvm-mt', path_list=paths, var='MT') self.find_program('llvm-mt', path_list=paths, var='MT')
conf.env.MTFLAGS = ['/nologo'] self.env.MTFLAGS = ['/nologo']
try: try:
conf.load('winres') self.load('winres')
except Errors.ConfigurationError: except Errors.ConfigurationError:
Logs.warn('Resource compiler not found. Compiling resource file is disabled') Logs.warn('Resource compiler not found. Compiling resource file is disabled')
def configure(conf): def configure(self):
if sys.platform == 'win32': if sys.platform == 'win32':
conf.autodetect(True) self.autodetect(True)
conf.find_msvc() self.find_msvc()
else: else:
conf.find_llvm_tools() self.find_llvm_tools()
conf.find_clang_cl() self.find_clang_cl()
conf.msvc_common_flags() self.msvc_common_flags()
conf.cc_load_tools() self.cc_load_tools()
conf.cxx_load_tools() self.cxx_load_tools()
conf.cc_add_flags() self.cc_add_flags()
conf.cxx_add_flags() self.cxx_add_flags()
conf.link_add_flags() self.link_add_flags()
conf.visual_studio_add_flags() self.visual_studio_add_flags()