aboutsummaryrefslogtreecommitdiff
path: root/scripts/cmake
diff options
context:
space:
mode:
authorBilly O'Neal <bion@microsoft.com>2021-01-20 12:07:41 -0800
committerGitHub <noreply@github.com>2021-01-20 12:07:41 -0800
commit4d136ef25f4fab5b744c7ae6acfa04d44f254f2b (patch)
treec6d0b0920106f03390e8d89c11bdf631cf1f28c7 /scripts/cmake
parent45fc55825db2a5bcaffccff1e6afadc519d164ea (diff)
downloadvcpkg-4d136ef25f4fab5b744c7ae6acfa04d44f254f2b.tar.gz
vcpkg-4d136ef25f4fab5b744c7ae6acfa04d44f254f2b.zip
[vcpkg] Add vcpkg_minimum_required as a replacement for VERSION.txt. (#15638)
Diffstat (limited to 'scripts/cmake')
-rw-r--r--scripts/cmake/vcpkg_minimum_required.cmake49
1 files changed, 49 insertions, 0 deletions
diff --git a/scripts/cmake/vcpkg_minimum_required.cmake b/scripts/cmake/vcpkg_minimum_required.cmake
new file mode 100644
index 000000000..202935b89
--- /dev/null
+++ b/scripts/cmake/vcpkg_minimum_required.cmake
@@ -0,0 +1,49 @@
+#[===[.md:
+# vcpkg_minimum_required
+
+Asserts that the version of the vcpkg program being used to build a port is later than the supplied date, inclusive.
+
+## Usage
+```cmake
+vcpkg_minimum_required(VERSION 2021-01-13)
+```
+
+## Parameters
+### VERSION
+The date-version to check against.
+#]===]
+
+function(vcpkg_minimum_required)
+ cmake_parse_arguments(PARSE_ARGV 0 _vcpkg "" "VERSION" "")
+ if (NOT DEFINED VCPKG_BASE_VERSION)
+ message(FATAL_ERROR
+ "Your vcpkg executable is outdated and is not compatible with the current CMake scripts. "
+ "Please re-acquire vcpkg by running bootstrap-vcpkg."
+ )
+ endif()
+
+ set(_vcpkg_date_regex "^[12][0-9][0-9][0-9]-[01][0-9]-[0-3][0-9]$")
+ if (NOT VCPKG_BASE_VERSION MATCHES "${_vcpkg_date_regex}")
+ message(FATAL_ERROR
+ "vcpkg internal failure; \${VCPKG_BASE_VERSION} (${VCPKG_BASE_VERSION}) was not a valid date."
+ )
+ endif()
+
+ if (NOT _vcpkg_VERSION MATCHES "${_vcpkg_date_regex}")
+ message(FATAL_ERROR
+ "VERSION parameter to vcpkg_minimum_required was not a valid date. "
+ "Comparing with vcpkg tool version ${_vcpkg_matched_base_version}"
+ )
+ endif()
+
+ string(REPLACE "-" "." _VCPKG_BASE_VERSION_as_dotted "${VCPKG_BASE_VERSION}")
+ string(REPLACE "-" "." _vcpkg_VERSION_as_dotted "${_vcpkg_VERSION}")
+
+ if (_VCPKG_BASE_VERSION_as_dotted VERSION_LESS _vcpkg_VERSION_as_dotted)
+ message(FATAL_ERROR
+ "Your vcpkg executable is from ${VCPKG_BASE_VERSION} which is older than required by the caller "
+ "of vcpkg_minimum_required (${_vcpkg_VERSION}). "
+ "Please re-acquire vcpkg by running bootstrap-vcpkg."
+ )
+ endif()
+endfunction()