aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2022-02-21 16:38:41 +0100
committerGitHub <noreply@github.com>2022-02-21 16:38:41 +0100
commitdd96597e86a0d4df1c6af0e32e1bb6bee1f840dd (patch)
treea569d78995d4c32d76d5a4195f353bfdf71a121d
parent1941f06e2767891e0d24e0547bbf7508b2839963 (diff)
parent88a4180271ac872084d42269fa3edbb1254116aa (diff)
downloadPROJ-dd96597e86a0d4df1c6af0e32e1bb6bee1f840dd.tar.gz
PROJ-dd96597e86a0d4df1c6af0e32e1bb6bee1f840dd.zip
Merge pull request #3062 from rouault/fix_3060
CMake: set RUN_NETWORK_DEPENDENT_TESTS to ON by default only if network seems available (fixes #3060)
-rw-r--r--test/CMakeLists.txt39
1 files changed, 38 insertions, 1 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index f3420237..84900692 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,6 +1,43 @@
set(GIE_BIN "gie")
-option(RUN_NETWORK_DEPENDENT_TESTS "Whether to run tests dependent on network availability" ON)
+if(CURL_ENABLED AND NOT DEFINED RUN_NETWORK_DEPENDENT_TESTS)
+ message(STATUS "Checking if network is available...")
+ # First try with curl as we can get an 'instant' answer if it is there
+ execute_process(
+ COMMAND curl -I https://www.google.com
+ OUTPUT_QUIET
+ ERROR_QUIET
+ RESULT_VARIABLE NO_CONNECTION
+ )
+ if(NOT NO_CONNECTION EQUAL 0)
+ # Then fallback to ping
+ # From https://stackoverflow.com/questions/62214621/how-to-check-for-internet-connection-with-cmake-automatically-prevent-fails-if/68376537#68376537
+ if(WIN32)
+ execute_process(
+ COMMAND ping www.google.com -n 2
+ OUTPUT_QUIET
+ ERROR_QUIET
+ RESULT_VARIABLE NO_CONNECTION
+ )
+ else()
+ execute_process(
+ COMMAND ping www.google.com -c 2
+ OUTPUT_QUIET
+ ERROR_QUIET
+ RESULT_VARIABLE NO_CONNECTION
+ )
+ endif()
+ endif()
+
+ if(NOT NO_CONNECTION EQUAL 0)
+ message(WARNING "... no. Skipping network dependent tests.")
+ set(RUN_NETWORK_DEPENDENT_TESTS_DEFAULT_VAL OFF)
+ else()
+ message(STATUS "... yes")
+ set(RUN_NETWORK_DEPENDENT_TESTS_DEFAULT_VAL ON)
+ endif()
+ option(RUN_NETWORK_DEPENDENT_TESTS "Whether to run tests dependent on network availability" ${RUN_NETWORK_DEPENDENT_TESTS_DEFAULT_VAL})
+endif()
# Regression tests
proj_add_gie_test("Builtins" "gie/builtins.gie")