Make getHeader specify which make strategy to use

Fix make call

Add comment
This commit is contained in:
Joey Yakimowich-Payne 2020-05-02 12:36:55 -06:00
commit 4144bbb66d

View file

@ -4,6 +4,15 @@ import os except findExe, sleep
import regex import regex
type
MakeType* = enum
mtConfMake, mtCMake
BuildStatus = object
built: bool
buildPath: string
error: string
# build specific debug since we cannot import globals (yet) # build specific debug since we cannot import globals (yet)
var var
gDebug* = false gDebug* = false
@ -771,20 +780,7 @@ proc getNumProcs(): string =
else: else:
"1" "1"
proc buildLibrary(lname, outdir, conFlags, cmakeFlags, makeFlags: string): string = proc buildWithCmake(outdir, flags: string): BuildStatus =
var
conDeps = false
conDepStr = ""
cmakeDeps = false
cmakeDepStr = ""
lpath = findFile(lname, outdir, regex = true)
makeFlagsProc = &"-j {getNumProcs()} {makeFlags}"
made = false
makePath = outdir
if lpath.len != 0:
return lpath
if not fileExists(outdir / "Makefile"): if not fileExists(outdir / "Makefile"):
if fileExists(outdir / "CMakeLists.txt"): if fileExists(outdir / "CMakeLists.txt"):
if findExe("cmake").len != 0: if findExe("cmake").len != 0:
@ -806,36 +802,59 @@ proc buildLibrary(lname, outdir, conFlags, cmakeFlags, makeFlags: string): strin
gen = "Unix Makefiles".quoteShell gen = "Unix Makefiles".quoteShell
if findExe("ccache").len != 0: if findExe("ccache").len != 0:
gen &= " -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" gen &= " -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
makePath = outdir / "buildcache" result.buildPath = outdir / "buildcache"
cmake(makePath, "Makefile", &".. -G {gen} {cmakeFlags}") cmake(result.buildPath, "Makefile", &".. -G {gen} {flags}")
cmakeDeps = true result.built = true
else: else:
cmakeDepStr &= "cmake executable missing" result.error = "cmake capable but cmake executable missing"
else:
result.buildPath = outdir
if not cmakeDeps: proc buildWithConfMake(outdir, flags: string): BuildStatus =
if findExe("bash").len != 0: if not fileExists(outdir / "Makefile"):
for file in @["configure", "configure.ac", "configure.in", "autogen.sh", "build/autogen.sh"]: if findExe("bash").len != 0:
if fileExists(outdir / file): for file in @["configure", "configure.ac", "configure.in", "autogen.sh", "build/autogen.sh"]:
configure(outdir, "Makefile", conFlags) if fileExists(outdir / file):
conDeps = true configure(outdir, "Makefile", flags)
result.buildPath = outdir
break result.built = true
else: break
conDepStr &= "bash executable missing" else:
result.error = "configure capable but bash executable missing"
if fileExists(makePath / "Makefile"): else:
make(makePath, lname, makeFlagsProc, regex = true) result.buildPath = outdir
made = true
proc buildLibrary(lname, outdir, conFlags, cmakeFlags, makeFlags: string, preferredMakeType: MakeType): string =
var var
error = "" lpath = findFile(lname, outdir, regex = true)
if not cmakeDeps and cmakeDepStr.len != 0: makeFlagsProc = &"-j {getNumProcs()} {makeFlags}"
error &= &"cmake capable but {cmakeDepStr}\n" makePath = outdir
if not conDeps and conDepStr.len != 0:
error &= &"configure capable but {conDepStr}\n" if lpath.len != 0:
if error.len == 0: return lpath
error = "No build files found in " & outdir
doAssert cmakeDeps or conDeps or made, &"\n# Build configuration failed - {error}\n" var buildStatus: BuildStatus
# Simply reverse order if we want configure/make vs CMake/make
case preferredMakeType
of mtCMake:
buildStatus = buildWithCmake(makePath, cmakeFlags)
if not buildStatus.built:
buildStatus = buildWithConfMake(makePath, conFlags)
of mtConfMake:
buildStatus = buildWithConfMake(makePath, conFlags)
if not buildStatus.built:
buildStatus = buildWithCmake(makePath, cmakeFlags)
if buildStatus.buildPath.len > 0:
buildStatus.built = findFile(lname, buildStatus.buildPath, regex = true).len > 0
if not buildStatus.built and fileExists(buildStatus.buildPath / "Makefile"):
make(buildStatus.buildPath, lname, makeFlagsProc, regex = true)
buildStatus.built = true
let error = if buildStatus.error.len > 0: buildStatus.error else: "No build files found in " & outdir
doAssert buildStatus.built, &"\n# Build configuration failed - {error}\n"
result = findFile(lname, outdir, regex = true) result = findFile(lname, outdir, regex = true)
@ -903,7 +922,7 @@ macro isDefined*(def: untyped): untyped =
macro getHeader*(header: static[string], giturl: static[string] = "", dlurl: static[string] = "", outdir: static[string] = "", macro getHeader*(header: static[string], giturl: static[string] = "", dlurl: static[string] = "", outdir: static[string] = "",
conFlags: static[string] = "", cmakeFlags: static[string] = "", makeFlags: static[string] = "", conFlags: static[string] = "", cmakeFlags: static[string] = "", makeFlags: static[string] = "",
altNames: static[string] = ""): untyped = altNames: static[string] = "", preferredMakeType: static[MakeType] = mtCMake): untyped =
## Get the path to a header file for wrapping with ## Get the path to a header file for wrapping with
## `cImport() <cimport.html#cImport.m%2C%2Cstring%2Cstring%2Cstring>`_ or ## `cImport() <cimport.html#cImport.m%2C%2Cstring%2Cstring%2Cstring>`_ or
## `c2nImport() <cimport.html#c2nImport.m%2C%2Cstring%2Cstring%2Cstring>`_. ## `c2nImport() <cimport.html#c2nImport.m%2C%2Cstring%2Cstring%2Cstring>`_.
@ -1056,7 +1075,7 @@ macro getHeader*(header: static[string], giturl: static[string] = "", dlurl: sta
when stdPath.len != 0 and stdLPath.len != 0: when stdPath.len != 0 and stdLPath.len != 0:
stdLPath stdLPath
else: else:
buildLibrary(`lname`, `outdir`, `conFlags`, `cmakeFlags`, `makeFlags`) buildLibrary(`lname`, `outdir`, `conFlags`, `cmakeFlags`, `makeFlags`, `preferredMakeType`.MakeType)
# Header path - search again in case header is generated in build # Header path - search again in case header is generated in build
`path`* = `path`* =