Skip to content

Commit 3781387

Browse files
bpinteadroberts195
andcommitted
Update CMake generation for Visual Studio 16 (#249)
* update CMake generation to Visual Studio 16 Update the how CMake generator specs to build with Visual Studio 2019 16. CMake 3.14 or newer is required for it. * add support for a multi-VS environment This adds support for both VS 2019 and 2017 editions being installed. The 'setup' will now take an optional parameter that dictates which of the editions to set up. If none is provided 2019 and 2017 are looked up, in that order. CMake now always receives the generator to use (through '-G' param) and target platform ('-A' param). The former is detected from the environment variables (VSCMD_VER), the latter, as before, in order of priority: cmd line param, env. var (VSCMD_ARG_TGT_ARCH) or registry key. * Update build.bat Co-authored-by: David Roberts <dave.roberts@elastic.co> * Fix: force script end on VS misdetection If setting a generator name fails, propagate the error and quite the script. Co-authored-by: David Roberts <dave.roberts@elastic.co> (cherry picked from commit a8ff3f1)
1 parent 49fe45b commit 3781387

File tree

2 files changed

+63
-35
lines changed

2 files changed

+63
-35
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ On the server side, the requirements follow Elasticsearch SQL's requirements.
3232
The project is CMake enabled, which generates the environment-dependent build
3333
pipeline. This is a general build requirement.
3434

35-
The building itself is then delegated to the platform-specific tools (MSVC or
36-
make).
35+
The building itself is then delegated to the platform-specific tools.
36+
37+
CMake 3.14 or newer is required for building with Visual Studio 2019.
3738

3839
### External libraries/headers
3940

@@ -75,9 +76,9 @@ The required libraries are added as subtrees to the project, in the libs directo
7576
Building the driver requires the installation of Microsoft tools. These can be
7677
from the Visual Studio pack or with the [standalone tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/).
7778

78-
Version 2017 Enterprise 15 is used to develop with, older versions
79+
Version 2019 Enterprise 16 is used to develop with, older versions
7980
should work fine too, with their corresponding modules. The lists of packages
80-
for MSVC 2017 are given below.
81+
for MSVC 2019 are given below.
8182

8283
Required packages:
8384

build.bat

+58-31
Original file line numberDiff line numberDiff line change
@@ -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

377377
REM 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+
496533
REM 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

589621
REM 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

Comments
 (0)