@@ -253,8 +253,9 @@ REM USAGE function: output a usage message
253253 echo help^ |*?* : output this message and exit; ?? for more options.
254254 echo 32^ |64 : set the architecture to x86 or x64, respectively;
255255 echo if none is specified, autodetection is attempted.
256- echo setup : invoke MSVC's build environment setup script before
257- echo building (requires 2017 version or later^ ).
256+ echo setup[:Y] : invoke MSVC's build environment setup script before
257+ echo building; optional Y specifies the release year
258+ echo (requires 2017 version or later^ ).
258259 echo clean : remove all the files in the build dir.
259260 echo proper : clean libs, builds, project dirs and exit.
260261 echo type:T : selects the build type, T: Debug or Release.
@@ -308,7 +309,6 @@ REM USAGE function: output a usage message
308309 echo param (needs Administrator privileges^ ).
309310 echo regdel : deregister the driver from the registry;
310311 echo (needs Administrator privileges^ ).
311- echo tests : (deprecated^ ) synonym with utests.
312312 echo .
313313 goto :eof
314314
@@ -376,22 +376,37 @@ REM CLEAN function: clean up the build dir.
376376
377377REM SETUP function: set-up the build environment
378378:SETUP
379- set RELEASE = 2017
380- for %%e in (Enterprise, Professional, Community) do (
381- if exist " C:\Program Files (x86)\Microsoft Visual Studio\%RELEASE% \%%e \Common7\Tools\VsDevCmd.bat" (
382- if /i " %%e " == " Community" (
383- echo .
384- echo %~nx0 : WARNING: Community edition is not licensed to build commerical projects.
385- echo .
379+ REM cycle through the args, look for '^setup:' token and use the
380+ REM remaining string in argument
381+ for %%a in (%ARG:" =% ) do (
382+ set crr = %%a
383+ if /i [" !crr:~0 ,6 ! " ] == [" setup:" ] (
384+ set VS_YEAR = !crr:~6 !
385+ )
386+ )
387+ if [%VS_YEAR% ] == [] (
388+ set VS_YEARS = 2019 2017
389+ ) else (
390+ set VS_YEARS = %VS_YEAR%
391+ )
392+
393+ for %%r in (%VS_YEARS% ) do (
394+ for %%e in (Enterprise, Professional, Community) do (
395+ if exist " C:\Program Files (x86)\Microsoft Visual Studio\%%r \%%e \Common7\Tools\VsDevCmd.bat" (
396+ if /i " %%e " == " Community" (
397+ echo .
398+ echo %~nx0 : WARNING: Community edition is not licensed to build commerical projects.
399+ echo .
400+ )
401+ call " C:\Program Files (x86)\Microsoft Visual Studio\%%r \%%e \Common7\Tools\VsDevCmd.bat" -arch=!TARCH!
402+ set EDITION = %%r
403+ goto :eof
386404 )
387- call " C:\Program Files (x86)\Microsoft Visual Studio\%RELEASE% \%%e \Common7\Tools\VsDevCmd.bat" -arch=!TARCH!
388- set EDITION = %%e
389- goto :eof
390405 )
391406 )
392407 if [%EDITION% ] == [] (
393408 echo .
394- echo %~nx0 : WARNING: no MSVC edition found, environment not set.
409+ echo %~nx0 : WARNING: no Visual Studio edition found, environment not set.
395410 echo .
396411 )
397412
@@ -493,6 +508,28 @@ REM BUILDTYPE function: set the build config to feed MSBuild
493508
494509 goto :eof
495510
511+ REM SETGENERATOR function: reads the environment variables and sets the
512+ REM generator string to feed CMake
513+ :SETGENERATOR
514+ for /f " tokens=1 delims=. " %%a in (" %VSCMD_VER% " ) do (
515+ set REL_MAJOR = %%a
516+ )
517+ if [%REL_MAJOR% ] == [16] (
518+ set VS_GENERATOR = " Visual Studio 16 2019"
519+ ) else if [%REL_MAJOR% ] == [15] (
520+ set VS_GENERATOR = " Visual Studio 15 2017"
521+ )
522+
523+ if [%VS_GENERATOR% ] == [] (
524+ echo .
525+ echo %~nx0 : ERROR: no Visual Studio edition detected (%VSCMD_VER% ^ ).
526+ echo %~nx0 : Retry running with 'setup' argument.
527+ echo .
528+ exit /b 1
529+ )
530+
531+ goto :eof
532+
496533REM BUILD function: build various targets
497534:BUILD
498535 REM set the wanted or previously set build type.
@@ -503,12 +540,13 @@ REM BUILD function: build various targets
503540 if not exist ALL_BUILD.vcxproj (
504541 echo %~nx0 : generating the project files.
505542
506- REM set the wanted build type.
507- rem call:BUILDTYPE
543+ call :SETGENERATOR
544+ if ERRORLEVEL 1 (
545+ goto :END
546+ )
508547
509548 set CMAKE_ARGS = -DDRIVER_BASE_NAME=%DRIVER_BASE_NAME%
510- REM no explicit x86 generator and is the default (MSVC2017 only?).
511- set CMAKE_ARGS = !CMAKE_ARGS! -G " Visual Studio 15 2017" -DCMAKE_GENERATOR_PLATFORM=%TARCH:x86 =%
549+ set CMAKE_ARGS = !CMAKE_ARGS! -G !VS_GENERATOR! -A %TARCH:x86 =Win32 %
512550
513551 if /i [!BUILD_TYPE! ] == [Debug] (
514552 set CMAKE_ARGS = !CMAKE_ARGS! -DLIBCURL_BUILD_TYPE=debug
@@ -530,13 +568,7 @@ REM BUILD function: build various targets
530568 goto :eof
531569 )
532570
533- if /i not [%ARG: tests =% ] == [%ARG% ] ( REM utests dup'd
534- echo %~nx0 : building all the project.
535- MSBuild ALL_BUILD.vcxproj %MSBUILD_ARGS%
536- if ERRORLEVEL 1 (
537- goto END
538- )
539- ) else if /i not [%ARG:utests =% ] == [%ARG% ] (
571+ if /i not [%ARG:utests =% ] == [%ARG% ] (
540572 echo %~nx0 : building all the project.
541573 MSBuild ALL_BUILD.vcxproj %MSBUILD_ARGS%
542574 if ERRORLEVEL 1 (
@@ -588,12 +620,7 @@ REM BUILD function: build various targets
588620
589621REM TESTS_SUITE_S function: run the compiled unit tests
590622:TESTS_SUITE_S
591- if /i not [%ARG: tests =% ] == [%ARG% ] ( REM utests dup'd
592- MSBuild RUN_TESTS.vcxproj !MSBUILD_ARGS!
593- if ERRORLEVEL 1 (
594- goto END
595- )
596- ) else if /i not [%ARG:utests =% ] == [%ARG% ] (
623+ if /i not [%ARG:utests =% ] == [%ARG% ] (
597624 MSBuild RUN_TESTS.vcxproj !MSBUILD_ARGS!
598625 if ERRORLEVEL 1 (
599626 goto END
0 commit comments