This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch iotdb in repository https://gitbox.apache.org/repos/asf/tsfile.git
commit 91ea85605fda2921d9f93da956b0ea4e8081d787 Author: Hongzhi Gao <[email protected]> AuthorDate: Mon Jul 22 16:28:12 2024 +0800 [CPP] Support alternative gtest url (#179) --- cpp/CMakeLists.txt | 5 ++++- cpp/test/CMakeLists.txt | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index ebc1d440..afca5202 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -74,5 +74,8 @@ configure_file( "${PROJECT_BINARY_DIR}/cmake_config.h" ) +set(TESTS_ENABLED OFF) add_subdirectory(test) -add_dependencies(TsFile_Test tsfile) \ No newline at end of file +if(TESTS_ENABLED) + add_dependencies(TsFile_Test tsfile) +endif() \ No newline at end of file diff --git a/cpp/test/CMakeLists.txt b/cpp/test/CMakeLists.txt index fc9469c3..91fa71c5 100644 --- a/cpp/test/CMakeLists.txt +++ b/cpp/test/CMakeLists.txt @@ -17,12 +17,45 @@ specific language governing permissions and limitations under the License. ]] include(FetchContent) -FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/refs/tags/v1.12.0.zip + +set(URL_LIST + "https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip" + "https://hub.nuaa.cf/google/googletest/archive/refs/tags/release-1.12.1.zip" + "https://hub.yzuu.cf/google/googletest/archive/refs/tags/release-1.12.1.zip" ) -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(googletest) + +set(DOWNLOADED 0) +set(GTEST_URL "") +set(TIMEOUT 30) + +foreach(URL ${URL_LIST}) + message(STATUS "Trying to download from ${URL}") + file(DOWNLOAD ${URL} "${CMAKE_BINARY_DIR}/googletest-release-1.12.1.zip" STATUS DOWNLOAD_STATUS TIMEOUT ${TIMEOUT}) + + list(GET DOWNLOAD_STATUS 0 DOWNLOAD_RESULT) + if(${DOWNLOAD_RESULT} EQUAL 0) + set(DOWNLOADED 1) + set(GTEST_URL ${URL}) + break() + endif() +endforeach() + +if(${DOWNLOADED}) + message(STATUS "Successfully downloaded googletest from ${GTEST_URL}") + FetchContent_Declare( + googletest + URL ${GTEST_URL} + ) + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) + set(TESTS_ENABLED ON PARENT_SCOPE) +else() + message(WARNING "Failed to download googletest from all provided URLs, setting TESTS_ENABLED to OFF") + set(TESTS_ENABLED OFF PARENT_SCOPE) + return() +endif() + +message(STATUS "Adding test configurations...") set(SDK_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/../src) message("SDK_INCLUDE_DIR: ${SDK_INCLUDE_DIR}")
