Skip to content

Commit

Permalink
Build using CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
KindDragon committed Mar 6, 2016
1 parent 0b17457 commit b7351d2
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 93 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Ignore CI build directory
build/
_build/

# Visual Studio files
*.sdf
Expand Down
91 changes: 33 additions & 58 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,83 +14,58 @@ platform:
- x64

configuration:
- Release
# - Release
- Debug

build:
verbosity: minimal

build_script:
artifacts:
- path: '_build/Testing/Temporary/*'
name: test_results

before_build:
- ps: |
Write-Output "Configuration: $env:CONFIGURATION"
Write-Output "Platform: $env:PLATFORM"
if (($env:Toolset -eq "v100") -and ($env:PLATFORM -eq "x64"))
$generator = switch ($env:TOOLSET)
{
return
"v140" {"Visual Studio 14 2015"}
"v120" {"Visual Studio 12 2013"}
"v110" {"Visual Studio 11 2012"}
"v100" {"Visual Studio 10 2010"}
}
& .\change_toolset.ps1 $env:Toolset
$solutions = @("googletest\msvc\2010\gtest.sln",
"googletest\msvc\2010\gtest-md.sln",
"googlemock\msvc\2010\gmock.sln")
foreach ($sln in $solutions) {
msbuild /v:m /p:"Configuration=$env:CONFIGURATION" /p:Platform="$env:PLATFORM" "$sln" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
if ($LastExitCode -ne 0) {
throw "Exec: $ErrorMessage"
}
if ($env:PLATFORM -eq "x64")
{
$generator = "$generator Win64"
}
test_script:
build_script:
- ps: |
if (($env:Toolset -eq "v100") -and ($env:PLATFORM -eq "x64"))
if (($env:TOOLSET -eq "v100") -and ($env:PLATFORM -eq "x64"))
{
return
}
md _build -Force | Out-Null
cd _build
function Add-GTest-Result($testResult)
{
$testsuites = ([xml](get-content $testResult)).testsuites
$testsCount = 0
$anyFailures = $FALSE
foreach ($testsuite in $testsuites.testsuite) {
foreach ($testcase in $testsuite.testcase) {
$testsCount++
if ($testcase.failure) {
$time = ([double]$testcase.time * 1000)
Add-AppveyorTest $testcase.name -Outcome Failed -FileName $testsuite.name -Duration $time -ErrorMessage $testcase.failure.message
Add-AppveyorMessage "$($testcase.name) failed" -Category Error
$anyFailures = $TRUE
}
elseif ($testcase.skipped) {
Add-AppveyorTest $testcase.name -Outcome Ignored -Filename $testsuite.name
}
else {
$time = ([double]$testcase.time * 1000)
Add-AppveyorTest $testcase.name -Outcome Passed -FileName $testsuite.name -Duration $time
}
}
}
return $testsCount, $anyFailures
& cmake -G "$generator" -DCMAKE_CONFIGURATION_TYPES="Debug;Release" -Dgtest_build_tests=ON -Dgtest_build_samples=ON -Dgmock_build_tests=ON ..
if ($LastExitCode -ne 0) {
throw "Exec: $ErrorMessage"
}
& cmake --build . --config $env:CONFIGURATION
if ($LastExitCode -ne 0) {
throw "Exec: $ErrorMessage"
}
$testsCount = 0
$anyFailures = $FALSE
# Run tests and upload results to AppVeyor one by one
Get-ChildItem ".\*test.exe" -Recurse | foreach {
$testfile = "$($_.FullName).xml"
& $_.FullName "--gtest_output=`"xml:$testfile`""
if (Test-Path $testfile)
{
$count, $testsResult = Add-GTest-Result $testfile
Write-Output "Found $testfile with $count tests"
$testsCount = $testsCount + $count
$anyFailures = $anyFailures -or $testsResult
}
test_script:
- ps: |
if (($env:Toolset -eq "v100") -and ($env:PLATFORM -eq "x64"))
{
return
}
if ($anyFailures -eq $TRUE){
Write-Output "Failing build as there are broken tests"
$host.SetShouldExit(1)
& ctest -C $env:CONFIGURATION --output-on-failure
if ($LastExitCode -ne 0) {
throw "Exec: $ErrorMessage"
}
21 changes: 0 additions & 21 deletions change_toolset.ps1

This file was deleted.

5 changes: 5 additions & 0 deletions googlemock/test/gmock-matchers_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
# include <forward_list> // NOLINT
#endif

// Disable MSVC warning: "decorated name length exceeded, name was truncated".
#ifdef _MSC_VER
# pragma warning(disable:4503)
#endif

namespace testing {

namespace internal {
Expand Down
16 changes: 14 additions & 2 deletions googletest/cmake/internal_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ macro(config_compiler_and_linker)
# http://stackoverflow.com/questions/3232669 explains the issue.
set(cxx_base_flags "${cxx_base_flags} -wd4702")
endif()
if (NOT (MSVC_VERSION GREATER 1900)) # 1900 is Visual Studio 2015
# BigObj required for tests.
set(cxx_base_flags "${cxx_base_flags} -bigobj")
endif()

set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32")
set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN")
Expand Down Expand Up @@ -235,8 +239,16 @@ function(py_test name)
# directly bind it from cmake. ${CTEST_CONFIGURATION_TYPE} is known
# only at ctest runtime (by calling ctest -c <Configuration>), so
# we have to escape $ to delay variable substitution here.
add_test(${name}
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.1)
add_test(
NAME ${name}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
--build_dir=${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>)
else (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.1)
add_test(
${name}
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
--build_dir=${CMAKE_CURRENT_BINARY_DIR}/\${CTEST_CONFIGURATION_TYPE})
endif (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.1)
endif()
endfunction()
17 changes: 14 additions & 3 deletions googletest/include/gtest/internal/gtest-port.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@
// -std={c,gnu}++{0x,11} is passed. The C++11 standard specifies a
// value for __cplusplus, and recent versions of clang, gcc, and
// probably other compilers set that too in C++11 mode.
# if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L
# if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L || _MSC_VER >= 1900
// Compiling in at least C++11 mode.
# define GTEST_LANG_CXX11 1
# else
Expand Down Expand Up @@ -355,7 +355,9 @@
#if GTEST_STDLIB_CXX11
# define GTEST_HAS_STD_BEGIN_AND_END_ 1
# define GTEST_HAS_STD_FORWARD_LIST_ 1
# define GTEST_HAS_STD_FUNCTION_ 1
# if !defined(_MSC_VER) || (_MSC_FULL_VER >= 190023824) // works only with VS2015U2 and better
# define GTEST_HAS_STD_FUNCTION_ 1
# endif
# define GTEST_HAS_STD_INITIALIZER_LIST_ 1
# define GTEST_HAS_STD_MOVE_ 1
# define GTEST_HAS_STD_SHARED_PTR_ 1
Expand Down Expand Up @@ -616,12 +618,21 @@ struct _RTL_CRITICAL_SECTION;
// Determines if hash_map/hash_set are available.
// Only used for testing against those containers.
#if !defined(GTEST_HAS_HASH_MAP_)
# if _MSC_VER
# if defined(_MSC_VER) && (_MSC_VER < 1900)
# define GTEST_HAS_HASH_MAP_ 1 // Indicates that hash_map is available.
# define GTEST_HAS_HASH_SET_ 1 // Indicates that hash_set is available.
# endif // _MSC_VER
#endif // !defined(GTEST_HAS_HASH_MAP_)

// Determines if unordered_map/unordered_set are available.
// Only used for testing against those containers.
#if !defined(GTEST_HAS_UNORDERED_MAP_)
# if defined(_MSC_VER) && (_MSC_VER >= 1900)
# define GTEST_HAS_UNORDERED_MAP_ 1 // Indicates that unordered_map is available.
# define GTEST_HAS_UNORDERED_SET_ 1 // Indicates that unordered_set is available.
# endif // _MSC_VER
#endif // !defined(GTEST_HAS_UNORDERED_MAP_)

// Determines whether Google Test can use tr1/tuple. You can define
// this macro to 0 to prevent Google Test from using tuple (any
// feature depending on tuple with be disabled in this mode).
Expand Down
43 changes: 38 additions & 5 deletions googletest/test/gtest-printers_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@
#include "gtest/gtest.h"

// hash_map and hash_set are available under Visual C++, or on Linux.
#if GTEST_HAS_HASH_MAP_
#if GTEST_HAS_UNORDERED_MAP_
# include <unordered_map> // NOLINT
#elif GTEST_HAS_HASH_MAP_
# include <hash_map> // NOLINT
#endif // GTEST_HAS_HASH_MAP_
#if GTEST_HAS_HASH_SET_

#if GTEST_HAS_UNORDERED_SET_
# include <unordered_set> // NOLINT
#elif GTEST_HAS_HASH_SET_
# include <hash_set> // NOLINT
#endif // GTEST_HAS_HASH_SET_

Expand Down Expand Up @@ -217,18 +222,46 @@ using ::testing::internal::string;
// The hash_* classes are not part of the C++ standard. STLport
// defines them in namespace std. MSVC defines them in ::stdext. GCC
// defines them in ::.
#if GTEST_HAS_UNORDERED_MAP_

#define GTEST_HAS_HASH_MAP_ 1
template<class Key, class T>
using hash_map = ::std::unordered_map<Key, T>;
template<class Key, class T>
using hash_multimap = ::std::unordered_multimap<Key, T>;

#elif GTEST_HAS_HASH_MAP_

#ifdef _STLP_HASH_MAP // We got <hash_map> from STLport.
using ::std::hash_map;
using ::std::hash_set;
using ::std::hash_multimap;
using ::std::hash_multiset;
#elif _MSC_VER
using ::stdext::hash_map;
using ::stdext::hash_set;
using ::stdext::hash_multimap;
#endif

#endif

#if GTEST_HAS_UNORDERED_SET_

#define GTEST_HAS_HASH_SET_ 1
template<class Key>
using hash_set = ::std::unordered_set<Key>;
template<class Key>
using hash_multiset = ::std::unordered_multiset<Key>;

#elif GTEST_HAS_HASH_SET_

#ifdef _STLP_HASH_MAP // We got <hash_map> from STLport.
using ::std::hash_set;
using ::std::hash_multiset;
#elif _MSC_VER
using ::stdext::hash_set;
using ::stdext::hash_multiset;
#endif

#endif

// Prints a value to a string using the universal value printer. This
// is a helper for testing UniversalPrinter<T>::Print() for various types.
template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion googletest/test/gtest_catch_exceptions_test_.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ TEST_F(CxxExceptionInConstructorTest, ThrowsExceptionInConstructor) {
}

// Exceptions in destructors are not supported in C++11.
#if !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L
#if !GTEST_LANG_CXX11
class CxxExceptionInDestructorTest : public Test {
public:
static void TearDownTestCase() {
Expand Down
4 changes: 2 additions & 2 deletions googletest/test/gtest_list_tests_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
TypedTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\.
TestA
TestB
TypedTest/1\. # TypeParam = int\s*\*
TypedTest/1\. # TypeParam = int\s*\*( __ptr64)?
TestA
TestB
TypedTest/2\. # TypeParam = .*MyArray<bool,\s*42>
Expand All @@ -80,7 +80,7 @@
My/TypeParamTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\.
TestA
TestB
My/TypeParamTest/1\. # TypeParam = int\s*\*
My/TypeParamTest/1\. # TypeParam = int\s*\*( __ptr64)?
TestA
TestB
My/TypeParamTest/2\. # TypeParam = .*MyArray<bool,\s*42>
Expand Down
2 changes: 1 addition & 1 deletion travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ cmake -Dgtest_build_samples=ON \
-DCMAKE_CXX_FLAGS=$CXX_FLAGS \
../../$GTEST_TARGET
make
make test
CTEST_OUTPUT_ON_FAILURE=1 make test

0 comments on commit b7351d2

Please sign in to comment.