File: make_windows.ps1

package info (click to toggle)
libm2k 0.9.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,580 kB
  • sloc: xml: 1,611,497; cpp: 16,278; python: 4,181; cs: 516; sh: 471; ansic: 403; makefile: 35
file content (131 lines) | stat: -rw-r--r-- 4,986 bytes parent folder | download | duplicates (2)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.2#erroractionpreference
$ErrorActionPreference = "Stop"
$ErrorView = "NormalView"

$COMPILER = $Env:COMPILER
$ARCH = $Env:ARCH        
$PLATFORM = $Env:PLATFORM

$SRC_DIR = Get-Item -Path $env:BUILD_SOURCESDIRECTORY # path to repo
$OUTSIDE_BUILD = $SRC_DIR.Parent.FullName
$DEPS_DIR= Join-Path $OUTSIDE_BUILD "deps"

$BUILD_DIR = Join-Path $OUTSIDE_BUILD "libm2k-$PLATFORM"
$TEMP_BUILD_DIR = Join-Path $SRC_DIR "tmp-build-$PLATFORM"
$DEST_LIBIIO = Join-Path $OUTSIDE_BUILD "libiio-$ARCH"

Write-Output "COMPILER  = $COMPILER"
Write-Output "ARCH  = $ARCH"
Write-Output "PLATFORM  = $PLATFORM"
Write-Output "SRC DIR = $SRC_DIR"
Write-Output "OUTSIDE_BUILD = $OUTSIDE_BUILD"
Write-Output "DEPS_DIR = $DEPS_DIR"
Write-Output "BUILD_DIR = $BUILD_DIR"
Write-Output "TEMP_BUILD_DIR  = $TEMP_BUILD_DIR"
Write-Output "DEST_LIBIIO  = $DEST_LIBIIO"

if (-not (Test-Path -Path $BUILD_DIR)) {
    New-Item -Path $BUILD_DIR -ItemType Directory
    New-Item -Path (Join-Path $BUILD_DIR "dist") -ItemType Directory
}

function Build-Libm2k {
    param(
        [string]$PLATFORM,
        [string]$PYTHON_VERSION,
        [string]$GENERATOR,
        [string]$ARCH
    )

    if (Test-Path -Path $TEMP_BUILD_DIR) {
        Remove-Item $TEMP_BUILD_DIR -Recurse -Force
    }
    New-Item -Path $TEMP_BUILD_DIR -ItemType Directory

    Set-Location $TEMP_BUILD_DIR

    $pythonExecutable = (python -c "import sys; print(sys.executable)") -replace '\\', '/'
    $PATH_SWIG_DIR = (Join-Path $DEPS_DIR "swig\Lib") -replace '\\', '/'
    $PATH_SWIG_EXE = (Join-Path $DEPS_DIR "swig\swig.exe") -replace '\\', '/'
    $SWIG_VERSION = "4.0.0"
    $IIO_LIBS_DIR= (Join-Path $DEST_LIBIIO "libiio.lib") -replace '\\', '/'
    $IIO_INCLUDE_DIR= ($DEST_LIBIIO) -replace '\\', '/'

    Write-Output "Running cmake on generator $GENERATOR for $ARCH"

    cmake -G "$GENERATOR" -A "$ARCH" -DIIO_LIBRARIES:FILEPATH="$IIO_LIBS_DIR" -DIIO_INCLUDE_DIRS:PATH="$IIO_INCLUDE_DIR" -DCMAKE_CONFIGURATION_TYPES=RELEASE -DSWIG_DIR="$PATH_SWIG_DIR" -DSWIG_EXECUTABLE="$PATH_SWIG_EXE" -DSWIG_VERSION="$SWIG_VERSION" -DENABLE_TOOLS=ON -DENABLE_LOG=ON -DPython_EXECUTABLE="$pythonExecutable" -DBUILD_EXAMPLES=ON -DENABLE_CSHARP=ON -DENABLE_LABVIEW=ON -DENABLE_PYTHON=ON ..
    
    if ($LASTEXITCODE -ne 0) {
        Write-Output "## cmake #1 failed with exit code $LASTEXITCODE"
        exit $LASTEXITCODE
    }

    Write-Output "Running second cmake"
    cmake --build . --config Release

    if ($LASTEXITCODE -ne 0) {
        Write-Output "## cmake #2 failed with exit code $LASTEXITCODE"
        exit $LASTEXITCODE
    }
	Get-Content setup.py
}

function Get-Dll-Paths() {
    $vsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
    if ($vsPath -eq $null) {
            Write-Host "Visual Studio (vswhere.exe) not found - can't find dll paths."
            return $null
    } 

    $vsInstallerPath = & $vsPath -latest -requires Microsoft.Component.MSBuild -property installationPath
    if ($vsInstallerPath -eq $null) {
        Write-Host "Visual Studio Installer path is not available"
        return $null
    }
    
    $msvcp140Path = Join-Path $vsInstallerPath 'VC\Tools\MSVC\14.*\bin\Hostx64\x64\msvcp140.dll'
    $vcruntime140Path = Join-Path $vsInstallerPath 'VC\Tools\MSVC\14.*\bin\Hostx64\x64\vcruntime140.dll'
    if (($msvcp140Path -eq $null) -or ($vcruntime140Path -eq $null)) {
        Write-Host "Dll paths not found in Visual Studion installation path."
        return $null
    }

    $result = New-Object PSObject -Property @{
        msvcp140Path = $msvcp140Path
        vcruntime140Path = $vcruntime140Path
    }
    return $result
}

function Move-To-Build-Dir() {
    $ddlPaths = Get-Dll-Paths

    if ($ddlPaths -ne $null) {
        Write-Host "msvcp140Path: $($ddlPaths.msvcp140Path)"
        Write-Host "vcruntime140Path: $($ddlPaths.vcruntime140Path)"
    } else {
        Write-Host "Dll Paths not found."
    }

    Copy-Item -Path $ddlPaths.msvcp140Path -Destination $BUILD_DIR
    Copy-Item -Path $ddlPaths.vcruntime140Path -Destination $BUILD_DIR

    Set-Location $TEMP_BUILD_DIR
    Copy-Item -Path "*.dll" -Destination $BUILD_DIR
    Copy-Item -Path "*.exe" -Destination $BUILD_DIR
    Copy-Item -Path "*libm2k.lib" -Destination $BUILD_DIR
    Copy-Item -Path "libm2k.exp" -Destination $BUILD_DIR
    Copy-Item -Path "*.iss" -Destination $BUILD_DIR

    Copy-Item -Path (Join-Path $OUTSIDE_BUILD "libiio-$ARCH\*.dll") -Destination $BUILD_DIR   
    Copy-Item -Path (Join-Path $OUTSIDE_BUILD "libiio-$ARCH\*.dll") -Destination $BUILD_DIR   
    Copy-Item -Path (Join-Path $OUTSIDE_BUILD "deps\glog\build_0_4_0-x64\Release\glog.dll") -Destination $BUILD_DIR  

    Set-Location $SRC_DIR
    xcopy include $BUILD_DIR /s /e /h
}

Build-Libm2k -PLATFORM $PLATFORM -GENERATOR $COMPILER -ARCH $ARCH 
Move-To-Build-Dir

Set-Location $SRC_DIR