Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
23ef2955
Commit
23ef2955
authored
Apr 21, 2021
by
Andy Soffer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3314 from Vollstrecker:master
PiperOrigin-RevId: 369550590
parents
f16d43cd
8043818e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
53 deletions
+13
-53
README.md
googletest/README.md
+13
-53
No files found.
googletest/README.md
View file @
23ef2955
...
@@ -82,61 +82,23 @@ main build can be done a few different ways:
...
@@ -82,61 +82,23 @@ main build can be done a few different ways:
possible or appropriate. Git submodules, for example, have their own set of
possible or appropriate. Git submodules, for example, have their own set of
advantages and drawbacks.
advantages and drawbacks.
*
Use CMake to download GoogleTest as part of the build's configure step. This
*
Use CMake to download GoogleTest as part of the build's configure step. This
is just a little more complex, but doesn't have the limitations of the other
approach doesn't have the limitations of the other methods.
methods.
The last of the above methods is implemented with a small piece of CMake code in
The last of the above methods is implemented with a small piece of CMake code
a separate file (e.g.
`CMakeLists.txt.in`
) which is copied to the build area and
that downloads and pulls the GoogleTest code into the main build.
then invoked as a sub-build _during the CMake stage_. That directory is then
pulled into the main build with
`add_subdirectory()`
. For example:
New file
`CMakeLists.txt.in
`
:
Just add to your
`CMakeLists.txt
`
:
```
cmake
```
cmake
cmake_minimum_required
(
VERSION 2.8.12
)
include
(
FetchContent
)
FetchContent_Declare
(
project
(
googletest-download NONE
)
googletest
# Specify the commit you depend on and update it regularly.
include
(
ExternalProject
)
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
ExternalProject_Add
(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
SOURCE_DIR
"
${
CMAKE_CURRENT_BINARY_DIR
}
/googletest-src"
BINARY_DIR
"
${
CMAKE_CURRENT_BINARY_DIR
}
/googletest-build"
CONFIGURE_COMMAND
""
BUILD_COMMAND
""
INSTALL_COMMAND
""
TEST_COMMAND
""
)
)
```
# For Windows: Prevent overriding the parent project's compiler/linker settings
Existing build's
`CMakeLists.txt`
:
```
cmake
# Download and unpack googletest at configure time
configure_file
(
CMakeLists.txt.in googletest-download/CMakeLists.txt
)
execute_process
(
COMMAND
${
CMAKE_COMMAND
}
-G
"
${
CMAKE_GENERATOR
}
"
.
RESULT_VARIABLE result
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
/googletest-download
)
if
(
result
)
message
(
FATAL_ERROR
"CMake step for googletest failed:
${
result
}
"
)
endif
()
execute_process
(
COMMAND
${
CMAKE_COMMAND
}
--build .
RESULT_VARIABLE result
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
/googletest-download
)
if
(
result
)
message
(
FATAL_ERROR
"Build step for googletest failed:
${
result
}
"
)
endif
()
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set
(
gtest_force_shared_crt ON CACHE BOOL
""
FORCE
)
set
(
gtest_force_shared_crt ON CACHE BOOL
""
FORCE
)
FetchContent_MakeAvailable
(
googletest
)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory
(
${
CMAKE_CURRENT_BINARY_DIR
}
/googletest-src
${
CMAKE_CURRENT_BINARY_DIR
}
/googletest-build
EXCLUDE_FROM_ALL
)
# Now simply link against gtest or gtest_main as needed. Eg
# Now simply link against gtest or gtest_main as needed. Eg
add_executable
(
example example.cpp
)
add_executable
(
example example.cpp
)
...
@@ -144,10 +106,8 @@ target_link_libraries(example gtest_main)
...
@@ -144,10 +106,8 @@ target_link_libraries(example gtest_main)
add_test
(
NAME example_test COMMAND example
)
add_test
(
NAME example_test COMMAND example
)
```
```
Note that this approach requires CMake 2.8.2 or later due to its use of the
Note that this approach requires CMake 3.14 or later due to its use of the
`ExternalProject_Add()`
command. The above technique is discussed in more detail
`FetchContent_MakeAvailable()`
command.
in
[
this separate article
](
http://crascit.com/2015/07/25/cmake-gtest/
)
which
also contains a link to a fully generalized implementation of the technique.
##### Visual Studio Dynamic vs Static Runtimes
##### Visual Studio Dynamic vs Static Runtimes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment