Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use llvm-config to get the library directory #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions configure.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down