Skip to content

Commit

Permalink
[CMake] Skip connection check if fail-on-missing=ON
Browse files Browse the repository at this point in the history
The connection check only makes sense for `fail-on-missing=OFF`, where
the result is used to decide whether to download a missing dependency as
a builtin from the internet, or to disable the feature that has the
missing dependency.

With `fail-on-missing=ON`, it doesn't matter because disabling features
is not allowed. Therefore, we can skip the connection check to save some
configuration overhead and just assume we have internet: if a builtin
can't be downloaded there will be a configuration failure either way.

Closes root-project#11603 without introducing an additional flag.
  • Loading branch information
guitargeek committed May 9, 2024
1 parent 949e490 commit 8108667
Showing 1 changed file with 42 additions and 32 deletions.
74 changes: 42 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,48 +76,58 @@ include(cmake/modules/SetROOTVersion.cmake)

message(STATUS "Building ROOT version ${ROOT_FULL_VERSION}")

#---Try to download a file to check internet connection-----------------------------------------
message(STATUS "Checking internet connectivity")
file(DOWNLOAD https://root.cern/files/cmake_connectivity_test.txt ${CMAKE_CURRENT_BINARY_DIR}/cmake_connectivity_test.txt
TIMEOUT 10 STATUS DOWNLOAD_STATUS
)
# Get the status code from the download status
list(GET DOWNLOAD_STATUS 0 STATUS_CODE)
# Check if download was successful.
if(${STATUS_CODE} EQUAL 0)
# Succcess
message(STATUS "Checking internet connectivity - found")
# Now let's delete the file
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cmake_connectivity_test.txt)
set(NO_CONNECTION FALSE)
else()
# Error
message(STATUS "Checking internet connectivity - failed: will not automatically download external dependencies")
set(NO_CONNECTION TRUE)
endif()

if(NO_CONNECTION)
if(clad AND fail-on-missing)
message(FATAL_ERROR "No internet connection. Please check your connection, or either disable the 'clad' option or the 'fail-on-missing' to automatically disable options requiring internet access")
elseif(clad)
message(STATUS "No internet connection, disabling the 'clad' option")
endif()
set(clad OFF CACHE BOOL "Disabled because there is no internet connection" FORCE)
endif()

#---Where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked-------------
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)

#---Enable Folders in IDE like Visual Studio----------------------------------------------------
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

#---Load some basic macros which are needed later for the confiuration and build----------------
#---Load some basic macros which are needed later for the configuration and build----------------
include(CheckCompiler)
include(RootBuildOptions)
include(RootMacros)
include(CheckAssembler)
include(CheckIntrinsics)

#---Try to download a file to check internet connection-----------------------------------------

# The connection check only makes sense for fail-on-missing=OFF, where the
# result is used to decide whether to download a missing dependency as a builtin
# from the internet, or to disable the feature that has the missing dependency.
# With fail-on-missing=ON, it doesn't matter because disabling features is not
# allowed. Therefore, we can skip the connection check to save some
# configuration overhead and just assume we have internet: if a builtin can't be
# downloaded there will be a configuration failure either way.

if(fail-on-missing)
set(NO_CONNECTION FALSE)
else()
message(STATUS "Checking internet connectivity")
file(DOWNLOAD https://root.cern/files/cmake_connectivity_test.txt ${CMAKE_CURRENT_BINARY_DIR}/cmake_connectivity_test.txt
TIMEOUT 10 STATUS DOWNLOAD_STATUS
)
# Get the status code from the download status
list(GET DOWNLOAD_STATUS 0 STATUS_CODE)
# Check if download was successful.
if(${STATUS_CODE} EQUAL 0)
# Success
message(STATUS "Checking internet connectivity - found")
# Now let's delete the file
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cmake_connectivity_test.txt)
set(NO_CONNECTION FALSE)
else()
# Error
message(STATUS "Checking internet connectivity - failed: will not automatically download external dependencies")
set(NO_CONNECTION TRUE)
endif()
endif()

if(NO_CONNECTION AND clad)
message(STATUS "No internet connection, disabling the 'clad' option")
set(clad OFF CACHE BOOL "Disabled because there is no internet connection" FORCE)
endif()


# relatedrepo_GetClosestMatch(REPO_NAME <repo> ORIGIN_PREFIX <originp> UPSTREAM_PREFIX <upstreamp>
# FETCHURL_VARIABLE <output_url> FETCHREF_VARIABLE <output_ref>)
# Return the clone URL and head/tag of the closest match for `repo` (e.g. roottest), based on the
Expand Down Expand Up @@ -553,7 +563,7 @@ else()
endif()

# FIXME: move installation of PCMS in ROOT_GENERATE_DICTIONARY().
# We are excluding directories, which are accidentaly copied via unxpected behaviour of install(DIRECTORY ..)
# We are excluding directories, which are accidentally copied via unexpected behaviour of install(DIRECTORY ..)
install(
DIRECTORY ${CMAKE_BINARY_DIR}/lib/
DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down Expand Up @@ -634,7 +644,7 @@ endif()
add_custom_target(distsrc COMMAND ${CMAKE_SOURCE_DIR}/build/unix/makedistsrc.sh "${ROOT_FULL_VERSION}" "${CMAKE_SOURCE_DIR}")
add_custom_target(dist COMMAND cpack --config CPackConfig.cmake)

#---Configure and install various files neded later and for clients -----------------------------
#---Configure and install various files needed later and for clients -----------------------------
include(RootConfiguration)

#---Installation of project-wise artifacts-------------------------------------------------------
Expand Down

0 comments on commit 8108667

Please sign in to comment.