Changes to the build scripts to support Visual Studio 2019

Changes to the build scripts to support Visual Studio 2019, to optionally use a toolset different from the default and to build correctly when more than a single Visual Studio version is installed.
This commit is contained in:
ahladik
2020-12-13 11:56:29 +01:00
committed by Thomas Krijnen
parent 3bbdc3f277
commit 36f51e19b5
4 changed files with 970 additions and 867 deletions
+560 -546
View File
File diff suppressed because it is too large Load Diff
+19 -19
View File
@@ -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. built or used as static libraries. Currently Release build is used for all libraries.
### MSVC ### MSVC
Execute `build-deps.cmd` to fetch, build and install the dependencies. The batch file will print the requirements for 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.
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.
`build-deps.cmd` expects a CMake generator as `%1` and a build configuration type (`RelWithDebInfo`, `Release`, `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.
`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. 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-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 "vs2013" => cmake -G "Visual Studio 12 2013" -A Win32
the defaults. The batch file will create `deps\` and `deps-vs<VERSION>-<ARCHITECTURE>-installed\` directories to the "vs2013-x86" => cmake -G "Visual Studio 12 2013" -A Win32
project root. Debug and release builds of the dependencies can co-exist by simply running "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<VERSION>-<PLATFORM>[-<TOOLSET>]-installed\` directories to the project root. Debug and release builds of the dependencies can co-exist by simply running:
``` ```
> build-deps.cmd <GENERATOR> Debug > build-deps.cmd <GENERATOR> Debug
> build-deps.cmd <GENERATOR> <Release|RelWithDebInfo|MinSizeRel> > build-deps.cmd <GENERATOR> <Release|RelWithDebInfo|MinSizeRel>
``` ```
After the dependencies are build, execute `run-cmake.bat`. The batch file expects a CMake generator as `%1` and the 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:
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 > 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 **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<VERSION>-<PLATFORM>[-<TOOLSET>]\` which will contain the solution and project files for MSVC.
script will create a folder of form `build-vs<VERSION>-<ARCHITECTURE>\` 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 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.
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 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 if wanted. Convenience batch files `build-ifcopenshell.bat` and `install-ifcopenshell.bat` can also be used. The batch
+135 -127
View File
@@ -1,127 +1,135 @@
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: :: :: ::
:: This file is part of IfcOpenShell. :: :: This file is part of IfcOpenShell. ::
:: :: :: ::
:: IfcOpenShell is free software: you can redistribute it and/or modify :: :: 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 :: :: 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 :: :: the Free Software Foundation, either version 3.0 of the License, or ::
:: (at your option) any later version. :: :: (at your option) any later version. ::
:: :: :: ::
:: IfcOpenShell is distributed in the hope that it will be useful, :: :: IfcOpenShell is distributed in the hope that it will be useful, ::
:: but WITHOUT ANY WARRANTY; without even the implied warranty of :: :: but WITHOUT ANY WARRANTY; without even the implied warranty of ::
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the :: :: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ::
:: Lesser GNU General Public License for more details. :: :: Lesser GNU General Public License for more details. ::
:: :: :: ::
:: You should have received a copy of the Lesser GNU General Public License :: :: You should have received a copy of the Lesser GNU General Public License ::
:: along with this program. If not, see <http://www.gnu.org/licenses/>. :: :: along with this program. If not, see <http://www.gnu.org/licenses/>. ::
:: :: :: ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off @echo off
echo. echo.
set PROJECT_NAME=IfcOpenShell set PROJECT_NAME=IfcOpenShell
setlocal EnableDelayedExpansion setlocal EnableDelayedExpansion
set IFCOS_PAUSE_ON_ERROR= set IFCOS_PAUSE_ON_ERROR=
:: Read cached variables from the most recently modified BuildDepsCache.txt. :: 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 "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 for /f "delims== tokens=1,2" %%G in (%%f) do set %%G=%%H
) )
set GENERATOR=%1 set GENERATOR=%1
if (%1)==() ( if (%1)==() (
if not defined GEN_SHORTHAND ( 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. 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 set IFCOS_PAUSE_ON_ERROR=pause
goto :Error goto :Error
) )
set GENERATOR=%GEN_SHORTHAND% set GENERATOR=%GEN_SHORTHAND%
echo Generator not passed, but GEN_SHORTHAND=!GENERATOR! read from BuildDepsCache echo Generator not passed, but GEN_SHORTHAND=!GENERATOR! read from BuildDepsCache
echo. echo.
) )
call vs-cfg.cmd %GENERATOR% call vs-cfg.cmd %GENERATOR%
IF NOT %ERRORLEVEL%==0 GOTO :Error 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, :: 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 :: 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 :: %6 %7 %8 %9. Work around that, http://scripts.dragon-it.co.uk/scripts.nsf/docs/batch-search-replace-substitute
if not (%1)==() ( if not (%1)==() (
set ARGUMENTS=%* set ARGUMENTS=%*
call set ARGUMENTS=%%ARGUMENTS:%1=%% call set ARGUMENTS=%%ARGUMENTS:%1=%%
) )
pushd .. pushd ..
set CMAKE_INSTALL_PREFIX=%CD%\installed-vs%VS_VER%-%TARGET_ARCH% set CMAKE_INSTALL_PREFIX=%CD%\installed-%GEN_SHORTHAND%
popd popd
IF NOT EXIST ..\%BUILD_DIR%. mkdir ..\%BUILD_DIR% IF NOT EXIST ..\%BUILD_DIR%. mkdir ..\%BUILD_DIR%
pushd ..\%BUILD_DIR% pushd ..\%BUILD_DIR%
:: tfk: todo remove duplication :: tfk: todo remove duplication
set BOOST_VERSION=1.67.0 set BOOST_VERSION=1.71.0
set BOOST_VER=%BOOST_VERSION:.=_% set BOOST_VER=%BOOST_VERSION:.=_%
set BOOST_ROOT=%DEPS_DIR%\boost_%BOOST_VER% set BOOST_ROOT=%DEPS_DIR%\boost_%BOOST_VER%
set BOOST_LIBRARYDIR=%BOOST_ROOT%\stage\vs%VS_VER%-%VS_PLATFORM%\lib 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_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 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_INCLUDE_DIR=%INSTALL_DIR%\OpenCOLLADA\include\opencollada
set OPENCOLLADA_LIBRARY_DIR=%INSTALL_DIR%\OpenCOLLADA\lib\opencollada set OPENCOLLADA_LIBRARY_DIR=%INSTALL_DIR%\OpenCOLLADA\lib\opencollada
set LIBXML2_INCLUDE_DIR=%DEPS_DIR%\OpenCOLLADA\Externals\LibXML\include set LIBXML2_INCLUDE_DIR=%DEPS_DIR%\OpenCOLLADA\Externals\LibXML\include
set LIBXML2_LIBRARIES=%INSTALL_DIR%\OpenCOLLADA\lib\opencollada\xml.lib 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 PY_VER_MAJOR_MINOR set PY_VER_MAJOR_MINOR=34
if not defined PYTHONHOME set PYTHONHOME=%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR% if not defined PYTHONHOME set PYTHONHOME=%INSTALL_DIR%\Python%PY_VER_MAJOR_MINOR%
set PYTHON_INCLUDE_DIR=%PYTHONHOME%\include set PYTHON_INCLUDE_DIR=%PYTHONHOME%\include
set PYTHON_LIBRARY=%PYTHONHOME%\libs\python%PY_VER_MAJOR_MINOR%.lib set PYTHON_LIBRARY=%PYTHONHOME%\libs\python%PY_VER_MAJOR_MINOR%.lib
set PYTHON_EXECUTABLE=%PYTHONHOME%\python.exe set PYTHON_EXECUTABLE=%PYTHONHOME%\python.exe
set SWIG_DIR=%INSTALL_DIR%\swigwin set SWIG_DIR=%INSTALL_DIR%\swigwin
set PATH=%PATH%;%SWIG_DIR%;%PYTHONHOME% set PATH=%PATH%;%SWIG_DIR%;%PYTHONHOME%
set JSON_INCLUDE_DIR=%INSTALL_DIR%\json set JSON_INCLUDE_DIR=%INSTALL_DIR%\json
echo. echo.
call cecho.cmd 0 10 "Script configuration:" call cecho.cmd 0 10 "Script configuration:"
echo Generator = %GENERATOR% echo Generator = %GENERATOR%
echo Arguments = %ARGUMENTS% echo Architecture = %VS_PLATFORM%
echo. echo Toolset = %VS_TOOLSET%
call cecho.cmd 0 10 "Dependency Environment Variables for %PROJECT_NAME%:" echo Arguments = %ARGUMENTS%
echo BOOST_ROOT = %BOOST_ROOT% echo.
echo BOOST_LIBRARYDIR = %BOOST_LIBRARYDIR% call cecho.cmd 0 10 "Dependency Environment Variables for %PROJECT_NAME%:"
echo OCC_INCLUDE_DIR = %OCC_INCLUDE_DIR% echo BOOST_ROOT = %BOOST_ROOT%
echo OCC_LIBRARY_DIR = %OCC_LIBRARY_DIR% echo BOOST_LIBRARYDIR = %BOOST_LIBRARYDIR%
echo OPENCOLLADA_INCLUDE_DIR = %OPENCOLLADA_INCLUDE_DIR% echo OCC_INCLUDE_DIR = %OCC_INCLUDE_DIR%
echo OPENCOLLADA_LIBRARY_DIR = %OPENCOLLADA_LIBRARY_DIR% echo OCC_LIBRARY_DIR = %OCC_LIBRARY_DIR%
echo LIBXML2_INCLUDE_DIR = %LIBXML2_INCLUDE_DIR% echo OPENCOLLADA_INCLUDE_DIR = %OPENCOLLADA_INCLUDE_DIR%
echo LIBXML2_LIBRARIES = %LIBXML2_LIBRARIES% echo OPENCOLLADA_LIBRARY_DIR = %OPENCOLLADA_LIBRARY_DIR%
echo PYTHONHOME = %PYTHONHOME% echo LIBXML2_INCLUDE_DIR = %LIBXML2_INCLUDE_DIR%
echo PYTHON_INCLUDE_DIR = %PYTHON_INCLUDE_DIR% echo LIBXML2_LIBRARIES = %LIBXML2_LIBRARIES%
echo PYTHON_LIBRARY = %PYTHON_LIBRARY% echo PYTHONHOME = %PYTHONHOME%
echo PYTHON_EXECUTABLE = %PYTHON_EXECUTABLE% echo PYTHON_INCLUDE_DIR = %PYTHON_INCLUDE_DIR%
echo SWIG_DIR = %SWIG_DIR% echo PYTHON_LIBRARY = %PYTHON_LIBRARY%
echo JSON_INCLUDE_DIR = %JSON_INCLUDE_DIR% echo PYTHON_EXECUTABLE = %PYTHON_EXECUTABLE%
echo. echo SWIG_DIR = %SWIG_DIR%
echo CMAKE_INSTALL_PREFIX = %CMAKE_INSTALL_PREFIX% echo JSON_INCLUDE_DIR = %JSON_INCLUDE_DIR%
echo. echo.
echo CMAKE_INSTALL_PREFIX = %CMAKE_INSTALL_PREFIX%
set CMAKELISTS_DIR=..\cmake echo.
:: Delete CMakeCache.txt if command-line options were provided for this batch script.
if not (%1)==() if exist CMakeCache.txt. del /Q CMakeCache.txt set CMAKELISTS_DIR=..\cmake
call cecho.cmd 0 13 "Running CMake for %PROJECT_NAME%." :: Delete CMakeCache.txt if command-line options were provided for this batch script.
cmake.exe %CMAKELISTS_DIR% -G %GENERATOR% -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" %ARGUMENTS% if not (%1)==() if exist CMakeCache.txt. del /Q CMakeCache.txt
IF NOT %ERRORLEVEL%==0 GOTO :Error call cecho.cmd 0 13 "Running CMake for %PROJECT_NAME%."
echo. IF DEFINED VS_TOOLSET (
cmake.exe %CMAKELISTS_DIR% -G %GENERATOR% -A %VS_PLATFORM% -T %VS_TOOLSET% -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" %ARGUMENTS%
set IFCOS_SCRIPT_RET=0 ) ELSE (
goto :Finish cmake.exe %CMAKELISTS_DIR% -G %GENERATOR% -A %VS_PLATFORM% -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" %ARGUMENTS%
)
:Error
echo. IF NOT %ERRORLEVEL%==0 GOTO :Error
call "%~dp0\utils\cecho.cmd" 0 12 "An error occurred! Aborting!"
%IFCOS_PAUSE_ON_ERROR% echo.
set IFCOS_SCRIPT_RET=1
goto :Finish set IFCOS_SCRIPT_RET=0
goto :Finish
:Finish
popd :Error
exit /b %IFCOS_SCRIPT_RET% 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%
+256 -175
View File
@@ -1,175 +1,256 @@
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: :: :: ::
:: This file is part of IfcOpenShell. :: :: This file is part of IfcOpenShell. ::
:: :: :: ::
:: IfcOpenShell is free software: you can redistribute it and/or modify :: :: 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 :: :: 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 :: :: the Free Software Foundation, either version 3.0 of the License, or ::
:: (at your option) any later version. :: :: (at your option) any later version. ::
:: :: :: ::
:: IfcOpenShell is distributed in the hope that it will be useful, :: :: IfcOpenShell is distributed in the hope that it will be useful, ::
:: but WITHOUT ANY WARRANTY; without even the implied warranty of :: :: but WITHOUT ANY WARRANTY; without even the implied warranty of ::
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the :: :: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ::
:: Lesser GNU General Public License for more details. :: :: Lesser GNU General Public License for more details. ::
:: :: :: ::
:: You should have received a copy of the Lesser GNU General Public License :: :: You should have received a copy of the Lesser GNU General Public License ::
:: along with this program. If not, see <http://www.gnu.org/licenses/>. :: :: along with this program. If not, see <http://www.gnu.org/licenses/>. ::
:: :: :: ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::
:: This script initializes various Visual Studio related environment variables needed for building. :: This script initializes various Visual Studio related environment variables.
:: 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. :: It expects a CMake generator as %1. If %1 is not provided, it is deduced from
:: User-friendly VS generators are allowed (e.g. "vs2013-x86") and converted to the appropriate CMake ones. :: the VisualStudioVersion environment variable and from the location of cl.exe.
::
:: NOTE This batch file expects the generator string to be CMake 3.0.0 and newer format, i.e. :: The generator string must be in the CMake 3.0 and newer format, i.e.
:: "Visual Studio 10 2010" instead of "Visual Studio 10". However, one can use this batch file :: "Visual Studio 10 2010" instead of "Visual Studio 10"
:: also with CMake 2 as the generator will be converted into the older format if necessary. ::
:: User-friendly VS generators are preferred, since they permit a more accurate
:: NOTE: The delayed environment variable expansion needs to be enabled before calling this. :: platform and toolset configuration. Some examples:
::
@echo off :: "vs2013" => cmake -G "Visual Studio 12 2013" -A Win32
:: "vs2013-x86" => cmake -G "Visual Studio 12 2013" -A Win32
set GENERATOR=%1 :: "vs2015-x64" => cmake -G "Visual Studio 14 2015" -A x64
:: "vs2017-ARM64" => cmake -G "Visual Studio 15 2017" -A ARM64
:: Supported Visual Studio versions: :: "vs2019-x86-v141_xp" => cmake -G "Visual Studio 16 2019" -A Win32 -T v141_xp
set GENERATORS[0]="Visual Studio 9 2008 Win64" ::
set GENERATORS[1]="Visual Studio 9 2008" :: NOTE: The delayed environment variable expansion needs to be enabled before calling this.
set GENERATORS[2]="Visual Studio 10 2010 Win64"
set GENERATORS[3]="Visual Studio 10 2010" @echo off
set GENERATORS[4]="Visual Studio 11 2012 Win64"
set GENERATORS[5]="Visual Studio 11 2012" set GENERATOR=%1
set GENERATORS[6]="Visual Studio 12 2013 Win64"
set GENERATORS[7]="Visual Studio 12 2013" :: Supported Visual Studio versions:
set GENERATORS[8]="Visual Studio 14 2015 Win64" set GENERATORS[1]="Visual Studio 9 2008"
set GENERATORS[9]="Visual Studio 14 2015" set GENERATORS[2]="Visual Studio 10 2010"
:: NOTE VC version for VS 2017 is not 15 but 14.1: have to wait and see set GENERATORS[3]="Visual Studio 11 2012"
:: if CMake generator string is updated to reflect this. set GENERATORS[4]="Visual Studio 12 2013"
set GENERATORS[10]="Visual Studio 15 2017 Win64" set GENERATORS[5]="Visual Studio 14 2015"
set GENERATORS[11]="Visual Studio 15 2017" set GENERATORS[6]="Visual Studio 15 2017"
set LAST_GENERATOR_IDX=11 set GENERATORS[7]="Visual Studio 16 2019"
set LAST_GENERATOR_IDX=7
set STEP=2
:: Is generator shorthand used? :: Is generator shorthand used?
set GEN_SHORTHAND=!GENERATOR:vs=! set GEN_SHORTHAND=!GENERATOR:vs=!
if not "!GEN_SHORTHAND!"=="" if !GEN_SHORTHAND!==!GENERATOR! goto :GeneratorShorthandCheckDone
set START=%LAST_GENERATOR_IDX% if not "!GEN_SHORTHAND!"=="" if !GEN_SHORTHAND!==!GENERATOR! goto :GeneratorShorthandCheckDone
:: "echo if" trick from http://stackoverflow.com/a/8758579 set VS_PLATFORM=Win32
echo(!GEN_SHORTHAND! | findstr /c:"-x86" >nul && ( set START=1 ) :: "echo if" trick from http://stackoverflow.com/a/8758579
echo(!GEN_SHORTHAND! | findstr /c:"-x64" >nul && ( set START=0 ) echo(!GEN_SHORTHAND! | findstr /c:"-x86" >nul && ( set "VS_PLATFORM=Win32" )
set VS_VER=!GEN_SHORTHAND:-x86=! echo(!GEN_SHORTHAND! | findstr /c:"-x64" >nul && ( set "VS_PLATFORM=x64" )
set VS_VER=!VS_VER:-x64=! echo(!GEN_SHORTHAND! | findstr /c:"-ARM" >nul && ( set "VS_PLATFORM=ARM" )
echo(!GENERATOR! | findstr /c:"vs20" >nul && ( echo(!GEN_SHORTHAND! | findstr /c:"-ARM64" >nul && ( set "VS_PLATFORM=ARM64" )
for /l %%i in (!START!,!STEP!,%LAST_GENERATOR_IDX%) do (
echo(!GENERATORS[%%i]! | findstr /c:"!VS_VER!" >nul && ( echo(!GEN_SHORTHAND! | findstr /c:"-v90" >nul && ( set "VS_TOOLSET=v90" ) && ( set "BOOST_TOOLSET=9.0" )
set GENERATOR=!GENERATORS[%%i]! echo(!GEN_SHORTHAND! | findstr /c:"-v100" >nul && ( set "VS_TOOLSET=v100" ) && ( set "BOOST_TOOLSET=10.0" )
goto :GeneratorShorthandCheckDone 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" )
:GeneratorShorthandCheckDone 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" )
:: Deduce desired architecture from the location of cl.exe echo(!GEN_SHORTHAND! | findstr /c:"-v141" >nul && ( set "VS_TOOLSET=v141" ) && ( set "BOOST_TOOLSET=14.1" )
:: TODO harmless "INFO: Could not find files for the given pattern(s)." spam if cl.exe not in path echo(!GEN_SHORTHAND! | findstr /c:"-v141_xp" >nul && ( set "VS_TOOLSET=v141_xp" ) && ( set "BOOST_TOOLSET=14.1" )
:: Look for path with either "amd64" or "x64" (VS 2017 and newer) echo(!GEN_SHORTHAND! | findstr /c:"-v142" >nul && ( set "VS_TOOLSET=v142" ) && ( set "BOOST_TOOLSET=14.2" )
where cl.exe | findstr "amd64 x64" >nul
set START=%ERRORLEVEL% SET VS_VER=%GEN_SHORTHAND:~0,4%
IF "!GENERATOR!"=="" IF NOT "%VisualStudioVersion%"=="" ( echo(!GENERATOR! | findstr /c:"vs20" >nul && (
set VC_VER=%VisualStudioVersion:.0=% for /L %%i in (0,1,%LAST_GENERATOR_IDX%) do (
FOR /l %%i in (%START%,%STEP%,%LAST_GENERATOR_IDX%) DO ( echo(!GENERATORS[%%i]! | findstr /c:"!VS_VER!" >nul && (
REM NOTE add space before VC_VER so that e.g. "12" doesn't match with "2012" set GENERATOR=!GENERATORS[%%i]!
echo(!GENERATORS[%%i]! | findstr /c:" !VC_VER!" >nul && ( goto :GeneratorShorthandCheckDone
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 :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
:: Check that the used CMake version supports the chosen generator :: Look for path with either "amd64" or "x64" (VS 2017 and newer)
set GENERATOR_CHECK=%GENERATOR: Win64=% where cl.exe | findstr "amd64 x64" >nul
cmake --help | findstr /c:%GENERATOR_CHECK% >nul set START=%ERRORLEVEL%
if not %ERRORLEVEL%==0 (
call utils\cecho.cmd 0 12 "%~nx0: The used CMake version does not support '`"!GENERATOR!`'"- cannot proceed." IF "!GENERATOR!"=="" IF NOT "%VisualStudioVersion%"=="" (
exit /b 1 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"
FOR /l %%i in (0,1,%LAST_GENERATOR_IDX%) DO ( echo(!GENERATORS[%%i]! | findstr /c:" !VC_VER!" >nul && (
IF !GENERATOR!==!GENERATORS[%%i]! GOTO :GeneratorValid set GENERATOR=!GENERATORS[%%i]!
) call utils\cecho.cmd black cyan "Generator not passed, but VisualStudioVersion=%VisualStudioVersion% environment variable detected:"
call utils\cecho.cmd 0 12 "%~nx0: Invalid or unsupported CMake generator string passed: '`"!GENERATOR!`'"- cannot proceed." call utils\cecho.cmd black cyan "using '`"!GENERATOR!`'" as the generator."
echo Supported CMake generator strings: GOTO :GeneratorValid
FOR /l %%i in (0,1,%LAST_GENERATOR_IDX%) DO ( )
echo !GENERATORS[%%i]! )
) )
exit /b 1
:: Check that the used CMake version supports the chosen generator
:GeneratorValid set GENERATOR_CHECK=%GENERATOR: Win64=%
:: Figure out the build configuration from the CMake generator string. cmake --help | findstr /c:%GENERATOR_CHECK% >nul
:: Are we building 32-bit or 64-bit version. if not %ERRORLEVEL%==0 (
set ARCH_BITS=32 call utils\cecho.cmd 0 12 "%~nx0: The used CMake version does not support '`"!GENERATOR!`'"- cannot proceed."
set TARGET_ARCH=x86 exit /b 1
:: Visual Studio platform name, Win32 (i.e. x86) or x64. )
set VS_PLATFORM=Win32
FOR /L %%i in (0,1,%LAST_GENERATOR_IDX%) DO (
:: Find out VS (e.g. 2015) and VC (e.g. 14) versions and are we targeting x64 or not (x86). IF !GENERATOR!==!GENERATORS[%%i]! GOTO :GeneratorValid
:: VS_VER and VC_VER are convenience variables used f.ex. for filenames. )
set GENERATOR_NO_DOUBLEQUOTES=%GENERATOR:"=% call utils\cecho.cmd 0 12 "%~nx0: Invalid or unsupported CMake generator string passed: '`"!GENERATOR!`'"- cannot proceed."
set GENERATOR_SPLIT=%GENERATOR_NO_DOUBLEQUOTES: =,% echo Supported CMake generator strings:
FOR %%i IN (%GENERATOR_SPLIT%) DO ( FOR /L %%i in (0,1,%LAST_GENERATOR_IDX%) DO (
call :StrLength LEN %%i echo !GENERATORS[%%i]!
IF !LEN!==1 set VC_VER=%%i )
IF !LEN!==2 set VC_VER=%%i exit /b 1
IF !LEN!==4 set VS_VER=%%i
REM Are going to perform a 64-bit build? :GeneratorValid
IF %%i==Win64 (
set ARCH_BITS=64 IF DEFINED VS_PLATFORM goto :PlatformDefined
set TARGET_ARCH=x64
set VS_PLATFORM=x64 :: 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.
:: Check CMake version and convert possible new format (>= 3.0) generator names to the old versions if using older CMake for VS <= 2013, set VS_PLATFORM=Win32
:: 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 :: Find out VS (e.g. 2015) and VC (e.g. 14) versions and are we targeting x64 or not (x86).
IF NOT "%CMAKE_PATH%"=="" ( :: VS_VER and VC_VER are convenience variables used f.ex. for filenames.
FOR /f "delims=" %%i in ('cmake --version ^| findstr /C:"cmake version 3"') DO GOTO :CMake3AndNewer set GENERATOR_NO_DOUBLEQUOTES=%GENERATOR:"=%
) set GENERATOR_SPLIT=%GENERATOR_NO_DOUBLEQUOTES: =,%
:: CMake older than 3.0.0: convert new format generators to the old format (simple brute force for simplicity) FOR %%i IN (%GENERATOR_SPLIT%) DO (
set GENERATOR=%GENERATOR: 2013=% call :StrLength LEN %%i
set GENERATOR=%GENERATOR: 2012=% IF !LEN!==1 set VC_VER=%%i
set GENERATOR=%GENERATOR: 2010=% IF !LEN!==2 set VC_VER=%%i
:CMake3AndNewer IF !LEN!==4 set VS_VER=%%i
:: Are going to perform a 64-bit build?
set GEN_SHORTHAND=vs%VS_VER%-%TARGET_ARCH% IF %%i==Win64 (
:: VS project file extension is different on older VS versions set VS_PLATFORM=x64
set VCPROJ_FILE_EXT=vcxproj )
IF %VS_VER%==2008 set VCPROJ_FILE_EXT=vcproj )
:: Add utils to PATH :PlatformDefined
set ORIGINAL_PATH=%PATH%
set PATH=%~dp0utils;%PATH% :: determine the Visual C++ default version
IF %VS_VER%==2008 ( set "VC_VER=9.0" )
:: Fetch and build the dependencies to a dedicated directory depending on the used VS version and target architecture. IF %VS_VER%==2010 ( set "VC_VER=10.0" )
:: NOTE For IfcOpenShell we can build all of our deps both x86 and x64 using different VS versions in the same directories IF %VS_VER%==2012 ( set "VC_VER=11.0" )
:: so no need for -%VS_VER%-%TARGET_ARCH% postfix. IF %VS_VER%==2013 ( set "VC_VER=12.0" )
:: set DEPS_DIR=%CD%\deps-%VS_VER%-%TARGET_ARCH% IF %VS_VER%==2015 ( set "VC_VER=14.0" )
pushd .. IF %VS_VER%==2017 ( set "VC_VER=14.1" )
set DEPS_DIR=%CD%\deps IF %VS_VER%==2019 ( set "VC_VER=14.2" )
set INSTALL_DIR=%CD%\deps-%GEN_SHORTHAND%-installed
REM set INSTALL_DIR=%CD%\deps-vs%VS_VER%-%TARGET_ARCH%-%DEBUG_OR_RELEASE_LOWERCASE%-installed :: determine the argument for Boost bootstrap
:: BUILD_DIR is a relative build directory used for CMake-based projects set BOOST_BOOTSTRAP_VER=vc%VC_VER%
set BUILD_DIR=build-%GEN_SHORTHAND% set BOOST_BOOTSTRAP_VER=%BOOST_BOOTSTRAP_VER:.=%
popd
:: determine the toolset and winapi for Boost b2
GOTO :EOF IF DEFINED VS_TOOLSET (
:: http://geekswithblogs.net/SoftwareDoneRight/archive/2010/01/30/useful-dos-batch-functions-substring-and-length.aspx set BOOST_TOOLSET=msvc-%BOOST_TOOLSET%
:StrLength if "!VS_TOOLSET:~-3!"=="_xp" (
set #=%2% set BOOST_WIN_API=define=BOOST_USE_WINAPI_VERSION=0x0501
set length=0 )
:stringLengthLoop ) ELSE (
if defined # (set #=%#:~1%&set /A length += 1&goto stringLengthLoop) set BOOST_TOOLSET=msvc-%VC_VER%
::echo the string is %length% characters long! set BOOST_WIN_API=
set "%~1=%length%" )
GOTO :EOF
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