Add version to all LLVM cmake package

Add a version to non-LLVM cmake package so that users needing an exact
version match can use the version parameter to find_package. Also adjust
the find_package(LLVM) to use an exact version match as well.

Reviewed By: arsenm, stellaraccident, mceier

Differential Revision: https://reviews.llvm.org/D138274
diff --git a/lld/cmake/modules/LLDConfigVersion.cmake.in b/lld/cmake/modules/LLDConfigVersion.cmake.in
new file mode 100644
index 0000000..e9ac4ed
--- /dev/null
+++ b/lld/cmake/modules/LLDConfigVersion.cmake.in
@@ -0,0 +1,13 @@
+set(PACKAGE_VERSION "@PACKAGE_VERSION@")
+
+# LLVM is API-compatible only with matching major.minor versions
+# and patch versions not less than that requested.
+if("@LLVM_VERSION_MAJOR@.@LLVM_VERSION_MINOR@" VERSION_EQUAL
+    "${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}"
+   AND NOT "@LLVM_VERSION_PATCH@" VERSION_LESS "${PACKAGE_FIND_VERSION_PATCH}")
+  set(PACKAGE_VERSION_COMPATIBLE 1)
+  if("@LLVM_VERSION_PATCH@" VERSION_EQUAL
+      "${PACKAGE_FIND_VERSION_PATCH}")
+    set(PACKAGE_VERSION_EXACT 1)
+  endif()
+endif()