diff --git a/cmake/external/mkldnn.cmake b/cmake/external/mkldnn.cmake
index 9dc73d239ea68eca2a88b7b04ed171bb22de0767..5c09507163244248dd3468924631ab0ce4118d57 100644
--- a/cmake/external/mkldnn.cmake
+++ b/cmake/external/mkldnn.cmake
@@ -28,7 +28,9 @@ IF(WIN32 OR APPLE)
         "Windows or Mac is not supported with MKLDNN in Paddle yet."
         "Force WITH_MKLDNN=OFF")
     SET(WITH_MKLDNN OFF CACHE STRING "Disable MKLDNN in Windows and MacOS" FORCE)
-    SET(WITH_MKL OFF CACHE STRING "Disable MKL for later scripts" FORCE)
+    IF ((NOT ${WITH_MKLDNN}) AND (NOT ${WITH_MKLML}))
+        SET(WITH_MKL OFF CACHE STRING "Disable MKL for later scripts" FORCE)
+    ENDIF()
     return()
 ENDIF()
 
diff --git a/cmake/external/mklml.cmake b/cmake/external/mklml.cmake
index 30e7b4a8b1e1605758d5e5ba41d955e9cd2428ae..ba00f0fe63cba17d851876b2ee7fe4875c2a0e48 100644
--- a/cmake/external/mklml.cmake
+++ b/cmake/external/mklml.cmake
@@ -21,7 +21,9 @@ IF(WIN32 OR APPLE)
         "Windows or Mac is not supported with MKLML in Paddle yet."
         "Force WITH_MKLML=OFF")
     SET(WITH_MKLML OFF CACHE STRING "Disable MKLML package in Windows and MacOS" FORCE)
-    SET(WITH_MKL OFF CACHE STRING "Disable MKL for later scripts" FORCE)
+    IF ((NOT ${WITH_MKLDNN}) AND (NOT ${WITH_MKLML}))
+        SET(WITH_MKL OFF CACHE STRING "Disable MKL for later scripts" FORCE)
+    ENDIF()
     return()
 ENDIF()