Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CPP] Support alternative gtest url #179

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,8 @@ configure_file(
"${PROJECT_BINARY_DIR}/cmake_config.h"
)

set(TESTS_ENABLED OFF)
add_subdirectory(test)
add_dependencies(TsFile_Test tsfile)
if(TESTS_ENABLED)
add_dependencies(TsFile_Test tsfile)
endif()
43 changes: 38 additions & 5 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down