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 4, 2016
1 parent 09a9b94 commit 0939d0a
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 88 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
104 changes: 63 additions & 41 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,42 @@ configuration:
build:
verbosity: minimal

build_script:
artifacts:
- path: '_build/**/*.xml'
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)
{
"v140" {"Visual Studio 14 2015"}
"v120" {"Visual Studio 12 2013"}
"v110" {"Visual Studio 11 2012"}
"v100" {"Visual Studio 10 2010"}
}
if ($env:PLATFORM -eq "x64")
{
$generator = "$generator Win64"
}
build_script:
- ps: |
if (($env:TOOLSET -eq "v100") -and ($env:PLATFORM -eq "x64"))
{
return
}
& .\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"
}
md _build -Force | Out-Null
cd _build
& 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"
}
test_script:
Expand All @@ -47,28 +65,34 @@ test_script:
return
}
function Add-GTest-Result($testResult)
& ctest -C $env:CONFIGURATION --output-on-failure
if ($LastExitCode -ne 0) {
throw "Exec: $ErrorMessage"
}
function Add-CTest-Result($testResult)
{
$testsuites = ([xml](get-content $testResult)).testsuites
$tests = ([xml](get-content $testResult)).Site.Testing
$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
}
foreach ($test in $tests.test) {
$testsCount++
$testName = $test.Name
$testpath = $test.Path
$timeNode = $test.SelectSingleNode('Results/NamedMeasurement[@name="Execution Time"]/Value')
if ($test.status -eq "failure") {
$time = ([double]$timeNode.InnerText * 1000)
Add-AppveyorTest $testName -Outcome Failed -FileName $testpath -Duration $time -ErrorMessage $($test.results.measurement.value)
Add-AppveyorMessage `"$testName failed`" -Category Error
$anyFailures = $TRUE
}
elseif ($test.status -eq "skipped") {
Add-AppveyorTest $testName -Outcome Ignored -Filename $testpath
}
else {
$time = ([double]$timeNode.InnerText * 1000)
Add-AppveyorTest $testName -Outcome Passed -FileName $testpath -Duration $time -StdOut $($test.results.measurement.value)
}
}
return $testsCount, $anyFailures
Expand All @@ -78,19 +102,17 @@ test_script:
$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
}
Get-ChildItem ".\Testing\*.xml" -Recurse | foreach {
$testfile = $_.fullname
$count, $testsResult = Add-CTest-Result $testfile
Write-Host "Found $testfile with $count tests"
$testsCount = $testsCount + $count
$anyFailures = $anyFailures -or $testsResult
}
Write-Host "There are $testsCount tests found"
if ($anyFailures -eq $TRUE){
Write-Output "Failing build as there are broken tests"
Write-Host "Failing build as there are broken tests"
$host.SetShouldExit(1)
}
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()
52 changes: 35 additions & 17 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 All @@ -340,27 +340,36 @@
// 20110325, but maintenance releases in the 4.4 and 4.5 series followed
// this date, so check for those versions by their date stamps.
// https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning
#if GTEST_LANG_CXX11 && \
(!defined(__GLIBCXX__) || ( \
#if GTEST_LANG_CXX11
// MSVC++ 2015 has many C++11 features
# if _MSC_VER >= 1900
# define GTEST_STDLIB_CXX11 1
# define GTEST_HAS_STD_BEGIN_AND_END_ 1
# define GTEST_HAS_STD_FORWARD_LIST_ 1
# define GTEST_HAS_STD_MOVE_ 1
# define GTEST_HAS_STD_SHARED_PTR_ 1
# define GTEST_HAS_STD_TYPE_TRAITS_ 1
# define GTEST_HAS_STD_UNIQUE_PTR_ 1
# define GTEST_HAS_STD_INITIALIZER_LIST_ 1
// not supported well enough
# define GTEST_HAS_STD_FUNCTION_ 0
# elif (!defined(__GLIBCXX__) || ( \
__GLIBCXX__ >= 20110325ul && /* GCC >= 4.6.0 */ \
/* Blacklist of patch releases of older branches: */ \
__GLIBCXX__ != 20110416ul && /* GCC 4.4.6 */ \
__GLIBCXX__ != 20120313ul && /* GCC 4.4.7 */ \
__GLIBCXX__ != 20110428ul && /* GCC 4.5.3 */ \
__GLIBCXX__ != 20120702ul)) /* GCC 4.5.4 */
# define GTEST_STDLIB_CXX11 1
#endif

// Only use C++11 library features if the library provides them.
#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
# define GTEST_HAS_STD_INITIALIZER_LIST_ 1
# define GTEST_HAS_STD_MOVE_ 1
# define GTEST_HAS_STD_SHARED_PTR_ 1
# define GTEST_HAS_STD_TYPE_TRAITS_ 1
# define GTEST_HAS_STD_UNIQUE_PTR_ 1
# define GTEST_STDLIB_CXX11 1
# define GTEST_HAS_STD_BEGIN_AND_END_ 1
# define GTEST_HAS_STD_FORWARD_LIST_ 1
# define GTEST_HAS_STD_FUNCTION_ 1
# define GTEST_HAS_STD_INITIALIZER_LIST_ 1
# define GTEST_HAS_STD_MOVE_ 1
# define GTEST_HAS_STD_SHARED_PTR_ 1
# define GTEST_HAS_STD_TYPE_TRAITS_ 1
# define GTEST_HAS_STD_UNIQUE_PTR_ 1
# endif
#endif

// C++11 specifies that <tuple> provides std::tuple.
Expand Down Expand Up @@ -616,12 +625,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
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 0939d0a

Please sign in to comment.