Skip to content

Commit

Permalink
Clone the github by git and allow users to select gtest manually
Browse files Browse the repository at this point in the history
There are reports saying clonning gtest all the time may failure in case
of bad network condition. So we tried to improve this by clonning with
git protocal and allow users to specify the gtest manually. See the
updated documents for details.
  • Loading branch information
ChuanqiXu9 committed Mar 14, 2024
1 parent ce035dc commit 7690a05
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ If you meet any problem about MSVC Compiler Error C4737. Try to add the /EHa opt
# Develop async_simple

The build of async_simple requires libaio, googletest and cmake. Both libaio and googletest
are optional. (Testing before using is highly suggested.)
are optional. (Testing before using is highly suggested.) By default, async_simple would try
to clone the googletest from git to make sure the version used is correct. But in case the
users have problems with networks, users can try to install the gtest libraries by the following instructions and use the CMake variables ('GMOCK_INCLUDE_DIR', 'GTEST_LIBRARIES', 'GMOCK_INCLUDE_DIR', 'GMOCK_LIBRARIES') to specify the location.

## Using apt (Ubuntu and Debian)

Expand Down Expand Up @@ -186,7 +188,7 @@ $ mkdir build && cd build
# Specify [-DASYNC_SIMPLE_ENABLE_TESTS=OFF] to skip tests.
# Specify [-DASYNC_SIMPLE_BUILD_DEMO_EXAMPLE=OFF] to skip build demo example.
# Specify [-DASYNC_SIMPLE_DISABLE_AIO=ON] to skip the build libaio
CXX=clang++ CC=clang cmake ../ -DCMAKE_BUILD_TYPE=[Release|Debug] [-DASYNC_SIMPLE_ENABLE_TESTS=OFF] [-DASYNC_SIMPLE_BUILD_DEMO_EXAMPLE=OFF] [-DASYNC_SIMPLE_DISABLE_AIO=ON]
CXX=clang++ CC=clang cmake ../ -DCMAKE_BUILD_TYPE=[Release|Debug] [-DASYNC_SIMPLE_ENABLE_TESTS=OFF] [-DASYNC_SIMPLE_BUILD_DEMO_EXAMPLE=OFF] [-DASYNC_SIMPLE_DISABLE_AIO=ON] [-DGMOCK_INCLUDE_DIR=<path-to-headers of gtest> -DGTEST_INCLUDE_DIR=<path-to-headers of mock> -DGTEST_LIBRARIES=<path-to-library-of-gtest> -DGMOCK_LIBRARIES=<path-to-library-of-gmock> ]
# for gcc, use CXX=g++ CC=gcc
make -j4
make test # optional
Expand Down
5 changes: 4 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ async\_simple 涉及 C++20 协程,对编译器版本有较高要求。需要 c

本项目编译运行测试需要 gtest和gmock,需要 libaio 的示例代码则依赖 libaio。

默认情况下,async_simple 会尝试从 git 拉取 gtest 源码以保证版本一致性。在用户存在网络的情况下,
建议用户按照以下指令安装对应版本的 gtest 并使用 CMake 变量 ('GMOCK_INCLUDE_DIR', 'GTEST_LIBRARIES', 'GMOCK_INCLUDE_DIR', 'GMOCK_LIBRARIES') 指定安装的 gtest 所在的位置。

## Debian/Ubuntu系列

- 安装clang11及其以上版本。安装方法见:[APT Packages](https://apt.llvm.org/)
Expand Down Expand Up @@ -181,7 +184,7 @@ mkdir build && cd build
# Specify [-DASYNC_SIMPLE_ENABLE_TESTS=OFF] to skip tests.
# Specify [-DASYNC_SIMPLE_BUILD_DEMO_EXAMPLE=OFF] to skip build demo example.
# Specify [-DASYNC_SIMPLE_DISABLE_AIO=ON] to skip the build libaio
CXX=clang++ CC=clang cmake ../ -DCMAKE_BUILD_TYPE=[Release|Debug] [-DASYNC_SIMPLE_ENABLE_TESTS=OFF] [-DASYNC_SIMPLE_BUILD_DEMO_EXAMPLE=OFF] [-DASYNC_SIMPLE_DISABLE_AIO=ON]
CXX=clang++ CC=clang cmake ../ -DCMAKE_BUILD_TYPE=[Release|Debug] [-DASYNC_SIMPLE_ENABLE_TESTS=OFF] [-DASYNC_SIMPLE_BUILD_DEMO_EXAMPLE=OFF] [-DASYNC_SIMPLE_DISABLE_AIO=ON] [-DGMOCK_INCLUDE_DIR=<path-to-headers of gtest> -DGTEST_INCLUDE_DIR=<path-to-headers of mock> -DGTEST_LIBRARIES=<path-to-library-of-gtest> -DGMOCK_LIBRARIES=<path-to-library-of-gmock> ]
make -j4
make test
make install
Expand Down
38 changes: 23 additions & 15 deletions cmake/FindGTest.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
message(STATUS "fetch GTest from https://github.com/google/googletest.git")
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_GMOCK ON CACHE BOOL "" FORCE)
set(BUILD_GTEST ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
set(GMOCK_INCLUDE_DIR ${CMAKE_BINARY_DIR}/_deps/googletest-src/googlemock/include/)
set(GTEST_INCLUDE_DIR ${CMAKE_BINARY_DIR}/_deps/googletest-src/googletest/include/)
set(GTEST_LIBRARIES gtest_main)
set(GMOCK_LIBRARIES gmock_main)
if (DEFINED GMOCK_INCLUDE_DIR AND DEFINED GTEST_INCLUDE_DIR
AND DEFINED GTEST_LIBRARIES AND DEFINED GMOCK_LIBRARIES)
message(STATUS "Using GTest from specified path")
else()
message(STATUS "Not all GTest variable got specified: "
"'GMOCK_INCLUDE_DIR', 'GTEST_INCLUDE_DIR', "
"'GTEST_LIBRARIES', 'GMOCK_LIBRARIES'")
message(STATUS "fetch GTest from git@github.com:google/googletest.git")
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY git@github.com:google/googletest.git
GIT_TAG release-1.11.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_GMOCK ON CACHE BOOL "" FORCE)
set(BUILD_GTEST ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
set(GMOCK_INCLUDE_DIR ${CMAKE_BINARY_DIR}/_deps/googletest-src/googlemock/include/)
set(GTEST_INCLUDE_DIR ${CMAKE_BINARY_DIR}/_deps/googletest-src/googletest/include/)
set(GTEST_LIBRARIES gtest_main)
set(GMOCK_LIBRARIES gmock_main)
endif()

message(STATUS "GTest: ${GTEST_INCLUDE_DIR}, ${GTEST_LIBRARIES}")
message(STATUS "GMock: ${GMOCK_INCLUDE_DIR}, ${GMOCK_LIBRARIES}")

0 comments on commit 7690a05

Please sign in to comment.