Skip to content

Commit 3134af2

Browse files
author
Sam Roth
authored
Merge pull request google#1 from google/master
Syncing my branch
2 parents 32b4a9b + 5e7fd50 commit 3134af2

File tree

8 files changed

+127
-8
lines changed

8 files changed

+127
-8
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 2.6.2)
1+
cmake_minimum_required(VERSION 2.6.4)
22

33
project( googletest-distribution )
44

googlemock/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ endif()
3838
# ${gmock_BINARY_DIR}.
3939
# Language "C" is required for find_package(Threads).
4040
project(gmock CXX C)
41-
cmake_minimum_required(VERSION 2.6.2)
41+
cmake_minimum_required(VERSION 2.6.4)
4242

4343
if (COMMAND set_up_hermetic_build)
4444
set_up_hermetic_build()

googlemock/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ build Google Mock and its tests, which has further requirements:
125125

126126
### Building Google Mock ###
127127

128+
If you have CMake available, it is recommended that you follow the
129+
[build instructions][gtest_cmakebuild]
130+
as described for Google Test. If are using Google Mock with an
131+
existing CMake project, the section
132+
[Incorporating Into An Existing CMake Project][gtest_incorpcmake]
133+
may be of particular interest. Otherwise, the following sections
134+
detail how to build Google Mock without CMake.
135+
128136
#### Preparing to Build (Unix only) ####
129137

130138
If you are using a Unix system and plan to use the GNU Autotools build
@@ -331,3 +339,5 @@ patch.
331339
Happy testing!
332340

333341
[gtest_readme]: ../googletest/README.md "googletest"
342+
[gtest_cmakebuild]: ../googletest/README.md#using-cmake "Using CMake"
343+
[gtest_incorpcmake]: ../googletest/README.md#incorporating-into-an-existing-cmake-project "Incorporating Into An Existing CMake Project"

googlemock/docs/CookBook.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ per-function syntactic overhead will be much lower.
218218

219219
If you are concerned about the performance overhead incurred by
220220
virtual functions, and profiling confirms your concern, you can
221-
combine this with the recipe for [mocking non-virtual methods](#Mocking_Nonvirtual_Methods.md).
221+
combine this with the recipe for [mocking non-virtual methods](#mocking-nonvirtual-methods).
222222

223223
## The Nice, the Strict, and the Naggy ##
224224

googletest/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ endif()
4545
# ${gtest_BINARY_DIR}.
4646
# Language "C" is required for find_package(Threads).
4747
project(gtest CXX C)
48-
cmake_minimum_required(VERSION 2.6.2)
48+
cmake_minimum_required(VERSION 2.6.4)
4949

5050
if (COMMAND set_up_hermetic_build)
5151
set_up_hermetic_build()

googletest/README.md

+105-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ cross-platform.). If you don't have CMake installed already, you can
5959
download it for free from <http://www.cmake.org/>.
6060

6161
CMake works by generating native makefiles or build projects that can
62-
be used in the compiler environment of your choice. The typical
62+
be used in the compiler environment of your choice. You can either
63+
build Google Test as a standalone project or it can be incorporated
64+
into an existing CMake build for another project.
65+
66+
#### Standalone CMake Project ####
67+
68+
When building Google Test as a standalone project, the typical
6369
workflow starts with:
6470

6571
mkdir mybuild # Create a directory to hold the build output.
@@ -80,13 +86,110 @@ using Visual Studio.
8086

8187
On Mac OS X with Xcode installed, a `.xcodeproj` file will be generated.
8288

89+
#### Incorporating Into An Existing CMake Project ####
90+
91+
If you want to use gtest in a project which already uses CMake, then a
92+
more robust and flexible approach is to build gtest as part of that
93+
project directly. This is done by making the GoogleTest source code
94+
available to the main build and adding it using CMake's
95+
`add_subdirectory()` command. This has the significant advantage that
96+
the same compiler and linker settings are used between gtest and the
97+
rest of your project, so issues associated with using incompatible
98+
libraries (eg debug/release), etc. are avoided. This is particularly
99+
useful on Windows. Making GoogleTest's source code available to the
100+
main build can be done a few different ways:
101+
102+
* Download the GoogleTest source code manually and place it at a
103+
known location. This is the least flexible approach and can make
104+
it more difficult to use with continuous integration systems, etc.
105+
* Embed the GoogleTest source code as a direct copy in the main
106+
project's source tree. This is often the simplest approach, but is
107+
also the hardest to keep up to date. Some organizations may not
108+
permit this method.
109+
* Add GoogleTest as a git submodule or equivalent. This may not
110+
always be possible or appropriate. Git submodules, for example,
111+
have their own set of advantages and drawbacks.
112+
* Use CMake to download GoogleTest as part of the build's configure
113+
step. This is just a little more complex, but doesn't have the
114+
limitations of the other methods.
115+
116+
The last of the above methods is implemented with a small piece
117+
of CMake code in a separate file (e.g. `CMakeLists.txt.in`) which
118+
is copied to the build area and then invoked as a sub-build
119+
_during the CMake stage_. That directory is then pulled into the
120+
main build with `add_subdirectory()`. For example:
121+
122+
New file `CMakeLists.txt.in`:
123+
124+
cmake_minimum_required(VERSION 2.8.2)
125+
126+
project(googletest-download NONE)
127+
128+
include(ExternalProject)
129+
ExternalProject_Add(googletest
130+
GIT_REPOSITORY https://github.com/google/googletest.git
131+
GIT_TAG master
132+
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
133+
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
134+
CONFIGURE_COMMAND ""
135+
BUILD_COMMAND ""
136+
INSTALL_COMMAND ""
137+
TEST_COMMAND ""
138+
)
139+
140+
Existing build's `CMakeLists.txt`:
141+
142+
# Download and unpack googletest at configure time
143+
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
144+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
145+
RESULT_VARIABLE result
146+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
147+
if(result)
148+
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
149+
endif()
150+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
151+
RESULT_VARIABLE result
152+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
153+
if(result)
154+
message(FATAL_ERROR "Build step for googletest failed: ${result}")
155+
endif()
156+
157+
# Prevent overriding the parent project's compiler/linker
158+
# settings on Windows
159+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
160+
161+
# Add googletest directly to our build. This defines
162+
# the gtest and gtest_main targets.
163+
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
164+
${CMAKE_BINARY_DIR}/googletest-build)
165+
166+
# The gtest/gtest_main targets carry header search path
167+
# dependencies automatically when using CMake 2.8.11 or
168+
# later. Otherwise we have to add them here ourselves.
169+
if (CMAKE_VERSION VERSION_LESS 2.8.11)
170+
include_directories("${gtest_SOURCE_DIR}/include")
171+
endif()
172+
173+
# Now simply link against gtest or gtest_main as needed. Eg
174+
add_executable(example example.cpp)
175+
target_link_libraries(example gtest_main)
176+
add_test(NAME example_test COMMAND example)
177+
178+
Note that this approach requires CMake 2.8.2 or later due to
179+
its use of the `ExternalProject_Add()` command. The above
180+
technique is discussed in more detail in
181+
[this separate article](http://crascit.com/2015/07/25/cmake-gtest/)
182+
which also contains a link to a fully generalized implementation
183+
of the technique.
184+
185+
83186
### Legacy Build Scripts ###
84187

85188
Before settling on CMake, we have been providing hand-maintained build
86189
projects/scripts for Visual Studio, Xcode, and Autotools. While we
87190
continue to provide them for convenience, they are not actively
88191
maintained any more. We highly recommend that you follow the
89-
instructions in the previous two sections to integrate Google Test
192+
instructions in the above sections to integrate Google Test
90193
with your existing build system.
91194

92195
If you still need to use the legacy build scripts, here's how:

googletest/include/gtest/internal/gtest-port.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,12 @@ using ::std::tuple_size;
760760

761761
# if GTEST_OS_LINUX && !defined(__ia64__)
762762
# if GTEST_OS_LINUX_ANDROID
763-
// On Android, clone() is only available on ARM starting with Gingerbread.
764-
# if defined(__arm__) && __ANDROID_API__ >= 9
763+
// On Android, clone() became available at different API levels for each 32-bit
764+
// architecture.
765+
# if defined(__LP64__) || \
766+
(defined(__arm__) && __ANDROID_API__ >= 9) || \
767+
(defined(__mips__) && __ANDROID_API__ >= 12) || \
768+
(defined(__i386__) && __ANDROID_API__ >= 17)
765769
# define GTEST_HAS_CLONE 1
766770
# else
767771
# define GTEST_HAS_CLONE 0

googletest/test/gtest-printers_test.cc

+2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ using ::testing::internal::Strings;
211211
using ::testing::internal::UniversalPrint;
212212
using ::testing::internal::UniversalPrinter;
213213
using ::testing::internal::UniversalTersePrint;
214+
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
214215
using ::testing::internal::UniversalTersePrintTupleFieldsToStrings;
216+
#endif
215217
using ::testing::internal::string;
216218

217219
// The hash_* classes are not part of the C++ standard. STLport

0 commit comments

Comments
 (0)