diff --git a/win/build-deps.cmd b/win/build-deps.cmd index b0a3a2fc5f..ffe124d26b 100644 --- a/win/build-deps.cmd +++ b/win/build-deps.cmd @@ -1,546 +1,560 @@ -::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -:: :: -:: This file is part of IfcOpenShell. :: -:: :: -:: IfcOpenShell is free software: you can redistribute it and/or modify :: -:: it under the terms of the Lesser GNU General Public License as published by :: -:: the Free Software Foundation, either version 3.0 of the License, or :: -:: (at your option) any later version. :: -:: :: -:: IfcOpenShell is distributed in the hope that it will be useful, :: -:: but WITHOUT ANY WARRANTY; without even the implied warranty of :: -:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the :: -:: Lesser GNU General Public License for more details. :: -:: :: -:: You should have received a copy of the Lesser GNU General Public License :: -:: along with this program. If not, see . :: -:: :: -::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - -:: This batch file expects CMake generator as %1 and build configuration type as %2. If not provided, -:: a deduced generator will be used for %1 and BUILD_CFG_DEFAULT for %2 (both set in vs-cfg.cmd) -:: Optionally a build type (Build/Rebuild/Clean) can be passed as %3. - -@echo off -echo. - -for %%Q in ("%~dp0\.") DO set "batpath=%%~fQ" - -if NOT "%CD%" == "%batpath%" ( - GOTO :ErrorAndPrintUsage -) - - -set PROJECT_NAME=IfcOpenShell -call utils\cecho.cmd 15 0 "This script fetches and builds all %PROJECT_NAME% dependencies" -echo. - -:: Enable the delayed environment variable expansion needed in vs-cfg.cmd. -setlocal EnableDelayedExpansion - -:: 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." - GOTO :ErrorAndPrintUsage -) - -:: Check for cl.exe - at least the "Typical" Visual Studio 2015 installation does not include the C++ toolset by default, -:: http://blogs.msdn.com/b/vcblog/archive/2015/07/24/setup-changes-in-visual-studio-2015-affecting-c-developers.aspx -where cl.exe 2>&1>NUL -if not %ERRORLEVEL%==0 ( - call utils\cecho.cmd 0 12 "%~nx0: cl.exe not in PATH. Make sure to select the C++ toolset when installing Visual Studio- cannot proceed." - GOTO :ErrorAndPrintUsage -) - -:: Set up variables depending on the used Visual Studio version -call vs-cfg.cmd %1 -IF NOT %ERRORLEVEL%==0 GOTO :Error -call build-type-cfg.cmd %2 -IF NOT %ERRORLEVEL%==0 GOTO :Error - -set BUILD_TYPE=%3 -IF "%BUILD_TYPE%"=="" set BUILD_TYPE=Build - -IF NOT "!BUILD_TYPE!"=="Build" IF NOT "!BUILD_TYPE!"=="Rebuild" IF NOT "!BUILD_TYPE!"=="Clean" ( - call utils\cecho.cmd 0 12 "Invalid build type passed: !BUILD_TYPE!. Cannot proceed, aborting!" - GOTO :Error -) - -:: Make sure deps and install folders exists. -IF NOT EXIST "%DEPS_DIR%". mkdir "%DEPS_DIR%" -IF NOT EXIST "%INSTALL_DIR%". mkdir "%INSTALL_DIR%" - -:: If we use VS2008, framework path (for MSBuild) may not be correctly set. Manually attempt to add in that case -IF %VS_VER%==2008 set PATH=C:\Windows\Microsoft.NET\Framework\v3.5;%PATH% - -:: User-configurable build options -IF NOT DEFINED IFCOS_USE_OCCT set IFCOS_USE_OCCT=TRUE -IF NOT DEFINED IFCOS_INSTALL_PYTHON set IFCOS_INSTALL_PYTHON=TRUE -IF NOT DEFINED IFCOS_USE_PYTHON2 set IFCOS_USE_PYTHON2=FALSE -IF NOT DEFINED IFCOS_NUM_BUILD_PROCS set IFCOS_NUM_BUILD_PROCS=%NUMBER_OF_PROCESSORS% - -:: For subroutines -set MSBUILD_CMD=MSBuild.exe /nologo /m:%IFCOS_NUM_BUILD_PROCS% /t:%BUILD_TYPE% -REM /clp:ErrorsOnly;WarningsOnly -:: Note BUILD_TYPE not passed, Clean e.g. wouldn't delete the installed files. -set INSTALL_CMD=MSBuild.exe /nologo /m:%IFCOS_NUM_BUILD_PROCS% - -echo. - -:: Check that required tools are in PATH -FOR %%i IN (powershell git cmake) DO ( - where.exe %%i 1> NUL 2> NUL || call cecho.cmd 0 12 "Required tool `'%%i`' not installed or not added to PATH" && goto :ErrorAndPrintUsage -) - -:: 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 - -cmake --version | findstr version > temp.txt -set /p CMAKE_VERSION="%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" - -echo. -set START_TIME=%TIME% -echo Build started at %START_TIME%. -set BUILD_STARTED=TRUE -echo. - -cd "%DEPS_DIR%" - -:: Note all of the dependencies have appropriate label so that user can easily skip something if wanted -:: by modifying this file and using goto. -:Boost -:: NOTE Boost < 1.64 doesn't work without tricks if the user has only VS 2017 installed and no earlier versions. -set BOOST_VERSION=1.67.0 -:: Version string with underscores instead of dots. -set BOOST_VER=%BOOST_VERSION:.=_% -:: DEPENDENCY_NAME is used for logging and DEPENDENCY_DIR for saving from some redundant typing -set DEPENDENCY_NAME=Boost %BOOST_VERSION% -set DEPENDENCY_DIR=%DEPS_DIR%\boost_%BOOST_VER% -set BOOST_LIBRARYDIR=%DEPENDENCY_DIR%\stage\%VS_PLATFORM%\lib -:: NOTE Also zip download exists, if encountering problems with 7z for some reason. -set ZIP_EXT=7z -set BOOST_ZIP=boost_%BOOST_VER%.%ZIP_EXT% - -call :DownloadFile https://dl.bintray.com/boostorg/release/%BOOST_VERSION%/source/%BOOST_ZIP% "%DEPS_DIR%" %BOOST_ZIP% - -IF NOT %ERRORLEVEL%==0 GOTO :Error -call :ExtractArchive %BOOST_ZIP% "%DEPS_DIR%" "%DEPENDENCY_DIR%" -IF NOT %ERRORLEVEL%==0 GOTO :Error - -:: Build Boost build script -if not exist "%DEPENDENCY_DIR%\project-config.jam". ( - cd "%DEPS_DIR%" - IF NOT EXIST "%DEPENDENCY_DIR%\boost.css" GOTO :Error - cd "%DEPENDENCY_DIR%" - call cecho.cmd 0 13 "Building Boost build script." - call bootstrap msvc - IF NOT %ERRORLEVEL%==0 GOTO :Error -) - -set BOOST_LIBS=--with-system --with-regex --with-thread --with-program_options --with-date_time --with-iostreams --with-filesystem -:: NOTE Boost is fast to build with limited set of libraries so build it always. -cd "%DEPENDENCY_DIR%" -call cecho.cmd 0 13 "Building %DEPENDENCY_NAME% %BOOST_LIBS% Please be patient, this will take a while." -IF EXIST "%DEPENDENCY_DIR%\bin.v2\project-cache.jam" del "%DEPS_DIR%\boost\bin.v2\project-cache.jam" -:: BOOST_VC_VER can be empty (or needs to be) for newer VS versions -set BOOST_VC_VER= -if %VS_VER% LSS 2017 ( - set BOOST_VC_VER=-%VC_VER%.0 -) - -call .\b2 toolset=msvc%BOOST_VC_VER% runtime-link=static address-model=%ARCH_BITS% -j%IFCOS_NUM_BUILD_PROCS% ^ - variant=%DEBUG_OR_RELEASE_LOWERCASE% %BOOST_LIBS% stage --stagedir=stage/vs%VS_VER%-%VS_PLATFORM% -IF NOT %ERRORLEVEL%==0 GOTO :Error - -:JSON -set DEPENDENCY_NAME=JSON for Modern C++ v3.6.1 -IF NOT EXIST "%INSTALL_DIR%\json\nlohmann". mkdir "%INSTALL_DIR%\json\nlohmann" -call :DownloadFile https://github.com/nlohmann/json/releases/download/v3.6.1/json.hpp "%INSTALL_DIR%\json\nlohmann" json.hpp - -:OpenCOLLADA -:: Note OpenCOLLADA has only Release and Debug builds. -set DEPENDENCY_NAME=OpenCOLLADA -set DEPENDENCY_DIR=%DEPS_DIR%\OpenCOLLADA -:: Use a fixed revision in order to prevent introducing breaking changes -call :GitCloneAndCheckoutRevision https://github.com/KhronosGroup/OpenCOLLADA.git "%DEPENDENCY_DIR%" 064a60b65c2c31b94f013820856bc84fb1937cc6 -IF NOT %ERRORLEVEL%==0 GOTO :Error -cd "%DEPENDENCY_DIR%" -:: Debug build of OpenCOLLADAValidator fails (https://github.com/KhronosGroup/OpenCOLLADA/issues/377) so -:: so disable it from the build altogether as we have no use for it -findstr #add_subdirectory(COLLADAValidator) CMakeLists.txt>NUL -IF NOT %ERRORLEVEL%==0 git apply --reject --whitespace=fix "%~dp0patches\OpenCOLLADA_CMakeLists.txt.patch" -:: NOTE OpenCOLLADA has been observed to have problems with switching between debug and release builds so -:: uncomment to following line in order to delete the CMakeCache.txt always if experiencing problems. -REM IF EXIST "%DEPENDENCY_DIR%\%BUILD_DIR%\CMakeCache.txt". del "%DEPENDENCY_DIR%\%BUILD_DIR%\CMakeCache.txt" -:: NOTE Enforce that the embedded LibXml2 and PCRE are used as there might be problems with arbitrary versions of the libraries. -call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\OpenCOLLADA" -DUSE_STATIC_MSVC_RUNTIME=1 -DCMAKE_DEBUG_POSTFIX=d ^ - -DLIBXML2_LIBRARIES="" -DLIBXML2_INCLUDE_DIR="" -DPCRE_INCLUDE_DIR="" -DPCRE_LIBRARIES="" -IF NOT %ERRORLEVEL%==0 GOTO :Error -REM IF NOT EXIST "%DEPS_DIR%\OpenCOLLADA\%BUILD_DIR%\lib\%DEBUG_OR_RELEASE%\OpenCOLLADASaxFrameworkLoader.lib". -call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\OPENCOLLADA.sln" %DEBUG_OR_RELEASE% -IF NOT %ERRORLEVEL%==0 GOTO :Error -call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %DEBUG_OR_RELEASE% -IF NOT %ERRORLEVEL%==0 GOTO :Error - -if %IFCOS_USE_OCCT%==FALSE goto :OCE -:OCCT -set OCCT_VERSION=7.3.0p3 -SET OCCT_VER=V%OCCT_VERSION:.=_% - -set OCC_INCLUDE_DIR=%INSTALL_DIR%\opencascade-%OCCT_VERSION%\inc>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" -set OCC_LIBRARY_DIR=%INSTALL_DIR%\opencascade-%OCCT_VERSION%\win%ARCH_BITS%\lib>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" -echo OCC_INCLUDE_DIR=%OCC_INCLUDE_DIR%>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" -echo OCC_LIBRARY_DIR=%OCC_LIBRARY_DIR%>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" - -:: OCCT has many dependencies but FreeType is the only mandatory -set DEPENDENCY_NAME=FreeType -set DEPENDENCY_DIR=%DEPS_DIR%\freetype-2.6.5 -set FREETYPE_ZIP=ft265.zip -cd "%DEPS_DIR%" -call :DownloadFile http://download.savannah.gnu.org/releases/freetype/%FREETYPE_ZIP% "%DEPS_DIR%" %FREETYPE_ZIP% -if not %ERRORLEVEL%==0 goto :Error -call :ExtractArchive %FREETYPE_ZIP% "%DEPS_DIR%" "%DEPENDENCY_DIR%" -if not %ERRORLEVEL%==0 goto :Error -cd "%DEPENDENCY_DIR%" -:: NOTE FreeType is built as a static library by default -call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\freetype" -if not %ERRORLEVEL%==0 goto :Error -call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\freetype.sln" %BUILD_CFG% -if not %ERRORLEVEL%==0 goto :Error -call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG% -if not %ERRORLEVEL%==0 goto :Error - -set DEPENDENCY_NAME=Open CASCADE %OCCT_VERSION% -set DEPENDENCY_DIR=%DEPS_DIR%\occt_git -cd "%DEPS_DIR%" -call :GitCloneAndCheckoutRevision https://git.dev.opencascade.org/repos/occt.git "%DEPENDENCY_DIR%" %OCCT_VER% -if not %ERRORLEVEL%==0 goto :Error - -:: Patching always blindly would trigger a rebuild each time -findstr IfcOpenShell "%DEPENDENCY_DIR%\CMakeLists.txt">NUL -if not %ERRORLEVEL%==0 ( - pushd "%DEPENDENCY_DIR%" - git apply --ignore-whitespace ""%~dp0patches\%OCCT_VER%.patch" - popd -) -findstr IfcOpenShell "%DEPENDENCY_DIR%\CMakeLists.txt">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 ^ - -DBUILD_MODULE_Draw=0 -D3RDPARTY_FREETYPE_DIR="%INSTALL_DIR%\freetype" -if not %ERRORLEVEL%==0 goto :Error -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 -:: Use a single lib directory for for release and debug libraries as is done with OCE -if not exist "%OCC_LIBRARY_DIR%". mkdir "%OCC_LIBRARY_DIR%" -:: NOTE OCCT (at least occt-V7_0_0-9059ca1) directory creation code is hardcoded and doesn't seem handle future VC versions -set OCCT_VC_VER=%VC_VER% -IF %OCCT_VC_VER% GTR 14 ( - set OCCT_VC_VER=14 -) -move /y "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\win%ARCH_BITS%\vc%OCCT_VC_VER%\libi\*.*" "%OCC_LIBRARY_DIR%" -move /y "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\win%ARCH_BITS%\vc%OCCT_VC_VER%\libd\*.*" "%OCC_LIBRARY_DIR%" -move /y "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\win%ARCH_BITS%\vc%OCCT_VC_VER%\lib\*.*" "%OCC_LIBRARY_DIR%" -rmdir /s /q "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\win%ARCH_BITS%\vc%OCCT_VC_VER%" -:: Removed unneeded bits -rmdir /s /q "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\data" -rmdir /s /q "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\samples" -del "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\*.bat" - -goto :Python - -:OCE -set OCC_INCLUDE_DIR=%INSTALL_DIR%\oce\include\oce>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" -set OCC_LIBRARY_DIR=%INSTALL_DIR%\oce\Win%ARCH_BITS%\lib>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" -echo OCC_INCLUDE_DIR=%OCC_INCLUDE_DIR%>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" -echo OCC_LIBRARY_DIR=%OCC_LIBRARY_DIR%>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" - -set DEPENDENCY_NAME=Open CASCADE Community Edition -set DEPENDENCY_DIR=%DEPS_DIR%\oce -set OCE_VERSION=OCE-0.18 -call :GitCloneAndCheckoutRevision https://github.com/tpaviot/oce.git "%DEPENDENCY_DIR%" %OCE_VERSION% -IF NOT %ERRORLEVEL%==0 GOTO :Error -:: Use the oce-win-bundle for OCE's dependencies -call :GitCloneOrPullRepository https://github.com/QbProg/oce-win-bundle.git "%DEPENDENCY_DIR%\oce-win-bundle" -IF NOT %ERRORLEVEL%==0 GOTO :Error - -cd "%DEPENDENCY_DIR%" -:: NOTE Specify OCE_NO_LIBRARY_VERSION as rc.exe can fail due to long filenames and huge command-line parameter -:: input (more than 32,000 characters). Could maybe try using subst for the build dir to overcome this. -call :RunCMake -DOCE_BUILD_SHARED_LIB=0 -DOCE_INSTALL_PREFIX="%INSTALL_DIR%\oce" -DOCE_TESTING=0 ^ - -DOCE_NO_LIBRARY_VERSION=1 -DOCE_USE_STATIC_MSVC_RUNTIME=1 -IF NOT %ERRORLEVEL%==0 GOTO :Error -call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\OCE.sln" %BUILD_CFG% -IF NOT %ERRORLEVEL%==0 GOTO :Error -call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG% -IF NOT %ERRORLEVEL%==0 GOTO :Error - -:Python -:: TODO Update to 3.5 when it's released as it will have an option to install debug libraries. -:: NOTE If updating the default Python version, change PY_VER_MAJOR_MINOR accordingly in run-cmake.bat -set PYTHON_VERSION=3.4.3 -IF "%IFCOS_USE_PYTHON2%"=="TRUE" set PYTHON_VERSION=2.7.10 -set PY_VER_MAJOR_MINOR=%PYTHON_VERSION:~0,3% -set PY_VER_MAJOR_MINOR=%PY_VER_MAJOR_MINOR:.=% -set PYTHONHOME=%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR% - -set DEPENDENCY_NAME=Python %PYTHON_VERSION% -set DEPENDENCY_DIR=N/A -set PYTHON_AMD64_POSTFIX=.amd64 -:: NOTE/TODO Beginning from 3.5.0: set PYTHON_AMD64_POSTFIX=-amd64 -IF NOT %TARGET_ARCH%==x64 set PYTHON_AMD64_POSTFIX= -set PYTHON_INSTALLER=python-%PYTHON_VERSION%%PYTHON_AMD64_POSTFIX%.msi -:: NOTE/TODO 3.5.0 doesn't use MSI any longer, but exe: set PYTHON_INSTALLER=python-%PYTHON_VERSION%%PYTHON_AMD64_POSTFIX%.exe -IF "%IFCOS_INSTALL_PYTHON%"=="TRUE" ( - REM Store Python versions to BuildDepsCache.txt for run-cmake.bat - echo PY_VER_MAJOR_MINOR=%PY_VER_MAJOR_MINOR%>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" - echo PYTHONHOME=%PYTHONHOME%>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" - - cd "%DEPS_DIR%" - call :DownloadFile https://www.python.org/ftp/python/%PYTHON_VERSION%/%PYTHON_INSTALLER% "%DEPS_DIR%" %PYTHON_INSTALLER% - IF NOT %ERRORLEVEL%==0 GOTO :Error - REM Uninstall if build Rebuild/Clean used - IF NOT %BUILD_TYPE%==Build ( - call cecho.cmd 0 13 "Uninstalling %DEPENDENCY_NAME%. Please be patient, this will take a while." - msiexec /x %PYTHON_INSTALLER% /qn - ) - - IF NOT EXIST "%PYTHONHOME%". ( - call cecho.cmd 0 13 "Installing %DEPENDENCY_NAME%. Please be patient, this will take a while." - msiexec /qn /i %PYTHON_INSTALLER% TARGETDIR="%PYTHONHOME%" - ) ELSE ( - call cecho.cmd 0 13 "%DEPENDENCY_NAME% already installed. Skipping." - ) -) ELSE ( - call cecho.cmd 0 13 "IFCOS_INSTALL_PYTHON not true, skipping installation of Python." -) - -:SWIG -set SWIG_VERSION=3.0.12 -set DEPENDENCY_NAME=SWIG %SWIG_VERSION% -set DEPENDENCY_DIR=N/A -set SWIG_ZIP=swigwin-%SWIG_VERSION%.zip -cd "%DEPS_DIR%" -call :DownloadFile https://sourceforge.net/projects/swig/files/swigwin/swigwin-%SWIG_VERSION%/%SWIG_ZIP% "%DEPS_DIR%" %SWIG_ZIP% -IF NOT %ERRORLEVEL%==0 GOTO :Error -call :ExtractArchive %SWIG_ZIP% "%DEPS_DIR%" "%DEPS_DIR%\swigwin" -IF NOT %ERRORLEVEL%==0 GOTO :Error -IF EXIST "%DEPS_DIR%\swigwin-%SWIG_VERSION%". ( - pushd "%DEPS_DIR%" - ren swigwin-%SWIG_VERSION% swigwin - popd -) -IF EXIST "%DEPS_DIR%\swigwin\". robocopy "%DEPS_DIR%\swigwin" "%INSTALL_DIR%\swigwin" /E /IS /MOVE /njh /njs - -:Successful -echo. -call "%~dp0\utils\cecho.cmd" 0 10 "%PROJECT_NAME% dependencies built." -set IFCOS_SCRIPT_RET=0 -goto :Finish - -:ErrorAndPrintUsage -echo. -call :PrintUsage -:Error -echo. -call "%~dp0\utils\cecho.cmd" 0 12 "An error occurred! Aborting!" -set IFCOS_SCRIPT_RET=1 -goto :Finish - -:Finish -:: Print end time and elapsed time, http://stackoverflow.com/a/9935540 -if not defined BUILD_STARTED goto :BuildTimeSkipped -set END_TIME=%TIME% -for /F "tokens=1-4 delims=:.," %%a in ("%START_TIME%") do ( - set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" -) -for /F "tokens=1-4 delims=:.," %%a in ("%END_TIME%") do ( - set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" -) -set /A elapsed=end-start -set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100 -if %mm% lss 10 set mm=0%mm% -if %ss% lss 10 set ss=0%ss% -if %cc% lss 10 set cc=0%cc% -echo. -echo Build ended at %END_TIME%. Time elapsed %hh%:%mm%:%ss%.%cc%. -:BuildTimeSkipped -set PATH=%ORIGINAL_PATH% -cd "%~dp0" -exit /b %IFCOS_SCRIPT_RET% - -::::::::::::::::::::::::::::::::::::: Subroutines ::::::::::::::::::::::::::::::::::::: - -:: DownloadFile - Downloads a file using PowerShell -:: Params: %1 url, %2 destinationDir, %3 filename -:DownloadFile -pushd "%2" -if not exist "%~3". ( - call cecho.cmd 0 13 "Downloading %DEPENDENCY_NAME% into %~2." - powershell -Command "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; $webClient = new-object System.Net.WebClient; $webClient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials; $webClient.DownloadFile('%1', '%3')" - REM Old wget version in case someone has problem with PowerShell: wget --no-check-certificate %1 -) else ( - call cecho.cmd 0 13 "%DEPENDENCY_NAME% already downloaded. Skipping." -) -set RET=%ERRORLEVEL% -popd -exit /b %RET% - -:: ExtractArchive - Extracts an archive file using 7-zip -:: Params: %1 filename, %2 destinationDir, %3 dirAfterExtraction -:ExtractArchive -if not exist "%~3". ( - call cecho.cmd 0 13 "Extracting %DEPENDENCY_NAME% into %~2." - 7za x %1 -y -o%2 > nul -) else ( - call cecho.cmd 0 13 "%DEPENDENCY_NAME% already extracted into %~3. Skipping." -) -exit /b %ERRORLEVEL% - -:: GitCloneOrPullRepository - Clones or pulls (if repository already cloned) a Git repository -:: Params: %1 gitUrl, %2 destDir -:: F.ex. call :GitCloneRepository https://github.com/KhronosGroup/OpenCOLLADA.git "%DEPS_DIR%\OpenCOLLADA\" -:GitCloneOrPullRepository -if not exist "%~2". ( - call cecho.cmd 0 13 "Cloning %DEPENDENCY_NAME% into %~2." - pushd "%DEPS_DIR%" - call git clone %1 %2 - set RET=%ERRORLEVEL% -) else ( - call cecho.cmd 0 13 "%DEPENDENCY_NAME% already cloned. Pulling latest changes." - pushd %2 - call git pull - set RET=0 -) -popd -exit /b %RET% - -:: GitCloneAndCheckoutRevision - Clones a Git repository and checks out a specific revision or tag -:: Params: %1 gitUrl, %2 destDir, %3 revision -:: F.ex. call :GitCloneAndCheckoutRevision https://github.com/KhronosGroup/OpenCOLLADA.git "%DEPENDENCY_DIR%" 064a60b65c2c31b94f013820856bc84fb1937cc6 -:GitCloneAndCheckoutRevision -if not exist "%~2". ( - call cecho.cmd 0 13 "Cloning %DEPENDENCY_NAME% into %~2." - pushd "%DEPS_DIR%" - call git clone %1 %2 - set RET=%ERRORLEVEL% - if not %RET%==0 exit /b %RET% - popd -) else ( - call cecho.cmd 0 13 "%DEPENDENCY_NAME% already cloned." - set RET=0 -) -pushd "%2" -call git fetch -call cecho.cmd 0 13 "Checking out %DEPENDENCY_NAME% revision %3." -call git checkout %3 -set RET=%ERRORLEVEL% -popd -exit /b %RET% - -:: RunCMake - Runs CMake for a CMake-based project -:: Params: %* cmakeOptions -:: NOTE cd to root CMakeLists.txt folder before calling this if the CMakeLists.txt is not in the repo root. -:RunCMake -call cecho.cmd 0 13 "Running CMake for %DEPENDENCY_NAME%." -IF NOT EXIST %BUILD_DIR%. mkdir %BUILD_DIR% -IF NOT %ERRORLEVEL%==0 GOTO :Error -pushd %BUILD_DIR% -:: TODO make deleting cache a parameter for this subroutine? We probably want to delete the -:: cache always e.g. when we've had new changes in the repository. -IF %BUILD_TYPE%==Rebuild IF EXIST CMakeCache.txt. del CMakeCache.txt -cmake .. -G %GENERATOR% %* -set RET=%ERRORLEVEL% -popd -exit /b %RET% - -:: TODO add BuildCMakeProject which utilizes cmake --build - -:: BuildSolution - Builds/Rebuilds/Cleans a solution using MSBuild -:: Params: %1 solutioName, %2 configuration -:BuildSolution -call cecho.cmd 0 13 "Building %2 %DEPENDENCY_NAME%. Please be patient, this will take a while." -%MSBUILD_CMD% %1 /p:configuration=%2;platform=%VS_PLATFORM% -exit /b %ERRORLEVEL% - -:: InstallCMakeProject - Builds the INSTALL project of CMake-based project -:: Params: %1 buildDir, %2 == configuration -:: NOTE the actual install dir is set during cmake run. -:: TODO Utilize cmake --build --target INSTALL -:InstallCMakeProject -pushd %1 -call cecho.cmd 0 13 "Installing %2 %DEPENDENCY_NAME%. Please be patient, this will take a while." -%INSTALL_CMD% INSTALL.%VCPROJ_FILE_EXT% /p:configuration=%2;platform=%VS_PLATFORM% -set RET=%ERRORLEVEL% -popd -exit /b %RET% - -:: PrintUsage - Prints usage information -:PrintUsage -call "%~dp0\utils\cecho.cmd" 0 10 "Requirements for a successful execution:" -echo 1. Install PowerShell (preinstalled in Windows ^>= 7) version 5 or higher and make sure 'powershell' is accessible from PATH. -echo - https://support.microsoft.com/en-us/kb/968929 -echo 2. Install Git and make sure 'git' is accessible from PATH. -echo - https://git-for-windows.github.io/ -echo 3. Install CMake and make sure 'cmake' is accessible from PATH. -echo - http://www.cmake.org/ -echo 4. Visual Studio 2008 or newer (2013 or newer recommended) with C++ toolset. -echo - https://www.visualstudio.com/ -echo 5. Run this batch script with Visual Studio environment variables set. -echo - https://msdn.microsoft.com/en-us/library/ms229859(v=vs.110).aspx -echo. -echo NB: This script needs to be ran from the directory directly containing it. -echo. +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: :: +:: This file is part of IfcOpenShell. :: +:: :: +:: IfcOpenShell is free software: you can redistribute it and/or modify :: +:: it under the terms of the Lesser GNU General Public License as published by :: +:: the Free Software Foundation, either version 3.0 of the License, or :: +:: (at your option) any later version. :: +:: :: +:: IfcOpenShell is distributed in the hope that it will be useful, :: +:: but WITHOUT ANY WARRANTY; without even the implied warranty of :: +:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the :: +:: Lesser GNU General Public License for more details. :: +:: :: +:: You should have received a copy of the Lesser GNU General Public License :: +:: along with this program. If not, see . :: +:: :: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:: This batch file expects CMake generator as %1 and build configuration type as %2. If not provided, +:: a deduced generator will be used for %1 and BUILD_CFG_DEFAULT for %2 (both set in vs-cfg.cmd) +:: Optionally a build type (Build/Rebuild/Clean) can be passed as %3. + +@echo off +echo. + +for %%Q in ("%~dp0\.") DO set "batpath=%%~fQ" + +if NOT "%CD%" == "%batpath%" ( + GOTO :ErrorAndPrintUsage +) + + +set PROJECT_NAME=IfcOpenShell +call utils\cecho.cmd 15 0 "This script fetches and builds all %PROJECT_NAME% dependencies" +echo. + +:: Enable the delayed environment variable expansion needed in vs-cfg.cmd. +setlocal EnableDelayedExpansion + +:: 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." + GOTO :ErrorAndPrintUsage +) + +:: Check for cl.exe - at least the "Typical" Visual Studio 2015 installation does not include the C++ toolset by default, +:: http://blogs.msdn.com/b/vcblog/archive/2015/07/24/setup-changes-in-visual-studio-2015-affecting-c-developers.aspx +where cl.exe 2>&1>NUL +if not %ERRORLEVEL%==0 ( + call utils\cecho.cmd 0 12 "%~nx0: cl.exe not in PATH. Make sure to select the C++ toolset when installing Visual Studio- cannot proceed." + GOTO :ErrorAndPrintUsage +) + +:: Set up variables depending on the used Visual Studio version +call vs-cfg.cmd %1 +IF NOT %ERRORLEVEL%==0 GOTO :Error + +:: Set up the BuildDepsCache.txt filename +IF DEFINED VS_TOOLSET ( + set BUILDDEPTHCACHE=BuildDepsCache-%VS_PLATFORM%-%VS_TOOLSET%.txt +) ELSE ( + set BUILDDEPTHCACHE=BuildDepsCache-%VS_PLATFORM%.txt +) + +call build-type-cfg.cmd %2 +IF NOT %ERRORLEVEL%==0 GOTO :Error + +set BUILD_TYPE=%3 +IF "%BUILD_TYPE%"=="" set BUILD_TYPE=Build + +IF NOT "!BUILD_TYPE!"=="Build" IF NOT "!BUILD_TYPE!"=="Rebuild" IF NOT "!BUILD_TYPE!"=="Clean" ( + call utils\cecho.cmd 0 12 "Invalid build type passed: !BUILD_TYPE!. Cannot proceed, aborting!" + GOTO :Error +) + +:: Make sure deps and install folders exists. +IF NOT EXIST "%DEPS_DIR%". mkdir "%DEPS_DIR%" +IF NOT EXIST "%INSTALL_DIR%". mkdir "%INSTALL_DIR%" + +:: If we use VS2008, framework path (for MSBuild) may not be correctly set. Manually attempt to add in that case +IF %VS_VER%==2008 set PATH=C:\Windows\Microsoft.NET\Framework\v3.5;%PATH% + +:: User-configurable build options +IF NOT DEFINED IFCOS_USE_OCCT set IFCOS_USE_OCCT=TRUE +IF NOT DEFINED IFCOS_INSTALL_PYTHON set IFCOS_INSTALL_PYTHON=TRUE +IF NOT DEFINED IFCOS_USE_PYTHON2 set IFCOS_USE_PYTHON2=FALSE +IF NOT DEFINED IFCOS_NUM_BUILD_PROCS set IFCOS_NUM_BUILD_PROCS=%NUMBER_OF_PROCESSORS% + +:: For subroutines +set MSBUILD_CMD=MSBuild.exe /nologo /m:%IFCOS_NUM_BUILD_PROCS% /t:%BUILD_TYPE% +REM /clp:ErrorsOnly;WarningsOnly +:: Note BUILD_TYPE not passed, Clean e.g. wouldn't delete the installed files. +set INSTALL_CMD=MSBuild.exe /nologo /m:%IFCOS_NUM_BUILD_PROCS% + +echo. + +:: Check that required tools are in PATH +FOR %%i IN (powershell git cmake) DO ( + where.exe %%i 1> NUL 2> NUL || call cecho.cmd 0 12 "Required tool `'%%i`' not installed or not added to PATH" && goto :ErrorAndPrintUsage +) + +:: 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 + +cmake --version | findstr version > temp.txt +set /p CMAKE_VERSION="%~dp0\%BUILDDEPTHCACHE%" + +echo. +set START_TIME=%TIME% +echo Build started at %START_TIME%. +set BUILD_STARTED=TRUE +echo. + +cd "%DEPS_DIR%" + +:: Note all of the dependencies have appropriate label so that user can easily skip something if wanted +:: by modifying this file and using goto. +:Boost +:: NOTE Boost < 1.64 doesn't work without tricks if the user has only VS 2017 installed and no earlier versions. +set BOOST_VERSION=1.71.0 +:: Version string with underscores instead of dots. +set BOOST_VER=%BOOST_VERSION:.=_% +:: DEPENDENCY_NAME is used for logging and DEPENDENCY_DIR for saving from some redundant typing +set DEPENDENCY_NAME=Boost %BOOST_VERSION% +set DEPENDENCY_DIR=%DEPS_DIR%\boost_%BOOST_VER% +set BOOST_LIBRARYDIR=%DEPENDENCY_DIR%\stage\%GEN_SHORTHAND%\lib +:: NOTE Also zip download exists, if encountering problems with 7z for some reason. +set ZIP_EXT=7z +set BOOST_ZIP=boost_%BOOST_VER%.%ZIP_EXT% + +call :DownloadFile https://dl.bintray.com/boostorg/release/%BOOST_VERSION%/source/%BOOST_ZIP% "%DEPS_DIR%" %BOOST_ZIP% + +IF NOT %ERRORLEVEL%==0 GOTO :Error +call :ExtractArchive %BOOST_ZIP% "%DEPS_DIR%" "%DEPENDENCY_DIR%" +IF NOT %ERRORLEVEL%==0 GOTO :Error + +:: Build Boost build script +if not exist "%DEPENDENCY_DIR%\project-config.jam". ( + cd "%DEPS_DIR%" + IF NOT EXIST "%DEPENDENCY_DIR%\boost.css" GOTO :Error + cd "%DEPENDENCY_DIR%" + call cecho.cmd 0 13 "Building Boost build script." + call bootstrap %BOOST_BOOTSTRAP_VER% + IF NOT %ERRORLEVEL%==0 GOTO :Error +) + +set BOOST_LIBS=--with-system --with-regex --with-thread --with-program_options --with-date_time --with-iostreams --with-filesystem +:: NOTE Boost is fast to build with limited set of libraries so build it always. +cd "%DEPENDENCY_DIR%" +call cecho.cmd 0 13 "Building %DEPENDENCY_NAME% %BOOST_LIBS% Please be patient, this will take a while." +IF EXIST "%DEPENDENCY_DIR%\bin.v2\project-cache.jam" del "%DEPS_DIR%\boost\bin.v2\project-cache.jam" + +call .\b2 toolset=%BOOST_TOOLSET% runtime-link=static address-model=%ARCH_BITS% -j%IFCOS_NUM_BUILD_PROCS% ^ + variant=%DEBUG_OR_RELEASE_LOWERCASE% %BOOST_WIN_API% %BOOST_LIBS% stage --stagedir=stage/%GEN_SHORTHAND% + +IF NOT %ERRORLEVEL%==0 GOTO :Error + +:JSON +set DEPENDENCY_NAME=JSON for Modern C++ v3.6.1 +IF NOT EXIST "%INSTALL_DIR%\json\nlohmann". mkdir "%INSTALL_DIR%\json\nlohmann" +call :DownloadFile https://github.com/nlohmann/json/releases/download/v3.6.1/json.hpp "%INSTALL_DIR%\json\nlohmann" json.hpp + +:OpenCOLLADA +:: Note OpenCOLLADA has only Release and Debug builds. +set DEPENDENCY_NAME=OpenCOLLADA +set DEPENDENCY_DIR=%DEPS_DIR%\OpenCOLLADA +:: Use a fixed revision in order to prevent introducing breaking changes +call :GitCloneAndCheckoutRevision https://github.com/KhronosGroup/OpenCOLLADA.git "%DEPENDENCY_DIR%" 064a60b65c2c31b94f013820856bc84fb1937cc6 +IF NOT %ERRORLEVEL%==0 GOTO :Error +cd "%DEPENDENCY_DIR%" +:: Debug build of OpenCOLLADAValidator fails (https://github.com/KhronosGroup/OpenCOLLADA/issues/377) so +:: so disable it from the build altogether as we have no use for it +findstr #add_subdirectory(COLLADAValidator) CMakeLists.txt>NUL +IF NOT %ERRORLEVEL%==0 git apply --reject --whitespace=fix "%~dp0patches\OpenCOLLADA_CMakeLists.txt.patch" +:: NOTE OpenCOLLADA has been observed to have problems with switching between debug and release builds so +:: uncomment to following line in order to delete the CMakeCache.txt always if experiencing problems. +REM IF EXIST "%DEPENDENCY_DIR%\%BUILD_DIR%\CMakeCache.txt". del "%DEPENDENCY_DIR%\%BUILD_DIR%\CMakeCache.txt" +:: NOTE Enforce that the embedded LibXml2 and PCRE are used as there might be problems with arbitrary versions of the libraries. +call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\OpenCOLLADA" -DUSE_STATIC_MSVC_RUNTIME=1 -DCMAKE_DEBUG_POSTFIX=d ^ + -DLIBXML2_LIBRARIES="" -DLIBXML2_INCLUDE_DIR="" -DPCRE_INCLUDE_DIR="" -DPCRE_LIBRARIES="" +IF NOT %ERRORLEVEL%==0 GOTO :Error +REM IF NOT EXIST "%DEPS_DIR%\OpenCOLLADA\%BUILD_DIR%\lib\%DEBUG_OR_RELEASE%\OpenCOLLADASaxFrameworkLoader.lib". +call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\OPENCOLLADA.sln" %DEBUG_OR_RELEASE% +IF NOT %ERRORLEVEL%==0 GOTO :Error +call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %DEBUG_OR_RELEASE% +IF NOT %ERRORLEVEL%==0 GOTO :Error + +if %IFCOS_USE_OCCT%==FALSE goto :OCE +:OCCT +set OCCT_VERSION=7.3.0p3 +SET OCCT_VER=V%OCCT_VERSION:.=_% + +set OCC_INCLUDE_DIR=%INSTALL_DIR%\opencascade-%OCCT_VERSION%\inc>>"%~dp0\%BUILDDEPTHCACHE%" +set OCC_LIBRARY_DIR=%INSTALL_DIR%\opencascade-%OCCT_VERSION%\win%ARCH_BITS%\lib>>"%~dp0\%BUILDDEPTHCACHE%" +echo OCC_INCLUDE_DIR=%OCC_INCLUDE_DIR%>>"%~dp0\%BUILDDEPTHCACHE%" +echo OCC_LIBRARY_DIR=%OCC_LIBRARY_DIR%>>"%~dp0\%BUILDDEPTHCACHE%" + +:: OCCT has many dependencies but FreeType is the only mandatory +set DEPENDENCY_NAME=FreeType +set DEPENDENCY_DIR=%DEPS_DIR%\freetype-2.6.5 +set FREETYPE_ZIP=ft265.zip +cd "%DEPS_DIR%" +call :DownloadFile http://download.savannah.gnu.org/releases/freetype/%FREETYPE_ZIP% "%DEPS_DIR%" %FREETYPE_ZIP% +if not %ERRORLEVEL%==0 goto :Error +call :ExtractArchive %FREETYPE_ZIP% "%DEPS_DIR%" "%DEPENDENCY_DIR%" +if not %ERRORLEVEL%==0 goto :Error +cd "%DEPENDENCY_DIR%" +:: NOTE FreeType is built as a static library by default +call :RunCMake -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%\freetype" +if not %ERRORLEVEL%==0 goto :Error +call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\freetype.sln" %BUILD_CFG% +if not %ERRORLEVEL%==0 goto :Error +call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG% +if not %ERRORLEVEL%==0 goto :Error + +set DEPENDENCY_NAME=Open CASCADE %OCCT_VERSION% +set DEPENDENCY_DIR=%DEPS_DIR%\occt_git +cd "%DEPS_DIR%" +call :GitCloneAndCheckoutRevision https://git.dev.opencascade.org/repos/occt.git "%DEPENDENCY_DIR%" %OCCT_VER% +if not %ERRORLEVEL%==0 goto :Error + +:: Patching always blindly would trigger a rebuild each time +findstr IfcOpenShell "%DEPENDENCY_DIR%\CMakeLists.txt">NUL +if not %ERRORLEVEL%==0 ( + pushd "%DEPENDENCY_DIR%" + git apply --ignore-whitespace ""%~dp0patches\%OCCT_VER%.patch" + popd +) +findstr IfcOpenShell "%DEPENDENCY_DIR%\CMakeLists.txt">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 ^ + -DBUILD_MODULE_Draw=0 -D3RDPARTY_FREETYPE_DIR="%INSTALL_DIR%\freetype" +if not %ERRORLEVEL%==0 goto :Error +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 +:: Use a single lib directory for release and debug libraries as is done with OCE +if not exist "%OCC_LIBRARY_DIR%". mkdir "%OCC_LIBRARY_DIR%" +:: NOTE OCCT (at least occt-V7_0_0-9059ca1) directory creation code is hardcoded and doesn't seem handle future VC versions +set OCCT_VC_VER=%VC_VER% +IF %OCCT_VC_VER% GTR 14 ( + set OCCT_VC_VER=14 +) +move /y "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\win%ARCH_BITS%\vc%OCCT_VC_VER%\libi\*.*" "%OCC_LIBRARY_DIR%" +move /y "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\win%ARCH_BITS%\vc%OCCT_VC_VER%\libd\*.*" "%OCC_LIBRARY_DIR%" +move /y "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\win%ARCH_BITS%\vc%OCCT_VC_VER%\lib\*.*" "%OCC_LIBRARY_DIR%" +rmdir /s /q "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\win%ARCH_BITS%\vc%OCCT_VC_VER%" +:: Removed unneeded bits +rmdir /s /q "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\data" +rmdir /s /q "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\samples" +del "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\*.bat" + +goto :Python + +:OCE +set OCC_INCLUDE_DIR=%INSTALL_DIR%\oce\include\oce>>"%~dp0\%BUILDDEPTHCACHE%" +set OCC_LIBRARY_DIR=%INSTALL_DIR%\oce\Win%ARCH_BITS%\lib>>"%~dp0\%BUILDDEPTHCACHE%" +echo OCC_INCLUDE_DIR=%OCC_INCLUDE_DIR%>>"%~dp0\%BUILDDEPTHCACHE%" +echo OCC_LIBRARY_DIR=%OCC_LIBRARY_DIR%>>"%~dp0\%BUILDDEPTHCACHE%" + +set DEPENDENCY_NAME=Open CASCADE Community Edition +set DEPENDENCY_DIR=%DEPS_DIR%\oce +set OCE_VERSION=OCE-0.18 +call :GitCloneAndCheckoutRevision https://github.com/tpaviot/oce.git "%DEPENDENCY_DIR%" %OCE_VERSION% +IF NOT %ERRORLEVEL%==0 GOTO :Error +:: Use the oce-win-bundle for OCE's dependencies +call :GitCloneOrPullRepository https://github.com/QbProg/oce-win-bundle.git "%DEPENDENCY_DIR%\oce-win-bundle" +IF NOT %ERRORLEVEL%==0 GOTO :Error + +cd "%DEPENDENCY_DIR%" +:: NOTE Specify OCE_NO_LIBRARY_VERSION as rc.exe can fail due to long filenames and huge command-line parameter +:: input (more than 32,000 characters). Could maybe try using subst for the build dir to overcome this. +call :RunCMake -DOCE_BUILD_SHARED_LIB=0 -DOCE_INSTALL_PREFIX="%INSTALL_DIR%\oce" -DOCE_TESTING=0 ^ + -DOCE_NO_LIBRARY_VERSION=1 -DOCE_USE_STATIC_MSVC_RUNTIME=1 +IF NOT %ERRORLEVEL%==0 GOTO :Error +call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\OCE.sln" %BUILD_CFG% +IF NOT %ERRORLEVEL%==0 GOTO :Error +call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG% +IF NOT %ERRORLEVEL%==0 GOTO :Error + +:Python +:: TODO Update to 3.5 when it's released as it will have an option to install debug libraries. +:: NOTE If updating the default Python version, change PY_VER_MAJOR_MINOR accordingly in run-cmake.bat +set PYTHON_VERSION=3.4.3 +IF "%IFCOS_USE_PYTHON2%"=="TRUE" set PYTHON_VERSION=2.7.10 +set PY_VER_MAJOR_MINOR=%PYTHON_VERSION:~0,3% +set PY_VER_MAJOR_MINOR=%PY_VER_MAJOR_MINOR:.=% +set PYTHONHOME=%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR% + +set DEPENDENCY_NAME=Python %PYTHON_VERSION% +set DEPENDENCY_DIR=N/A +set PYTHON_AMD64_POSTFIX=.amd64 +:: NOTE/TODO Beginning from 3.5.0: set PYTHON_AMD64_POSTFIX=-amd64 +IF NOT %TARGET_ARCH%==x64 set PYTHON_AMD64_POSTFIX= +set PYTHON_INSTALLER=python-%PYTHON_VERSION%%PYTHON_AMD64_POSTFIX%.msi +:: NOTE/TODO 3.5.0 doesn't use MSI any longer, but exe: set PYTHON_INSTALLER=python-%PYTHON_VERSION%%PYTHON_AMD64_POSTFIX%.exe +IF "%IFCOS_INSTALL_PYTHON%"=="TRUE" ( + REM Store Python versions to BuildDepsCache.txt for run-cmake.bat + echo PY_VER_MAJOR_MINOR=%PY_VER_MAJOR_MINOR%>>"%~dp0\%BUILDDEPTHCACHE%" + echo PYTHONHOME=%PYTHONHOME%>>"%~dp0\%BUILDDEPTHCACHE%" + + cd "%DEPS_DIR%" + call :DownloadFile https://www.python.org/ftp/python/%PYTHON_VERSION%/%PYTHON_INSTALLER% "%DEPS_DIR%" %PYTHON_INSTALLER% + IF NOT %ERRORLEVEL%==0 GOTO :Error + REM Uninstall if build Rebuild/Clean used + IF NOT %BUILD_TYPE%==Build ( + call cecho.cmd 0 13 "Uninstalling %DEPENDENCY_NAME%. Please be patient, this will take a while." + msiexec /x %PYTHON_INSTALLER% /qn + ) + + IF NOT EXIST "%PYTHONHOME%". ( + call cecho.cmd 0 13 "Installing %DEPENDENCY_NAME%. Please be patient, this will take a while." + msiexec /qn /i %PYTHON_INSTALLER% TARGETDIR="%PYTHONHOME%" + ) ELSE ( + call cecho.cmd 0 13 "%DEPENDENCY_NAME% already installed. Skipping." + ) +) ELSE ( + call cecho.cmd 0 13 "IFCOS_INSTALL_PYTHON not true, skipping installation of Python." +) + +:SWIG +set SWIG_VERSION=3.0.12 +set DEPENDENCY_NAME=SWIG %SWIG_VERSION% +set DEPENDENCY_DIR=N/A +set SWIG_ZIP=swigwin-%SWIG_VERSION%.zip +cd "%DEPS_DIR%" +call :DownloadFile https://sourceforge.net/projects/swig/files/swigwin/swigwin-%SWIG_VERSION%/%SWIG_ZIP% "%DEPS_DIR%" %SWIG_ZIP% +IF NOT %ERRORLEVEL%==0 GOTO :Error +call :ExtractArchive %SWIG_ZIP% "%DEPS_DIR%" "%DEPS_DIR%\swigwin" +IF NOT %ERRORLEVEL%==0 GOTO :Error +IF EXIST "%DEPS_DIR%\swigwin-%SWIG_VERSION%". ( + pushd "%DEPS_DIR%" + ren swigwin-%SWIG_VERSION% swigwin + popd +) +IF EXIST "%DEPS_DIR%\swigwin\". robocopy "%DEPS_DIR%\swigwin" "%INSTALL_DIR%\swigwin" /E /IS /MOVE /njh /njs + +:Successful +echo. +call "%~dp0\utils\cecho.cmd" 0 10 "%PROJECT_NAME% dependencies built." +set IFCOS_SCRIPT_RET=0 +goto :Finish + +:ErrorAndPrintUsage +echo. +call :PrintUsage +:Error +echo. +call "%~dp0\utils\cecho.cmd" 0 12 "An error occurred! Aborting!" +set IFCOS_SCRIPT_RET=1 +goto :Finish + +:Finish +:: Print end time and elapsed time, http://stackoverflow.com/a/9935540 +if not defined BUILD_STARTED goto :BuildTimeSkipped +set END_TIME=%TIME% +for /F "tokens=1-4 delims=:.," %%a in ("%START_TIME%") do ( + set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" +) +for /F "tokens=1-4 delims=:.," %%a in ("%END_TIME%") do ( + set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" +) +set /A elapsed=end-start +set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100 +if %mm% lss 10 set mm=0%mm% +if %ss% lss 10 set ss=0%ss% +if %cc% lss 10 set cc=0%cc% +echo. +echo Build ended at %END_TIME%. Time elapsed %hh%:%mm%:%ss%.%cc%. +:BuildTimeSkipped +set PATH=%ORIGINAL_PATH% +cd "%~dp0" +exit /b %IFCOS_SCRIPT_RET% + +::::::::::::::::::::::::::::::::::::: Subroutines ::::::::::::::::::::::::::::::::::::: + +:: DownloadFile - Downloads a file using PowerShell +:: Params: %1 url, %2 destinationDir, %3 filename +:DownloadFile +pushd "%2" +if not exist "%~3". ( + call cecho.cmd 0 13 "Downloading %DEPENDENCY_NAME% into %~2." + powershell -Command "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; $webClient = new-object System.Net.WebClient; $webClient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials; $webClient.DownloadFile('%1', '%3')" + REM Old wget version in case someone has problem with PowerShell: wget --no-check-certificate %1 +) else ( + call cecho.cmd 0 13 "%DEPENDENCY_NAME% already downloaded. Skipping." +) +set RET=%ERRORLEVEL% +popd +exit /b %RET% + +:: ExtractArchive - Extracts an archive file using 7-zip +:: Params: %1 filename, %2 destinationDir, %3 dirAfterExtraction +:ExtractArchive +if not exist "%~3". ( + call cecho.cmd 0 13 "Extracting %DEPENDENCY_NAME% into %~2." + 7za x %1 -y -o%2 > nul +) else ( + call cecho.cmd 0 13 "%DEPENDENCY_NAME% already extracted into %~3. Skipping." +) +exit /b %ERRORLEVEL% + +:: GitCloneOrPullRepository - Clones or pulls (if repository already cloned) a Git repository +:: Params: %1 gitUrl, %2 destDir +:: F.ex. call :GitCloneRepository https://github.com/KhronosGroup/OpenCOLLADA.git "%DEPS_DIR%\OpenCOLLADA\" +:GitCloneOrPullRepository +if not exist "%~2". ( + call cecho.cmd 0 13 "Cloning %DEPENDENCY_NAME% into %~2." + pushd "%DEPS_DIR%" + call git clone %1 %2 + set RET=%ERRORLEVEL% +) else ( + call cecho.cmd 0 13 "%DEPENDENCY_NAME% already cloned. Pulling latest changes." + pushd %2 + call git pull + set RET=0 +) +popd +exit /b %RET% + +:: GitCloneAndCheckoutRevision - Clones a Git repository and checks out a specific revision or tag +:: Params: %1 gitUrl, %2 destDir, %3 revision +:: F.ex. call :GitCloneAndCheckoutRevision https://github.com/KhronosGroup/OpenCOLLADA.git "%DEPENDENCY_DIR%" 064a60b65c2c31b94f013820856bc84fb1937cc6 +:GitCloneAndCheckoutRevision +if not exist "%~2". ( + call cecho.cmd 0 13 "Cloning %DEPENDENCY_NAME% into %~2." + pushd "%DEPS_DIR%" + call git clone %1 %2 + set RET=%ERRORLEVEL% + if not %RET%==0 exit /b %RET% + popd +) else ( + call cecho.cmd 0 13 "%DEPENDENCY_NAME% already cloned." + set RET=0 +) +pushd "%2" +call git fetch +call cecho.cmd 0 13 "Checking out %DEPENDENCY_NAME% revision %3." +call git checkout %3 +set RET=%ERRORLEVEL% +popd +exit /b %RET% + +:: RunCMake - Runs CMake for a CMake-based project +:: Params: %* cmakeOptions +:: NOTE cd to root CMakeLists.txt folder before calling this if the CMakeLists.txt is not in the repo root. +:RunCMake +call cecho.cmd 0 13 "Running CMake for %DEPENDENCY_NAME%." +IF NOT EXIST %BUILD_DIR%. mkdir %BUILD_DIR% +IF NOT %ERRORLEVEL%==0 GOTO :Error +pushd %BUILD_DIR% +:: TODO make deleting cache a parameter for this subroutine? We probably want to delete the +:: cache always e.g. when we've had new changes in the repository. +IF %BUILD_TYPE%==Rebuild IF EXIST CMakeCache.txt. del CMakeCache.txt + +IF DEFINED VS_TOOLSET ( + cmake .. -G %GENERATOR% -A %VS_PLATFORM% -T %VS_TOOLSET% %* +) ELSE ( + cmake .. -G %GENERATOR% -A %VS_PLATFORM% %* +) + +set RET=%ERRORLEVEL% +popd +exit /b %RET% + +:: TODO add BuildCMakeProject which utilizes cmake --build + +:: BuildSolution - Builds/Rebuilds/Cleans a solution using MSBuild +:: Params: %1 solutioName, %2 configuration +:BuildSolution +call cecho.cmd 0 13 "Building %2 %DEPENDENCY_NAME%. Please be patient, this will take a while." +%MSBUILD_CMD% %1 /p:configuration=%2;platform=%VS_PLATFORM% +exit /b %ERRORLEVEL% + +:: InstallCMakeProject - Builds the INSTALL project of CMake-based project +:: Params: %1 buildDir, %2 == configuration +:: NOTE the actual install dir is set during cmake run. +:: TODO Utilize cmake --build --target INSTALL +:InstallCMakeProject +pushd %1 +call cecho.cmd 0 13 "Installing %2 %DEPENDENCY_NAME%. Please be patient, this will take a while." +%INSTALL_CMD% INSTALL.%VCPROJ_FILE_EXT% /p:configuration=%2;platform=%VS_PLATFORM% +set RET=%ERRORLEVEL% +popd +exit /b %RET% + +:: PrintUsage - Prints usage information +:PrintUsage +call "%~dp0\utils\cecho.cmd" 0 10 "Requirements for a successful execution:" +echo 1. Install PowerShell (preinstalled in Windows ^>= 7) version 5 or higher and make sure 'powershell' is accessible from PATH. +echo - https://support.microsoft.com/en-us/kb/968929 +echo 2. Install Git and make sure 'git' is accessible from PATH. +echo - https://git-for-windows.github.io/ +echo 3. Install CMake and make sure 'cmake' is accessible from PATH. +echo - http://www.cmake.org/ +echo 4. Visual Studio 2008 or newer (2013 or newer recommended) with C++ toolset. +echo - https://www.visualstudio.com/ +echo 5. Run this batch script with Visual Studio environment variables set. +echo - https://msdn.microsoft.com/en-us/library/ms229859(v=vs.110).aspx +echo. +echo NB: This script needs to be ran from the directory directly containing it. +echo. diff --git a/win/readme.md b/win/readme.md index e8e4c5107a..31ada3fefb 100644 --- a/win/readme.md +++ b/win/readme.md @@ -18,36 +18,36 @@ of the shell scripts before using them. Note that contrary to MSVC, with MSYS al built or used as static libraries. Currently Release build is used for all libraries. ### MSVC -Execute `build-deps.cmd` to fetch, build and install the dependencies. The batch file will print the requirements for -a successful execution. The script allows a few user-configurable build options which are listed in the usage -instructions. Either edit the script file or set these values before running the script. +Launch the proper Visual Studio command prompt, cd to the 'win' directory inside the IfcOpenShell directory and execute `build-deps.cmd` to fetch, build and install the dependencies. The batch file will print the requirements for a successful execution. The script allows a few user-configurable build options which are listed below. -`build-deps.cmd` expects a CMake generator as `%1` and a build configuration type (`RelWithDebInfo`, `Release`, -`MinSizeRel`, or `Debug`, defaults to `RelWithDebInfo`) as `%2`. If the generator is not provided, the generator is -deduced from the MSVC environment variables. User-friendly VS generator shorthands are supported, e.g. -`vs2013-x86` or `vs2015-x64`, and these are converted to the appropriate CMake ones by the scripts. A build type -(`Build`, `Rebuild`, or `Clean`, defaults to `Build`) can be provided as `%3`. See `vs-cfg.cmd` if you wish to change -the defaults. The batch file will create `deps\` and `deps-vs--installed\` directories to the -project root. Debug and release builds of the dependencies can co-exist by simply running +`build-deps.cmd` expects a CMake generator as `%1` and a build configuration type (`RelWithDebInfo`, `Release`, `MinSizeRel`, or `Debug`, defaults to `RelWithDebInfo`) as `%2`. If the generator is not provided, the generator is deduced from the MSVC environment variables. + +User-friendly CMake Visual Studio generator shorthands are supported. They are converted to the appropriate CMake generators and options. Shorthands are indeed the preferable way to specify the generator, since they allow a more accurate platform and toolset configuration. Here are some examples: +``` +"vs2013" => cmake -G "Visual Studio 12 2013" -A Win32 +"vs2013-x86" => cmake -G "Visual Studio 12 2013" -A Win32 +"vs2015-x64" => cmake -G "Visual Studio 14 2015" -A x64 +"vs2017-ARM64" => cmake -G "Visual Studio 15 2017" -A ARM64 +"vs2019-x86-v141_xp" => cmake -G "Visual Studio 16 2019" -A Win32 -T v141_xp +``` +Of course not all Visual C++ compilers support any platform or toolset, refer to the Visual Studio and CMake documentation for this. If you do not specify a toolset, the compiler will use the default toolset for the version, i.e. vs2019 will use the v142 toolset. + +A build type (`Build`, `Rebuild`, or `Clean`, defaults to `Build`) can be provided as `%3`. + +See `vs-cfg.cmd` if you wish to change the defaults. The batch file will create `deps\` and `deps-vs-[-]-installed\` directories to the project root. Debug and release builds of the dependencies can co-exist by simply running: ``` > build-deps.cmd Debug > build-deps.cmd ``` -After the dependencies are build, execute `run-cmake.bat`. The batch file expects a CMake generator as `%1` and the -rest of possible parameters are passed as is. If a generator is not provided, the generator is read from the -BuildDepsCache file, or tried to be deduced from the location of `cl.exe`. If passing build options for the script, -the generator must be always passed as the first option: +After the dependencies are build, execute `run-cmake.bat`. The batch file expects a CMake generator as `%1`, that is interpreted just like the `build-deps.cmd` script, and the rest of possible parameters are passed as is. If a generator is not provided, the generator is read from the BuildDepsCache file, or tried to be deduced from the location of `cl.exe`. If passing build options for the script, the generator must be always passed as the first option: ``` > run-cmake.bat vs2015-x64 -DUSE_IFC4=1 -DBUILD_IFCPYTHON=0 ``` -**If you wish to use any library from a custom location, modify the paths in `run-cmake.bat` accordingly**. The batch -script will create a folder of form `build-vs-\` which will contain the solution and project -files for MSVC. +**If you wish to use any library from a custom location, modify the paths in `run-cmake.bat` accordingly**. The batch script will create a folder of form `build-vs-[-]\` which will contain the solution and project files for MSVC. -Note that building IfcOpenShell as 64-bit is recommended as many of real life IFC files has been observed to take -easily more than 2 GBs of RAM while converting. +Note that building IfcOpenShell as 64-bit is recommended as many of real life IFC files has been observed to take easily more than 2 GBs of RAM while converting. After this, one can build the project using the `IfcOpenShell.sln` file in the build folder. Build the `INSTALL` project if wanted. Convenience batch files `build-ifcopenshell.bat` and `install-ifcopenshell.bat` can also be used. The batch diff --git a/win/run-cmake.bat b/win/run-cmake.bat index 8154b3a4bc..eb2b597746 100755 --- a/win/run-cmake.bat +++ b/win/run-cmake.bat @@ -1,127 +1,135 @@ -::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -:: :: -:: This file is part of IfcOpenShell. :: -:: :: -:: IfcOpenShell is free software: you can redistribute it and/or modify :: -:: it under the terms of the Lesser GNU General Public License as published by :: -:: the Free Software Foundation, either version 3.0 of the License, or :: -:: (at your option) any later version. :: -:: :: -:: IfcOpenShell is distributed in the hope that it will be useful, :: -:: but WITHOUT ANY WARRANTY; without even the implied warranty of :: -:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the :: -:: Lesser GNU General Public License for more details. :: -:: :: -:: You should have received a copy of the Lesser GNU General Public License :: -:: along with this program. If not, see . :: -:: :: -::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - -@echo off -echo. - -set PROJECT_NAME=IfcOpenShell - -setlocal EnableDelayedExpansion -set IFCOS_PAUSE_ON_ERROR= - -:: Read cached variables from the most recently modified BuildDepsCache.txt. -for /f "tokens=*" %%f in ('dir BuildDepsCache-*.txt /o:-n /t:a /b') do ( - for /f "delims== tokens=1,2" %%G in (%%f) do set %%G=%%H -) - -set GENERATOR=%1 -if (%1)==() ( - if not defined GEN_SHORTHAND ( - echo BuildDepsCache file does not exist and/or GEN_SHORTHAND missing from it. Run build-deps.cmd to create it. - set IFCOS_PAUSE_ON_ERROR=pause - goto :Error - ) - set GENERATOR=%GEN_SHORTHAND% - echo Generator not passed, but GEN_SHORTHAND=!GENERATOR! read from BuildDepsCache - echo. -) -call vs-cfg.cmd %GENERATOR% -IF NOT %ERRORLEVEL%==0 GOTO :Error -:: As CMake options are typically of format -DSOMETHING:BOOL=ON or -DSOMETHING=1, i.e. they contain an equal sign, -:: they will mess up the batch file argument parsing if the arguments are passed on by splitting them %2 %3 %4 %5 -:: %6 %7 %8 %9. Work around that, http://scripts.dragon-it.co.uk/scripts.nsf/docs/batch-search-replace-substitute -if not (%1)==() ( - set ARGUMENTS=%* - call set ARGUMENTS=%%ARGUMENTS:%1=%% -) - -pushd .. -set CMAKE_INSTALL_PREFIX=%CD%\installed-vs%VS_VER%-%TARGET_ARCH% -popd - -IF NOT EXIST ..\%BUILD_DIR%. mkdir ..\%BUILD_DIR% -pushd ..\%BUILD_DIR% - -:: tfk: todo remove duplication -set BOOST_VERSION=1.67.0 -set BOOST_VER=%BOOST_VERSION:.=_% - -set BOOST_ROOT=%DEPS_DIR%\boost_%BOOST_VER% -set BOOST_LIBRARYDIR=%BOOST_ROOT%\stage\vs%VS_VER%-%VS_PLATFORM%\lib -if not defined OCC_INCLUDE_DIR set OCC_INCLUDE_DIR=%INSTALL_DIR%\oce\include\oce -if not defined OCC_LIBRARY_DIR set OCC_LIBRARY_DIR=%INSTALL_DIR%\oce\Win%ARCH_BITS%\lib -set OPENCOLLADA_INCLUDE_DIR=%INSTALL_DIR%\OpenCOLLADA\include\opencollada -set OPENCOLLADA_LIBRARY_DIR=%INSTALL_DIR%\OpenCOLLADA\lib\opencollada -set LIBXML2_INCLUDE_DIR=%DEPS_DIR%\OpenCOLLADA\Externals\LibXML\include -set LIBXML2_LIBRARIES=%INSTALL_DIR%\OpenCOLLADA\lib\opencollada\xml.lib -if not defined PY_VER_MAJOR_MINOR set PY_VER_MAJOR_MINOR=34 -if not defined PYTHONHOME set PYTHONHOME=%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR% -set PYTHON_INCLUDE_DIR=%PYTHONHOME%\include -set PYTHON_LIBRARY=%PYTHONHOME%\libs\python%PY_VER_MAJOR_MINOR%.lib -set PYTHON_EXECUTABLE=%PYTHONHOME%\python.exe -set SWIG_DIR=%INSTALL_DIR%\swigwin -set PATH=%PATH%;%SWIG_DIR%;%PYTHONHOME% -set JSON_INCLUDE_DIR=%INSTALL_DIR%\json - -echo. -call cecho.cmd 0 10 "Script configuration:" -echo Generator = %GENERATOR% -echo Arguments = %ARGUMENTS% -echo. -call cecho.cmd 0 10 "Dependency Environment Variables for %PROJECT_NAME%:" -echo BOOST_ROOT = %BOOST_ROOT% -echo BOOST_LIBRARYDIR = %BOOST_LIBRARYDIR% -echo OCC_INCLUDE_DIR = %OCC_INCLUDE_DIR% -echo OCC_LIBRARY_DIR = %OCC_LIBRARY_DIR% -echo OPENCOLLADA_INCLUDE_DIR = %OPENCOLLADA_INCLUDE_DIR% -echo OPENCOLLADA_LIBRARY_DIR = %OPENCOLLADA_LIBRARY_DIR% -echo LIBXML2_INCLUDE_DIR = %LIBXML2_INCLUDE_DIR% -echo LIBXML2_LIBRARIES = %LIBXML2_LIBRARIES% -echo PYTHONHOME = %PYTHONHOME% -echo PYTHON_INCLUDE_DIR = %PYTHON_INCLUDE_DIR% -echo PYTHON_LIBRARY = %PYTHON_LIBRARY% -echo PYTHON_EXECUTABLE = %PYTHON_EXECUTABLE% -echo SWIG_DIR = %SWIG_DIR% -echo JSON_INCLUDE_DIR = %JSON_INCLUDE_DIR% -echo. -echo CMAKE_INSTALL_PREFIX = %CMAKE_INSTALL_PREFIX% -echo. - -set CMAKELISTS_DIR=..\cmake -:: Delete CMakeCache.txt if command-line options were provided for this batch script. -if not (%1)==() if exist CMakeCache.txt. del /Q CMakeCache.txt -call cecho.cmd 0 13 "Running CMake for %PROJECT_NAME%." -cmake.exe %CMAKELISTS_DIR% -G %GENERATOR% -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" %ARGUMENTS% -IF NOT %ERRORLEVEL%==0 GOTO :Error - -echo. - -set IFCOS_SCRIPT_RET=0 -goto :Finish - -:Error -echo. -call "%~dp0\utils\cecho.cmd" 0 12 "An error occurred! Aborting!" -%IFCOS_PAUSE_ON_ERROR% -set IFCOS_SCRIPT_RET=1 -goto :Finish - -:Finish -popd -exit /b %IFCOS_SCRIPT_RET% +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: :: +:: This file is part of IfcOpenShell. :: +:: :: +:: IfcOpenShell is free software: you can redistribute it and/or modify :: +:: it under the terms of the Lesser GNU General Public License as published by :: +:: the Free Software Foundation, either version 3.0 of the License, or :: +:: (at your option) any later version. :: +:: :: +:: IfcOpenShell is distributed in the hope that it will be useful, :: +:: but WITHOUT ANY WARRANTY; without even the implied warranty of :: +:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the :: +:: Lesser GNU General Public License for more details. :: +:: :: +:: You should have received a copy of the Lesser GNU General Public License :: +:: along with this program. If not, see . :: +:: :: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +@echo off +echo. + +set PROJECT_NAME=IfcOpenShell + +setlocal EnableDelayedExpansion +set IFCOS_PAUSE_ON_ERROR= + +:: Read cached variables from the most recently modified BuildDepsCache.txt. +for /f "tokens=*" %%f in ('dir BuildDepsCache-*.txt /o:-n /t:a /b') do ( + for /f "delims== tokens=1,2" %%G in (%%f) do set %%G=%%H +) + +set GENERATOR=%1 +if (%1)==() ( + if not defined GEN_SHORTHAND ( + echo BuildDepsCache file does not exist and/or GEN_SHORTHAND missing from it. Run build-deps.cmd to create it. + set IFCOS_PAUSE_ON_ERROR=pause + goto :Error + ) + set GENERATOR=%GEN_SHORTHAND% + echo Generator not passed, but GEN_SHORTHAND=!GENERATOR! read from BuildDepsCache + echo. +) +call vs-cfg.cmd %GENERATOR% +IF NOT %ERRORLEVEL%==0 GOTO :Error +:: As CMake options are typically of format -DSOMETHING:BOOL=ON or -DSOMETHING=1, i.e. they contain an equal sign, +:: they will mess up the batch file argument parsing if the arguments are passed on by splitting them %2 %3 %4 %5 +:: %6 %7 %8 %9. Work around that, http://scripts.dragon-it.co.uk/scripts.nsf/docs/batch-search-replace-substitute +if not (%1)==() ( + set ARGUMENTS=%* + call set ARGUMENTS=%%ARGUMENTS:%1=%% +) + +pushd .. +set CMAKE_INSTALL_PREFIX=%CD%\installed-%GEN_SHORTHAND% +popd + +IF NOT EXIST ..\%BUILD_DIR%. mkdir ..\%BUILD_DIR% +pushd ..\%BUILD_DIR% + +:: tfk: todo remove duplication +set BOOST_VERSION=1.71.0 +set BOOST_VER=%BOOST_VERSION:.=_% + +set BOOST_ROOT=%DEPS_DIR%\boost_%BOOST_VER% +set BOOST_LIBRARYDIR=%BOOST_ROOT%\stage\%GEN_SHORTHAND%\lib +if not defined OCC_INCLUDE_DIR set OCC_INCLUDE_DIR=%INSTALL_DIR%\oce\include\oce +if not defined OCC_LIBRARY_DIR set OCC_LIBRARY_DIR=%INSTALL_DIR%\oce\Win%ARCH_BITS%\lib +set OPENCOLLADA_INCLUDE_DIR=%INSTALL_DIR%\OpenCOLLADA\include\opencollada +set OPENCOLLADA_LIBRARY_DIR=%INSTALL_DIR%\OpenCOLLADA\lib\opencollada +set LIBXML2_INCLUDE_DIR=%DEPS_DIR%\OpenCOLLADA\Externals\LibXML\include +set LIBXML2_LIBRARIES=%INSTALL_DIR%\OpenCOLLADA\lib\opencollada\xml.lib +if not defined PY_VER_MAJOR_MINOR set PY_VER_MAJOR_MINOR=34 +if not defined PYTHONHOME set PYTHONHOME=%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR% +set PYTHON_INCLUDE_DIR=%PYTHONHOME%\include +set PYTHON_LIBRARY=%PYTHONHOME%\libs\python%PY_VER_MAJOR_MINOR%.lib +set PYTHON_EXECUTABLE=%PYTHONHOME%\python.exe +set SWIG_DIR=%INSTALL_DIR%\swigwin +set PATH=%PATH%;%SWIG_DIR%;%PYTHONHOME% +set JSON_INCLUDE_DIR=%INSTALL_DIR%\json + +echo. +call cecho.cmd 0 10 "Script configuration:" +echo Generator = %GENERATOR% +echo Architecture = %VS_PLATFORM% +echo Toolset = %VS_TOOLSET% +echo Arguments = %ARGUMENTS% +echo. +call cecho.cmd 0 10 "Dependency Environment Variables for %PROJECT_NAME%:" +echo BOOST_ROOT = %BOOST_ROOT% +echo BOOST_LIBRARYDIR = %BOOST_LIBRARYDIR% +echo OCC_INCLUDE_DIR = %OCC_INCLUDE_DIR% +echo OCC_LIBRARY_DIR = %OCC_LIBRARY_DIR% +echo OPENCOLLADA_INCLUDE_DIR = %OPENCOLLADA_INCLUDE_DIR% +echo OPENCOLLADA_LIBRARY_DIR = %OPENCOLLADA_LIBRARY_DIR% +echo LIBXML2_INCLUDE_DIR = %LIBXML2_INCLUDE_DIR% +echo LIBXML2_LIBRARIES = %LIBXML2_LIBRARIES% +echo PYTHONHOME = %PYTHONHOME% +echo PYTHON_INCLUDE_DIR = %PYTHON_INCLUDE_DIR% +echo PYTHON_LIBRARY = %PYTHON_LIBRARY% +echo PYTHON_EXECUTABLE = %PYTHON_EXECUTABLE% +echo SWIG_DIR = %SWIG_DIR% +echo JSON_INCLUDE_DIR = %JSON_INCLUDE_DIR% +echo. +echo CMAKE_INSTALL_PREFIX = %CMAKE_INSTALL_PREFIX% +echo. + +set CMAKELISTS_DIR=..\cmake +:: Delete CMakeCache.txt if command-line options were provided for this batch script. +if not (%1)==() if exist CMakeCache.txt. del /Q CMakeCache.txt +call cecho.cmd 0 13 "Running CMake for %PROJECT_NAME%." + +IF DEFINED VS_TOOLSET ( + cmake.exe %CMAKELISTS_DIR% -G %GENERATOR% -A %VS_PLATFORM% -T %VS_TOOLSET% -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" %ARGUMENTS% +) ELSE ( + cmake.exe %CMAKELISTS_DIR% -G %GENERATOR% -A %VS_PLATFORM% -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" %ARGUMENTS% +) + +IF NOT %ERRORLEVEL%==0 GOTO :Error + +echo. + +set IFCOS_SCRIPT_RET=0 +goto :Finish + +:Error +echo. +call "%~dp0\utils\cecho.cmd" 0 12 "An error occurred! Aborting!" +%IFCOS_PAUSE_ON_ERROR% +set IFCOS_SCRIPT_RET=1 +goto :Finish + +:Finish +popd +exit /b %IFCOS_SCRIPT_RET% diff --git a/win/vs-cfg.cmd b/win/vs-cfg.cmd index 992de2ef5a..4b461883d7 100644 --- a/win/vs-cfg.cmd +++ b/win/vs-cfg.cmd @@ -1,175 +1,256 @@ -::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -:: :: -:: This file is part of IfcOpenShell. :: -:: :: -:: IfcOpenShell is free software: you can redistribute it and/or modify :: -:: it under the terms of the Lesser GNU General Public License as published by :: -:: the Free Software Foundation, either version 3.0 of the License, or :: -:: (at your option) any later version. :: -:: :: -:: IfcOpenShell is distributed in the hope that it will be useful, :: -:: but WITHOUT ANY WARRANTY; without even the implied warranty of :: -:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the :: -:: Lesser GNU General Public License for more details. :: -:: :: -:: You should have received a copy of the Lesser GNU General Public License :: -:: along with this program. If not, see . :: -:: :: -::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::: - -:: This script initializes various Visual Studio related environment variables needed for building. -:: the dependencies. This batch file expects a CMake generator as %1. If %1 is not provided, it is -:: deduced from the VisualStudioVersion environment variable and from the location of cl.exe. -:: User-friendly VS generators are allowed (e.g. "vs2013-x86") and converted to the appropriate CMake ones. - -:: NOTE This batch file expects the generator string to be CMake 3.0.0 and newer format, i.e. -:: "Visual Studio 10 2010" instead of "Visual Studio 10". However, one can use this batch file -:: also with CMake 2 as the generator will be converted into the older format if necessary. - -:: NOTE: The delayed environment variable expansion needs to be enabled before calling this. - -@echo off - -set GENERATOR=%1 - -:: Supported Visual Studio versions: -set GENERATORS[0]="Visual Studio 9 2008 Win64" -set GENERATORS[1]="Visual Studio 9 2008" -set GENERATORS[2]="Visual Studio 10 2010 Win64" -set GENERATORS[3]="Visual Studio 10 2010" -set GENERATORS[4]="Visual Studio 11 2012 Win64" -set GENERATORS[5]="Visual Studio 11 2012" -set GENERATORS[6]="Visual Studio 12 2013 Win64" -set GENERATORS[7]="Visual Studio 12 2013" -set GENERATORS[8]="Visual Studio 14 2015 Win64" -set GENERATORS[9]="Visual Studio 14 2015" -:: NOTE VC version for VS 2017 is not 15 but 14.1: have to wait and see -:: if CMake generator string is updated to reflect this. -set GENERATORS[10]="Visual Studio 15 2017 Win64" -set GENERATORS[11]="Visual Studio 15 2017" -set LAST_GENERATOR_IDX=11 - -set STEP=2 -:: Is generator shorthand used? -set GEN_SHORTHAND=!GENERATOR:vs=! -if not "!GEN_SHORTHAND!"=="" if !GEN_SHORTHAND!==!GENERATOR! goto :GeneratorShorthandCheckDone -set START=%LAST_GENERATOR_IDX% -:: "echo if" trick from http://stackoverflow.com/a/8758579 -echo(!GEN_SHORTHAND! | findstr /c:"-x86" >nul && ( set START=1 ) -echo(!GEN_SHORTHAND! | findstr /c:"-x64" >nul && ( set START=0 ) -set VS_VER=!GEN_SHORTHAND:-x86=! -set VS_VER=!VS_VER:-x64=! -echo(!GENERATOR! | findstr /c:"vs20" >nul && ( - for /l %%i in (!START!,!STEP!,%LAST_GENERATOR_IDX%) do ( - echo(!GENERATORS[%%i]! | findstr /c:"!VS_VER!" >nul && ( - set GENERATOR=!GENERATORS[%%i]! - goto :GeneratorShorthandCheckDone - ) - ) -) -:GeneratorShorthandCheckDone - -:: Deduce desired architecture from the location of cl.exe -:: TODO harmless "INFO: Could not find files for the given pattern(s)." spam if cl.exe not in path -:: Look for path with either "amd64" or "x64" (VS 2017 and newer) -where cl.exe | findstr "amd64 x64" >nul -set START=%ERRORLEVEL% - -IF "!GENERATOR!"=="" IF NOT "%VisualStudioVersion%"=="" ( - set VC_VER=%VisualStudioVersion:.0=% - FOR /l %%i in (%START%,%STEP%,%LAST_GENERATOR_IDX%) DO ( - REM NOTE add space before VC_VER so that e.g. "12" doesn't match with "2012" - echo(!GENERATORS[%%i]! | findstr /c:" !VC_VER!" >nul && ( - set GENERATOR=!GENERATORS[%%i]! - call utils\cecho.cmd black cyan "Generator not passed, but VisualStudioVersion=%VisualStudioVersion% environment variable detected:" - call utils\cecho.cmd black cyan "using '`"!GENERATOR!`'" as the generator." - GOTO :GeneratorValid - ) - ) -) -:: Check that the used CMake version supports the chosen generator -set GENERATOR_CHECK=%GENERATOR: Win64=% -cmake --help | findstr /c:%GENERATOR_CHECK% >nul -if not %ERRORLEVEL%==0 ( -call utils\cecho.cmd 0 12 "%~nx0: The used CMake version does not support '`"!GENERATOR!`'"- cannot proceed." -exit /b 1 -) - -FOR /l %%i in (0,1,%LAST_GENERATOR_IDX%) DO ( - IF !GENERATOR!==!GENERATORS[%%i]! GOTO :GeneratorValid -) -call utils\cecho.cmd 0 12 "%~nx0: Invalid or unsupported CMake generator string passed: '`"!GENERATOR!`'"- cannot proceed." -echo Supported CMake generator strings: -FOR /l %%i in (0,1,%LAST_GENERATOR_IDX%) DO ( - echo !GENERATORS[%%i]! -) -exit /b 1 - -:GeneratorValid -:: Figure out the build configuration from the CMake generator string. -:: Are we building 32-bit or 64-bit version. -set ARCH_BITS=32 -set TARGET_ARCH=x86 -:: Visual Studio platform name, Win32 (i.e. x86) or x64. -set VS_PLATFORM=Win32 - -:: Find out VS (e.g. 2015) and VC (e.g. 14) versions and are we targeting x64 or not (x86). -:: VS_VER and VC_VER are convenience variables used f.ex. for filenames. -set GENERATOR_NO_DOUBLEQUOTES=%GENERATOR:"=% -set GENERATOR_SPLIT=%GENERATOR_NO_DOUBLEQUOTES: =,% -FOR %%i IN (%GENERATOR_SPLIT%) DO ( - call :StrLength LEN %%i - IF !LEN!==1 set VC_VER=%%i - IF !LEN!==2 set VC_VER=%%i - IF !LEN!==4 set VS_VER=%%i - REM Are going to perform a 64-bit build? - IF %%i==Win64 ( - set ARCH_BITS=64 - set TARGET_ARCH=x64 - set VS_PLATFORM=x64 - ) -) - -:: Check CMake version and convert possible new format (>= 3.0) generator names to the old versions if using older CMake for VS <= 2013, -:: see http://www.cmake.org/cmake/help/v3.0/release/3.0.0.html#other-changes -FOR /f "delims=" %%i in ('where cmake') DO set CMAKE_PATH=%%i -IF NOT "%CMAKE_PATH%"=="" ( - FOR /f "delims=" %%i in ('cmake --version ^| findstr /C:"cmake version 3"') DO GOTO :CMake3AndNewer -) -:: CMake older than 3.0.0: convert new format generators to the old format (simple brute force for simplicity) -set GENERATOR=%GENERATOR: 2013=% -set GENERATOR=%GENERATOR: 2012=% -set GENERATOR=%GENERATOR: 2010=% -:CMake3AndNewer - -set GEN_SHORTHAND=vs%VS_VER%-%TARGET_ARCH% -:: VS project file extension is different on older VS versions -set VCPROJ_FILE_EXT=vcxproj -IF %VS_VER%==2008 set VCPROJ_FILE_EXT=vcproj - -:: Add utils to PATH -set ORIGINAL_PATH=%PATH% -set PATH=%~dp0utils;%PATH% - -:: Fetch and build the dependencies to a dedicated directory depending on the used VS version and target architecture. -:: NOTE For IfcOpenShell we can build all of our deps both x86 and x64 using different VS versions in the same directories -:: so no need for -%VS_VER%-%TARGET_ARCH% postfix. -:: set DEPS_DIR=%CD%\deps-%VS_VER%-%TARGET_ARCH% -pushd .. -set DEPS_DIR=%CD%\deps -set INSTALL_DIR=%CD%\deps-%GEN_SHORTHAND%-installed -REM set INSTALL_DIR=%CD%\deps-vs%VS_VER%-%TARGET_ARCH%-%DEBUG_OR_RELEASE_LOWERCASE%-installed -:: BUILD_DIR is a relative build directory used for CMake-based projects -set BUILD_DIR=build-%GEN_SHORTHAND% -popd - -GOTO :EOF -:: http://geekswithblogs.net/SoftwareDoneRight/archive/2010/01/30/useful-dos-batch-functions-substring-and-length.aspx -:StrLength -set #=%2% -set length=0 -:stringLengthLoop -if defined # (set #=%#:~1%&set /A length += 1&goto stringLengthLoop) -::echo the string is %length% characters long! -set "%~1=%length%" -GOTO :EOF +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: :: +:: This file is part of IfcOpenShell. :: +:: :: +:: IfcOpenShell is free software: you can redistribute it and/or modify :: +:: it under the terms of the Lesser GNU General Public License as published by :: +:: the Free Software Foundation, either version 3.0 of the License, or :: +:: (at your option) any later version. :: +:: :: +:: IfcOpenShell is distributed in the hope that it will be useful, :: +:: but WITHOUT ANY WARRANTY; without even the implied warranty of :: +:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the :: +:: Lesser GNU General Public License for more details. :: +:: :: +:: You should have received a copy of the Lesser GNU General Public License :: +:: along with this program. If not, see . :: +:: :: +::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::: + +:: This script initializes various Visual Studio related environment variables. +:: +:: It expects a CMake generator as %1. If %1 is not provided, it is deduced from +:: the VisualStudioVersion environment variable and from the location of cl.exe. +:: +:: The generator string must be in the CMake 3.0 and newer format, i.e. +:: "Visual Studio 10 2010" instead of "Visual Studio 10" +:: +:: User-friendly VS generators are preferred, since they permit a more accurate +:: platform and toolset configuration. Some examples: +:: +:: "vs2013" => cmake -G "Visual Studio 12 2013" -A Win32 +:: "vs2013-x86" => cmake -G "Visual Studio 12 2013" -A Win32 +:: "vs2015-x64" => cmake -G "Visual Studio 14 2015" -A x64 +:: "vs2017-ARM64" => cmake -G "Visual Studio 15 2017" -A ARM64 +:: "vs2019-x86-v141_xp" => cmake -G "Visual Studio 16 2019" -A Win32 -T v141_xp +:: +:: NOTE: The delayed environment variable expansion needs to be enabled before calling this. + +@echo off + +set GENERATOR=%1 + +:: Supported Visual Studio versions: +set GENERATORS[1]="Visual Studio 9 2008" +set GENERATORS[2]="Visual Studio 10 2010" +set GENERATORS[3]="Visual Studio 11 2012" +set GENERATORS[4]="Visual Studio 12 2013" +set GENERATORS[5]="Visual Studio 14 2015" +set GENERATORS[6]="Visual Studio 15 2017" +set GENERATORS[7]="Visual Studio 16 2019" +set LAST_GENERATOR_IDX=7 + +:: Is generator shorthand used? +set GEN_SHORTHAND=!GENERATOR:vs=! + +if not "!GEN_SHORTHAND!"=="" if !GEN_SHORTHAND!==!GENERATOR! goto :GeneratorShorthandCheckDone +set VS_PLATFORM=Win32 +:: "echo if" trick from http://stackoverflow.com/a/8758579 +echo(!GEN_SHORTHAND! | findstr /c:"-x86" >nul && ( set "VS_PLATFORM=Win32" ) +echo(!GEN_SHORTHAND! | findstr /c:"-x64" >nul && ( set "VS_PLATFORM=x64" ) +echo(!GEN_SHORTHAND! | findstr /c:"-ARM" >nul && ( set "VS_PLATFORM=ARM" ) +echo(!GEN_SHORTHAND! | findstr /c:"-ARM64" >nul && ( set "VS_PLATFORM=ARM64" ) + +echo(!GEN_SHORTHAND! | findstr /c:"-v90" >nul && ( set "VS_TOOLSET=v90" ) && ( set "BOOST_TOOLSET=9.0" ) +echo(!GEN_SHORTHAND! | findstr /c:"-v100" >nul && ( set "VS_TOOLSET=v100" ) && ( set "BOOST_TOOLSET=10.0" ) +echo(!GEN_SHORTHAND! | findstr /c:"-v110" >nul && ( set "VS_TOOLSET=v110" ) && ( set "BOOST_TOOLSET=11.0" ) +echo(!GEN_SHORTHAND! | findstr /c:"-v110_xp" >nul && ( set "VS_TOOLSET=v110_xp" ) && ( set "BOOST_TOOLSET=11.0" ) +echo(!GEN_SHORTHAND! | findstr /c:"-v120" >nul && ( set "VS_TOOLSET=v120" ) && ( set "BOOST_TOOLSET=12.0" ) +echo(!GEN_SHORTHAND! | findstr /c:"-v120_xp" >nul && ( set "VS_TOOLSET=v120_xp" ) && ( set "BOOST_TOOLSET=12.0" ) +echo(!GEN_SHORTHAND! | findstr /c:"-v140" >nul && ( set "VS_TOOLSET=v140" ) && ( set "BOOST_TOOLSET=14.0" ) +echo(!GEN_SHORTHAND! | findstr /c:"-v140_xp" >nul && ( set "VS_TOOLSET=v140_xp" ) && ( set "BOOST_TOOLSET=14.0" ) +echo(!GEN_SHORTHAND! | findstr /c:"-v141" >nul && ( set "VS_TOOLSET=v141" ) && ( set "BOOST_TOOLSET=14.1" ) +echo(!GEN_SHORTHAND! | findstr /c:"-v141_xp" >nul && ( set "VS_TOOLSET=v141_xp" ) && ( set "BOOST_TOOLSET=14.1" ) +echo(!GEN_SHORTHAND! | findstr /c:"-v142" >nul && ( set "VS_TOOLSET=v142" ) && ( set "BOOST_TOOLSET=14.2" ) + +SET VS_VER=%GEN_SHORTHAND:~0,4% + +echo(!GENERATOR! | findstr /c:"vs20" >nul && ( + for /L %%i in (0,1,%LAST_GENERATOR_IDX%) do ( + echo(!GENERATORS[%%i]! | findstr /c:"!VS_VER!" >nul && ( + set GENERATOR=!GENERATORS[%%i]! + goto :GeneratorShorthandCheckDone + ) + ) +) +:GeneratorShorthandCheckDone + +:: Deduce desired architecture from the location of cl.exe +:: TODO harmless "INFO: Could not find files for the given pattern(s)." spam if cl.exe not in path +:: Look for path with either "amd64" or "x64" (VS 2017 and newer) +where cl.exe | findstr "amd64 x64" >nul +set START=%ERRORLEVEL% + +IF "!GENERATOR!"=="" IF NOT "%VisualStudioVersion%"=="" ( + set VC_VER=%VisualStudioVersion:.0=% + FOR /L %%i in (%START%,1,%LAST_GENERATOR_IDX%) DO ( + :: NOTE add space before VC_VER so that e.g. "12" doesn't match with "2012" + echo(!GENERATORS[%%i]! | findstr /c:" !VC_VER!" >nul && ( + set GENERATOR=!GENERATORS[%%i]! + call utils\cecho.cmd black cyan "Generator not passed, but VisualStudioVersion=%VisualStudioVersion% environment variable detected:" + call utils\cecho.cmd black cyan "using '`"!GENERATOR!`'" as the generator." + GOTO :GeneratorValid + ) + ) +) + +:: Check that the used CMake version supports the chosen generator +set GENERATOR_CHECK=%GENERATOR: Win64=% +cmake --help | findstr /c:%GENERATOR_CHECK% >nul +if not %ERRORLEVEL%==0 ( +call utils\cecho.cmd 0 12 "%~nx0: The used CMake version does not support '`"!GENERATOR!`'"- cannot proceed." +exit /b 1 +) + +FOR /L %%i in (0,1,%LAST_GENERATOR_IDX%) DO ( + IF !GENERATOR!==!GENERATORS[%%i]! GOTO :GeneratorValid +) +call utils\cecho.cmd 0 12 "%~nx0: Invalid or unsupported CMake generator string passed: '`"!GENERATOR!`'"- cannot proceed." +echo Supported CMake generator strings: +FOR /L %%i in (0,1,%LAST_GENERATOR_IDX%) DO ( + echo !GENERATORS[%%i]! +) +exit /b 1 + +:GeneratorValid + +IF DEFINED VS_PLATFORM goto :PlatformDefined + +:: If we do not have defined a platform yet, +:: figure out the build configuration from the CMake generator string. +:: Are we building 32-bit or 64-bit version. +:: Visual Studio platform name, Win32 (i.e. x86) or x64. +set VS_PLATFORM=Win32 + +:: Find out VS (e.g. 2015) and VC (e.g. 14) versions and are we targeting x64 or not (x86). +:: VS_VER and VC_VER are convenience variables used f.ex. for filenames. +set GENERATOR_NO_DOUBLEQUOTES=%GENERATOR:"=% +set GENERATOR_SPLIT=%GENERATOR_NO_DOUBLEQUOTES: =,% +FOR %%i IN (%GENERATOR_SPLIT%) DO ( + call :StrLength LEN %%i + IF !LEN!==1 set VC_VER=%%i + IF !LEN!==2 set VC_VER=%%i + IF !LEN!==4 set VS_VER=%%i + :: Are going to perform a 64-bit build? + IF %%i==Win64 ( + set VS_PLATFORM=x64 + ) +) + +:PlatformDefined + +:: determine the Visual C++ default version +IF %VS_VER%==2008 ( set "VC_VER=9.0" ) +IF %VS_VER%==2010 ( set "VC_VER=10.0" ) +IF %VS_VER%==2012 ( set "VC_VER=11.0" ) +IF %VS_VER%==2013 ( set "VC_VER=12.0" ) +IF %VS_VER%==2015 ( set "VC_VER=14.0" ) +IF %VS_VER%==2017 ( set "VC_VER=14.1" ) +IF %VS_VER%==2019 ( set "VC_VER=14.2" ) + +:: determine the argument for Boost bootstrap +set BOOST_BOOTSTRAP_VER=vc%VC_VER% +set BOOST_BOOTSTRAP_VER=%BOOST_BOOTSTRAP_VER:.=% + +:: determine the toolset and winapi for Boost b2 +IF DEFINED VS_TOOLSET ( + set BOOST_TOOLSET=msvc-%BOOST_TOOLSET% + if "!VS_TOOLSET:~-3!"=="_xp" ( + set BOOST_WIN_API=define=BOOST_USE_WINAPI_VERSION=0x0501 + ) +) ELSE ( + set BOOST_TOOLSET=msvc-%VC_VER% + set BOOST_WIN_API= +) + +IF %VS_PLATFORM%==Win32 ( + set ARCH_BITS=32 + set TARGET_ARCH=x86 +) + +IF %VS_PLATFORM%==x64 ( + set ARCH_BITS=64 + set TARGET_ARCH=x64 +) + +IF %VS_PLATFORM%==ARM ( + set ARCH_BITS=32 + set TARGET_ARCH=ARM +) + +IF %VS_PLATFORM%==ARM64 ( + set ARCH_BITS=64 + set TARGET_ARCH=ARM64 +) + +:: Check CMake version and convert possible new format (>= 3.0) generator names to the old versions if using older CMake for VS <= 2013, +:: see http://www.cmake.org/cmake/help/v3.0/release/3.0.0.html#other-changes +FOR /f "delims=" %%i in ('where cmake') DO set CMAKE_PATH=%%i +IF NOT "%CMAKE_PATH%"=="" ( + FOR /f "delims=" %%i in ('cmake --version ^| findstr /C:"cmake version 3"') DO GOTO :CMake3AndNewer +) +:: CMake older than 3.0.0: convert new format generators to the old format (simple brute force for simplicity) +set GENERATOR=%GENERATOR: 2013=% +set GENERATOR=%GENERATOR: 2012=% +set GENERATOR=%GENERATOR: 2010=% +:CMake3AndNewer + + :: check variables for debugging + echo GENERATOR: [!GENERATOR!] + echo VS_VER: [!VS_VER!] + echo VS_PLATFORM: [!VS_PLATFORM!] + echo VS_TOOLSET: [!VS_TOOLSET!] + echo VC_VER: [!VC_VER!] + echo ARCH_BITS: [!ARCH_BITS!] + echo TARGET_ARCH: [!TARGET_ARCH!] + echo BOOST_BOOTSTRAP_VER: [!BOOST_BOOTSTRAP_VER!] + echo BOOST_TOOLSET: [!BOOST_TOOLSET!] + echo BOOST_WIN_API: [!BOOST_WIN_API!] + pause + +IF DEFINED VS_TOOLSET ( + set GEN_SHORTHAND=vs%VS_VER%-%VS_PLATFORM%-%VS_TOOLSET% +) ELSE ( + set GEN_SHORTHAND=vs%VS_VER%-%VS_PLATFORM% +) + +:: VS project file extension is different on older VS versions +set VCPROJ_FILE_EXT=vcxproj +IF %VS_VER%==2008 set VCPROJ_FILE_EXT=vcproj + +:: Add utils to PATH +set ORIGINAL_PATH=%PATH% +set PATH=%~dp0utils;%PATH% + +:: Fetch and build the dependencies to a dedicated directory depending on the used VS version and target architecture. +:: NOTE For IfcOpenShell we can build all of our deps both x86 and x64 using different VS versions in the same directories +:: so no need for -%VS_VER%-%TARGET_ARCH% postfix. +:: set DEPS_DIR=%CD%\deps-%VS_VER%-%TARGET_ARCH% +pushd .. +set DEPS_DIR=%CD%\deps +set INSTALL_DIR=%CD%\deps-%GEN_SHORTHAND%-installed +:: set INSTALL_DIR=%CD%\deps-vs%VS_VER%-%TARGET_ARCH%-%DEBUG_OR_RELEASE_LOWERCASE%-installed +:: BUILD_DIR is a relative build directory used for CMake-based projects +set BUILD_DIR=build-%GEN_SHORTHAND% +popd + +GOTO :EOF +:: http://geekswithblogs.net/SoftwareDoneRight/archive/2010/01/30/useful-dos-batch-functions-substring-and-length.aspx +:StrLength +set #=%2% +set length=0 +:stringLengthLoop +if defined # (set #=%#:~1%&set /A length += 1&goto stringLengthLoop) +::echo the string is %length% characters long! +set "%~1=%length%" +GOTO :EOF