Skip to content

Commit

Permalink
Update cmake for Hunter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackarain committed Apr 9, 2020
1 parent 04cef67 commit a040b36
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 48 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ option(USE_HUNTER "Use hunter" OFF)
if (USE_HUNTER)
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.19.102.tar.gz"
SHA1 "49a8333d7efc24c531aed97159fe58a68374185f"
URL "https://github.com/cpp-pm/hunter/archive/v0.23.253.tar.gz"
SHA1 "88ea6d37c897a81a080eb9ae0f69d7807bbb3c73"
)
endif()

Expand Down
91 changes: 45 additions & 46 deletions cmake/HunterGate.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2017, Ruslan Baratov
# Copyright (c) 2013-2019, Ruslan Baratov
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand All @@ -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.0)
# cmake_minimum_required(VERSION 3.2)
#
# include("cmake/HunterGate.cmake")
# HunterGate(
Expand All @@ -43,40 +43,45 @@
# * https://github.com/ruslo/hunter

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

if(HUNTER_ENABLED)
if(CMAKE_VERSION VERSION_LESS "3.0")
message(FATAL_ERROR "At least CMake version 3.0 required for hunter dependency management."
" Update CMake or set HUNTER_ENABLED to OFF.")
if(CMAKE_VERSION VERSION_LESS "3.2")
message(
FATAL_ERROR
"At least CMake version 3.2 required for Hunter dependency management."
" Update CMake or set HUNTER_ENABLED to OFF."
)
endif()
endif()

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_WIKI "https://github.com/ruslo/hunter/wiki")
set(HUNTER_ERROR_PAGE "https://docs.hunter.sh/en/latest/reference/errors")

function(hunter_gate_status_print)
foreach(print_message ${ARGV})
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
foreach(print_message ${ARGV})
message(STATUS "[hunter] ${print_message}")
endif()
endforeach()
endforeach()
endif()
endfunction()

function(hunter_gate_status_debug)
foreach(print_message ${ARGV})
if(HUNTER_STATUS_DEBUG)
if(HUNTER_STATUS_DEBUG)
foreach(print_message ${ARGV})
string(TIMESTAMP timestamp)
message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}")
endif()
endforeach()
endforeach()
endif()
endfunction()

function(hunter_gate_wiki wiki_page)
message("------------------------------ WIKI -------------------------------")
message(" ${HUNTER_WIKI}/${wiki_page}")
function(hunter_gate_error_page error_page)
message("------------------------------ ERROR ------------------------------")
message(" ${HUNTER_ERROR_PAGE}/${error_page}.html")
message("-------------------------------------------------------------------")
message("")
message(FATAL_ERROR "")
Expand All @@ -89,26 +94,25 @@ function(hunter_gate_internal_error)
endforeach()
message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
message("")
hunter_gate_wiki("error.internal")
hunter_gate_error_page("error.internal")
endfunction()

function(hunter_gate_fatal_error)
cmake_parse_arguments(hunter "" "WIKI" "" "${ARGV}")
string(COMPARE EQUAL "${hunter_WIKI}" "" have_no_wiki)
if(have_no_wiki)
hunter_gate_internal_error("Expected wiki")
cmake_parse_arguments(hunter "" "ERROR_PAGE" "" "${ARGV}")
if("${hunter_ERROR_PAGE}" STREQUAL "")
hunter_gate_internal_error("Expected ERROR_PAGE")
endif()
message("")
foreach(x ${hunter_UNPARSED_ARGUMENTS})
message("[hunter ** FATAL ERROR **] ${x}")
endforeach()
message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
message("")
hunter_gate_wiki("${hunter_WIKI}")
hunter_gate_error_page("${hunter_ERROR_PAGE}")
endfunction()

function(hunter_gate_user_error)
hunter_gate_fatal_error(${ARGV} WIKI "error.incorrect.input.data")
hunter_gate_fatal_error(${ARGV} ERROR_PAGE "error.incorrect.input.data")
endfunction()

function(hunter_gate_self root version sha1 result)
Expand Down Expand Up @@ -190,24 +194,10 @@ function(hunter_gate_detect_root)

hunter_gate_fatal_error(
"Can't detect HUNTER_ROOT"
WIKI "error.detect.hunter.root"
ERROR_PAGE "error.detect.hunter.root"
)
endfunction()

macro(hunter_gate_lock dir)
if(NOT HUNTER_SKIP_LOCK)
if("${CMAKE_VERSION}" VERSION_LESS "3.2")
hunter_gate_fatal_error(
"Can't lock, upgrade to CMake 3.2 or use HUNTER_SKIP_LOCK"
WIKI "error.can.not.lock"
)
endif()
hunter_gate_status_debug("Locking directory: ${dir}")
file(LOCK "${dir}" DIRECTORY GUARD FUNCTION)
hunter_gate_status_debug("Lock done")
endif()
endmacro()

function(hunter_gate_download dir)
string(
COMPARE
Expand All @@ -223,7 +213,7 @@ function(hunter_gate_download dir)
"Settings:"
" HUNTER_ROOT: ${HUNTER_GATE_ROOT}"
" HUNTER_SHA1: ${HUNTER_GATE_SHA1}"
WIKI "error.run.install"
ERROR_PAGE "error.run.install"
)
endif()
string(COMPARE EQUAL "${dir}" "" is_bad)
Expand All @@ -247,7 +237,10 @@ function(hunter_gate_download dir)
set(build_dir "${dir}/Build")
set(cmakelists "${dir}/CMakeLists.txt")

hunter_gate_lock("${dir}")
hunter_gate_status_debug("Locking directory: ${dir}")
file(LOCK "${dir}" DIRECTORY GUARD FUNCTION)
hunter_gate_status_debug("Lock done")

if(EXISTS "${done_location}")
# while waiting for lock other instance can do all the job
hunter_gate_status_debug("File '${done_location}' found, skip install")
Expand All @@ -264,7 +257,7 @@ function(hunter_gate_download dir)
file(
WRITE
"${cmakelists}"
"cmake_minimum_required(VERSION 3.0)\n"
"cmake_minimum_required(VERSION 3.2)\n"
"project(HunterDownload LANGUAGES NONE)\n"
"include(ExternalProject)\n"
"ExternalProject_Add(\n"
Expand All @@ -275,6 +268,8 @@ function(hunter_gate_download dir)
" SHA1=${HUNTER_GATE_SHA1}\n"
" DOWNLOAD_DIR\n"
" \"${dir}\"\n"
" TLS_VERIFY\n"
" ${HUNTER_TLS_VERIFY}\n"
" SOURCE_DIR\n"
" \"${dir}/Unpacked\"\n"
" CONFIGURE_COMMAND\n"
Expand Down Expand Up @@ -327,7 +322,11 @@ function(hunter_gate_download dir)
)

if(NOT download_result EQUAL 0)
hunter_gate_internal_error("Configure project failed")
hunter_gate_internal_error(
"Configure project failed."
"To reproduce the error run: ${CMAKE_COMMAND} -H${dir} -B${build_dir} -G${CMAKE_GENERATOR} ${toolchain_arg} ${make_arg}"
"In directory ${dir}"
)
endif()

hunter_gate_status_print(
Expand Down Expand Up @@ -393,14 +392,14 @@ macro(HunterGate)
)
include("${_hunter_self}/cmake/Hunter")
else()
set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_LIST_DIR}")
set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}")

string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name)
if(_have_project_name)
hunter_gate_fatal_error(
"Please set HunterGate *before* 'project' command. "
"Detected project: ${PROJECT_NAME}"
WIKI "error.huntergate.before.project"
ERROR_PAGE "error.huntergate.before.project"
)
endif()

Expand Down Expand Up @@ -470,7 +469,7 @@ macro(HunterGate)
"HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces."
"Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error"
"(Use at your own risk!)"
WIKI "error.spaces.in.hunter.root"
ERROR_PAGE "error.spaces.in.hunter.root"
)
endif()
endif()
Expand Down

0 comments on commit a040b36

Please sign in to comment.