4141:: Enable the delayed environment variable expansion needed in vs-cfg.cmd.
4242setlocal EnableDelayedExpansion
4343
44+ set SCRIPT_DIR = %~dp0
45+
4446:: Make sure vcvarsall.bat is called and dev env set is up.
4547IF " %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
109111powershell -c " exit $PSVersionTable.PSVersion.Major -lt 5"
110112IF 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
112115cmake --version | findstr version > temp.txt
113116set /p CMAKE_VERSION = < temp.txt
@@ -358,12 +361,12 @@ popd
358361set DEPENDENCY_NAME = hdf5
359362set DEPENDENCY_DIR = %DEPS_DIR% \hdf5-%HDF5_VERSION%
360363set 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
368371if " %ARCH_BITS% " == " 64" set ARCH_BITS_64 = 64
369372call :DownloadFile ^
@@ -383,6 +386,7 @@ call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\HDF5.sln" %DEBUG_OR_RELEASE%
383386IF NOT %ERRORLEVEL% == 0 GOTO :Error
384387call :InstallCMakeProject " %DEPENDENCY_DIR% \%BUILD_DIR% " %DEBUG_OR_RELEASE%
385388IF NOT %ERRORLEVEL% == 0 GOTO :Error
389+ call :MarkInstallation
386390popd
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.
444448set DEPENDENCY_NAME = OpenCOLLADA
445449set 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
448454call :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
456459IF NOT %ERRORLEVEL% == 0 GOTO :Error
457460cd " %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.
464467REM 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=" "
468471IF NOT %ERRORLEVEL% == 0 GOTO :Error
469472REM IF NOT EXIST "%DEPS_DIR%\OpenCOLLADA\%BUILD_DIR%\lib\%DEBUG_OR_RELEASE%\OpenCOLLADASaxFrameworkLoader.lib".
470473call :BuildSolution " %DEPENDENCY_DIR% \%BUILD_DIR% \OPENCOLLADA.sln" %DEBUG_OR_RELEASE%
471474IF NOT %ERRORLEVEL% == 0 GOTO :Error
472475call :InstallCMakeProject " %DEPENDENCY_DIR% \%BUILD_DIR% " %DEBUG_OR_RELEASE%
473476IF NOT %ERRORLEVEL% == 0 GOTO :Error
477+ call :MarkInstallation
474478
475479:OCCT
476480
477481SET 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
485492set DEPENDENCY_NAME = FreeType
@@ -502,6 +509,7 @@ if not %ERRORLEVEL%==0 goto :Error
502509
503510set DEPENDENCY_NAME = Open CASCADE %OCCT_VERSION%
504511set DEPENDENCY_DIR = %DEPS_DIR% \occt_git
512+ set DEPENDENCY_INSTALL_NAME = %OCCT_DEPENDENCY_INSTALL_NAME%
505513cd " %DEPS_DIR% "
506514call :GitCloneAndCheckoutRevision https://github.com/Open-Cascade-SAS/OCCT " %DEPENDENCY_DIR% " %OCCT_VER%
507515if not %ERRORLEVEL% == 0 goto :Error
@@ -517,7 +525,7 @@ findstr IfcOpenShell "%DEPENDENCY_DIR%\CMakeLists.txt">NUL
517525if not %ERRORLEVEL% == 0 goto :Error
518526
519527cd " %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"
522530if not %ERRORLEVEL% == 0 goto :Error
523531
@@ -532,6 +540,7 @@ call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\OCCT.sln" %BUILD_CFG%
532540if not %ERRORLEVEL% == 0 goto :Error
533541call :InstallCMakeProject " %DEPENDENCY_DIR% \%BUILD_DIR% " %BUILD_CFG%
534542if not %ERRORLEVEL% == 0 goto :Error
543+ call :MarkInstallation
535544
536545SET COMPILE_WITH_WPO = FALSE
537546
@@ -694,11 +703,11 @@ set DEPENDENCY_NAME=rocksdb
694703set ROCKSDB_VERSION = 9.11.2
695704set ROCKSDB_ZIP = rocksdb-%ROCKSDB_VERSION% .zip
696705set 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
703712cd %DEPS_DIR%
704713call :DownloadFile ^
@@ -713,7 +722,7 @@ cd "%DEPENDENCY_DIR%"
713722set ZSTD_INCLUDE = %INSTALL_DIR% \zstd\include
714723set ZSTD_LIB_DEBUG = %INSTALL_DIR% \zstd\lib\zstd_static.lib
715724set 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"
726736IF NOT %ERRORLEVEL% == 0 GOTO :Error
727737call :BuildSolution " %DEPENDENCY_DIR% \%BUILD_DIR% \rocksdb.sln" %BUILD_CFG%
728738IF NOT %ERRORLEVEL% == 0 GOTO :Error
729739call :InstallCMakeProject " %DEPENDENCY_DIR% \%BUILD_DIR% " %BUILD_CFG%
730740IF 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
804815set PATH = %ORIGINAL_PATH%
805816cd " %~dp0 "
806- exit /b %IFCOS_SCRIPT_RET%
817+ exit %IFCOS_SCRIPT_RET%
807818
808819:: ::::::::::::::::::::::::::::::::::: Subroutines :::::::::::::::::::::::::::::::::::::
809820
@@ -945,6 +956,33 @@ set RET=%ERRORLEVEL%
945956popd
946957exit /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
950988call " %~dp0 \utils\cecho.cmd" 0 10 " Requirements for a successful execution:"
0 commit comments