Skip to content

Commit

Permalink
Merge e6cba4f into 8353cd2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kohki Akikaze authored Jan 30, 2022
2 parents 8353cd2 + e6cba4f commit a4fe340
Showing 1 changed file with 99 additions and 86 deletions.
185 changes: 99 additions & 86 deletions tools/find-tools.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,38 @@ setlocal

if "%1" equ "clear" (
endlocal
set CMD_GIT=
set CMD_7Z=
set CMD_HHC=
set CMD_ISCC=
set CMD_CPPCHECK=
set CMD_DOXYGEN=
set CMD_VSWHERE=
set CMD_MSBUILD=
set CMD_CMAKE=
set CMD_NINJA=
set CMD_LEPROC=
set CMD_PYTHON=
set NUM_VSVERSION=
set CMAKE_G_PARAM=
set FIND_TOOLS_CALLED=
call :clear_variables
echo find-tools.bat has been cleared
exit /b
) else if "%~1" neq "" (
)

if not defined CMD_VSWHERE call :vswhere 2> nul
if not exist "%CMD_VSWHERE%" (
echo vswhere was not found
exit /b
)

set ARG_VSVERSION=
if "%1" neq "" (
set "ARG_VSVERSION=%~1"
)
call :convert_arg_vsversion
if not defined ARG_VSVERSION (
call :convert_arg_vsversion
)

if defined NUM_VSVERSION (
if "%ARG_VSVERSION%" neq "%NUM_VSVERSION%" (
endlocal
call :clear_variables
setlocal
set "ARG_VSVERSION=%~1"
call :vswhere
call :convert_arg_vsversion
)
)
set NUM_VSVERSION=%ARG_VSVERSION%

if defined FIND_TOOLS_CALLED (
echo find-tools.bat already called
exit /b
Expand All @@ -35,7 +47,6 @@ if not defined CMD_HHC call :hhc 2> nul
if not defined CMD_ISCC call :iscc 2> nul
if not defined CMD_CPPCHECK call :cppcheck 2> nul
if not defined CMD_DOXYGEN call :doxygen 2> nul
if not defined CMD_VSWHERE call :vswhere 2> nul
if not defined CMD_MSBUILD call :msbuild 2> nul
if not defined CMD_CMAKE call :cmake 2> nul
if not defined CMD_NINJA call :cmake 2> nul
Expand Down Expand Up @@ -75,6 +86,62 @@ endlocal ^
set FIND_TOOLS_CALLED=1
exit /b

:clear_variables
set CMD_GIT=
set CMD_7Z=
set CMD_HHC=
set CMD_ISCC=
set CMD_CPPCHECK=
set CMD_DOXYGEN=
set CMD_VSWHERE=
set CMD_MSBUILD=
set CMD_CMAKE=
set CMD_NINJA=
set CMD_LEPROC=
set CMD_PYTHON=
set NUM_VSVERSION=
set CMAKE_G_PARAM=
set FIND_TOOLS_CALLED=
exit /b

:convert_arg_vsversion
if not defined ARG_VSVERSION (
set "ARG_VSVERSION=%NUM_VSVERSION%"
)
if not defined ARG_VSVERSION (
set "ARG_VSVERSION=latest"
)

:: convert productLineVersion to Internal Major Version
if "%ARG_VSVERSION%" == "2017" (
set ARG_VSVERSION=15
) else if "%ARG_VSVERSION%" == "2019" (
set ARG_VSVERSION=16
) else if "%ARG_VSVERSION%" == "2022" (
set ARG_VSVERSION=17
) else if "%ARG_VSVERSION%" == "latest" (
call :get_latest_installed_vsversion
)
::指定されたバージョンのC++がインストールされているかチェック
set /a ARG_VSVERSION_NEXT=ARG_VSVERSION + 1
for /f "usebackq delims=" %%d in (`"%CMD_VSWHERE%" -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -version [%ARG_VSVERSION%^,%ARG_VSVERSION_NEXT%^)`) do (
if exist "%%d" exit /b
)
::指定されたバージョンが存在しなければ「指定なし」にしてやり直す
set ARG_VSVERSION=
exit /b

:get_latest_installed_vsversion
for /f "usebackq delims=" %%v in (`"%CMD_VSWHERE%" -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationVersion -latest`) do (
set VSVERSION=%%v
)
if defined VSVERSION (
set ARG_VSVERSION=%VSVERSION:~0,2%
) else (
set ARG_VSVERSION=15
)
exit /b

:Git
set APPDIR=Git\Cmd
set PATH2=%PATH%;%ProgramFiles%\%APPDIR%\;%ProgramFiles(x86)%\%APPDIR%\;%ProgramW6432%\%APPDIR%\;
Expand Down Expand Up @@ -152,95 +219,41 @@ exit /b

:: ---------------------------------------------------------------------------------------------------------------------
:: sub routine for finding msbuild
::
:: ARG_VSVERSION
:: latest => the latest version of installed Visual Studio
:: 2017 => Visual Studio 2017
:: 2019 => Visual Studio 2019
:: 15 => Visual Studio 2017
:: 16 => Visual Studio 2019
:: ---------------------------------------------------------------------------------------------------------------------
:msbuild
:: convert productLineVersion to Internal Major Version
if "%ARG_VSVERSION%" == "" (
set NUM_VSVERSION=15
) else if "%ARG_VSVERSION%" == "2017" (
set NUM_VSVERSION=15
) else if "%ARG_VSVERSION%" == "2019" (
set NUM_VSVERSION=16
) else if "%ARG_VSVERSION%" == "2022" (
set NUM_VSVERSION=17
) else if "%ARG_VSVERSION%" == "latest" (
call :check_latest_installed_vsversion
) else (
set NUM_VSVERSION=%ARG_VSVERSION%
)

call :check_installed_vsversion

call :find_msbuild
if not exist "%CMD_MSBUILD%" (
call :find_msbuild_legacy
set NUM_VSVERSION=15
)

:: vs2017単独インストールで導入されるvswhereには機能制限がある
if "%NUM_VSVERSION%" == "15" (
call :find_msbuild_legacy
set CMAKE_G_PARAM=Visual Studio 15 2017
) else if "%NUM_VSVERSION%" == "16" (
set CMAKE_G_PARAM=Visual Studio 16 2019
) else if "%NUM_VSVERSION%" == "17" (
set CMAKE_G_PARAM=Visual Studio 17 2022
) else (
call :find_msbuild
call :set_cmake_gparam_automatically
)
exit /b

:set_cmake_gparam_automatically
call :get_product_line_version
set CMAKE_G_PARAM=Visual Studio %NUM_VSVERSION% %VS_PRODUCT_LINE_VERSION%
exit /b

:get_product_line_version
set /a NUM_VSVERSION_NEXT=NUM_VSVERSION + 1
for /f "usebackq delims=" %%v in (`"%CMD_VSWHERE%" -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property catalog_productLineVersion -version [%NUM_VSVERSION%^,%NUM_VSVERSION_NEXT%^)`) do (
set VS_PRODUCT_LINE_VERSION=%%v
)
exit /b

:check_latest_installed_vsversion
for /f "usebackq delims=" %%v in (`"%CMD_VSWHERE%" -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationVersion -latest`) do (
set VSVERSION=%%v
)
set NUM_VSVERSION=%VSVERSION:~0,2%
exit /b

:check_installed_vsversion
set /a NUM_VSVERSION_NEXT=NUM_VSVERSION + 1
for /f "usebackq delims=" %%d in (`"%CMD_VSWHERE%" -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -version [%NUM_VSVERSION%^,%NUM_VSVERSION_NEXT%^)`) do (
if exist "%%d" exit /b
)
call :check_latest_installed_vsversion
exit /b

:find_msbuild
set /a NUM_VSVERSION_NEXT=NUM_VSVERSION + 1
for /f "usebackq delims=" %%a in (`"%CMD_VSWHERE%" -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe -version [%NUM_VSVERSION%^,%NUM_VSVERSION_NEXT%^)`) do (
set "CMD_MSBUILD=%%a"
)
if exist "%CMD_MSBUILD%" (
exit /b
)
set CMD_MSBUILD=
exit /b

:find_msbuild_legacy
for /f "usebackq delims=" %%d in (`"%CMD_VSWHERE%" -requires Microsoft.Component.MSBuild -property installationPath -version [15^,16^)`) do (
set "CMD_MSBUILD=%%d\MSBuild\15.0\Bin\MSBuild.exe"
)
if exist "%CMD_MSBUILD%" (
exit /b
exit /b

:set_cmake_gparam_automatically
call :get_product_line_version
set CMAKE_G_PARAM=Visual Studio %NUM_VSVERSION% %VS_PRODUCT_LINE_VERSION%
exit /b

:get_product_line_version
set /a NUM_VSVERSION_NEXT=NUM_VSVERSION + 1
for /f "usebackq delims=" %%v in (`"%CMD_VSWHERE%" -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property catalog_productLineVersion -version [%NUM_VSVERSION%^,%NUM_VSVERSION_NEXT%^)`) do (
set VS_PRODUCT_LINE_VERSION=%%v
)
set CMD_MSBUILD=
exit /b

:cmake
Expand Down Expand Up @@ -284,7 +297,7 @@ exit /b
call :find_py
call :check_python_version
if defined CMD_PYTHON (
exit /b 0
exit /b 0
)

call :find_python
Expand Down

0 comments on commit a4fe340

Please sign in to comment.