Skip to content

Commit

Permalink
Merge dff7132 into 2545777
Browse files Browse the repository at this point in the history
  • Loading branch information
berryzplus authored Apr 19, 2020
2 parents 2545777 + dff7132 commit 1397eca
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 170 deletions.
8 changes: 4 additions & 4 deletions build-sln.bat
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ if errorlevel 1 (
)

if "%SONAR_QUBE_TOKEN%" == "" (
@echo "%CMD_MSBUILD%" %SLN_FILE% %PARAM_VSVERSION% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Build" %EXTRA_CMD% %LOG_OPTION%
"%CMD_MSBUILD%" %SLN_FILE% %PARAM_VSVERSION% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Build" %EXTRA_CMD% %LOG_OPTION%
@echo "%CMD_MSBUILD%" %SLN_FILE% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Build" %EXTRA_CMD% %LOG_OPTION%
"%CMD_MSBUILD%" %SLN_FILE% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Build" %EXTRA_CMD% %LOG_OPTION%
) else (
@echo "%BUILDWRAPPER_EXE%" --out-dir %~dp0bw-output "%CMD_MSBUILD%" %SLN_FILE% %PARAM_VSVERSION% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Rebuild" %LOG_OPTION%
"%BUILDWRAPPER_EXE%" --out-dir %~dp0bw-output "%CMD_MSBUILD%" %SLN_FILE% %PARAM_VSVERSION% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Rebuild" %LOG_OPTION%
@echo "%BUILDWRAPPER_EXE%" --out-dir %~dp0bw-output "%CMD_MSBUILD%" %SLN_FILE% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Rebuild" %LOG_OPTION%
"%BUILDWRAPPER_EXE%" --out-dir %~dp0bw-output "%CMD_MSBUILD%" %SLN_FILE% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Rebuild" %LOG_OPTION%
)
if errorlevel 1 (
echo ERROR in msbuild.exe errorlevel %errorlevel%
Expand Down
100 changes: 64 additions & 36 deletions tests/googletest.build.cmd
Original file line number Diff line number Diff line change
@@ -1,53 +1,81 @@
setlocal
set SOURCE_DIR=%1
set GENERATOR=%~2
set CONFIGURATION=%~3
set VCVARSALL_PATH=%4
set VCVARS_ARCH=%~5

@rem call vcvasall.bat when we run in the Visual Studio IDE.
if defined VCVARSALL_PATH (
call %VCVARSALL_PATH% %VCVARS_ARCH% || endlocal && exit /b 1
set BUILD_BASE_DIR=%~dp1
set GOOGLETEST_INSTALL_PATH=%~dp2

set SOURCE_DIR=%~dp0googletest

:: find generic tools
if not defined CMD_VSWHERE call %~dp0..\tools\find-tools.bat

set /a NUM_VSVERSION_NEXT=NUM_VSVERSION + 1

if not exist "%CMD_CMAKE%" (
echo "no cmake found."
exit /b 1
)

if not exist CMakeCache.txt (
call :run_cmake_configure
pushd "%SOURCE_DIR%" || exit /b 1
if not exist CMakeLists.txt (
if not exist "%CMD_GIT%" (
echo "no git found."
exit /b 1
)
"%CMD_GIT%" submodule update --init || exit /b 1
)
popd

if not exist "%CMD_NINJA%" (
set GENERATOR="%CMAKE_G_PARAM%"
set GENERATOR_OPTS=-A %PLATFORM% "-DCMAKE_CONFIGURATION_TYPES=Debug;Release"
set "MAKE_PROGRAM=%CMD_MSBUILD%"
set "BUILD_DIR=%BUILD_BASE_DIR%googletest\%platform%"
) else (
set GENERATOR=Ninja
set GENERATOR_OPTS=-DCMAKE_BUILD_TYPE=%CONFIGURATION%
set "MAKE_PROGRAM=%CMD_NINJA%"
set "BUILD_DIR=%BUILD_BASE_DIR%googletest\%platform%\%configuration%"
)

mkdir %BUILD_DIR% > NUL 2>&1
pushd %BUILD_DIR%

cmake --build . --config %CONFIGURATION% || endlocal && exit /b 1
call :run_cmake_install

endlocal && exit /b 0

:run_cmake_install
call :run_cmake_configure
"%CMD_CMAKE%" --build . --config %CONFIGURATION% --target install || endlocal && exit /b 1
goto :EOF

:run_cmake_configure
where ninja.exe > NUL 2>&1
if not errorlevel 1 (
set GENERATOR=Ninja
set GENERATOR_OPTS=-DCMAKE_BUILD_TYPE=%CONFIGURATION%
)
call :find_cl_compiler

@rem find cl.exe in the PATH
call :find_cl_exe
:: replace back-slash to slash in the path.
set CL_COMPILER=%CMD_CL:\=/%

if not defined CMD_CL (
echo cl.exe was not found.
endlocal && exit /b 1
:: install lib64 for x64-platform.
if "%PLATFORM%" == "x64" (
set GENERATOR_OPTS=-DCMAKE_INSTALL_LIBDIR=lib64 %GENERATOR_OPTS%
)
set CMD_CL=%CMD_CL:\=/%

cmake -G "%GENERATOR%" %GENERATOR_OPTS% ^
"-DCMAKE_C_COMPILER=%CMD_CL%" ^
"-DCMAKE_CXX_COMPILER=%CMD_CL%" ^
-DBUILD_GMOCK=OFF ^
-Dgtest_build_tests=OFF ^
-Dgtest_build_samples=OFF ^
%SOURCE_DIR% ^
|| endlocal && exit /b 1

:: run cmake configuration.
"%CMD_CMAKE%" -G %GENERATOR% ^
"-DCMAKE_MAKE_PROGRAM=%MAKE_PROGRAM%" ^
"-DCMAKE_C_COMPILER=%CL_COMPILER%" ^
"-DCMAKE_CXX_COMPILER=%CL_COMPILER%" ^
-DCMAKE_INSTALL_PREFIX=%GOOGLETEST_INSTALL_PATH% ^
%GENERATOR_OPTS% ^
-DBUILD_GMOCK=OFF ^
-Dgtest_build_tests=OFF ^
-Dgtest_build_samples=OFF ^
%SOURCE_DIR% ^
|| endlocal && exit /b 1
goto :EOF


:find_cl_exe
:find_cl_compiler
for /f "usebackq delims=" %%a in (`where cl.exe`) do (
set CMD_CL=%%a
goto :EOF
set "CMD_CL=%%a"
goto :EOF
)
goto :EOF
58 changes: 16 additions & 42 deletions tests/googletest.targets
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="GoogleTest">
<GoogleTestSourceDir>$(MSBuildThisFileDirectory)googletest\</GoogleTestSourceDir>
<GoogleTestBuildDir>$(MSBuildThisFileDirectory)build\$(Platform)\$(Configuration)\googletest</GoogleTestBuildDir>
<IncludePath>$(GoogleTestSourceDir)googletest\include;$(IncludePath)</IncludePath>
<LibraryPath>$(GoogleTestBuildDir)\lib;$(GoogleTestBuildDir)\lib\$(Configuration);$(LibraryPath)</LibraryPath>
<GoogleTestSourceDir>$(MSBuildThisFileDirectory)googletest</GoogleTestSourceDir>
<GoogleTestBuildDir>$(MSBuildThisFileDirectory)build\</GoogleTestBuildDir>
<GoogleTestInstallDir>$([MsBuild]::NormalizePath('$(MSBuildThisFileDirectory)..\tools\googletest\'))</GoogleTestInstallDir>
<IncludePath>$(GoogleTestInstallDir)include;$(IncludePath)</IncludePath>
<LibraryPath Condition="'$(Platform)' == 'Win32'">$(GoogleTestInstallDir)lib;$(LibraryPath)</LibraryPath>
<LibraryPath Condition="'$(Platform)' == 'x64'">$(GoogleTestInstallDir)lib64;$(LibraryPath)</LibraryPath>
<NameSuffix Condition="'$(Configuration)' == 'Debug'">d</NameSuffix>
<NameSuffix Condition="'$(Configuration)' == 'Release'"></NameSuffix>
</PropertyGroup>
Expand All @@ -18,51 +20,23 @@
<AdditionalDependencies>gtest_main$(NameSuffix).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Target Name="FindGit" Condition="'$(GitCmd)' == ''">
<Message Text="Checking Git for Windows" Importance="high" />
<Exec Command="where &quot;$(PATH);$(ProgramW6432)\Git\Cmd;$(ProgramFiles)\Git\Cmd:git&quot;" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GitCmd" />
</Exec>
<PropertyGroup>
<GitCmd>$([System.Text.RegularExpressions.Regex]::Replace('$(GitCmd)', '^([^;]+);.*', '$1'))</GitCmd>
</PropertyGroup>
</Target>
<Target Name="UpdateGoogleTest" DependsOnTargets="FindGit" Condition="!Exists('$(GoogleTestSourceDir)\CMakeLists.txt')">
<Exec Command="&quot;$(GitCmd)&quot; submodule init" WorkingDirectory="$(GoogleTestSourceDir)" />
<Exec Command="&quot;$(GitCmd)&quot; submodule update" WorkingDirectory="$(GoogleTestSourceDir)" />
</Target>
<Target Name="MakeGoogleTestBuildDir" Condition="!Exists('$(GoogleTestBuildDir)')">
<MakeDir Directories="$(GoogleTestBuildDir)" />
</Target>
<Target Name="BuildGoogleTest" DependsOnTargets="UpdateGoogleTest;MakeGoogleTestBuildDir" BeforeTargets="ClCompile">
<Target Name="MakeGoogleTestInstallDir" Condition="!Exists('$(GoogleTestInstallDir)')">
<MakeDir Directories="$(GoogleTestInstallDir)" />
</Target>
<Target Name="BuildGoogleTest" DependsOnTargets="MakeGoogleTestBuildDir;MakeGoogleTestInstallDir" BeforeTargets="ClCompile">
<PropertyGroup>
<VcVarsArchitecture Condition="'$(PROCESSOR_ARCHITECTURE)' == 'x86' And '$(PlatformTarget)' == 'x86'">x86</VcVarsArchitecture>
<VcVarsArchitecture Condition="'$(PROCESSOR_ARCHITECTURE)' == 'x86' And '$(PlatformTarget)' == 'x64'">x86_amd64</VcVarsArchitecture>
<VcVarsArchitecture Condition="'$(PROCESSOR_ARCHITECTURE)' == 'AMD64' And '$(PlatformTarget)' == 'x86'">amd64_x86</VcVarsArchitecture>
<VcVarsArchitecture Condition="'$(PROCESSOR_ARCHITECTURE)' == 'AMD64' And '$(PlatformTarget)' == 'x64'">amd64</VcVarsArchitecture>
<NumVersion>$([System.Text.RegularExpressions.Regex]::Replace('$(VisualStudioVersion)', '^(\d+).*', '$1'))</NumVersion>
<ProductLineVersion>$([System.Text.RegularExpressions.Regex]::Replace('$(VisualStudioEdition)', '^.* (\d+).*', '$1'))</ProductLineVersion>
<GeneratorSuffix Condition="'$(PlatformTarget)' == 'x86'"></GeneratorSuffix>
<GeneratorSuffix Condition="'$(PlatformTarget)' == 'x64'"> Win64</GeneratorSuffix>
<VsGeneratorName>Visual Studio $(NumVersion) $(ProductLineVersion)$(GeneratorSuffix)</VsGeneratorName>
<VsVersion>$([System.Text.RegularExpressions.Regex]::Replace('$(VisualStudioVersion)', '^(\d+).*', '$1'))</VsVersion>
</PropertyGroup>
<Exec Command="$(MSBuildThisFileDirectory)googletest.build.cmd $(GoogleTestSourceDir) &quot;$(VsGeneratorName)&quot; $(Configuration) &quot;$(VSInstallRoot)/VC/Auxiliary/Build/vcvarsall.bat&quot; $(VcVarsArchitecture)" WorkingDirectory="$(GoogleTestBuildDir)" />
</Target>
<Target Name="CopyGoogleTestPdb" AfterTargets="BuildGoogleTest">
<ItemGroup>
<GoogleTestPdb Include="$(GoogleTestBuildDir)\bin\gtest$(NameSuffix).pdb" Condition="Exists('$(GoogleTestBuildDir)\bin\gtest$(NameSuffix).pdb')" />
<GoogleTestPdb Include="$(GoogleTestBuildDir)\bin\gtest_main$(NameSuffix).pdb" Condition="Exists('$(GoogleTestBuildDir)\bin\gtest_main$(NameSuffix).pdb')" />
<GoogleTestPdb Include="$(GoogleTestBuildDir)\bin\$(Configuration)\gtest$(NameSuffix).pdb" Condition="Exists('$(GoogleTestBuildDir)\bin\$(Configuration)\gtest$(NameSuffix).pdb')" />
<GoogleTestPdb Include="$(GoogleTestBuildDir)\bin\$(Configuration)\gtest_main$(NameSuffix).pdb" Condition="Exists('$(GoogleTestBuildDir)\bin\$(Configuration)\gtest_main$(NameSuffix).pdb')" />
</ItemGroup>
<Copy SourceFiles="@(GoogleTestPdbFound)" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true" UseHardlinksIfPossible="true" />
<SetEnv name="platform" value="$(Platform)" prefix="false" />
<SetEnv name="configuration" value="$(Configuration)" prefix="false" />
<SetEnv name="NUM_VSVERSION" value="$(VsVersion)" prefix="false" />
<Exec Command="$(MSBuildThisFileDirectory)googletest.build.cmd &quot;$(GoogleTestBuildDir)&quot; &quot;$(GoogleTestInstallDir)&quot;" ConsoleToMSBuild="true" />
</Target>
<Target Name="AppendCleanTargets" BeforeTargets="CoreClean">
<!-- Add files to @Clean just before running CoreClean. -->
<ItemGroup>
<Clean Include="$(OutDir)gtest$(NameSuffix).pdb" />
<Clean Include="$(OutDir)gtest_main$(NameSuffix).pdb" />
</ItemGroup>
<RemoveDir Directories="$(GoogleTestBuildDir)" />
<RemoveDir Directories="$(GoogleTestInstallDir)" />
</Target>
</Project>
Loading

0 comments on commit 1397eca

Please sign in to comment.