--- contrib/lua-torch/torch7/lib/TH/CMakeLists.txt.orig	2018-06-16 00:02:13 UTC
+++ contrib/lua-torch/torch7/lib/TH/CMakeLists.txt
@@ -230,22 +230,26 @@ ELSE()
   ENDIF()
 ENDIF()
 
-FIND_PACKAGE(BLAS)
-IF(BLAS_FOUND)
-  SET(USE_BLAS 1)
-  TARGET_LINK_LIBRARIES(TH ${BLAS_LIBRARIES})
-  IF(BLAS_INFO STREQUAL "mkl")
-    ADD_DEFINITIONS(-DTH_BLAS_MKL)
-  ELSEIF(BLAS_INFO STREQUAL "open")
-    ADD_DEFINITIONS(-DTH_BLAS_OPEN)
-  ENDIF()
-ENDIF(BLAS_FOUND)
+IF(WITH_BLAS)
+  FIND_PACKAGE(BLAS)
+  IF(BLAS_FOUND)
+    SET(USE_BLAS 1)
+    TARGET_LINK_LIBRARIES(TH ${BLAS_LIBRARIES})
+    IF(BLAS_INFO STREQUAL "mkl")
+      ADD_DEFINITIONS(-DTH_BLAS_MKL)
+    ELSEIF(BLAS_INFO STREQUAL "open")
+      ADD_DEFINITIONS(-DTH_BLAS_OPEN)
+    ENDIF()
+  ENDIF(BLAS_FOUND)
+ENDIF(WITH_BLAS)
 
-FIND_PACKAGE(LAPACK)
-IF(LAPACK_FOUND)
-  SET(USE_LAPACK 1)
-  TARGET_LINK_LIBRARIES(TH ${LAPACK_LIBRARIES})
-ENDIF(LAPACK_FOUND)
+IF(WITH_LAPACK)
+  FIND_PACKAGE(LAPACK)
+  IF(LAPACK_FOUND)
+    SET(USE_LAPACK 1)
+    TARGET_LINK_LIBRARIES(TH ${LAPACK_LIBRARIES})
+  ENDIF(LAPACK_FOUND)
+ENDIF(WITH_LAPACK)
 
 IF (UNIX AND NOT APPLE)
    INCLUDE(CheckLibraryExists)
