Skip to content

Commit 30a4ce4

Browse files
authored
Update minimum CMake to v3.10 and HunterGate.cmake (#449)
Starting from CMake 4.0, any project that does not explicitly declare compatibility with version 3.5 or newer fail hards. As HunterGate.cmake also refers to old CMake 3.0, so new version was imported from https://github.com/cpp-pm/gate/blob/master/cmake/HunterGate.cmake As new HunterGate.cmake requires CMake>=3.10, `cmake_minimum_required` is now set to `3.10...4.0`. Closes #448
1 parent ecdad45 commit 30a4ce4

3 files changed

Lines changed: 61 additions & 61 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.2)
1+
cmake_minimum_required(VERSION 3.10...4.0)
22

33
set(FDEEP_TOP_DIR ${CMAKE_CURRENT_LIST_DIR})
44

INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ The basic idea is to use the standard hunter setup but to add a git submodule to
8585
Your CMakeLists.txt should look something like
8686

8787
```cmake
88-
cmake_minimum_required(VERSION 3.0) # minimum requirement for Hunter
88+
cmake_minimum_required(VERSION 3.10...4.0) # minimum requirement for Hunter
8989
9090
include("cmake/HunterGate.cmake") # teach your project about Hunter (before project())
9191
HunterGate( # Latest release shown here: https://github.com/ruslo/hunter/releases

cmake/HunterGate.cmake

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2013-2017, Ruslan Baratov
1+
# Copyright (c) 2013-2019, Ruslan Baratov
22
# All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without
@@ -25,7 +25,7 @@
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.0)
28+
# cmake_minimum_required(VERSION 3.10)
2929
#
3030
# include("cmake/HunterGate.cmake")
3131
# HunterGate(
@@ -39,14 +39,18 @@
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

4545
option(HUNTER_ENABLED "Enable Hunter package manager support" ON)
46+
4647
if(HUNTER_ENABLED)
47-
if(CMAKE_VERSION VERSION_LESS "3.0")
48-
message(FATAL_ERROR "At least CMake version 3.0 required for hunter dependency management."
49-
" Update CMake or set HUNTER_ENABLED to OFF.")
48+
if(CMAKE_VERSION VERSION_LESS "3.10")
49+
message(
50+
FATAL_ERROR
51+
"At least CMake version 3.10 required for Hunter dependency management."
52+
" Update CMake or set HUNTER_ENABLED to OFF."
53+
)
5054
endif()
5155
endif()
5256

@@ -55,29 +59,30 @@ include(CMakeParseArguments) # cmake_parse_arguments
5559
option(HUNTER_STATUS_PRINT "Print working status" ON)
5660
option(HUNTER_STATUS_DEBUG "Print a lot info" OFF)
5761
option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON)
62+
set(HUNTER_ROOT "" CACHE FILEPATH "Override the HUNTER_ROOT.")
5863

59-
set(HUNTER_WIKI "https://github.com/ruslo/hunter/wiki")
64+
set(HUNTER_ERROR_PAGE "https://hunter.readthedocs.io/en/latest/reference/errors")
6065

6166
function(hunter_gate_status_print)
62-
foreach(print_message ${ARGV})
63-
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
67+
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
68+
foreach(print_message ${ARGV})
6469
message(STATUS "[hunter] ${print_message}")
65-
endif()
66-
endforeach()
70+
endforeach()
71+
endif()
6772
endfunction()
6873

6974
function(hunter_gate_status_debug)
70-
foreach(print_message ${ARGV})
71-
if(HUNTER_STATUS_DEBUG)
75+
if(HUNTER_STATUS_DEBUG)
76+
foreach(print_message ${ARGV})
7277
string(TIMESTAMP timestamp)
7378
message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}")
74-
endif()
75-
endforeach()
79+
endforeach()
80+
endif()
7681
endfunction()
7782

78-
function(hunter_gate_wiki wiki_page)
79-
message("------------------------------ WIKI -------------------------------")
80-
message(" ${HUNTER_WIKI}/${wiki_page}")
83+
function(hunter_gate_error_page error_page)
84+
message("------------------------------ ERROR ------------------------------")
85+
message(" ${HUNTER_ERROR_PAGE}/${error_page}.html")
8186
message("-------------------------------------------------------------------")
8287
message("")
8388
message(FATAL_ERROR "")
@@ -90,26 +95,25 @@ function(hunter_gate_internal_error)
9095
endforeach()
9196
message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
9297
message("")
93-
hunter_gate_wiki("error.internal")
98+
hunter_gate_error_page("error.internal")
9499
endfunction()
95100

96101
function(hunter_gate_fatal_error)
97-
cmake_parse_arguments(hunter "" "WIKI" "" "${ARGV}")
98-
string(COMPARE EQUAL "${hunter_WIKI}" "" have_no_wiki)
99-
if(have_no_wiki)
100-
hunter_gate_internal_error("Expected wiki")
102+
cmake_parse_arguments(hunter "" "ERROR_PAGE" "" "${ARGV}")
103+
if("${hunter_ERROR_PAGE}" STREQUAL "")
104+
hunter_gate_internal_error("Expected ERROR_PAGE")
101105
endif()
102106
message("")
103107
foreach(x ${hunter_UNPARSED_ARGUMENTS})
104108
message("[hunter ** FATAL ERROR **] ${x}")
105109
endforeach()
106110
message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
107111
message("")
108-
hunter_gate_wiki("${hunter_WIKI}")
112+
hunter_gate_error_page("${hunter_ERROR_PAGE}")
109113
endfunction()
110114

111115
function(hunter_gate_user_error)
112-
hunter_gate_fatal_error(${ARGV} WIKI "error.incorrect.input.data")
116+
hunter_gate_fatal_error(${ARGV} ERROR_PAGE "error.incorrect.input.data")
113117
endfunction()
114118

115119
function(hunter_gate_self root version sha1 result)
@@ -145,42 +149,37 @@ endfunction()
145149
# Set HUNTER_GATE_ROOT cmake variable to suitable value.
146150
function(hunter_gate_detect_root)
147151
# Check CMake variable
148-
string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty)
149-
if(not_empty)
152+
if(HUNTER_ROOT)
150153
set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE)
151154
hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable")
152155
return()
153156
endif()
154157

155158
# Check environment variable
156-
string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty)
157-
if(not_empty)
159+
if(DEFINED ENV{HUNTER_ROOT})
158160
set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE)
159161
hunter_gate_status_debug("HUNTER_ROOT detected by environment variable")
160162
return()
161163
endif()
162164

163165
# Check HOME environment variable
164-
string(COMPARE NOTEQUAL "$ENV{HOME}" "" result)
165-
if(result)
166+
if(DEFINED ENV{HOME})
166167
set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE)
167168
hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable")
168169
return()
169170
endif()
170171

171172
# Check SYSTEMDRIVE and USERPROFILE environment variable (windows only)
172173
if(WIN32)
173-
string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result)
174-
if(result)
174+
if(DEFINED ENV{SYSTEMDRIVE})
175175
set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE)
176176
hunter_gate_status_debug(
177177
"HUNTER_ROOT set using SYSTEMDRIVE environment variable"
178178
)
179179
return()
180180
endif()
181181

182-
string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result)
183-
if(result)
182+
if(DEFINED ENV{USERPROFILE})
184183
set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE)
185184
hunter_gate_status_debug(
186185
"HUNTER_ROOT set using USERPROFILE environment variable"
@@ -191,24 +190,10 @@ function(hunter_gate_detect_root)
191190

192191
hunter_gate_fatal_error(
193192
"Can't detect HUNTER_ROOT"
194-
WIKI "error.detect.hunter.root"
193+
ERROR_PAGE "error.detect.hunter.root"
195194
)
196195
endfunction()
197196

198-
macro(hunter_gate_lock dir)
199-
if(NOT HUNTER_SKIP_LOCK)
200-
if("${CMAKE_VERSION}" VERSION_LESS "3.2")
201-
hunter_gate_fatal_error(
202-
"Can't lock, upgrade to CMake 3.2 or use HUNTER_SKIP_LOCK"
203-
WIKI "error.can.not.lock"
204-
)
205-
endif()
206-
hunter_gate_status_debug("Locking directory: ${dir}")
207-
file(LOCK "${dir}" DIRECTORY GUARD FUNCTION)
208-
hunter_gate_status_debug("Lock done")
209-
endif()
210-
endmacro()
211-
212197
function(hunter_gate_download dir)
213198
string(
214199
COMPARE
@@ -224,7 +209,7 @@ function(hunter_gate_download dir)
224209
"Settings:"
225210
" HUNTER_ROOT: ${HUNTER_GATE_ROOT}"
226211
" HUNTER_SHA1: ${HUNTER_GATE_SHA1}"
227-
WIKI "error.run.install"
212+
ERROR_PAGE "error.run.install"
228213
)
229214
endif()
230215
string(COMPARE EQUAL "${dir}" "" is_bad)
@@ -248,7 +233,10 @@ function(hunter_gate_download dir)
248233
set(build_dir "${dir}/Build")
249234
set(cmakelists "${dir}/CMakeLists.txt")
250235

251-
hunter_gate_lock("${dir}")
236+
hunter_gate_status_debug("Locking directory: ${dir}")
237+
file(LOCK "${dir}" DIRECTORY GUARD FUNCTION)
238+
hunter_gate_status_debug("Lock done")
239+
252240
if(EXISTS "${done_location}")
253241
# while waiting for lock other instance can do all the job
254242
hunter_gate_status_debug("File '${done_location}' found, skip install")
@@ -265,7 +253,13 @@ function(hunter_gate_download dir)
265253
file(
266254
WRITE
267255
"${cmakelists}"
268-
"cmake_minimum_required(VERSION 3.0)\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"
269263
"project(HunterDownload LANGUAGES NONE)\n"
270264
"include(ExternalProject)\n"
271265
"ExternalProject_Add(\n"
@@ -330,7 +324,11 @@ function(hunter_gate_download dir)
330324
)
331325

332326
if(NOT download_result EQUAL 0)
333-
hunter_gate_internal_error("Configure project failed")
327+
hunter_gate_internal_error(
328+
"Configure project failed."
329+
"To reproduce the error run: ${CMAKE_COMMAND} -H${dir} -B${build_dir} -G${CMAKE_GENERATOR} ${toolchain_arg} ${make_arg}"
330+
"In directory ${dir}"
331+
)
334332
endif()
335333

336334
hunter_gate_status_print(
@@ -396,14 +394,14 @@ macro(HunterGate)
396394
)
397395
include("${_hunter_self}/cmake/Hunter")
398396
else()
399-
set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_LIST_DIR}")
397+
set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}")
400398

401399
string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name)
402400
if(_have_project_name)
403401
hunter_gate_fatal_error(
404402
"Please set HunterGate *before* 'project' command. "
405403
"Detected project: ${PROJECT_NAME}"
406-
WIKI "error.huntergate.before.project"
404+
ERROR_PAGE "error.huntergate.before.project"
407405
)
408406
endif()
409407

@@ -473,7 +471,7 @@ macro(HunterGate)
473471
"HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces."
474472
"Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error"
475473
"(Use at your own risk!)"
476-
WIKI "error.spaces.in.hunter.root"
474+
ERROR_PAGE "error.spaces.in.hunter.root"
477475
)
478476
endif()
479477
endif()
@@ -521,7 +519,9 @@ macro(HunterGate)
521519
hunter_gate_internal_error("${_sha1_location} not found")
522520
endif()
523521
file(READ "${_sha1_location}" _sha1_value)
524-
string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal)
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)
525525
if(NOT _is_equal)
526526
hunter_gate_internal_error(
527527
"Short SHA1 collision:"

0 commit comments

Comments
 (0)