@@ -59,8 +59,9 @@ include(CMakeParseArguments) # cmake_parse_arguments
5959option (HUNTER_STATUS_PRINT "Print working status" ON )
6060option (HUNTER_STATUS_DEBUG "Print a lot info" OFF )
6161option (HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON )
62+ set (HUNTER_ROOT "" CACHE FILEPATH "Override the HUNTER_ROOT." )
6263
63- set (HUNTER_ERROR_PAGE "https://docs. hunter.sh /en/latest/reference/errors" )
64+ set (HUNTER_ERROR_PAGE "https://hunter.readthedocs.io /en/latest/reference/errors" )
6465
6566function (hunter_gate_status_print)
6667 if (HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
@@ -133,53 +134,52 @@ function(hunter_gate_self root version sha1 result)
133134
134135 string (SUBSTRING "${sha1} " 0 7 archive_id)
135136
136- set (
137- hunter_self
138- "${root} /_Base/Download/Hunter/${version} /${archive_id} /Unpacked"
139- )
137+ if (EXISTS "${root} /cmake/Hunter" )
138+ set (hunter_self "${root} " )
139+ else ()
140+ set (
141+ hunter_self
142+ "${root} /_Base/Download/Hunter/${version} /${archive_id} /Unpacked"
143+ )
144+ endif ()
140145
141146 set ("${result} " "${hunter_self} " PARENT_SCOPE)
142147endfunction ()
143148
144149# Set HUNTER_GATE_ROOT cmake variable to suitable value.
145150function (hunter_gate_detect_root)
146151 # Check CMake variable
147- string (COMPARE NOTEQUAL "${HUNTER_ROOT} " "" not_empty)
148- if (not_empty)
152+ if (HUNTER_ROOT)
149153 set (HUNTER_GATE_ROOT "${HUNTER_ROOT} " PARENT_SCOPE)
150154 hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable" )
151155 return ()
152156 endif ()
153157
154158 # Check environment variable
155- string (COMPARE NOTEQUAL "$ENV{HUNTER_ROOT} " "" not_empty)
156- if (not_empty)
159+ if (DEFINED ENV{HUNTER_ROOT})
157160 set (HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT} " PARENT_SCOPE)
158161 hunter_gate_status_debug("HUNTER_ROOT detected by environment variable" )
159162 return ()
160163 endif ()
161164
162165 # Check HOME environment variable
163- string (COMPARE NOTEQUAL "$ENV{HOME} " "" result)
164- if (result)
166+ if (DEFINED ENV{HOME})
165167 set (HUNTER_GATE_ROOT "$ENV{HOME} /.hunter" PARENT_SCOPE)
166168 hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable" )
167169 return ()
168170 endif ()
169171
170172 # Check SYSTEMDRIVE and USERPROFILE environment variable (windows only)
171173 if (WIN32 )
172- string (COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE} " "" result)
173- if (result)
174+ if (DEFINED ENV{SYSTEMDRIVE})
174175 set (HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE} /.hunter" PARENT_SCOPE)
175176 hunter_gate_status_debug(
176177 "HUNTER_ROOT set using SYSTEMDRIVE environment variable"
177178 )
178179 return ()
179180 endif ()
180181
181- string (COMPARE NOTEQUAL "$ENV{USERPROFILE} " "" result)
182- if (result)
182+ if (DEFINED ENV{USERPROFILE})
183183 set (HUNTER_GATE_ROOT "$ENV{USERPROFILE} /.hunter" PARENT_SCOPE)
184184 hunter_gate_status_debug(
185185 "HUNTER_ROOT set using USERPROFILE environment variable"
@@ -490,37 +490,46 @@ macro(HunterGate)
490490 )
491491
492492 set (_master_location "${_hunter_self} /cmake/Hunter" )
493- get_filename_component (_archive_id_location "${_hunter_self} /.." ABSOLUTE )
494- set (_done_location "${_archive_id_location} /DONE" )
495- set (_sha1_location "${_archive_id_location} /SHA1" )
496-
497- # Check Hunter already downloaded by HunterGate
498- if (NOT EXISTS "${_done_location} " )
499- hunter_gate_download("${_archive_id_location} " )
500- endif ()
493+ if (EXISTS "${HUNTER_GATE_ROOT} /cmake/Hunter" )
494+ # Hunter downloaded manually (e.g. by 'git clone')
495+ set (_unused "xxxxxxxxxx" )
496+ set (HUNTER_GATE_SHA1 "${_unused} " )
497+ set (HUNTER_GATE_VERSION "${_unused} " )
498+ else ()
499+ get_filename_component (_archive_id_location "${_hunter_self} /.." ABSOLUTE )
500+ set (_done_location "${_archive_id_location} /DONE" )
501+ set (_sha1_location "${_archive_id_location} /SHA1" )
502+
503+ # Check Hunter already downloaded by HunterGate
504+ if (NOT EXISTS "${_done_location} " )
505+ hunter_gate_download("${_archive_id_location} " )
506+ endif ()
501507
502- if (NOT EXISTS "${_done_location} " )
503- hunter_gate_internal_error("hunter_gate_download failed" )
504- endif ()
508+ if (NOT EXISTS "${_done_location} " )
509+ hunter_gate_internal_error("hunter_gate_download failed" )
510+ endif ()
505511
506- if (NOT EXISTS "${_sha1_location} " )
507- hunter_gate_internal_error("${_sha1_location} not found" )
508- endif ()
509- file (READ "${_sha1_location} " _sha1_value)
510- string (COMPARE EQUAL "${_sha1_value} " "${HUNTER_GATE_SHA1} " _is_equal)
511- if (NOT _is_equal)
512- hunter_gate_internal_error(
513- "Short SHA1 collision:"
514- " ${_sha1_value} (from ${_sha1_location} )"
515- " ${HUNTER_GATE_SHA1} (HunterGate)"
516- )
517- endif ()
518- if (NOT EXISTS "${_master_location} " )
519- hunter_gate_user_error(
520- "Master file not found:"
521- " ${_master_location} "
522- "try to update Hunter/HunterGate"
523- )
512+ if (NOT EXISTS "${_sha1_location} " )
513+ hunter_gate_internal_error("${_sha1_location} not found" )
514+ endif ()
515+ file (READ "${_sha1_location} " _sha1_value)
516+ string (TOLOWER "${_sha1_value} " _sha1_value_lower)
517+ string (TOLOWER "${HUNTER_GATE_SHA1} " _HUNTER_GATE_SHA1_lower)
518+ string (COMPARE EQUAL "${_sha1_value_lower} " "${_HUNTER_GATE_SHA1_lower} " _is_equal)
519+ if (NOT _is_equal)
520+ hunter_gate_internal_error(
521+ "Short SHA1 collision:"
522+ " ${_sha1_value} (from ${_sha1_location} )"
523+ " ${HUNTER_GATE_SHA1} (HunterGate)"
524+ )
525+ endif ()
526+ if (NOT EXISTS "${_master_location} " )
527+ hunter_gate_user_error(
528+ "Master file not found:"
529+ " ${_master_location} "
530+ "try to update Hunter/HunterGate"
531+ )
532+ endif ()
524533 endif ()
525534 include ("${_master_location} " )
526535 set_property (GLOBAL PROPERTY HUNTER_GATE_DONE YES )
0 commit comments