227 lines
4.2 KiB
Batchfile

setlocal
SET HELP_STRING="Usage: build generate_only no|[yes] x64 yes|[no] x86 yes|[no] build_type release|[debug] skip_status_string no|[yes] "
if not DEFINED SDK_CMAKE_GENERATOR (
set SDK_CMAKE_GENERATOR=Visual Studio 16 2019
REM "Visual Studio 16 2019"
)
SET GENERATE_ONLY=no
SET BUILD_x64=yes
SET BUILD_x86=yes
SET BUILD_TYPE=Release
SET SKIP_STATUS_STRING=no
SET BUILD_OUT_ROOT=MyBuild
call :ParseArgs %*
if errorlevel 1 goto :Failure
goto :Build.Flow
:ParseArgs
:parse.argument
SET arg_name=%1
if /i "%arg_name%"=="" goto :finished.parsing.arguments
SET arg_value=%2
shift
shift
if /i %arg_name%==help (
echo %HELP_STRING%
exit /b 1
)
if /i %arg_name%==generate_only (
if /i %arg_value%==yes (
set GENERATE_ONLY=yes
set SKIP_STATUS_STRING=yes
set KW_SCAN=0
)
goto :parse.argument
)
if /i %arg_name%==x64 (
if /i %arg_value%==no (
set BUILD_x64=no
)
goto :parse.argument
)
if /i %arg_name%==x86 (
if /i %arg_value%==no (
set BUILD_x86=no
)
goto :parse.argument
)
if /i %arg_name%==skip_status_string (
if /i %arg_value%==yes (
set SKIP_STATUS_STRING=yes
)
goto :parse.argument
)
if /i %arg_name%==build_type (
if /i %arg_value%==debug (
SET BUILD_TYPE=Debug
)
goto :parse.argument
)
if /i %arg_name%==build_out_root (
SET BUILD_OUT_ROOT=%arg_value%
goto :parse.argument
)
echo %arg_name% is unknown parameter, ignoring
exit /b 1
goto :eof
:finished.parsing.arguments
exit /b 0
goto :eof
:Build.Flow
echo GENERATE_ONLY=%GENERATE_ONLY%
echo BUILD_x64=%BUILD_x64%
echo BUILD_x86=%BUILD_x86%
echo BUILD_TYPE=%BUILD_TYPE%
echo SKIP_STATUS_STRING=%SKIP_STATUS_STRING%
pushd ..\Tools\
if errorlevel 1 goto :Failure
set LOCAL_TOOLS_DIR=%cd%\
popd
set CMAKE_DIR=%LOCAL_TOOLS_DIR%CMake\bin\
SET PATH=%CMAKE_DIR%;%PATH%
If NOT DEFINED BUILD_VERSION (
SET BUILD_VERSION=99.99.99.7001
)
del /Q /S version.h
mkdir %BUILD_OUT_ROOT%
pushd %BUILD_OUT_ROOT%
REM ====================== x64 BUILD
if /I "%BUILD_x64%"=="yes" (
set CMAKE_BUILD_TYPE=%BUILD_TYPE%
mkdir x64
pushd x64
cmake ..\..\ -G "%SDK_CMAKE_GENERATOR%" -A x64 -DCMAKE_BUILD_TYPE=%BUILD_TYPE%
if errorlevel 1 (
popd
goto :Failure
)
if /I NOT "%GENERATE_ONLY%"=="yes" (
cmake --build . --config %BUILD_TYPE%
if errorlevel 1 (
popd
goto :Failure
)
)
popd
)
REM ====================== x86 BUILD
if /I "%BUILD_x86%"=="yes" (
set CMAKE_BUILD_TYPE=%BUILD_TYPE%
mkdir x86
pushd x86
cmake ..\..\ -G "%SDK_CMAKE_GENERATOR%" -A Win32 -DCMAKE_BUILD_TYPE=%BUILD_TYPE%
if errorlevel 1 (
popd
goto :Failure
)
if /I NOT "%GENERATE_ONLY%"=="yes" (
cmake --build . --config %BUILD_TYPE%
if errorlevel 1 (
popd
goto :Failure
)
popd
)
)
if /I "%GENERATE_ONLY%"=="yes" (
goto :Success
)
REM Now you are in BUILD_OUT_ROOT
REM ================= Copy files
for %%F IN (CimOpenWsmanClient CimWinRMClient) DO (
if /I "%BUILD_x64%"=="yes" (
if NOT EXIST x64\CimBin\%BUILD_TYPE%\%%F.lib goto :Failure
copy /Y /B x64\CimBin\%BUILD_TYPE%\%%F.lib x64\CimBin\%BUILD_TYPE%\%%F_x64.lib
del x64\CimBin\%BUILD_TYPE%\%%F.lib
if errorlevel 1 goto :Failure
)
)
REM ================= Sign files
if not defined KW_SCAN (
echo Sign files
FOR %%F IN ( CPPCimFrameworkUntyped.dll CPPCimFramework.dll ) DO (
signtool.exe sign /v /sha1 %CERT_THUMBPRINT% /fd sha256 /tr http://timestamp.comodoca.com/rfc3161 /td sha256 x86\CimBin\%BUILD_TYPE%\%%F
if errorlevel 1 goto :Failure
signtool.exe verify /v /debug /pa x86\CimBin\%BUILD_TYPE%\%%F
if errorlevel 1 goto Failure
)
FOR %%F IN ( CPPCimFrameworkUntyped_x64.dll CPPCimFramework_x64.dll ) DO (
signtool.exe sign /v /sha1 %CERT_THUMBPRINT% /fd sha256 /tr http://timestamp.comodoca.com/rfc3161 /td sha256 x64\CimBin\%BUILD_TYPE%\%%F
if errorlevel 1 goto :Failure
signtool.exe verify /v /debug /pa x64\CimBin\%BUILD_TYPE%\%%F
if errorlevel 1 goto Failure
)
)
goto Success
:Failure
popd
endlocal
exit /b 1
:Success
popd
rem if /I NOT "%KW_SCAN%"=="1" rmdir %BUILD_OUT_ROOT% /Q /S
endlocal
exit /b 0