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
+37 -23
View File
@@ -55,6 +55,14 @@ if not %ERRORLEVEL%==0 (
:: Set up variables depending on the used Visual Studio version :: Set up variables depending on the used Visual Studio version
call vs-cfg.cmd %1 call vs-cfg.cmd %1
IF NOT %ERRORLEVEL%==0 GOTO :Error 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 call build-type-cfg.cmd %2
IF NOT %ERRORLEVEL%==0 GOTO :Error IF NOT %ERRORLEVEL%==0 GOTO :Error
@@ -111,6 +119,10 @@ call cecho.cmd 0 13 "* CMake Generator`t= '`"%GENERATOR%`'`t
echo - Passed to CMake -G option. echo - Passed to CMake -G option.
call cecho.cmd 0 13 "* Target Architecture`t= %TARGET_ARCH%" call cecho.cmd 0 13 "* Target Architecture`t= %TARGET_ARCH%"
echo - Whether were doing 32-bit (x86) or 64-bit (x64) build. echo - Whether were doing 32-bit (x86) or 64-bit (x64) build.
call cecho.cmd 0 13 "* Target Platform`t= %VS_PLATFORM%"
echo - Passed to CMake -A option.
call cecho.cmd 0 13 "* Target Toolset`t= %VS_TOOLSET%"
echo - Passed to CMake -T option.
call cecho.cmd 0 13 "* Dependency Directory`t= %DEPS_DIR%" call cecho.cmd 0 13 "* Dependency Directory`t= %DEPS_DIR%"
echo - The directory where %PROJECT_NAME% dependencies are fetched and built. echo - The directory where %PROJECT_NAME% dependencies are fetched and built.
call cecho.cmd 0 13 "* Installation Directory = %INSTALL_DIR%" call cecho.cmd 0 13 "* Installation Directory = %INSTALL_DIR%"
@@ -146,7 +158,7 @@ set /p do_continue="> "
if "%do_continue%"=="n" goto :Finish if "%do_continue%"=="n" goto :Finish
:: Cache last used CMake generator for other scripts to use :: Cache last used CMake generator for other scripts to use
if defined GEN_SHORTHAND echo GEN_SHORTHAND=%GEN_SHORTHAND%>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" if defined GEN_SHORTHAND echo GEN_SHORTHAND=%GEN_SHORTHAND%>"%~dp0\%BUILDDEPTHCACHE%"
echo. echo.
set START_TIME=%TIME% set START_TIME=%TIME%
@@ -160,13 +172,13 @@ cd "%DEPS_DIR%"
:: by modifying this file and using goto. :: by modifying this file and using goto.
:Boost :Boost
:: NOTE Boost < 1.64 doesn't work without tricks if the user has only VS 2017 installed and no earlier versions. :: 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 set BOOST_VERSION=1.71.0
:: Version string with underscores instead of dots. :: Version string with underscores instead of dots.
set BOOST_VER=%BOOST_VERSION:.=_% set BOOST_VER=%BOOST_VERSION:.=_%
:: DEPENDENCY_NAME is used for logging and DEPENDENCY_DIR for saving from some redundant typing :: DEPENDENCY_NAME is used for logging and DEPENDENCY_DIR for saving from some redundant typing
set DEPENDENCY_NAME=Boost %BOOST_VERSION% set DEPENDENCY_NAME=Boost %BOOST_VERSION%
set DEPENDENCY_DIR=%DEPS_DIR%\boost_%BOOST_VER% set DEPENDENCY_DIR=%DEPS_DIR%\boost_%BOOST_VER%
set BOOST_LIBRARYDIR=%DEPENDENCY_DIR%\stage\%VS_PLATFORM%\lib set BOOST_LIBRARYDIR=%DEPENDENCY_DIR%\stage\%GEN_SHORTHAND%\lib
:: NOTE Also zip download exists, if encountering problems with 7z for some reason. :: NOTE Also zip download exists, if encountering problems with 7z for some reason.
set ZIP_EXT=7z set ZIP_EXT=7z
set BOOST_ZIP=boost_%BOOST_VER%.%ZIP_EXT% set BOOST_ZIP=boost_%BOOST_VER%.%ZIP_EXT%
@@ -183,7 +195,7 @@ if not exist "%DEPENDENCY_DIR%\project-config.jam". (
IF NOT EXIST "%DEPENDENCY_DIR%\boost.css" GOTO :Error IF NOT EXIST "%DEPENDENCY_DIR%\boost.css" GOTO :Error
cd "%DEPENDENCY_DIR%" cd "%DEPENDENCY_DIR%"
call cecho.cmd 0 13 "Building Boost build script." call cecho.cmd 0 13 "Building Boost build script."
call bootstrap msvc call bootstrap %BOOST_BOOTSTRAP_VER%
IF NOT %ERRORLEVEL%==0 GOTO :Error IF NOT %ERRORLEVEL%==0 GOTO :Error
) )
@@ -192,14 +204,10 @@ set BOOST_LIBS=--with-system --with-regex --with-thread --with-program_options -
cd "%DEPENDENCY_DIR%" cd "%DEPENDENCY_DIR%"
call cecho.cmd 0 13 "Building %DEPENDENCY_NAME% %BOOST_LIBS% Please be patient, this will take a while." 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" 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% ^ call .\b2 toolset=%BOOST_TOOLSET% 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% variant=%DEBUG_OR_RELEASE_LOWERCASE% %BOOST_WIN_API% %BOOST_LIBS% stage --stagedir=stage/%GEN_SHORTHAND%
IF NOT %ERRORLEVEL%==0 GOTO :Error IF NOT %ERRORLEVEL%==0 GOTO :Error
:JSON :JSON
@@ -237,10 +245,10 @@ if %IFCOS_USE_OCCT%==FALSE goto :OCE
set OCCT_VERSION=7.3.0p3 set OCCT_VERSION=7.3.0p3
SET OCCT_VER=V%OCCT_VERSION:.=_% SET OCCT_VER=V%OCCT_VERSION:.=_%
set OCC_INCLUDE_DIR=%INSTALL_DIR%\opencascade-%OCCT_VERSION%\inc>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" 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\BuildDepsCache-%TARGET_ARCH%.txt" set OCC_LIBRARY_DIR=%INSTALL_DIR%\opencascade-%OCCT_VERSION%\win%ARCH_BITS%\lib>>"%~dp0\%BUILDDEPTHCACHE%"
echo OCC_INCLUDE_DIR=%OCC_INCLUDE_DIR%>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" echo OCC_INCLUDE_DIR=%OCC_INCLUDE_DIR%>>"%~dp0\%BUILDDEPTHCACHE%"
echo OCC_LIBRARY_DIR=%OCC_LIBRARY_DIR%>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" echo OCC_LIBRARY_DIR=%OCC_LIBRARY_DIR%>>"%~dp0\%BUILDDEPTHCACHE%"
:: OCCT has many dependencies but FreeType is the only mandatory :: OCCT has many dependencies but FreeType is the only mandatory
set DEPENDENCY_NAME=FreeType set DEPENDENCY_NAME=FreeType
@@ -284,7 +292,7 @@ call :BuildSolution "%DEPENDENCY_DIR%\%BUILD_DIR%\OCCT.sln" %BUILD_CFG%
if not %ERRORLEVEL%==0 goto :Error if not %ERRORLEVEL%==0 goto :Error
call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG% call :InstallCMakeProject "%DEPENDENCY_DIR%\%BUILD_DIR%" %BUILD_CFG%
if not %ERRORLEVEL%==0 goto :Error if not %ERRORLEVEL%==0 goto :Error
:: Use a single lib directory for for release and debug libraries as is done with OCE :: 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%" 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 :: 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% set OCCT_VC_VER=%VC_VER%
@@ -303,10 +311,10 @@ del "%INSTALL_DIR%\opencascade-%OCCT_VERSION%\*.bat"
goto :Python goto :Python
:OCE :OCE
set OCC_INCLUDE_DIR=%INSTALL_DIR%\oce\include\oce>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" set OCC_INCLUDE_DIR=%INSTALL_DIR%\oce\include\oce>>"%~dp0\%BUILDDEPTHCACHE%"
set OCC_LIBRARY_DIR=%INSTALL_DIR%\oce\Win%ARCH_BITS%\lib>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" set OCC_LIBRARY_DIR=%INSTALL_DIR%\oce\Win%ARCH_BITS%\lib>>"%~dp0\%BUILDDEPTHCACHE%"
echo OCC_INCLUDE_DIR=%OCC_INCLUDE_DIR%>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" echo OCC_INCLUDE_DIR=%OCC_INCLUDE_DIR%>>"%~dp0\%BUILDDEPTHCACHE%"
echo OCC_LIBRARY_DIR=%OCC_LIBRARY_DIR%>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" echo OCC_LIBRARY_DIR=%OCC_LIBRARY_DIR%>>"%~dp0\%BUILDDEPTHCACHE%"
set DEPENDENCY_NAME=Open CASCADE Community Edition set DEPENDENCY_NAME=Open CASCADE Community Edition
set DEPENDENCY_DIR=%DEPS_DIR%\oce set DEPENDENCY_DIR=%DEPS_DIR%\oce
@@ -346,8 +354,8 @@ 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 :: 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" ( IF "%IFCOS_INSTALL_PYTHON%"=="TRUE" (
REM Store Python versions to BuildDepsCache.txt for run-cmake.bat 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 PY_VER_MAJOR_MINOR=%PY_VER_MAJOR_MINOR%>>"%~dp0\%BUILDDEPTHCACHE%"
echo PYTHONHOME=%PYTHONHOME%>>"%~dp0\BuildDepsCache-%TARGET_ARCH%.txt" echo PYTHONHOME=%PYTHONHOME%>>"%~dp0\%BUILDDEPTHCACHE%"
cd "%DEPS_DIR%" cd "%DEPS_DIR%"
call :DownloadFile https://www.python.org/ftp/python/%PYTHON_VERSION%/%PYTHON_INSTALLER% "%DEPS_DIR%" %PYTHON_INSTALLER% call :DownloadFile https://www.python.org/ftp/python/%PYTHON_VERSION%/%PYTHON_INSTALLER% "%DEPS_DIR%" %PYTHON_INSTALLER%
@@ -502,7 +510,13 @@ pushd %BUILD_DIR%
:: TODO make deleting cache a parameter for this subroutine? We probably want to delete the :: 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. :: 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 %BUILD_TYPE%==Rebuild IF EXIST CMakeCache.txt. del CMakeCache.txt
cmake .. -G %GENERATOR% %*
IF DEFINED VS_TOOLSET (
cmake .. -G %GENERATOR% -A %VS_PLATFORM% -T %VS_TOOLSET% %*
) ELSE (
cmake .. -G %GENERATOR% -A %VS_PLATFORM% %*
)
set RET=%ERRORLEVEL% set RET=%ERRORLEVEL%
popd popd
exit /b %RET% exit /b %RET%
+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
+12 -4
View File
@@ -52,18 +52,18 @@ if not (%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
@@ -82,6 +82,8 @@ 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 Architecture = %VS_PLATFORM%
echo Toolset = %VS_TOOLSET%
echo Arguments = %ARGUMENTS% echo Arguments = %ARGUMENTS%
echo. echo.
call cecho.cmd 0 10 "Dependency Environment Variables for %PROJECT_NAME%:" call cecho.cmd 0 10 "Dependency Environment Variables for %PROJECT_NAME%:"
@@ -107,7 +109,13 @@ set CMAKELISTS_DIR=..\cmake
:: Delete CMakeCache.txt if command-line options were provided for this batch script. :: Delete CMakeCache.txt if command-line options were provided for this batch script.
if not (%1)==() if exist CMakeCache.txt. del /Q CMakeCache.txt if not (%1)==() if exist CMakeCache.txt. del /Q CMakeCache.txt
call cecho.cmd 0 13 "Running CMake for %PROJECT_NAME%." call cecho.cmd 0 13 "Running CMake for %PROJECT_NAME%."
cmake.exe %CMAKELISTS_DIR% -G %GENERATOR% -DCMAKE_INSTALL_PREFIX="%CMAKE_INSTALL_PREFIX%" %ARGUMENTS%
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 IF NOT %ERRORLEVEL%==0 GOTO :Error
echo. echo.
+123 -42
View File
@@ -17,15 +17,23 @@
:: :: :: ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::
:: 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
:: 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. :: NOTE: The delayed environment variable expansion needs to be enabled before calling this.
@echo off @echo off
@@ -33,34 +41,42 @@
set GENERATOR=%1 set GENERATOR=%1
:: Supported Visual Studio versions: :: Supported Visual Studio versions:
set GENERATORS[0]="Visual Studio 9 2008 Win64"
set GENERATORS[1]="Visual Studio 9 2008" set GENERATORS[1]="Visual Studio 9 2008"
set GENERATORS[2]="Visual Studio 10 2010 Win64" set GENERATORS[2]="Visual Studio 10 2010"
set GENERATORS[3]="Visual Studio 10 2010" set GENERATORS[3]="Visual Studio 11 2012"
set GENERATORS[4]="Visual Studio 11 2012 Win64" set GENERATORS[4]="Visual Studio 12 2013"
set GENERATORS[5]="Visual Studio 11 2012" set GENERATORS[5]="Visual Studio 14 2015"
set GENERATORS[6]="Visual Studio 12 2013 Win64" set GENERATORS[6]="Visual Studio 15 2017"
set GENERATORS[7]="Visual Studio 12 2013" set GENERATORS[7]="Visual Studio 16 2019"
set GENERATORS[8]="Visual Studio 14 2015 Win64" set LAST_GENERATOR_IDX=7
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? :: Is generator shorthand used?
set GEN_SHORTHAND=!GENERATOR:vs=! set GEN_SHORTHAND=!GENERATOR:vs=!
if not "!GEN_SHORTHAND!"=="" if !GEN_SHORTHAND!==!GENERATOR! goto :GeneratorShorthandCheckDone if not "!GEN_SHORTHAND!"=="" if !GEN_SHORTHAND!==!GENERATOR! goto :GeneratorShorthandCheckDone
set START=%LAST_GENERATOR_IDX% set VS_PLATFORM=Win32
:: "echo if" trick from http://stackoverflow.com/a/8758579 :: "echo if" trick from http://stackoverflow.com/a/8758579
echo(!GEN_SHORTHAND! | findstr /c:"-x86" >nul && ( set START=1 ) echo(!GEN_SHORTHAND! | findstr /c:"-x86" >nul && ( set "VS_PLATFORM=Win32" )
echo(!GEN_SHORTHAND! | findstr /c:"-x64" >nul && ( set START=0 ) echo(!GEN_SHORTHAND! | findstr /c:"-x64" >nul && ( set "VS_PLATFORM=x64" )
set VS_VER=!GEN_SHORTHAND:-x86=! echo(!GEN_SHORTHAND! | findstr /c:"-ARM" >nul && ( set "VS_PLATFORM=ARM" )
set VS_VER=!VS_VER:-x64=! 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 && ( echo(!GENERATOR! | findstr /c:"vs20" >nul && (
for /l %%i in (!START!,!STEP!,%LAST_GENERATOR_IDX%) do ( for /L %%i in (0,1,%LAST_GENERATOR_IDX%) do (
echo(!GENERATORS[%%i]! | findstr /c:"!VS_VER!" >nul && ( echo(!GENERATORS[%%i]! | findstr /c:"!VS_VER!" >nul && (
set GENERATOR=!GENERATORS[%%i]! set GENERATOR=!GENERATORS[%%i]!
goto :GeneratorShorthandCheckDone goto :GeneratorShorthandCheckDone
@@ -77,8 +93,8 @@ set START=%ERRORLEVEL%
IF "!GENERATOR!"=="" IF NOT "%VisualStudioVersion%"=="" ( IF "!GENERATOR!"=="" IF NOT "%VisualStudioVersion%"=="" (
set VC_VER=%VisualStudioVersion:.0=% set VC_VER=%VisualStudioVersion:.0=%
FOR /l %%i in (%START%,%STEP%,%LAST_GENERATOR_IDX%) DO ( FOR /L %%i in (%START%,1,%LAST_GENERATOR_IDX%) DO (
REM NOTE add space before VC_VER so that e.g. "12" doesn't match with "2012" :: NOTE add space before VC_VER so that e.g. "12" doesn't match with "2012"
echo(!GENERATORS[%%i]! | findstr /c:" !VC_VER!" >nul && ( echo(!GENERATORS[%%i]! | findstr /c:" !VC_VER!" >nul && (
set GENERATOR=!GENERATORS[%%i]! 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 "Generator not passed, but VisualStudioVersion=%VisualStudioVersion% environment variable detected:"
@@ -87,6 +103,7 @@ IF "!GENERATOR!"=="" IF NOT "%VisualStudioVersion%"=="" (
) )
) )
) )
:: Check that the used CMake version supports the chosen generator :: Check that the used CMake version supports the chosen generator
set GENERATOR_CHECK=%GENERATOR: Win64=% set GENERATOR_CHECK=%GENERATOR: Win64=%
cmake --help | findstr /c:%GENERATOR_CHECK% >nul cmake --help | findstr /c:%GENERATOR_CHECK% >nul
@@ -95,21 +112,23 @@ call utils\cecho.cmd 0 12 "%~nx0: The used CMake version does not support '`"!GE
exit /b 1 exit /b 1
) )
FOR /l %%i in (0,1,%LAST_GENERATOR_IDX%) DO ( FOR /L %%i in (0,1,%LAST_GENERATOR_IDX%) DO (
IF !GENERATOR!==!GENERATORS[%%i]! GOTO :GeneratorValid IF !GENERATOR!==!GENERATORS[%%i]! GOTO :GeneratorValid
) )
call utils\cecho.cmd 0 12 "%~nx0: Invalid or unsupported CMake generator string passed: '`"!GENERATOR!`'"- cannot proceed." call utils\cecho.cmd 0 12 "%~nx0: Invalid or unsupported CMake generator string passed: '`"!GENERATOR!`'"- cannot proceed."
echo Supported CMake generator strings: echo Supported CMake generator strings:
FOR /l %%i in (0,1,%LAST_GENERATOR_IDX%) DO ( FOR /L %%i in (0,1,%LAST_GENERATOR_IDX%) DO (
echo !GENERATORS[%%i]! echo !GENERATORS[%%i]!
) )
exit /b 1 exit /b 1
:GeneratorValid :GeneratorValid
:: Figure out the build configuration from the CMake generator string.
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. :: 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. :: Visual Studio platform name, Win32 (i.e. x86) or x64.
set VS_PLATFORM=Win32 set VS_PLATFORM=Win32
@@ -122,14 +141,58 @@ FOR %%i IN (%GENERATOR_SPLIT%) DO (
IF !LEN!==1 set VC_VER=%%i IF !LEN!==1 set VC_VER=%%i
IF !LEN!==2 set VC_VER=%%i IF !LEN!==2 set VC_VER=%%i
IF !LEN!==4 set VS_VER=%%i IF !LEN!==4 set VS_VER=%%i
REM Are going to perform a 64-bit build? :: Are going to perform a 64-bit build?
IF %%i==Win64 ( IF %%i==Win64 (
set ARCH_BITS=64
set TARGET_ARCH=x64
set VS_PLATFORM=x64 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, :: 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 :: 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 FOR /f "delims=" %%i in ('where cmake') DO set CMAKE_PATH=%%i
@@ -142,7 +205,25 @@ set GENERATOR=%GENERATOR: 2012=%
set GENERATOR=%GENERATOR: 2010=% set GENERATOR=%GENERATOR: 2010=%
:CMake3AndNewer :CMake3AndNewer
set GEN_SHORTHAND=vs%VS_VER%-%TARGET_ARCH% :: 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 :: VS project file extension is different on older VS versions
set VCPROJ_FILE_EXT=vcxproj set VCPROJ_FILE_EXT=vcxproj
IF %VS_VER%==2008 set VCPROJ_FILE_EXT=vcproj IF %VS_VER%==2008 set VCPROJ_FILE_EXT=vcproj
@@ -158,7 +239,7 @@ set PATH=%~dp0utils;%PATH%
pushd .. pushd ..
set DEPS_DIR=%CD%\deps set DEPS_DIR=%CD%\deps
set INSTALL_DIR=%CD%\deps-%GEN_SHORTHAND%-installed set INSTALL_DIR=%CD%\deps-%GEN_SHORTHAND%-installed
REM set INSTALL_DIR=%CD%\deps-vs%VS_VER%-%TARGET_ARCH%-%DEBUG_OR_RELEASE_LOWERCASE%-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 :: BUILD_DIR is a relative build directory used for CMake-based projects
set BUILD_DIR=build-%GEN_SHORTHAND% set BUILD_DIR=build-%GEN_SHORTHAND%
popd popd