diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2022-02-16 16:54:10 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2022-02-18 11:55:23 +0100 |
| commit | 88a4180271ac872084d42269fa3edbb1254116aa (patch) | |
| tree | b2d4bed036e2b88f9fbbcb36b83ee0f6df263808 /test/CMakeLists.txt | |
| parent | 524b76f2e9f4bb8e4a8d2a4287c23e67c67fce07 (diff) | |
| download | PROJ-88a4180271ac872084d42269fa3edbb1254116aa.tar.gz PROJ-88a4180271ac872084d42269fa3edbb1254116aa.zip | |
CMake: set RUN_NETWORK_DEPENDENT_TESTS to ON by default only if network seems available (fixes #3060)
Diffstat (limited to 'test/CMakeLists.txt')
| -rw-r--r-- | test/CMakeLists.txt | 39 |
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") |
