diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-09-23 14:52:34 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-10-02 15:31:53 -0500 |
| commit | f21315ff1747ce0814f3a1e480f7b2e01ad9a278 (patch) | |
| tree | 401f1976ada7dd0aa32d78a3d9e748405ea0f8ab | |
| parent | 4ed751ad5a64c868cf5cc087114827b426a9c07e (diff) | |
| download | nimterop-f21315ff1747ce0814f3a1e480f7b2e01ad9a278.tar.gz nimterop-f21315ff1747ce0814f3a1e480f7b2e01ad9a278.zip | |
More build helpers
| -rw-r--r-- | nimterop/build.nim | 40 | ||||
| -rw-r--r-- | tests/zlib.nim | 4 |
2 files changed, 40 insertions, 4 deletions
diff --git a/nimterop/build.nim b/nimterop/build.nim index f2d4692..494bc48 100644 --- a/nimterop/build.nim +++ b/nimterop/build.nim @@ -4,8 +4,8 @@ import os except findExe import "."/[compat] -proc sanitizePath*(path: string, noQuote = false): string = - result = path.multiReplace([("\\\\", $DirSep), ("\\", $DirSep), ("/", $DirSep)]) +proc sanitizePath*(path: string, noQuote = false, sep = $DirSep): string = + result = path.multiReplace([("\\\\", sep), ("\\", sep), ("/", sep)]) if not noQuote: result = result.quoteShell @@ -265,6 +265,20 @@ proc findFile*(file: string|Regex, dir: string, recurse = true, first = false): result = f 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 = "") = ## Run the GNU `configure` command to generate all Makefiles or other ## build scripts in the specified path @@ -318,6 +332,15 @@ proc configure*(path, check: string, flags = "") = proc getCmakePropertyStr(name, property, value: string): string = &"\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) = ## Set a `cmake` property in `outdir / CMakeLists.txt` - usable in the `xxxPreBuild` hook ## for `getHeader()` @@ -361,6 +384,19 @@ proc setCmakeLibName*(outdir, name, prefix = "", oname = "", suffix = "") = if str.len != 0: 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) = ## Run the `cmake` command to generate all Makefiles or other ## build scripts in the specified path diff --git a/tests/zlib.nim b/tests/zlib.nim index f2cc16a..6da7cdc 100644 --- a/tests/zlib.nim +++ b/tests/zlib.nim @@ -57,8 +57,8 @@ when defined(posix): cSkipSymbol(@["u_int8_t", "u_int16_t", "u_int32_t", "u_int64_t"]) when defined(zlibGit) or defined(zlibDL): - when dirExists(baseDir / "build"): - cIncludeDir(baseDir / "build") + when dirExists(baseDir / "buildcache"): + cIncludeDir(baseDir / "buildcache") when not defined(zlibStatic): cImport(zlibPath, recurse = true, dynlib = "zlibLPath") |
