diff --git a/mpcdf_common.py b/mpcdf_common.py
index da606c946f9b81f97ec6bd07bdce5f4cecd1df9e..57e70f9e2750ff3d80a320b51ab0c91624bb7ca8 100644
--- a/mpcdf_common.py
+++ b/mpcdf_common.py
@@ -480,9 +480,16 @@ Macros:
         a.tail = "\n  "
         r.tail = "\n  "
 
+        # In order to be able to figure out the matching MKL version for a given
+        # compiler/MPI repository we emit a new macro '%matching_mkl_version' in
+        # the cases this makes sense
+        matching_mkl = []
         prjconf.append("%if %_repository == {0}".format(name))
         for prefer in prefers(name):
+            if prefer.startswith("mkl_"):
+                matching_mkl.append(prefer)
             prjconf.append("Prefer: " + prefer)
+
         prjconf.append("Macros:")
 
         prjconf.append("%is_compiler_repository {0}".format(1 if is_compiler else 0))
@@ -497,6 +504,12 @@ Macros:
         if is_cuda:
             prjconf.append("%cuda_repository {0}".format(cuda_repo))
 
+        if matching_mkl:
+            matching_mkl, = matching_mkl
+            matching_mkl, _ = matching_mkl[len("mkl_"):].split("-module")
+            matching_mkl = matching_mkl.replace("_", ".")
+            prjconf.append("%matching_mkl_version {0}".format(matching_mkl))
+
         for macro, value in kwargs.items():
             prjconf.append("%{0} {1}".format(macro, value))