aboutsummaryrefslogtreecommitdiff
path: root/tests/zlib.nim
blob: ce26c9a1a3681d7cfae4e563a559e22f0f183d40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os, strutils

import nimterop/[build, cimport]

const
  baseDir = getProjectCacheDir("nimterop" / "tests" / "zlib")

static:
  cDebug()

proc zlibPreBuild(outdir, path: string) =
  let
    mf = outdir / "Makefile"
  if mf.fileExists():
    # Delete default Makefile
    if mf.readFile().contains("configure first"):
      mf.rmFile()
      when defined(windows):
        # Fix static lib name on Windows
        setCmakeLibName(outdir, "zlibstatic", prefix = "lib", oname = "zlib", suffix = ".a")

when defined(envTest):
  setDefines(@["zlibGit"])
elif defined(envTestStatic):
  setDefines(@["zlibGit", "zlibStatic"])

getHeader(
  "zlib.h",
  giturl = "https://github.com/madler/zlib",
  dlurl = "http://zlib.net/zlib-$1.tar.gz",
  outdir = baseDir,
  altNames = "z,zlib"
)

cPlugin:
  import regex, strutils

  proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
    sym.name = sym.name.replace(re"_[_]+", "_").strip(chars = {'_'})

cOverride:
  type
    voidpf = ptr object
    voidpc = ptr object
    voidp = ptr object
    uLongf = culong
    z_size_t = culong
    z_crc_t = culong
    alloc_func* {.importc.} = proc(opaque: voidpf, items, size: uint) {.cdecl.}
    Bytef {.importc.} = object

when defined(posix):
  cOverride:
    type
      pthread_mutex_s = object
      pthread_cond_s = object
      pthread_rwlock_arch_t = object
      extension = object
      fd_set = object

when defined(posix):
  static:
    cSkipSymbol(@["u_int8_t", "u_int16_t", "u_int32_t", "u_int64_t"])

when zlibGit or zlibDL:
  when dirExists(baseDir / "buildcache"):
    cIncludeDir(baseDir / "buildcache")

when not zlibStatic:
  cImport(zlibPath, recurse = true, dynlib = "zlibLPath")
else:
  cImport(zlibPath, recurse = true)

echo "zlib version = " & $zlibVersion()