55# The complete license agreement can be obtained at:
66# http://arrayfire.com/licenses/BSD-3-Clause
77
8- option (FG_BUILD_OFFLINE "Build Forge assuming there is no network" OFF )
8+ file (DOWNLOAD
9+ "https://github.com/arrayfire/forge/blob/v1.0.0/CMakeLists.txt"
10+ "${Forge_BINARY_DIR} /download_copy_cmakelists.stamp"
11+ STATUS fg_check_result
12+ TIMEOUT 4
13+ )
14+ list (GET fg_check_result 0 fg_is_connected)
15+ if (${fg_is_connected} )
16+ set (BUILD_OFFLINE ON )
17+ # Turn ON disconnected flag when connected to cloud
18+ set (FETCHCONTENT_FULLY_DISCONNECTED ON CACHE BOOL
19+ "Disable Download/Update stages of FetchContent workflow" FORCE )
20+
21+ message (STATUS "No cloud connection. Attempting offline build if dependencies are available" )
22+ else ()
23+ set (BUILD_OFFLINE OFF )
24+ # Turn OFF disconnected flag when connected to cloud
25+ # This is required especially in the following scenario:
26+ # - cmake run successfully first
27+ # - lost connection, but development can still be done
28+ # - Now, connection regained. Hence updates should be allowed
29+ set (FETCHCONTENT_FULLY_DISCONNECTED OFF CACHE BOOL
30+ "Disable Download/Update stages of FetchContent workflow" FORCE )
31+ endif ()
32+
33+ # Track dependencies download persistently across multiple
34+ # cmake configure runs. *_POPULATED variables are reset for each
35+ # cmake run to 0. Hence, this internal cache value is needed to
36+ # check for already (from previous cmake run's) populated data
37+ # during the current cmake run if it looses network connection.
38+ set (FG_INTERNAL_DOWNLOAD_FLAG OFF CACHE BOOL "Dependencies Download Tracker Flag" )
939
1040# Override fetch content base dir before including AFfetch_content
1141set (FETCHCONTENT_BASE_DIR "${Forge_BINARY_DIR} /extern" CACHE PATH
1242 "Base directory where Forge dependencies are downloaded and/or built" FORCE )
1343
1444include (ForgeFetchContent )
1545
16- macro (set_and_mark_depname var name )
46+ mark_as_advanced (
47+ FG_INTERNAL_DOWNLOAD_FLAG
48+ FETCHCONTENT_BASE_DIR
49+ FETCHCONTENT_QUIET
50+ FETCHCONTENT_FULLY_DISCONNECTED
51+ FETCHCONTENT_UPDATES_DISCONNECTED
52+ )
53+
54+ macro (set_and_mark_depnames_advncd var name )
1755 string (TOLOWER ${name} ${var} )
1856 string (TOUPPER ${name} ${var} _ucname)
1957 mark_as_advanced (
@@ -22,31 +60,79 @@ macro(set_and_mark_depname var name)
2260 )
2361endmacro ()
2462
25- mark_as_advanced (
26- FETCHCONTENT_BASE_DIR
27- FETCHCONTENT_QUIET
28- FETCHCONTENT_FULLY_DISCONNECTED
29- FETCHCONTENT_UPDATES_DISCONNECTED
30- )
63+ set_and_mark_depnames_advncd (glad_prefix "fg_glad" )
64+ set_and_mark_depnames_advncd (glm_prefix "fg_glm" )
3165
32- set_and_mark_depname (glad_prefix "fg_glad" )
33- set_and_mark_depname (glm_prefix "fg_glm" )
66+ macro (fg_dep_check_and_populate dep_prefix )
67+ set (single_args URI REF)
68+ cmake_parse_arguments (fdcp_args "" "${single_args} " "" ${ARGN} )
3469
35- if (FG_BUILD_OFFLINE )
36- macro ( set_fetchcontent_src_dir prefix_var dep_name )
37- set (FETCHCONTENT_SOURCE_DIR_${ ${prefix_var} _ucname}
38- " ${FETCHCONTENT_BASE_DIR} /${ ${prefix_var} }-src" CACHE PATH
39- "Source directory for ${dep_name} dependency" )
40- mark_as_advanced ( FETCHCONTENT_SOURCE_DIR_${${prefix_var}_ucname} )
41- endmacro ()
70+ if (" ${fdcp_args_URI} " STREQUAL "" )
71+ message ( FATAL_ERROR [=[
72+ Cannot check requested dependency source's availability.
73+ Please provide a valid URI(almost always a URL to a github repo).
74+ Note that the above error message if for developers of Forge.
75+ ]=] )
76+ endif ()
4277
43- set_fetchcontent_src_dir (assets_prefix "glad" )
44- set_fetchcontent_src_dir (testdata_prefix "glm" )
45- endif ()
78+ string (FIND "${fdcp_args_REF} " "=" fdcp_has_algo_id)
4679
47- macro (fg_check_and_populate prefix )
48- FetchContent_GetProperties (${prefix} )
49- if (NOT ${prefix} _POPULATED)
50- FetchContent_Populate (${prefix} )
80+ if (${BUILD_OFFLINE} AND NOT ${FG_INTERNAL_DOWNLOAD_FLAG} )
81+ if (NOT ${fdcp_has_algo_id} EQUAL -1)
82+ FetchContent_Populate (${dep_prefix}
83+ QUIET
84+ URL ${fdcp_args_URI}
85+ URL_HASH ${fdcp_args_REF}
86+ DOWNLOAD_COMMAND \"\"
87+ UPDATE_DISCONNECTED ON
88+ SOURCE_DIR " ${Forge_SOURCE_DIR} /extern/${dep_prefix} -src"
89+ BINARY_DIR " ${Forge_BINARY_DIR} /extern/${dep_prefix} -build"
90+ SUBBUILD_DIR " ${Forge_BINARY_DIR} /extern/${dep_prefix} -subbuild"
91+ )
92+ elseif(" ${fdcp_args_REF} " STREQUAL "")
93+ FetchContent_Populate(${dep_prefix}
94+ QUIET
95+ URL ${fdcp_args_URI}
96+ DOWNLOAD_COMMAND \"\"
97+ UPDATE_DISCONNECTED ON
98+ SOURCE_DIR " ${Forge_SOURCE_DIR} /extern/${dep_prefix} -src"
99+ BINARY_DIR " ${Forge_BINARY_DIR} /extern/${dep_prefix} -build"
100+ SUBBUILD_DIR " ${Forge_BINARY_DIR} /extern/${dep_prefix} -subbuild"
101+ )
102+ else()
103+ # The left over alternative is assumed to be a cloud hosted git repository
104+ FetchContent_Populate(${dep_prefix}
105+ QUIET
106+ GIT_REPOSITORY ${fdcp_args_URI}
107+ GIT_TAG ${fdcp_args_REF}
108+ DOWNLOAD_COMMAND \"\"
109+ UPDATE_DISCONNECTED ON
110+ SOURCE_DIR " ${Forge_SOURCE_DIR} /extern/${dep_prefix} -src"
111+ BINARY_DIR " ${Forge_BINARY_DIR} /extern/${dep_prefix} -build"
112+ SUBBUILD_DIR " ${Forge_BINARY_DIR} /extern/${dep_prefix} -subbuild"
113+ )
114+ endif()
115+ else()
116+ if(NOT ${fdcp_has_algo_id} EQUAL -1)
117+ FetchContent_Declare(${dep_prefix}
118+ URL ${fdcp_args_URI}
119+ URL_HASH ${fdcp_args_REF}
120+ )
121+ elseif(" ${fdcp_args_REF} " STREQUAL "")
122+ FetchContent_Declare(${dep_prefix}
123+ URL ${fdcp_args_URI}
124+ )
125+ else()
126+ # The left over alternative is assumed to be a cloud hosted git repository
127+ FetchContent_Declare(${dep_prefix}
128+ GIT_REPOSITORY ${fdcp_args_URI}
129+ GIT_TAG ${fdcp_args_REF}
130+ )
131+ endif()
132+ FetchContent_GetProperties(${dep_prefix} )
133+ if(NOT ${dep_prefix} _POPULATED)
134+ FetchContent_Populate(${dep_prefix} )
135+ endif()
136+ set(FG_INTERNAL_DOWNLOAD_FLAG ON CACHE BOOL " Dependencies Download Tracker Flag" FORCE)
51137 endif()
52138endmacro()
0 commit comments