2525# This is a gate file to Hunter package manager.
2626# Include this file using `include` command and add package you need, example:
2727#
28- # cmake_minimum_required(VERSION 3.2 )
28+ # cmake_minimum_required(VERSION 3.10 )
2929#
3030# include("cmake/HunterGate.cmake")
3131# HunterGate(
3939# hunter_add_package(Boo COMPONENTS Bar Baz)
4040#
4141# Projects:
42- # * https://github.com/hunter-packages /gate/
43- # * https://github.com/ruslo /hunter
42+ # * https://github.com/cpp-pm /gate/
43+ # * https://github.com/cpp-pm /hunter
4444
4545option (HUNTER_ENABLED "Enable Hunter package manager support" ON )
4646
4747if (HUNTER_ENABLED)
48- if (CMAKE_VERSION VERSION_LESS "3.2 " )
48+ if (CMAKE_VERSION VERSION_LESS "3.10 " )
4949 message (
5050 FATAL_ERROR
51- "At least CMake version 3.2 required for Hunter dependency management."
51+ "At least CMake version 3.10 required for Hunter dependency management."
5252 " Update CMake or set HUNTER_ENABLED to OFF."
5353 )
5454 endif ()
@@ -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"
@@ -253,7 +253,13 @@ function(hunter_gate_download dir)
253253 file (
254254 WRITE
255255 "${cmakelists} "
256- "cmake_minimum_required(VERSION 3.2)\n "
256+ "cmake_minimum_required(VERSION 3.10)\n "
257+ "if(POLICY CMP0114)\n "
258+ " cmake_policy(SET CMP0114 NEW)\n "
259+ "endif()\n "
260+ "if(POLICY CMP0135)\n "
261+ " cmake_policy(SET CMP0135 NEW)\n "
262+ "endif()\n "
257263 "project(HunterDownload LANGUAGES NONE)\n "
258264 "include(ExternalProject)\n "
259265 "ExternalProject_Add(\n "
@@ -490,37 +496,46 @@ macro(HunterGate)
490496 )
491497
492498 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 ()
499+ if (EXISTS "${HUNTER_GATE_ROOT} /cmake/Hunter" )
500+ # Hunter downloaded manually (e.g. by 'git clone')
501+ set (_unused "xxxxxxxxxx" )
502+ set (HUNTER_GATE_SHA1 "${_unused} " )
503+ set (HUNTER_GATE_VERSION "${_unused} " )
504+ else ()
505+ get_filename_component (_archive_id_location "${_hunter_self} /.." ABSOLUTE )
506+ set (_done_location "${_archive_id_location} /DONE" )
507+ set (_sha1_location "${_archive_id_location} /SHA1" )
508+
509+ # Check Hunter already downloaded by HunterGate
510+ if (NOT EXISTS "${_done_location} " )
511+ hunter_gate_download("${_archive_id_location} " )
512+ endif ()
501513
502- if (NOT EXISTS "${_done_location} " )
503- hunter_gate_internal_error("hunter_gate_download failed" )
504- endif ()
514+ if (NOT EXISTS "${_done_location} " )
515+ hunter_gate_internal_error("hunter_gate_download failed" )
516+ endif ()
505517
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- )
518+ if (NOT EXISTS "${_sha1_location} " )
519+ hunter_gate_internal_error("${_sha1_location} not found" )
520+ endif ()
521+ file (READ "${_sha1_location} " _sha1_value)
522+ string (TOLOWER "${_sha1_value} " _sha1_value_lower)
523+ string (TOLOWER "${HUNTER_GATE_SHA1} " _HUNTER_GATE_SHA1_lower)
524+ string (COMPARE EQUAL "${_sha1_value_lower} " "${_HUNTER_GATE_SHA1_lower} " _is_equal)
525+ if (NOT _is_equal)
526+ hunter_gate_internal_error(
527+ "Short SHA1 collision:"
528+ " ${_sha1_value} (from ${_sha1_location} )"
529+ " ${HUNTER_GATE_SHA1} (HunterGate)"
530+ )
531+ endif ()
532+ if (NOT EXISTS "${_master_location} " )
533+ hunter_gate_user_error(
534+ "Master file not found:"
535+ " ${_master_location} "
536+ "try to update Hunter/HunterGate"
537+ )
538+ endif ()
524539 endif ()
525540 include ("${_master_location} " )
526541 set_property (GLOBAL PROPERTY HUNTER_GATE_DONE YES )
0 commit comments