|
| 1 | +# Copyright (c) 2018, Ruslan Baratov |
| 2 | +# All rights reserved. |
| 3 | + |
| 4 | +include(CMakeParseArguments) # cmake_parse_arguments |
| 5 | + |
| 6 | +include(hunter_status_debug) |
| 7 | +include(hunter_user_error) |
| 8 | + |
| 9 | +function(hunter_cache_server_password) |
| 10 | + set(opt SUB_SHA1_SUFFIX) |
| 11 | + set(one SERVER USERNAME PASSWORD) |
| 12 | + set(multi HTTPHEADER) |
| 13 | + |
| 14 | + cmake_parse_arguments(x "${opt}" "${one}" "${multi}" "${ARGN}") |
| 15 | + # -> x_SUB_SHA1_SUFFIX |
| 16 | + # -> x_SERVER |
| 17 | + # -> x_USERNAME |
| 18 | + # -> x_PASSWORD |
| 19 | + # -> x_HTTPHEADER |
| 20 | + |
| 21 | + string(COMPARE NOTEQUAL "${x_UNPARSED_ARGUMENTS}" "" has_unparsed) |
| 22 | + if(has_unparsed) |
| 23 | + hunter_user_error( |
| 24 | + "'hunter_cache_server_password' unparsed arguments: ${x_UNPARSED_ARGUMENTS}" |
| 25 | + ) |
| 26 | + endif() |
| 27 | + |
| 28 | + string(COMPARE EQUAL "${x_SERVER}" "" no_server) |
| 29 | + if(no_server) |
| 30 | + hunter_user_error("'SERVER' required") |
| 31 | + endif() |
| 32 | + |
| 33 | + string(COMPARE EQUAL "${HUNTER_CACHE_SERVER_NAME}" "" no_cache_server) |
| 34 | + if(no_cache_server) |
| 35 | + return() |
| 36 | + endif() |
| 37 | + |
| 38 | + string(COMPARE EQUAL "${HUNTER_CACHE_SERVER_NAME}" "${x_SERVER}" hit) |
| 39 | + if(NOT hit) |
| 40 | + hunter_status_debug("Skip '${HUNTER_CACHE_SERVER_NAME}' server") |
| 41 | + return() |
| 42 | + endif() |
| 43 | + |
| 44 | + set(httpheaders) |
| 45 | + foreach(httpheader ${x_HTTPHEADER}) |
| 46 | + list(APPEND httpheaders HTTPHEADER "${httpheader}") |
| 47 | + endforeach() |
| 48 | + |
| 49 | + string(COMPARE NOTEQUAL "${x_USERNAME}" "" has_username) |
| 50 | + string(COMPARE NOTEQUAL "${x_PASSWORD}" "" has_password) |
| 51 | + set(userpwd) |
| 52 | + if(has_username OR has_password) |
| 53 | + set(userpwd USERPWD "${x_USERNAME}:${x_PASSWORD}") |
| 54 | + endif() |
| 55 | + |
| 56 | + set(HUNTER_CACHE_SERVER_USERPWD "${userpwd}" PARENT_SCOPE) |
| 57 | + set(HUNTER_CACHE_SERVER_HTTPHEADER "${httpheaders}" PARENT_SCOPE) |
| 58 | + set(HUNTER_CACHE_SERVER_SUB_SHA1_SUFFIX "${x_SUB_SHA1_SUFFIX}" PARENT_SCOPE) |
| 59 | +endfunction() |
0 commit comments