More build helpers
This commit is contained in:
parent
4ed751ad5a
commit
f21315ff17
2 changed files with 40 additions and 4 deletions
|
|
@ -4,8 +4,8 @@ import os except findExe
|
||||||
|
|
||||||
import "."/[compat]
|
import "."/[compat]
|
||||||
|
|
||||||
proc sanitizePath*(path: string, noQuote = false): string =
|
proc sanitizePath*(path: string, noQuote = false, sep = $DirSep): string =
|
||||||
result = path.multiReplace([("\\\\", $DirSep), ("\\", $DirSep), ("/", $DirSep)])
|
result = path.multiReplace([("\\\\", sep), ("\\", sep), ("/", sep)])
|
||||||
if not noQuote:
|
if not noQuote:
|
||||||
result = result.quoteShell
|
result = result.quoteShell
|
||||||
|
|
||||||
|
|
@ -265,6 +265,20 @@ proc findFile*(file: string|Regex, dir: string, recurse = true, first = false):
|
||||||
result = f
|
result = f
|
||||||
if first: break
|
if first: break
|
||||||
|
|
||||||
|
proc flagBuild*(base: string, flags: openArray[string]): string =
|
||||||
|
## Simple helper proc to generate flags for `configure`, `cmake`, etc.
|
||||||
|
##
|
||||||
|
## Every entry in `flags` is replaced into the `base` string and
|
||||||
|
## concatenated to the result.
|
||||||
|
##
|
||||||
|
## E.g.
|
||||||
|
## `base = "--disable-$#"`
|
||||||
|
## `flags = @["one", "two"]`
|
||||||
|
##
|
||||||
|
## `flagBuild(base, flags) => " --disable-one --disable-two"`
|
||||||
|
for i in flags:
|
||||||
|
result &= " " & base % i
|
||||||
|
|
||||||
proc configure*(path, check: string, flags = "") =
|
proc configure*(path, check: string, flags = "") =
|
||||||
## Run the GNU `configure` command to generate all Makefiles or other
|
## Run the GNU `configure` command to generate all Makefiles or other
|
||||||
## build scripts in the specified path
|
## build scripts in the specified path
|
||||||
|
|
@ -318,6 +332,15 @@ proc configure*(path, check: string, flags = "") =
|
||||||
proc getCmakePropertyStr(name, property, value: string): string =
|
proc getCmakePropertyStr(name, property, value: string): string =
|
||||||
&"\nset_target_properties({name} PROPERTIES {property} \"{value}\")\n"
|
&"\nset_target_properties({name} PROPERTIES {property} \"{value}\")\n"
|
||||||
|
|
||||||
|
proc getCmakeIncludePath*(paths: openArray[string]): string =
|
||||||
|
## Create a `cmake` flag to specify custom include paths
|
||||||
|
##
|
||||||
|
## Result can be included in the `flag` parameter for `cmake()` or
|
||||||
|
## the `cmakeFlags` parameter for `getHeader()`.
|
||||||
|
for path in paths:
|
||||||
|
result &= path & ";"
|
||||||
|
result = " -DCMAKE_INCLUDE_PATH=" & result[0 .. ^2].sanitizePath(sep = "/")
|
||||||
|
|
||||||
proc setCmakeProperty*(outdir, name, property, value: string) =
|
proc setCmakeProperty*(outdir, name, property, value: string) =
|
||||||
## Set a `cmake` property in `outdir / CMakeLists.txt` - usable in the `xxxPreBuild` hook
|
## Set a `cmake` property in `outdir / CMakeLists.txt` - usable in the `xxxPreBuild` hook
|
||||||
## for `getHeader()`
|
## for `getHeader()`
|
||||||
|
|
@ -361,6 +384,19 @@ proc setCmakeLibName*(outdir, name, prefix = "", oname = "", suffix = "") =
|
||||||
if str.len != 0:
|
if str.len != 0:
|
||||||
cm.writeFile(cm.readFile() & str)
|
cm.writeFile(cm.readFile() & str)
|
||||||
|
|
||||||
|
proc setCmakePositionIndependentCode*(outdir: string) =
|
||||||
|
## Set a `cmake` directive to create libraries with -fPIC enabled
|
||||||
|
let
|
||||||
|
cm = outdir / "CMakeLists.txt"
|
||||||
|
if cm.fileExists():
|
||||||
|
let
|
||||||
|
pic = "set(CMAKE_POSITION_INDEPENDENT_CODE ON)"
|
||||||
|
cmd = cm.readFile()
|
||||||
|
if not cmd.contains(pic):
|
||||||
|
cm.writeFile(
|
||||||
|
pic & "\n" & cmd
|
||||||
|
)
|
||||||
|
|
||||||
proc cmake*(path, check, flags: string) =
|
proc cmake*(path, check, flags: string) =
|
||||||
## Run the `cmake` command to generate all Makefiles or other
|
## Run the `cmake` command to generate all Makefiles or other
|
||||||
## build scripts in the specified path
|
## build scripts in the specified path
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,8 @@ when defined(posix):
|
||||||
cSkipSymbol(@["u_int8_t", "u_int16_t", "u_int32_t", "u_int64_t"])
|
cSkipSymbol(@["u_int8_t", "u_int16_t", "u_int32_t", "u_int64_t"])
|
||||||
|
|
||||||
when defined(zlibGit) or defined(zlibDL):
|
when defined(zlibGit) or defined(zlibDL):
|
||||||
when dirExists(baseDir / "build"):
|
when dirExists(baseDir / "buildcache"):
|
||||||
cIncludeDir(baseDir / "build")
|
cIncludeDir(baseDir / "buildcache")
|
||||||
|
|
||||||
when not defined(zlibStatic):
|
when not defined(zlibStatic):
|
||||||
cImport(zlibPath, recurse = true, dynlib = "zlibLPath")
|
cImport(zlibPath, recurse = true, dynlib = "zlibLPath")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue