From b4cfe45ed64951065581bbb20eef0b47537d57a8 Mon Sep 17 00:00:00 2001 From: Boris Carvajal Date: Tue, 1 Oct 2019 23:40:07 -0300 Subject: [PATCH] Use llvm-config to get the library directory --- configure.d | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/configure.d b/configure.d index c77fd244..2d163347 100644 --- a/configure.d +++ b/configure.d @@ -80,10 +80,49 @@ struct Options /// The path to the LLVM/Clang library directory. string llvmLibPath () { + auto libPath = llvmconfigGetOpts("--libdir", llvmPath); + + if (libPath) + return libPath; + return llvmPath.empty ? "" : buildPath(llvmPath, "lib"); } } +/** + * Get the output of llvm-config program. + * + * Params: + * cmdOptions = the arguments to parse. If multiple, pass a string array + * llvmPath = optional LLVM root path to look for the executable + * + * Return: the command output stripping newlines, otherwise `null` + */ +string llvmconfigGetOpts(T)(T cmdOptions, string llvmPath = "") + if (is(T == string) || is(T == string[])) +{ + import std.ascii : newline; + + string binDir = llvmPath.empty ? "" : buildPath(llvmPath, "bin"); + string llvmconfig = buildPath(binDir, DefaultConfig.llvmConfigExecutable); + + static if (is(T == string)) + string[] options = [cmdOptions]; + else + alias options = cmdOptions; + + try + { + auto run = execute(llvmconfig ~ options); + + if (run.status == 0) + return run.output.strip(newline); + } + catch(ProcessException) {} + + return null; +} + /// This struct contains the name and filename of a library. struct LibraryName {