Skip to content

Commit 517ba23

Browse files
committed
build-deps - coexisting Release and Debug installations
1 parent 994a364 commit 517ba23

2 files changed

Lines changed: 201 additions & 23 deletions

File tree

win/build-deps.cmd

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ echo.
4141
:: Enable the delayed environment variable expansion needed in vs-cfg.cmd.
4242
setlocal EnableDelayedExpansion
4343

44+
set SCRIPT_DIR=%~dp0
45+
4446
:: Make sure vcvarsall.bat is called and dev env set is up.
4547
IF "%VSINSTALLDIR%"=="" (
4648
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 (
108110
:: Check powershell version
109111
powershell -c "exit $PSVersionTable.PSVersion.Major -lt 5"
110112
IF NOT %ERRORLEVEL%==0 call cecho.cmd 0 12 "Powershell version 5 or higher required" && goto :ErrorAndPrintUsage
113+
set PWSH_TOOLS=powershell -NonInteractive -File %SCRIPT_DIR%\utils\tools.ps1
111114

112115
cmake --version | findstr version > temp.txt
113116
set /p CMAKE_VERSION=<temp.txt
@@ -358,12 +361,12 @@ popd
358361
set DEPENDENCY_NAME=hdf5
359362
set DEPENDENCY_DIR=%DEPS_DIR%\hdf5-%HDF5_VERSION%
360363
set HDF5_CMAKE_ZIP=hdf5-%HDF5_VERSION%.zip
361-
set HDF5_INSTALL_NAME=HDF5-%HDF5_VERSION%-win%ARCH_BITS%
364+
set DEPENDENCY_INSTALL_NAME=HDF5-%HDF5_VERSION%-win%ARCH_BITS%
365+
set HDF5_INSTALL_NAME=%DEPENDENCY_INSTALL_NAME%
366+
set NEXT_DEPENDENCY_LABEL=Boost
362367

363-
IF EXIST "%INSTALL_DIR%\%HDF5_INSTALL_NAME%" (
364-
echo Found existing "%INSTALL_DIR%\%HDF5_INSTALL_NAME%", skipping
365-
goto :Boost
366-
)
368+
call :CheckInstallation
369+
if %ERRORLEVEL%==200 GOTO %NEXT_DEPENDENCY_LABEL%
367370

368371
if "%ARCH_BITS%"=="64" set ARCH_BITS_64=64
369372
call :DownloadFile ^
@@ -383,6 +386,7 @@ call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\HDF5.sln" %DEBUG_OR_RELEASE%
383386
IF NOT %ERRORLEVEL%==0 GOTO :Error
384387
call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %DEBUG_OR_RELEASE%
385388
IF NOT %ERRORLEVEL%==0 GOTO :Error
389+
call :MarkInstallation
386390
popd
387391

388392
:: Note all of the dependencies have appropriate label so that user can easily skip something if wanted
@@ -443,15 +447,14 @@ call :DownloadFile https://github.com/nlohmann/json/releases/download/v3.6.1/jso
443447
:: Note OpenCOLLADA has only Release and Debug builds.
444448
set DEPENDENCY_NAME=OpenCOLLADA
445449
set DEPENDENCY_DIR=%DEPS_DIR%\OpenCOLLADA
450+
set DEPENDENCY_INSTALL_NAME=OpenCOLLADA
451+
set NEXT_DEPENDENCY_LABEL=OCCT
446452
:: Always clone it, even if it's installed, because it contains xml headers we need.
447453
:: Use a fixed revision in order to prevent introducing breaking changes
448454
call :GitCloneAndCheckoutRevision https://github.com/KhronosGroup/OpenCOLLADA.git "%DEPENDENCY_DIR%" 064a60b65c2c31b94f013820856bc84fb1937cc6
449455

450-
IF EXIST "%INSTALL_DIR%\OpenCOLLADA" (
451-
echo Found existing "%INSTALL_DIR%\OpenCOLLADA", skipping
452-
:: we do need to clone though because the bundled libxml includes are not installed
453-
goto :OCCT
454-
)
456+
call :CheckInstallation
457+
if %ERRORLEVEL%==200 GOTO %NEXT_DEPENDENCY_LABEL%
455458

456459
IF NOT %ERRORLEVEL%==0 GOTO :Error
457460
cd "%DEPENDENCY_DIR%"
@@ -463,23 +466,27 @@ IF NOT %ERRORLEVEL%==0 git apply --reject --whitespace=fix "%~dp0patches\OpenCOL
463466
:: uncomment to following line in order to delete the CMakeCache.txt always if experiencing problems.
464467
REM IF EXIST "%DEPENDENCY_DIR%\%BUILD_DIR%\CMakeCache.txt". del "%DEPENDENCY_DIR%\%BUILD_DIR%\CMakeCache.txt"
465468
:: NOTE Enforce that the embedded LibXml2 and PCRE are used as there might be problems with arbitrary versions of the libraries.
466-
call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\OpenCOLLADA" -DUSE_STATIC_MSVC_RUNTIME=0 -DCMAKE_DEBUG_POSTFIX=d ^
469+
call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\%DEPENDENCY_INSTALL_NAME%" -DUSE_STATIC_MSVC_RUNTIME=0 -DCMAKE_DEBUG_POSTFIX=d ^
467470
-DLIBXML2_LIBRARIES="" -DLIBXML2_INCLUDE_DIR="" -DPCRE_INCLUDE_DIR="" -DPCRE_LIBRARIES=""
468471
IF NOT %ERRORLEVEL%==0 GOTO :Error
469472
REM IF NOT EXIST "%DEPS_DIR%\OpenCOLLADA\%BUILD_DIR%\lib\%DEBUG_OR_RELEASE%\OpenCOLLADASaxFrameworkLoader.lib".
470473
call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\OPENCOLLADA.sln" %DEBUG_OR_RELEASE%
471474
IF NOT %ERRORLEVEL%==0 GOTO :Error
472475
call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %DEBUG_OR_RELEASE%
473476
IF NOT %ERRORLEVEL%==0 GOTO :Error
477+
call :MarkInstallation
474478

475479
:OCCT
476480

477481
SET OCCT_VER=V%OCCT_VERSION:.=_%
478482

479-
IF EXIST "%INSTALL_DIR%\opencascade-%OCCT_VERSION%" (
480-
echo Found existing "%INSTALL_DIR%\opencascade-%OCCT_VERSION%", skipping
481-
goto :Python
482-
)
483+
set DEPENDENCY_NAME=OpenCASCADE
484+
set OCCT_DEPENDENCY_INSTALL_NAME=opencascade-%OCCT_VERSION%
485+
set DEPENDENCY_INSTALL_NAME=%OCCT_DEPENDENCY_INSTALL_NAME%
486+
set NEXT_DEPENDENCY_LABEL=Python
487+
488+
call :CheckInstallation
489+
if %ERRORLEVEL%==200 GOTO %NEXT_DEPENDENCY_LABEL%
483490

484491
:: OCCT has many dependencies but FreeType is the only mandatory
485492
set DEPENDENCY_NAME=FreeType
@@ -502,6 +509,7 @@ if not %ERRORLEVEL%==0 goto :Error
502509

503510
set DEPENDENCY_NAME=Open CASCADE %OCCT_VERSION%
504511
set DEPENDENCY_DIR=%DEPS_DIR%\occt_git
512+
set DEPENDENCY_INSTALL_NAME=%OCCT_DEPENDENCY_INSTALL_NAME%
505513
cd "%DEPS_DIR%"
506514
call :GitCloneAndCheckoutRevision https://github.com/Open-Cascade-SAS/OCCT "%DEPENDENCY_DIR%" %OCCT_VER%
507515
if not %ERRORLEVEL%==0 goto :Error
@@ -517,7 +525,7 @@ findstr IfcOpenShell "%DEPENDENCY_DIR%\CMakeLists.txt">NUL
517525
if not %ERRORLEVEL%==0 goto :Error
518526

519527
cd "%DEPENDENCY_DIR%"
520-
call :RunCMake -DINSTALL_DIR="%INSTALL_DIR%\opencascade-%OCCT_VERSION%" -DBUILD_LIBRARY_TYPE="Static" -DCMAKE_DEBUG_POSTFIX=d ^
528+
call :RunCMake -DINSTALL_DIR="%INSTALL_DIR%\%DEPENDENCY_INSTALL_NAME%" -DBUILD_LIBRARY_TYPE="Static" -DCMAKE_DEBUG_POSTFIX=d ^
521529
-DBUILD_MODULE_Draw=0 -D3RDPARTY_FREETYPE_DIR="%INSTALL_DIR%\freetype"
522530
if not %ERRORLEVEL%==0 goto :Error
523531

@@ -532,6 +540,7 @@ call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\OCCT.sln" %BUILD_CFG%
532540
if not %ERRORLEVEL%==0 goto :Error
533541
call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG%
534542
if not %ERRORLEVEL%==0 goto :Error
543+
call :MarkInstallation
535544

536545
SET COMPILE_WITH_WPO=FALSE
537546

@@ -694,11 +703,11 @@ set DEPENDENCY_NAME=rocksdb
694703
set ROCKSDB_VERSION=9.11.2
695704
set ROCKSDB_ZIP=rocksdb-%ROCKSDB_VERSION%.zip
696705
set DEPENDENCY_DIR=%DEPS_DIR%\%DEPENDENCY_NAME%-%ROCKSDB_VERSION%
706+
set DEPENDENCY_INSTALL_NAME=%DEPENDENCY_NAME%
707+
set NEXT_DEPENDENCY_LABEL=Successful
697708

698-
IF EXIST "%INSTALL_DIR%\%DEPENDENCY_NAME%" (
699-
echo Found existing "%INSTALL_DIR%\%DEPENDENCY_NAME%", skipping
700-
goto :Successful
701-
)
709+
call :CheckInstallation
710+
if %ERRORLEVEL%==200 GOTO %NEXT_DEPENDENCY_LABEL%
702711

703712
cd %DEPS_DIR%
704713
call :DownloadFile ^
@@ -713,7 +722,7 @@ cd "%DEPENDENCY_DIR%"
713722
set ZSTD_INCLUDE=%INSTALL_DIR%\zstd\include
714723
set ZSTD_LIB_DEBUG=%INSTALL_DIR%\zstd\lib\zstd_static.lib
715724
set ZSTD_LIB_RELEASE=%INSTALL_DIR%\zstd\lib\zstd_static.lib
716-
call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\rocksdb" ^
725+
call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\%DEPENDENCY_INSTALL_NAME%" ^
717726
-DROCKSDB_INSTALL_ON_WINDOWS=On ^
718727
-DFAIL_ON_WARNINGS=Off ^
719728
-DWITH_TESTS=OFF ^
@@ -722,12 +731,14 @@ call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\rocksdb" ^
722731
-DWITH_CORE_TOOLS=OFF ^
723732
-DROCKSDB_BUILD_SHARED=OFF ^
724733
-DWITH_ZSTD=On ^
725-
-DPORTABLE=1
734+
-DPORTABLE=1 ^
735+
-DCMAKE_DEBUG_POSTFIX="_d"
726736
IF NOT %ERRORLEVEL%==0 GOTO :Error
727737
call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\rocksdb.sln" %BUILD_CFG%
728738
IF NOT %ERRORLEVEL%==0 GOTO :Error
729739
call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG%
730740
IF NOT %ERRORLEVEL%==0 GOTO :Error
741+
call :MarkInstallation
731742

732743
:: :tbb
733744
:: set DEPENDENCY_NAME=tbb
@@ -803,7 +814,7 @@ echo Build ended at %END_TIME%. Time elapsed %hh%:%mm%:%ss%.%cc%.
803814
:BuildTimeSkipped
804815
set PATH=%ORIGINAL_PATH%
805816
cd "%~dp0"
806-
exit /b %IFCOS_SCRIPT_RET%
817+
exit %IFCOS_SCRIPT_RET%
807818

808819
::::::::::::::::::::::::::::::::::::: Subroutines :::::::::::::::::::::::::::::::::::::
809820

@@ -945,6 +956,33 @@ set RET=%ERRORLEVEL%
945956
popd
946957
exit /b %RET%
947958

959+
:: Checks whether a dependency is already installed for the specified config
960+
:: Doesn't work for dependencies, only for those that need separate Debug/Release installs.
961+
:: Required vars:
962+
:: - DEPENDENCY_NAME
963+
:: - DEPENDENCY_INSTALL_NAME
964+
:: - NEXT_DEPENDENCY_LABEL
965+
:: Always intended to be used with the code below
966+
:: (unfortunately we can't move `GOTO` to the this label too,
967+
:: because of how it would interact with `call` and `exit /b`):
968+
:: ```
969+
:: call :CheckInstallation
970+
:: if %ERRORLEVEL%==200 GOTO %NEXT_DEPENDENCY_LABEL%
971+
:: ```
972+
:CheckInstallation
973+
%PWSH_TOOLS% check_installation %DEPENDENCY_NAME% "%INSTALL_DIR%\%DEPENDENCY_INSTALL_NAME%"
974+
set RET=%ERRORLEVEL%
975+
if %RET%==200 echo Found existing "%INSTALL_DIR%\%DEPENDENCY_INSTALL_NAME%" for %BUILD_CFG%, skipping && exit /b 200
976+
if %RET% NEQ 404 GOTO :Error
977+
exit /b 0
978+
979+
:: Required vars:
980+
:: - DEPENDENCY_INSTALL_NAME
981+
:MarkInstallation
982+
%PWSH_TOOLS% mark "%INSTALL_DIR%\%DEPENDENCY_INSTALL_NAME%"
983+
IF NOT %ERRORLEVEL%==0 GOTO :Error
984+
exit /b 0
985+
948986
:: PrintUsage - Prints usage information
949987
:PrintUsage
950988
call "%~dp0\utils\cecho.cmd" 0 10 "Requirements for a successful execution:"

win/utils/tools.ps1

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
Set-PSDebug -Trace 0
2+
Set-StrictMode -Version 3
3+
$ErrorActionPreference = "Stop"
4+
5+
6+
# Create marker file to indicate whether Release or Debug build was installed.
7+
function mark {
8+
param(
9+
[Parameter(Mandatory = $true)]
10+
[string]$installation_dir
11+
)
12+
13+
if (-not (Test-Path -Path $installation_dir)) {
14+
throw "Directory '$installation_dir' does not exist."
15+
}
16+
17+
$marker_filepath = Join-Path -Path $installation_dir -ChildPath $ENV:MARKER_FILE
18+
if (Test-Path -Path $marker_filepath) {
19+
return
20+
}
21+
echo "Marking installation in '$installation_dir' with '$ENV:MARKER_FILE'."
22+
New-Item -Path $marker_filepath -ItemType File | Out-Null
23+
}
24+
25+
# This function can be deprecated in the future, since installations are marked automatically.
26+
# It's here only to avoid some disruption during the transition period.
27+
function mark_based_on_artifacts {
28+
param(
29+
[Parameter(Mandatory = $true)]
30+
[string]$dependency_name,
31+
32+
[Parameter(Mandatory = $true)]
33+
[string]$installation_dir
34+
)
35+
36+
if ($dependency_name -eq "hdf5") {
37+
if ($env:BUILD_CFG -eq "Debug") {
38+
$artifact = "lib\libhdf5_D.lib"
39+
}
40+
else {
41+
$artifact = "lib\libhdf5.lib"
42+
}
43+
}
44+
elseif ($dependency_name -eq "opencollada") {
45+
if ($env:BUILD_CFG -eq "Debug") {
46+
$artifact = "lib\opencollada\OpenCOLLADAFrameworkd.lib"
47+
}
48+
else {
49+
$artifact = "lib\opencollada\OpenCOLLADAFramework.lib"
50+
}
51+
}
52+
elseif ($dependency_name -eq "OpenCASCADE") {
53+
if ($env:BUILD_CFG -eq "Debug") {
54+
$artifact = "win64\lib\TKerneld.lib"
55+
}
56+
else {
57+
$artifact = "win64\lib\TKernel.lib"
58+
}
59+
}
60+
elseif ($dependency_name -eq "rocksdb") {
61+
if ($env:BUILD_CFG -eq "Debug") {
62+
$artifact = "lib\rocksdb_d.lib"
63+
}
64+
else {
65+
$artifact = "lib\rocksdb.lib"
66+
}
67+
}
68+
else {
69+
throw "Unexpected dependency name '$dependency_name'."
70+
}
71+
$artifact_filepath = Join-Path -Path $installation_dir -ChildPath $artifact
72+
if (-not (Test-Path -Path $artifact_filepath)) {
73+
return
74+
}
75+
if (-not (Test-Path -Path $installation_dir)) {
76+
throw "Directory '$installation_dir' does not exist."
77+
}
78+
$marker_filepath = Join-Path -Path $installation_dir -ChildPath $ENV:MARKER_FILE
79+
if (Test-Path -Path $marker_filepath) {
80+
return
81+
}
82+
echo "Found artifact '$artifact' for dependency '$dependency_name' $env:BUILD_CFG."
83+
& mark $installation_dir
84+
}
85+
86+
# Check if installation exists for the current `BUILD_CFG`.
87+
# Returns exit code 200 if installation exists, 404 otherwise.
88+
# Since we want Release and Debug installation to coexist,
89+
# we add special marker file to indicate which build type was installed.
90+
function check_installation {
91+
param(
92+
[Parameter(Mandatory = $true)]
93+
[string]$dependency_name,
94+
[Parameter(Mandatory = $true)]
95+
[string]$installation_dir
96+
)
97+
98+
if (-not (Test-Path -Path $installation_dir)) {
99+
exit 404
100+
}
101+
102+
& mark_based_on_artifacts $dependency_name $installation_dir
103+
104+
$marker_filepath = Join-Path -Path $installation_dir -ChildPath $ENV:MARKER_FILE
105+
if (-not (Test-Path -Path $marker_filepath)) {
106+
exit 404
107+
}
108+
exit 200
109+
}
110+
111+
112+
# Dependencies Release/Debug configs compatibility:
113+
# - hdf5: incompatible
114+
# - OpenCASCADE: incompatible
115+
# - rocksdb: incompatible
116+
# - opencollada: incompatible
117+
# - zstd: compatible
118+
119+
function setup_build_cfg {
120+
if (-not $env:BUILD_CFG) {
121+
throw "Variable 'BUILD_CFG' is not defined."
122+
}
123+
if ($env:BUILD_CFG -eq "Debug") {
124+
$ENV:MARKER_FILE = ".debug_installation"
125+
}
126+
else {
127+
$ENV:MARKER_FILE = ".release_installation"
128+
}
129+
}
130+
131+
function main {
132+
& setup_build_cfg
133+
# Dispatch command.
134+
$command = $Args[0]
135+
$command_args = $Args[1..($args.Count - 1)]
136+
& $command @command_args
137+
}
138+
139+
& main @Args
140+
exit 0

0 commit comments

Comments
 (0)