vs-cfg.cmd: provide support for user-friendly VS generators, e.g. vs2013-x86, and converted them to the appropriate CMake ones.

This commit is contained in:
Stinkfist0
2016-02-03 15:21:12 +02:00
parent 2e6601b3e7
commit 21e8a1e8e6
2 changed files with 29 additions and 11 deletions
+5 -4
View File
@@ -16,10 +16,11 @@ running the script.
`build-deps.cmd` expects a CMake generator as `%1` and a build configuration type (`RelWithDebInfo/Release/MinSizeRel/Debug`, `build-deps.cmd` expects a CMake generator as `%1` and a build configuration type (`RelWithDebInfo/Release/MinSizeRel/Debug`,
defaults to `RelWithDebInfo`) as `%2`. If the generator is not provided, the generator is deduced from the Visual Studio defaults to `RelWithDebInfo`) as `%2`. If the generator is not provided, the generator is deduced from the Visual Studio
environment variables. A build type (`Build/Rebuild/Clean`, defaults to `Build`) can be provided as `%3`. See `vs-cfg.cmd` environment variables. User-friendly VS generator shorthands are supported, e.g. `vs2013-x86` or `vs2015-x64`, and these are
if you wish to change the defaults. The batch file will create `deps\` and `deps-vs<VERSION>-<ARCHITECTURE>-installed\` converted to the appropriate CMake ones by the scripts. A build type (`Build/Rebuild/Clean`, defaults to `Build`) can be
directories to the project root. Debug and release builds of the depedencies can co-exist by simply running provided as `%3`. See `vs-cfg.cmd` if you wish to change the defaults. The batch file will create `deps\` and
`build-deps.cmd <GENERATOR> Debug` and `build-deps.cmd <GENERATOR> <Release|RelWithDebInfo|MinSizeRel>`. `deps-vs<VERSION>-<ARCHITECTURE>-installed\` directories to the project root. Debug and release builds of the depedencies
can co-exist by simply running `build-deps.cmd <GENERATOR> Debug` and `build-deps.cmd <GENERATOR> <Release|RelWithDebInfo|MinSizeRel>`.
After the dependencies are build, execute `run-cmake.bat`. The batch file expects always a CMake generator as `%1` After the dependencies are build, execute `run-cmake.bat`. The batch file expects always a CMake generator as `%1`
(if not provided, the same default value as above is used), and the rest of possible parameters are passed as is. (if not provided, the same default value as above is used), and the rest of possible parameters are passed as is.
+24 -7
View File
@@ -20,6 +20,7 @@
:: This script initializes various Visual Studio related environment variables needed for building. :: 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 :: 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. :: 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. :: 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 :: "Visual Studio 10 2010" instead of "Visual Studio 10". However, one can use this batch file
@@ -31,8 +32,6 @@
set GENERATOR=%1 set GENERATOR=%1
:: TODO IDEA: Take more user-friendly VS generators (e.g. "vs2013-x86") and convert them to the CMake ones?
:: Supported Visual Studio versions: :: Supported Visual Studio versions:
set GENERATORS[0]="Visual Studio 9 2008 Win64" set GENERATORS[0]="Visual Studio 9 2008 Win64"
set GENERATORS[1]="Visual Studio 9 2008" set GENERATORS[1]="Visual Studio 9 2008"
@@ -46,17 +45,35 @@ set GENERATORS[8]="Visual Studio 14 2015 Win64"
set GENERATORS[9]="Visual Studio 14 2015" set GENERATORS[9]="Visual Studio 14 2015"
set LAST_GENERATOR_IDX=9 set LAST_GENERATOR_IDX=9
:: Deduce desired architecture from the location of cl.exe
where cl.exe | findstr /r /c:"amd64" >nul
set START=%ERRORLEVEL%
set STEP=2 set STEP=2
:: Is generator shorthand used?
set GEN_SHORTHAND=!GENERATOR:vs=!
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
where cl.exe | findstr /c:"amd64" >nul
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%,%STEP%,%LAST_GENERATOR_IDX%) DO (
REM http://stackoverflow.com/a/8758579
REM NOTE add space before VC_VER so that e.g. "12" doesn't match with "2012" REM NOTE add space before VC_VER so that e.g. "12" doesn't match with "2012"
echo(!GENERATORS[%%i]! | findstr /r /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:"
call utils\cecho.cmd black cyan "using '`"!GENERATOR!`'" as the generator." call utils\cecho.cmd black cyan "using '`"!GENERATOR!`'" as the generator."