Created
May 24, 2023 21:09
-
-
Save kfsone/12a9b86ce349ade41879b1a01cc3a28e to your computer and use it in GitHub Desktop.
Build wxWidgets by fetching from source.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
CMake-Build produces reproducible builds of wxWidgets binaries. | |
.Description | |
The CMake-Build script can fetch latest or a specific hash of the | |
wxWidgets library source from the official github, or it can use | |
an existing local source directory. | |
It will configure it for Nuo use, build the binaries, and then | |
install them in-tree to your Nuo checkout. | |
#> | |
Param( | |
[Parameter(HelpMessage="CMake Version string (e.g 3.2.0)")] | |
[String] $Version = "3.2.0", | |
# Or use Master | |
[Parameter(HelpMessage="Use master instead of a version")] | |
[Switch] $UseMaster, | |
[Parameter(HelpMessage="Specify CMake generator to use.")] | |
[String] $Generator, | |
[Parameter(HelpMessage="URL for the wxWidgets git repository.")] | |
[String] $RepoUrl = "https://github.com/wxWidgets/wxWidgets.git", | |
[Parameter(HelpMessage="Path to the cmake executable to use.")] | |
[String] $CMake, | |
[Parameter(HelpMessage="Source hash to use.")] | |
[String] $SourceHash, | |
[Parameter(HelpMessage="Force recreation of the directory.", ParameterSetName="Fresh")] | |
[Switch] $Fresh, | |
[Parameter(Mandatory, HelpMessage="Using existing directories.", ParameterSetName="Existing")] | |
[Switch] $Existing, | |
[Parameter(HelpMessage="Don't re-run generate if we can avoid it.", ParameterSetName="Existing")] | |
[Switch] $AvoidGenerate, | |
[Parameter(HelpMessage="Enable wx_USE_UNICODE_UTF8 or not.")] | |
[Switch] $UseUTF8, | |
[Parameter(HelpMessage="Remove source after finishing.")] | |
[Switch] $Clean | |
) | |
$ErrorActionPreference = "Stop" | |
if ($IsWindows -or $PSTable.Edition -eq "Desktop") { | |
$Platform = "win" | |
} elseif ($IsMacos) { | |
$Platform = "macintel" | |
} else { | |
throw "Only windows and mac are supported." | |
} | |
Function ensure_dir { | |
Param([String] $Path) | |
if (-Not (Test-Path $Path)) { | |
if (-Not (New-Item -Type Directory $Path)) { | |
Write-Error "${Path} does not exist and could creation attempt failed." -ErrorAction stop | |
exit 1 | |
} | |
} | |
} | |
if (-Not "${Version}" -Match "^\d+\.\d+\.\d+$") { | |
Write-Error "Invalid version string, expected <major>.<minor>.<patch> e.g 3.1.5" -ErrorAction stop | |
exit 1 | |
} | |
# Make sure cmake is available before we start doing things. | |
if (-Not $cmake) { | |
$cmakecmd = Get-Command "cmake" -erroraction ignore | |
if (-Not $cmakecmd) { | |
if ($Platform -eq "win") { | |
Write-Warning "No 'cmake' command in path; run 'Enable-VSDevShell' (aka 'vsdev') to enable build tool access, or use the -cmake argument" | |
} else { | |
Write-Warning "No 'cmake' command in path; use the '-cmake' argument to specify one." | |
} | |
exit 1 | |
} | |
$CMake = $cmakecmd.path | |
} | |
if (-Not (Test-Path $CMake)) { | |
throw "Specified cmake command doesn't exist: ${CMake}" | |
} | |
$VersionDir = Join-Path $PWD "Version_${Version}" | |
$WorkDir = Join-Path $VersionDir "build-in-progress" | |
$SourceDir = Join-Path $WorkDir "source-from-git" | |
$BuildDir = Join-Path $WorkDir "build" $Platform | |
$DstDir = Join-Path $VersionDir "build-${Platform}" | |
Write-Host "==== VersionDir: ${VersionDir}" | |
Write-Host "==== WorkingDir: ${WorkDir}" | |
Write-Host "==== SourceDir: ${SourceDir}" | |
Write-Host "==== BuildDir: ${BuildDir}" | |
Write-Host "==== DstDir: ${DstDir}" | |
ensure_dir $VersionDir | |
if ($Fresh -And (Test-Path $WorkDir)) { | |
Remove-Item -Rec -For $WorkDir | |
} | |
# Create the top level directories if they need to be there. | |
ensure_dir $WorkDir | |
if (-Not $Existing) { | |
if (Test-Path $SourceDir) { | |
Write-Error "${SourceDir} already exists. Remove or specify -Fresh or -existing" | |
exit 1 | |
} | |
if (Test-Path $BuildDir) { | |
Write-Error "${BuildDir} already exists. Remove or specify -Fresh or -existing" | |
exit 1 | |
} | |
} | |
## Pull the one branch with no history. | |
$RemoteBranch = if ($UseMaster) { "master" } else { "v${Version}" } | |
if (-Not (Test-Path $SourceDir)) { | |
Write-Host "==== Checkout ${RepoUrl} -> ${SourceDir}" | |
git clone $RepoUrl ` | |
--recurse-submodules ` | |
--single-branch ` | |
--depth 1 ` | |
--branch $RemoteBranch ` | |
--quiet ` | |
$SourceDir ` | |
|| { | |
Write-Error "git clone failed" | |
Remove-Item -Rec -For $SourceDir | |
exit 1 | |
} | |
# Force a regenerate. | |
if (Test-Path $BuildDir) { | |
Remove-Item -Rec -For $BuildDir | |
} | |
} | |
$GitDir = Join-Path $SourceDir .git | |
# Capture the source hash | |
if ($SourceHash) { | |
git --git-dir=$GitDir checkout $SourceHash | |
} | |
$SrcHash = git --git-dir (Join-Path $SourceDir .git) rev-parse HEAD | |
Write-Host "==== WxWidgets Source Hash: ${SrcHash}" | |
# Do we *need* to force a regenerate? | |
$NeedGenerate = -Not (Test-Path $BuildDir) -or -Not $AvoidGenerate -or $SourceHash | |
# Configure | |
if ($NeedGenerate) { | |
Write-Host "==== Configuring" | |
$utf8 = if ($UseUTF8) { "ON" } else { "OFF" } | |
& $cmake -B $BuildDir ` | |
"$(if ("$Generator") { "${Generator}" })" ` | |
"-DCMAKE_CONFIGURATION_TYPES=Debug;RelWithDebInfo" ` | |
-DwxBUILD_BENCHMARKS=OFF ` | |
-DwxBUILD_CXX_STANDARD=17 ` | |
-DwxBUILD_DEMOS=OFF ` | |
-DwxBUILD_INSTALL=OFF ` | |
-DwxBUILD_MONOLITHIC=ON ` | |
-DwxBUILD_MSVC_MULTIPROC=ON ` | |
-DwxBUILD_OPTIMISE=ON ` | |
-DwxBUILD_PRECOMP=ON ` | |
-DwxBUILD_SAMPLES=OFF ` | |
-DwxBUILD_SHARED=OFF ` | |
-DwxBUILD_STRIPPED_RELEASE=ON ` | |
-DwxBUILD_TESTS=OFF ` | |
-DwxUSE_EXPAT=builtin ` | |
-DwxUSE_LIBJPEG=builtin ` | |
-DwxUSE_LIBLZMA=OFF ` | |
-DwxUSE_LIBPNG=builtin ` | |
-DwxUSE_LIBTIFF=builtin ` | |
-DwxUSE_MEDIACTRL=OFF ` | |
-DwxUSE_POSTSCRIPT=OFF ` | |
-DwxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW=OFF ` | |
-DwxUSE_PRINTING_ARCHITECTURE=OFF ` | |
-DwxUSE_RIBBON=OFF ` | |
-DwxUSE_SOUND=OFF ` | |
-DwxUSE_SVG=OFF ` | |
-DwxUSE_STL=OFF ` | |
-DwxUSE_ZLIB=builtin ` | |
-DwxUSE_UNICODE=ON ` | |
-DwxDEBUG_LEVEL=0 ` | |
"-DwxUSE_UNICODE_UTF8=${utf8}" ` | |
$SourceDir | |
# -DwxUSE_STC=OFF | |
#-DwxUSE_WEBVIEW=ON | |
#-DwxUSE_WEBVIEW_EDGE=ON | |
#-DwxUSE_WEBVIEW_EDGE_STATIC=ON | |
#-DwxUSE_WEBVIEW_IE=OFF | |
Write-Output "-- done generating" | |
} | |
foreach ($release in "Debug", "RelWithDebInfo") { | |
Write-Host "==== Building ${release}" | |
& $cmake --build $BuildDir --config $release $(if (-Not $AvoidGenerate) { "--clean-first" }) -j9 | |
} | |
$BinaryRoot = Join-Path $BuildDir lib | |
if (-Not (Test-Path $BinaryRoot)) { | |
Write-Error "${Release}: Binary Root ${BinaryRoot} does not exist." | |
exit 1 | |
} | |
# Copy include files. | |
$IncludesSrc = Join-Path $SourceDir "include" | |
$IncludesDst = Join-Path $VersionDir "include" | |
Write-Host "==== Copying headers ${IncludesSrc} -> ${IncludesDst}" | |
Copy-Item ${IncludesSrc} -Destination $VersionDir -Recurse -Force | |
# Copy binary files. | |
$LibSrc = $BinaryRoot | |
$LibDst = Join-Path $DstDir lib | |
$LibExt = if ($IsWindows) { "lib" } else { "a" } | |
ensure_dir $LibDst | |
Write-Host "==== Copying library files ${LibSrc} *.$LibExt -> ${LibDst}" | |
Copy-Item (Get-ChildItem -Recurse -Path $BinaryRoot *.$LibExt) $LibDst | |
$WxDst = Join-Path $DstDir wx | |
ensure_dir $WxDst | |
$WxSrc = Get-ChildItem -Recurse -Path $LibSrc setup.h | Select-Object -First 1 | |
Write-Host "==== Copying setup.h ${WxSrc} -> ${WxDst}" | |
Copy-Item $WxSrc $WxDst -Force | |
Write-Output >(Join-Path $DstDir "source-hash.txt") "${SrcHash}" | |
Write-Output >(Join-Path $VersionDir "source-hash.${platform}.txt") "${SrcHash}" | |
if ($Clean) { | |
Write-Host "==== Removing ${WorkDir}" | |
Remove-Item -Rec -For $WorkDir | |
} | |
Write-Output "==== Finished building ${DstDir} from ${SrcHash}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment