diff --git a/win/build-deps.cmd b/win/build-deps.cmd index 03bb37aedb..ac643f1bba 100644 --- a/win/build-deps.cmd +++ b/win/build-deps.cmd @@ -41,6 +41,8 @@ echo. :: Enable the delayed environment variable expansion needed in vs-cfg.cmd. setlocal EnableDelayedExpansion +set SCRIPT_DIR=%~dp0 + :: Make sure vcvarsall.bat is called and dev env set is up. IF "%VSINSTALLDIR%"=="" ( call utils\cecho.cmd 0 12 "Visual Studio environment variables not set- cannot proceed." @@ -108,6 +110,7 @@ FOR %%i IN (powershell git cmake) DO ( :: Check powershell version powershell -c "exit $PSVersionTable.PSVersion.Major -lt 5" IF NOT %ERRORLEVEL%==0 call cecho.cmd 0 12 "Powershell version 5 or higher required" && goto :ErrorAndPrintUsage +set PWSH_TOOLS=powershell -NonInteractive -File %SCRIPT_DIR%\utils\tools.ps1 cmake --version | findstr version > temp.txt set /p CMAKE_VERSION=NUL if not %ERRORLEVEL%==0 goto :Error cd "%DEPENDENCY_DIR%" -call :RunCMake -DINSTALL_DIR="%INSTALL_DIR%\opencascade-%OCCT_VERSION%" -DBUILD_LIBRARY_TYPE="Static" -DCMAKE_DEBUG_POSTFIX=d ^ +call :RunCMake -DINSTALL_DIR="%INSTALL_DIR%\%DEPENDENCY_INSTALL_NAME%" -DBUILD_LIBRARY_TYPE="Static" -DCMAKE_DEBUG_POSTFIX=d ^ -DBUILD_MODULE_Draw=0 -D3RDPARTY_FREETYPE_DIR="%INSTALL_DIR%\freetype" if not %ERRORLEVEL%==0 goto :Error @@ -532,6 +540,7 @@ call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\OCCT.sln" %BUILD_CFG% if not %ERRORLEVEL%==0 goto :Error call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG% if not %ERRORLEVEL%==0 goto :Error +call :MarkInstallation SET COMPILE_WITH_WPO=FALSE @@ -694,11 +703,11 @@ set DEPENDENCY_NAME=rocksdb set ROCKSDB_VERSION=9.11.2 set ROCKSDB_ZIP=rocksdb-%ROCKSDB_VERSION%.zip set DEPENDENCY_DIR=%DEPS_DIR%\%DEPENDENCY_NAME%-%ROCKSDB_VERSION% +set DEPENDENCY_INSTALL_NAME=%DEPENDENCY_NAME% +set NEXT_DEPENDENCY_LABEL=Successful -IF EXIST "%INSTALL_DIR%\%DEPENDENCY_NAME%" ( - echo Found existing "%INSTALL_DIR%\%DEPENDENCY_NAME%", skipping - goto :Successful -) +call :CheckInstallation +if %ERRORLEVEL%==200 GOTO %NEXT_DEPENDENCY_LABEL% cd %DEPS_DIR% call :DownloadFile ^ @@ -713,7 +722,7 @@ cd "%DEPENDENCY_DIR%" set ZSTD_INCLUDE=%INSTALL_DIR%\zstd\include set ZSTD_LIB_DEBUG=%INSTALL_DIR%\zstd\lib\zstd_static.lib set ZSTD_LIB_RELEASE=%INSTALL_DIR%\zstd\lib\zstd_static.lib -call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\rocksdb" ^ +call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\%DEPENDENCY_INSTALL_NAME%" ^ -DROCKSDB_INSTALL_ON_WINDOWS=On ^ -DFAIL_ON_WARNINGS=Off ^ -DWITH_TESTS=OFF ^ @@ -722,12 +731,14 @@ call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\rocksdb" ^ -DWITH_CORE_TOOLS=OFF ^ -DROCKSDB_BUILD_SHARED=OFF ^ -DWITH_ZSTD=On ^ - -DPORTABLE=1 + -DPORTABLE=1 ^ + -DCMAKE_DEBUG_POSTFIX="_d" IF NOT %ERRORLEVEL%==0 GOTO :Error call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\rocksdb.sln" %BUILD_CFG% IF NOT %ERRORLEVEL%==0 GOTO :Error call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG% IF NOT %ERRORLEVEL%==0 GOTO :Error +call :MarkInstallation :: :tbb :: set DEPENDENCY_NAME=tbb @@ -803,7 +814,7 @@ echo Build ended at %END_TIME%. Time elapsed %hh%:%mm%:%ss%.%cc%. :BuildTimeSkipped set PATH=%ORIGINAL_PATH% cd "%~dp0" -exit /b %IFCOS_SCRIPT_RET% +exit %IFCOS_SCRIPT_RET% ::::::::::::::::::::::::::::::::::::: Subroutines ::::::::::::::::::::::::::::::::::::: @@ -945,6 +956,33 @@ set RET=%ERRORLEVEL% popd exit /b %RET% +:: Checks whether a dependency is already installed for the specified config +:: Doesn't work for dependencies, only for those that need separate Debug/Release installs. +:: Required vars: +:: - DEPENDENCY_NAME +:: - DEPENDENCY_INSTALL_NAME +:: - NEXT_DEPENDENCY_LABEL +:: Always intended to be used with the code below +:: (unfortunately we can't move `GOTO` to the this label too, +:: because of how it would interact with `call` and `exit /b`): +:: ``` +:: call :CheckInstallation +:: if %ERRORLEVEL%==200 GOTO %NEXT_DEPENDENCY_LABEL% +:: ``` +:CheckInstallation +%PWSH_TOOLS% check_installation %DEPENDENCY_NAME% "%INSTALL_DIR%\%DEPENDENCY_INSTALL_NAME%" +set RET=%ERRORLEVEL% +if %RET%==200 echo Found existing "%INSTALL_DIR%\%DEPENDENCY_INSTALL_NAME%" for %BUILD_CFG%, skipping && exit /b 200 +if %RET% NEQ 404 GOTO :Error +exit /b 0 + +:: Required vars: +:: - DEPENDENCY_INSTALL_NAME +:MarkInstallation +%PWSH_TOOLS% mark "%INSTALL_DIR%\%DEPENDENCY_INSTALL_NAME%" +IF NOT %ERRORLEVEL%==0 GOTO :Error +exit /b 0 + :: PrintUsage - Prints usage information :PrintUsage call "%~dp0\utils\cecho.cmd" 0 10 "Requirements for a successful execution:" diff --git a/win/utils/tools.ps1 b/win/utils/tools.ps1 new file mode 100644 index 0000000000..1bdad544f9 --- /dev/null +++ b/win/utils/tools.ps1 @@ -0,0 +1,140 @@ +Set-PSDebug -Trace 0 +Set-StrictMode -Version 3 +$ErrorActionPreference = "Stop" + + +# Create marker file to indicate whether Release or Debug build was installed. +function mark { + param( + [Parameter(Mandatory = $true)] + [string]$installation_dir + ) + + if (-not (Test-Path -Path $installation_dir)) { + throw "Directory '$installation_dir' does not exist." + } + + $marker_filepath = Join-Path -Path $installation_dir -ChildPath $ENV:MARKER_FILE + if (Test-Path -Path $marker_filepath) { + return + } + echo "Marking installation in '$installation_dir' with '$ENV:MARKER_FILE'." + New-Item -Path $marker_filepath -ItemType File | Out-Null +} + +# This function can be deprecated in the future, since installations are marked automatically. +# It's here only to avoid some disruption during the transition period. +function mark_based_on_artifacts { + param( + [Parameter(Mandatory = $true)] + [string]$dependency_name, + + [Parameter(Mandatory = $true)] + [string]$installation_dir + ) + + if ($dependency_name -eq "hdf5") { + if ($env:BUILD_CFG -eq "Debug") { + $artifact = "lib\libhdf5_D.lib" + } + else { + $artifact = "lib\libhdf5.lib" + } + } + elseif ($dependency_name -eq "opencollada") { + if ($env:BUILD_CFG -eq "Debug") { + $artifact = "lib\opencollada\OpenCOLLADAFrameworkd.lib" + } + else { + $artifact = "lib\opencollada\OpenCOLLADAFramework.lib" + } + } + elseif ($dependency_name -eq "OpenCASCADE") { + if ($env:BUILD_CFG -eq "Debug") { + $artifact = "win64\lib\TKerneld.lib" + } + else { + $artifact = "win64\lib\TKernel.lib" + } + } + elseif ($dependency_name -eq "rocksdb") { + if ($env:BUILD_CFG -eq "Debug") { + $artifact = "lib\rocksdb_d.lib" + } + else { + $artifact = "lib\rocksdb.lib" + } + } + else { + throw "Unexpected dependency name '$dependency_name'." + } + $artifact_filepath = Join-Path -Path $installation_dir -ChildPath $artifact + if (-not (Test-Path -Path $artifact_filepath)) { + return + } + if (-not (Test-Path -Path $installation_dir)) { + throw "Directory '$installation_dir' does not exist." + } + $marker_filepath = Join-Path -Path $installation_dir -ChildPath $ENV:MARKER_FILE + if (Test-Path -Path $marker_filepath) { + return + } + echo "Found artifact '$artifact' for dependency '$dependency_name' $env:BUILD_CFG." + & mark $installation_dir +} + +# Check if installation exists for the current `BUILD_CFG`. +# Returns exit code 200 if installation exists, 404 otherwise. +# Since we want Release and Debug installation to coexist, +# we add special marker file to indicate which build type was installed. +function check_installation { + param( + [Parameter(Mandatory = $true)] + [string]$dependency_name, + [Parameter(Mandatory = $true)] + [string]$installation_dir + ) + + if (-not (Test-Path -Path $installation_dir)) { + exit 404 + } + + & mark_based_on_artifacts $dependency_name $installation_dir + + $marker_filepath = Join-Path -Path $installation_dir -ChildPath $ENV:MARKER_FILE + if (-not (Test-Path -Path $marker_filepath)) { + exit 404 + } + exit 200 +} + + +# Dependencies Release/Debug configs compatibility: +# - hdf5: incompatible +# - OpenCASCADE: incompatible +# - rocksdb: incompatible +# - opencollada: incompatible +# - zstd: compatible + +function setup_build_cfg { + if (-not $env:BUILD_CFG) { + throw "Variable 'BUILD_CFG' is not defined." + } + if ($env:BUILD_CFG -eq "Debug") { + $ENV:MARKER_FILE = ".debug_installation" + } + else { + $ENV:MARKER_FILE = ".release_installation" + } +} + +function main { + & setup_build_cfg + # Dispatch command. + $command = $Args[0] + $command_args = $Args[1..($args.Count - 1)] + & $command @command_args +} + +& main @Args +exit 0