From 21e8a1e8e64ed9019adfb8bcb9e66d81359af0b1 Mon Sep 17 00:00:00 2001 From: Stinkfist0 Date: Wed, 3 Feb 2016 15:21:12 +0200 Subject: [PATCH] vs-cfg.cmd: provide support for user-friendly VS generators, e.g. vs2013-x86, and converted them to the appropriate CMake ones. --- win/readme.md | 9 +++++---- win/vs-cfg.cmd | 31 ++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/win/readme.md b/win/readme.md index 4f1ea5ca37..0c1f0357bf 100644 --- a/win/readme.md +++ b/win/readme.md @@ -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`, 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` -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 depedencies can co-exist by simply running -`build-deps.cmd Debug` and `build-deps.cmd `. +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/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 depedencies +can co-exist by simply running `build-deps.cmd Debug` and `build-deps.cmd `. 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. diff --git a/win/vs-cfg.cmd b/win/vs-cfg.cmd index 98bedad576..5b5d1de346 100644 --- a/win/vs-cfg.cmd +++ b/win/vs-cfg.cmd @@ -20,6 +20,7 @@ :: 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 @@ -31,8 +32,6 @@ 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: set GENERATORS[0]="Visual Studio 9 2008 Win64" 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 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 +:: 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%"=="" ( set VC_VER=%VisualStudioVersion:.0=% 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" - echo(!GENERATORS[%%i]! | findstr /r /c:" !VC_VER!" >nul && ( + 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."