Skip to content

Commit

Permalink
Improve compatibility with CMake 3.27 (#701)
Browse files Browse the repository at this point in the history
- Set CMake policy settings to 3.27.
- Upgrade Hunter to v0.25.3 (with HunterGate).
  • Loading branch information
chfast authored Dec 20, 2023
1 parent 24f939e commit 82d298b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 57 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Documentation of all notable changes to the **EVMC** project.
The format is based on [Keep a Changelog],
and this project adheres to [Semantic Versioning].

## [11.0.1] — unreleased

### Changed

- Improved compatibility with CMake 3.27.
[#701](https://github.com/ethereum/evmc/pull/701)

## [11.0.0] — 2023-11-29

### Added
Expand Down Expand Up @@ -704,6 +711,7 @@ removed.
[#52](https://github.com/ethereum/evmc/pull/52)


[11.0.1]: https://github.com/ethereum/evmc/compare/v11.0.0..master
[11.0.0]: https://github.com/ethereum/evmc/releases/tag/v11.0.0
[10.1.1]: https://github.com/ethereum/evmc/releases/tag/v10.1.1
[10.1.0]: https://github.com/ethereum/evmc/releases/tag/v10.1.0
Expand Down
6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
# Copyright 2016 The EVMC Authors.
# Licensed under the Apache License, Version 2.0.

cmake_minimum_required(VERSION 3.16...3.24)

if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
cmake_minimum_required(VERSION 3.16...3.27)

if(TARGET evmc)
# The evmc library has been already created (probably by other submodule).
Expand Down
4 changes: 2 additions & 2 deletions cmake/Hunter/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
# Hunter is going to be initialized only if building with tests,
# where it is needed to get dependencies.
HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.24.3.tar.gz"
SHA1 "10738b59e539818a01090e64c2d09896247530c7"
URL "https://github.com/cpp-pm/hunter/archive/v0.25.3.tar.gz"
SHA1 "0dfbc2cb5c4cf7e83533733bdfd2125ff96680cb"
)
115 changes: 65 additions & 50 deletions cmake/cable/HunterGate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# This is a gate file to Hunter package manager.
# Include this file using `include` command and add package you need, example:
#
# cmake_minimum_required(VERSION 3.2)
# cmake_minimum_required(VERSION 3.5)
#
# include("cmake/HunterGate.cmake")
# HunterGate(
Expand All @@ -39,16 +39,16 @@
# hunter_add_package(Boo COMPONENTS Bar Baz)
#
# Projects:
# * https://github.com/hunter-packages/gate/
# * https://github.com/ruslo/hunter
# * https://github.com/cpp-pm/gate/
# * https://github.com/cpp-pm/hunter

option(HUNTER_ENABLED "Enable Hunter package manager support" ON)

if(HUNTER_ENABLED)
if(CMAKE_VERSION VERSION_LESS "3.2")
if(CMAKE_VERSION VERSION_LESS "3.5")
message(
FATAL_ERROR
"At least CMake version 3.2 required for Hunter dependency management."
"At least CMake version 3.5 required for Hunter dependency management."
" Update CMake or set HUNTER_ENABLED to OFF."
)
endif()
Expand All @@ -59,8 +59,9 @@ include(CMakeParseArguments) # cmake_parse_arguments
option(HUNTER_STATUS_PRINT "Print working status" ON)
option(HUNTER_STATUS_DEBUG "Print a lot info" OFF)
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)
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
Expand Down Expand Up @@ -133,53 +134,52 @@ function(hunter_gate_self root version sha1 result)

string(SUBSTRING "${sha1}" 0 7 archive_id)

set(
hunter_self
"${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked"
)
if(EXISTS "${root}/cmake/Hunter")
set(hunter_self "${root}")
else()
set(
hunter_self
"${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked"
)
endif()

set("${result}" "${hunter_self}" PARENT_SCOPE)
endfunction()

# Set HUNTER_GATE_ROOT cmake variable to suitable value.
function(hunter_gate_detect_root)
# Check CMake variable
string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty)
if(not_empty)
if(HUNTER_ROOT)
set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable")
return()
endif()

# Check environment variable
string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty)
if(not_empty)
if(DEFINED ENV{HUNTER_ROOT})
set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT detected by environment variable")
return()
endif()

# Check HOME environment variable
string(COMPARE NOTEQUAL "$ENV{HOME}" "" result)
if(result)
if(DEFINED ENV{HOME})
set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable")
return()
endif()

# Check SYSTEMDRIVE and USERPROFILE environment variable (windows only)
if(WIN32)
string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result)
if(result)
if(DEFINED ENV{SYSTEMDRIVE})
set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug(
"HUNTER_ROOT set using SYSTEMDRIVE environment variable"
)
return()
endif()

string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result)
if(result)
if(DEFINED ENV{USERPROFILE})
set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug(
"HUNTER_ROOT set using USERPROFILE environment variable"
Expand Down Expand Up @@ -253,7 +253,13 @@ function(hunter_gate_download dir)
file(
WRITE
"${cmakelists}"
"cmake_minimum_required(VERSION 3.2)\n"
"cmake_minimum_required(VERSION 3.5)\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"
"include(ExternalProject)\n"
"ExternalProject_Add(\n"
Expand Down Expand Up @@ -490,37 +496,46 @@ macro(HunterGate)
)

set(_master_location "${_hunter_self}/cmake/Hunter")
get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE)
set(_done_location "${_archive_id_location}/DONE")
set(_sha1_location "${_archive_id_location}/SHA1")

# Check Hunter already downloaded by HunterGate
if(NOT EXISTS "${_done_location}")
hunter_gate_download("${_archive_id_location}")
endif()
if(EXISTS "${HUNTER_GATE_ROOT}/cmake/Hunter")
# Hunter downloaded manually (e.g. by 'git clone')
set(_unused "xxxxxxxxxx")
set(HUNTER_GATE_SHA1 "${_unused}")
set(HUNTER_GATE_VERSION "${_unused}")
else()
get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE)
set(_done_location "${_archive_id_location}/DONE")
set(_sha1_location "${_archive_id_location}/SHA1")

# Check Hunter already downloaded by HunterGate
if(NOT EXISTS "${_done_location}")
hunter_gate_download("${_archive_id_location}")
endif()

if(NOT EXISTS "${_done_location}")
hunter_gate_internal_error("hunter_gate_download failed")
endif()
if(NOT EXISTS "${_done_location}")
hunter_gate_internal_error("hunter_gate_download failed")
endif()

if(NOT EXISTS "${_sha1_location}")
hunter_gate_internal_error("${_sha1_location} not found")
endif()
file(READ "${_sha1_location}" _sha1_value)
string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal)
if(NOT _is_equal)
hunter_gate_internal_error(
"Short SHA1 collision:"
" ${_sha1_value} (from ${_sha1_location})"
" ${HUNTER_GATE_SHA1} (HunterGate)"
)
endif()
if(NOT EXISTS "${_master_location}")
hunter_gate_user_error(
"Master file not found:"
" ${_master_location}"
"try to update Hunter/HunterGate"
)
if(NOT EXISTS "${_sha1_location}")
hunter_gate_internal_error("${_sha1_location} not found")
endif()
file(READ "${_sha1_location}" _sha1_value)
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)
hunter_gate_internal_error(
"Short SHA1 collision:"
" ${_sha1_value} (from ${_sha1_location})"
" ${HUNTER_GATE_SHA1} (HunterGate)"
)
endif()
if(NOT EXISTS "${_master_location}")
hunter_gate_user_error(
"Master file not found:"
" ${_master_location}"
"try to update Hunter/HunterGate"
)
endif()
endif()
include("${_master_location}")
set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES)
Expand Down

0 comments on commit 82d298b

Please sign in to comment.