|
| 1 | +# Windows build functions for PopSift |
| 2 | +# Usage: source this file and call the individual functions |
| 3 | + |
| 4 | +<# |
| 5 | +.SYNOPSIS |
| 6 | +Creates the necessary build directories for different build types on Windows. |
| 7 | +
|
| 8 | +.DESCRIPTION |
| 9 | +Sets up build directories for the main PopSift build and third-party build testing. |
| 10 | +Creates directories with lowercase build type names (e.g. build_release) following Windows conventions. |
| 11 | +
|
| 12 | +.PARAMETER BuildType |
| 13 | +The build configuration (Release or Debug) |
| 14 | +#> |
| 15 | +function Setup-Directories { |
| 16 | + param([string]$BuildType) |
| 17 | + |
| 18 | + Write-Host "Setting up build directories for $BuildType..." |
| 19 | + $buildDir = "build_$($BuildType.ToLower())" |
| 20 | + $thirdPartyDir = "build_as_3rdparty_$($BuildType.ToLower())" |
| 21 | + |
| 22 | + New-Item -ItemType Directory -Path $buildDir -Force | Out-Null |
| 23 | + New-Item -ItemType Directory -Path $thirdPartyDir -Force | Out-Null |
| 24 | +} |
| 25 | + |
| 26 | +<# |
| 27 | +.SYNOPSIS |
| 28 | +Configures CMake for PopSift build on Windows using vcpkg for dependency management. |
| 29 | +
|
| 30 | +.DESCRIPTION |
| 31 | +Sets up CMake configuration with Visual Studio 2022 generator, enables shared libraries, |
| 32 | +and configures PopSift-specific options. Uses vcpkg manifest mode for dependency management. |
| 33 | +
|
| 34 | +.PARAMETER BuildType |
| 35 | +The build configuration (Release or Debug) |
| 36 | +
|
| 37 | +.PARAMETER VcpkgRoot |
| 38 | +Path to the vcpkg installation directory |
| 39 | +
|
| 40 | +.PARAMETER WorkspaceDir |
| 41 | +Path to the workspace directory for install location |
| 42 | +#> |
| 43 | +function Configure-CMake { |
| 44 | + param( |
| 45 | + [string]$BuildType, |
| 46 | + [string]$VcpkgRoot, |
| 47 | + [string]$WorkspaceDir |
| 48 | + ) |
| 49 | + |
| 50 | + Write-Host "Configuring CMake for $BuildType..." |
| 51 | + $buildDir = "build_$($BuildType.ToLower())" |
| 52 | + $installDir = "$WorkspaceDir/install_$($BuildType.ToLower())" |
| 53 | + $vcpkgToolchain = "$VcpkgRoot/scripts/buildsystems/vcpkg.cmake" |
| 54 | + |
| 55 | + Set-Location $buildDir |
| 56 | + cmake .. -G "Visual Studio 17 2022" -A x64 ` |
| 57 | + -DBUILD_SHARED_LIBS:BOOL=ON ` |
| 58 | + -DCMAKE_GENERATOR_TOOLSET="cuda=$env:CUDA_PATH" ` |
| 59 | + -DPopSift_USE_GRID_FILTER:BOOL=ON ` |
| 60 | + -DPopSift_BUILD_DOCS:BOOL=OFF ` |
| 61 | + -DPopSift_USE_POSITION_INDEPENDENT_CODE:BOOL=ON ` |
| 62 | + -DPopSift_BUILD_EXAMPLES:BOOL=ON ` |
| 63 | + -DCMAKE_BUILD_TYPE="$BuildType" ` |
| 64 | + -DCMAKE_INSTALL_PREFIX="$installDir" ` |
| 65 | + -DVCPKG_INSTALLED_DIR="$env:VCPKG_INSTALLED_DIR" ` |
| 66 | + -DCMAKE_TOOLCHAIN_FILE="$vcpkgToolchain" |
| 67 | + |
| 68 | + if ($LASTEXITCODE -ne 0) { |
| 69 | + throw "CMake configuration failed for $BuildType" |
| 70 | + } |
| 71 | + Set-Location .. |
| 72 | +} |
| 73 | + |
| 74 | +<# |
| 75 | +.SYNOPSIS |
| 76 | +Builds and installs PopSift for the specified build configuration. |
| 77 | +
|
| 78 | +.DESCRIPTION |
| 79 | +Performs parallel build using all available CPU cores and installs the built |
| 80 | +libraries and executables to the configured install directory. |
| 81 | +
|
| 82 | +.PARAMETER BuildType |
| 83 | +The build configuration (Release or Debug) |
| 84 | +#> |
| 85 | +function Build-AndInstall { |
| 86 | + param([string]$BuildType) |
| 87 | + |
| 88 | + Write-Host "Building and installing $BuildType..." |
| 89 | + $buildDir = "build_$($BuildType.ToLower())" |
| 90 | + |
| 91 | + Set-Location $buildDir |
| 92 | + cmake --build . --config $BuildType --parallel |
| 93 | + if ($LASTEXITCODE -ne 0) { |
| 94 | + throw "Build failed for $BuildType" |
| 95 | + } |
| 96 | + |
| 97 | + cmake --build . --config $BuildType --target install |
| 98 | + if ($LASTEXITCODE -ne 0) { |
| 99 | + throw "Install failed for $BuildType" |
| 100 | + } |
| 101 | + Set-Location .. |
| 102 | +} |
| 103 | + |
| 104 | +<# |
| 105 | +.SYNOPSIS |
| 106 | +Tests building PopSift applications as a third-party consumer on Windows. |
| 107 | +
|
| 108 | +.DESCRIPTION |
| 109 | +Verifies that the installed PopSift can be found and used by external projects. |
| 110 | +This is important for testing the installation and packaging. Uses vcpkg manifest |
| 111 | +mode dependencies from the main project build since src/application doesn't have |
| 112 | +its own vcpkg.json file. |
| 113 | +
|
| 114 | +.PARAMETER BuildType |
| 115 | +The build configuration (Release or Debug) |
| 116 | +
|
| 117 | +.PARAMETER VcpkgRoot |
| 118 | +Path to the vcpkg installation directory |
| 119 | +
|
| 120 | +.PARAMETER WorkspaceDir |
| 121 | +Path to the workspace directory containing the main build and install |
| 122 | +#> |
| 123 | +function Build-AsThirdParty { |
| 124 | + param( |
| 125 | + [string]$BuildType, |
| 126 | + [string]$VcpkgRoot, |
| 127 | + [string]$WorkspaceDir |
| 128 | + ) |
| 129 | + |
| 130 | + Write-Host "Testing third-party build for $BuildType..." |
| 131 | + $thirdPartyDir = "build_as_3rdparty_$($BuildType.ToLower())" |
| 132 | + $installDir = "$WorkspaceDir/install_$($BuildType.ToLower())" |
| 133 | + $vcpkgToolchain = "$VcpkgRoot/scripts/buildsystems/vcpkg.cmake" |
| 134 | + |
| 135 | + # In vcpkg manifest mode, dependencies are installed locally in vcpkg_installed/ |
| 136 | + # Since src/application doesn't have vcpkg.json, we need to point to the main project's vcpkg_installed directory so the third-party build can find the dependencies |
| 137 | + $mainProjectVcpkgInstalled = $env:VCPKG_INSTALLED_DIR |
| 138 | + Write-Host "Dependencies installed in $mainProjectVcpkgInstalled..." |
| 139 | + # print first level content of the folder mainProjectVcpkgInstalled |
| 140 | + Get-ChildItem -Path $mainProjectVcpkgInstalled -Directory | ForEach-Object { Write-Host " - $($_.Name)" } |
| 141 | + |
| 142 | + Set-Location $thirdPartyDir |
| 143 | + cmake ../src/application -G "Visual Studio 17 2022" -A x64 ` |
| 144 | + -DBUILD_SHARED_LIBS:BOOL=ON ` |
| 145 | + -DCMAKE_BUILD_TYPE=$BuildType ` |
| 146 | + -DCMAKE_PREFIX_PATH="$installDir;$mainProjectVcpkgInstalled/x64-windows" ` |
| 147 | + -DCMAKE_TOOLCHAIN_FILE="$vcpkgToolchain" ` |
| 148 | + -DVCPKG_INSTALLED_DIR="$mainProjectVcpkgInstalled" ` |
| 149 | + -DVCPKG_TARGET_TRIPLET=x64-windows |
| 150 | + |
| 151 | + if ($LASTEXITCODE -ne 0) { |
| 152 | + throw "Third-party CMake configuration failed for $BuildType" |
| 153 | + } |
| 154 | + |
| 155 | + cmake --build . --config $BuildType --parallel |
| 156 | + if ($LASTEXITCODE -ne 0) { |
| 157 | + throw "Third-party build failed for $BuildType" |
| 158 | + } |
| 159 | + Set-Location .. |
| 160 | +} |
0 commit comments