Update HunterGate cmake to support newer cmake versions (>4)

This commit is contained in:
Joe Donofry 2025-06-16 21:19:28 -04:00
parent 5f84baaa16
commit 1140f975d1

View file

@ -25,7 +25,7 @@
# This is a gate file to Hunter package manager. # This is a gate file to Hunter package manager.
# Include this file using `include` command and add package you need, example: # Include this file using `include` command and add package you need, example:
# #
# cmake_minimum_required(VERSION 3.2) # cmake_minimum_required(VERSION 3.10)
# #
# include("cmake/HunterGate.cmake") # include("cmake/HunterGate.cmake")
# HunterGate( # HunterGate(
@ -39,16 +39,16 @@
# hunter_add_package(Boo COMPONENTS Bar Baz) # hunter_add_package(Boo COMPONENTS Bar Baz)
# #
# Projects: # Projects:
# * https://github.com/hunter-packages/gate/ # * https://github.com/cpp-pm/gate/
# * https://github.com/ruslo/hunter # * https://github.com/cpp-pm/hunter
option(HUNTER_ENABLED "Enable Hunter package manager support" ON) option(HUNTER_ENABLED "Enable Hunter package manager support" ON)
if(HUNTER_ENABLED) if(HUNTER_ENABLED)
if(CMAKE_VERSION VERSION_LESS "3.2") if(CMAKE_VERSION VERSION_LESS "3.10")
message( message(
FATAL_ERROR FATAL_ERROR
"At least CMake version 3.2 required for Hunter dependency management." "At least CMake version 3.10 required for Hunter dependency management."
" Update CMake or set HUNTER_ENABLED to OFF." " Update CMake or set HUNTER_ENABLED to OFF."
) )
endif() endif()
@ -59,8 +59,9 @@ include(CMakeParseArguments) # cmake_parse_arguments
option(HUNTER_STATUS_PRINT "Print working status" ON) option(HUNTER_STATUS_PRINT "Print working status" ON)
option(HUNTER_STATUS_DEBUG "Print a lot info" OFF) option(HUNTER_STATUS_DEBUG "Print a lot info" OFF)
option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON) option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON)
set(HUNTER_ROOT "" CACHE FILEPATH "Override the HUNTER_ROOT.")
set(HUNTER_ERROR_PAGE "https://docs.hunter.sh/en/latest/reference/errors") set(HUNTER_ERROR_PAGE "https://hunter.readthedocs.io/en/latest/reference/errors")
function(hunter_gate_status_print) function(hunter_gate_status_print)
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG) if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
@ -148,24 +149,21 @@ endfunction()
# Set HUNTER_GATE_ROOT cmake variable to suitable value. # Set HUNTER_GATE_ROOT cmake variable to suitable value.
function(hunter_gate_detect_root) function(hunter_gate_detect_root)
# Check CMake variable # Check CMake variable
string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty) if(HUNTER_ROOT)
if(not_empty)
set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE) set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable") hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable")
return() return()
endif() endif()
# Check environment variable # Check environment variable
string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty) if(DEFINED ENV{HUNTER_ROOT})
if(not_empty)
set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE) set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT detected by environment variable") hunter_gate_status_debug("HUNTER_ROOT detected by environment variable")
return() return()
endif() endif()
# Check HOME environment variable # Check HOME environment variable
string(COMPARE NOTEQUAL "$ENV{HOME}" "" result) if(DEFINED ENV{HOME})
if(result)
set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE) set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable") hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable")
return() return()
@ -173,8 +171,7 @@ function(hunter_gate_detect_root)
# Check SYSTEMDRIVE and USERPROFILE environment variable (windows only) # Check SYSTEMDRIVE and USERPROFILE environment variable (windows only)
if(WIN32) if(WIN32)
string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result) if(DEFINED ENV{SYSTEMDRIVE})
if(result)
set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE) set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug( hunter_gate_status_debug(
"HUNTER_ROOT set using SYSTEMDRIVE environment variable" "HUNTER_ROOT set using SYSTEMDRIVE environment variable"
@ -182,8 +179,7 @@ function(hunter_gate_detect_root)
return() return()
endif() endif()
string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result) if(DEFINED ENV{USERPROFILE})
if(result)
set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE) set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug( hunter_gate_status_debug(
"HUNTER_ROOT set using USERPROFILE environment variable" "HUNTER_ROOT set using USERPROFILE environment variable"
@ -257,7 +253,13 @@ function(hunter_gate_download dir)
file( file(
WRITE WRITE
"${cmakelists}" "${cmakelists}"
"cmake_minimum_required(VERSION 3.2)\n" "cmake_minimum_required(VERSION 3.10)\n"
"if(POLICY CMP0114)\n"
" cmake_policy(SET CMP0114 NEW)\n"
"endif()\n"
"if(POLICY CMP0135)\n"
" cmake_policy(SET CMP0135 NEW)\n"
"endif()\n"
"project(HunterDownload LANGUAGES NONE)\n" "project(HunterDownload LANGUAGES NONE)\n"
"include(ExternalProject)\n" "include(ExternalProject)\n"
"ExternalProject_Add(\n" "ExternalProject_Add(\n"
@ -517,7 +519,9 @@ macro(HunterGate)
hunter_gate_internal_error("${_sha1_location} not found") hunter_gate_internal_error("${_sha1_location} not found")
endif() endif()
file(READ "${_sha1_location}" _sha1_value) file(READ "${_sha1_location}" _sha1_value)
string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal) string(TOLOWER "${_sha1_value}" _sha1_value_lower)
string(TOLOWER "${HUNTER_GATE_SHA1}" _HUNTER_GATE_SHA1_lower)
string(COMPARE EQUAL "${_sha1_value_lower}" "${_HUNTER_GATE_SHA1_lower}" _is_equal)
if(NOT _is_equal) if(NOT _is_equal)
hunter_gate_internal_error( hunter_gate_internal_error(
"Short SHA1 collision:" "Short SHA1 collision:"