diff --git a/cmake_modules/morse/find/FindCBLAS.cmake b/cmake_modules/morse/find/FindCBLAS.cmake
index df8e867f2c7dd52a0067aae68d57270f7286fea1..acfd9c9fb224109cc198ab3110e0569c379a694e 100644
--- a/cmake_modules/morse/find/FindCBLAS.cmake
+++ b/cmake_modules/morse/find/FindCBLAS.cmake
@@ -241,7 +241,12 @@ if (BLAS_FOUND)
             # check a function to validate the find
             set(CMAKE_REQUIRED_INCLUDES  "${CBLAS_INCLUDE_DIRS};${BLAS_INCLUDE_DIRS}")
             set(CMAKE_REQUIRED_LIBRARIES "${CBLAS_LIBRARIES};${BLAS_LIBRARIES}")
-            set(CMAKE_REQUIRED_FLAGS     "-L${CBLAS_LIBRARY_DIRS} -L${BLAS_LIBRARY_DIRS}")
+            if (CBLAS_LIBRARY_DIRS)
+                set(CMAKE_REQUIRED_FLAGS "-L${CBLAS_LIBRARY_DIRS}")
+                if (BLAS_LIBRARY_DIRS)
+                    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${BLAS_LIBRARY_DIRS}")
+                endif()
+            endif()
 
             unset(CBLAS_WORKS CACHE)
             include(CheckFunctionExists)
diff --git a/cmake_modules/morse/find/FindCHAMELEON.cmake b/cmake_modules/morse/find/FindCHAMELEON.cmake
index eda7ce6842c947e0979955d1c5e4f6e37ab92325..2ca145bba64b0eab569022fe7a007c89dd3e8416 100644
--- a/cmake_modules/morse/find/FindCHAMELEON.cmake
+++ b/cmake_modules/morse/find/FindCHAMELEON.cmake
@@ -446,56 +446,76 @@ if(NOT CHAMELEON_FOUND OR NOT CHAMELEON_LIBRARIES)
         set(CMAKE_REQUIRED_INCLUDES "${CHAMELEON_INCLUDE_DIRS}")
         set(CMAKE_REQUIRED_FLAGS)
         foreach(libdir ${CHAMELEON_LIBRARY_DIRS})
-            #list(APPEND CMAKE_REQUIRED_FLAGS "-L${libdir}")
+            if (libdir)
+                list(APPEND CMAKE_REQUIRED_FLAGS "-L${libdir}")
+            endif()
         endforeach()
         set(CMAKE_REQUIRED_LIBRARIES "${CHAMELEON_LIBRARIES}")
         if (STARPU_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${STARPU_INCLUDE_DIRS}")
-            #list(APPEND CMAKE_REQUIRED_FLAGS "-L${STARPU_LIBRARY_DIRS}")
+            if(STARPU_LIBRARY_DIRS)
+                list(APPEND CMAKE_REQUIRED_FLAGS "-L${STARPU_LIBRARY_DIRS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${STARPU_LIBRARIES}")
         endif()
         if (QUARK_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "$QUARK_INCLUDE_DIRS}")
-            #list(APPEND CMAKE_REQUIRED_FLAGS "-L${QUARK_LIBRARY_DIRS}")
+            if(QUARK_LIBRARY_DIRS)
+                list(APPEND CMAKE_REQUIRED_FLAGS "-L${QUARK_LIBRARY_DIRS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${QUARK_LIBRARIES}")
         endif()
         if (CUDA_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${CUDA_INCLUDE_DIRS}")
-            #list(APPEND CMAKE_REQUIRED_FLAGS "-L${CUDA_LIBRARY_DIRS}")
+            if(QUARK_LIBRARY_DIRS)
+                list(APPEND CMAKE_REQUIRED_FLAGS "-L${CUDA_LIBRARY_DIRS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${CUDA_CUBLAS_LIBRARIES};${CUDA_LIBRARIES}")
         endif()
         if (MAGMA_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${MAGMA_INCLUDE_DIRS}")
-            #list(APPEND CMAKE_REQUIRED_FLAGS "-L${MAGMA_LIBRARY_DIRS}")
+            if(QUARK_LIBRARY_DIRS)
+                list(APPEND CMAKE_REQUIRED_FLAGS "-L${MAGMA_LIBRARY_DIRS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${${MAGMA_LIBRARIES}}")
         endif()
         if (MPI_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${MPI_C_INCLUDE_PATH}")
-            #list(APPEND CMAKE_REQUIRED_FLAGS "-L${MPI_C_LINK_FLAGS}")
+            if(QUARK_LIBRARY_DIRS)
+                list(APPEND CMAKE_REQUIRED_FLAGS "-L${MPI_C_LINK_FLAGS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${MPI_C_LIBRARIES}")
         endif()
         if (HWLOC_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${HWLOC_INCLUDE_DIRS}")
-            #list(APPEND CMAKE_REQUIRED_FLAGS "-L${HWLOC_LIBRARY_DIRS}")
+            if(QUARK_LIBRARY_DIRS)
+                list(APPEND CMAKE_REQUIRED_FLAGS "-L${HWLOC_LIBRARY_DIRS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${HWLOC_LIBRARIES}")
         endif()
         if (TMG_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${TMG_INCLUDE_DIRS}")
-            #list(APPEND CMAKE_REQUIRED_FLAGS "-L${TMG_LIBRARY_DIRS}")
+            if(QUARK_LIBRARY_DIRS)
+                list(APPEND CMAKE_REQUIRED_FLAGS "-L${TMG_LIBRARY_DIRS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${TMG_LIBRARIES}")
         endif()
         if (LAPACKE_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${LAPACKE_INCLUDE_DIRS}")
-            #list(APPEND CMAKE_REQUIRED_FLAGS "-L${LAPACKE_LIBRARY_DIRS}")
+            if(QUARK_LIBRARY_DIRS)
+                list(APPEND CMAKE_REQUIRED_FLAGS "-L${LAPACKE_LIBRARY_DIRS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${LAPACKE_LIBRARIES}")
         endif()
         if (CBLAS_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${CBLAS_INCLUDE_DIRS}")
-            #list(APPEND CMAKE_REQUIRED_FLAGS "-L${CBLAS_LIBRARY_DIRS}")
+            if(QUARK_LIBRARY_DIRS)
+                list(APPEND CMAKE_REQUIRED_FLAGS "-L${CBLAS_LIBRARY_DIRS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${CBLAS_LIBRARIES}")
         endif()
         list(APPEND CMAKE_REQUIRED_LIBRARIES ${CHAMELEON_EXTRA_LIBRARIES})
-        #string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
+        string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
 
         unset(CHAMELEON_WORKS CACHE)
         include(CheckFunctionExists)
diff --git a/cmake_modules/morse/find/FindFXT.cmake b/cmake_modules/morse/find/FindFXT.cmake
index 49ff7e86cd8ec7f6e4f09bdab8a6d970e1c71576..bb00f93fd7f0a2e0beefe517cca4323e819d8f01 100644
--- a/cmake_modules/morse/find/FindFXT.cmake
+++ b/cmake_modules/morse/find/FindFXT.cmake
@@ -204,7 +204,9 @@ if(NOT FXT_FOUND OR NOT FXT_LIBRARIES)
         # check a function to validate the find
         set(CMAKE_REQUIRED_INCLUDES  "${FXT_INCLUDE_DIRS}")
         set(CMAKE_REQUIRED_LIBRARIES "${FXT_LIBRARIES}")
-        set(CMAKE_REQUIRED_FLAGS     "-L${FXT_LIBRARY_DIRS}")
+        if (FXT_LIBRARY_DIRS)
+            set(CMAKE_REQUIRED_FLAGS     "-L${FXT_LIBRARY_DIRS}")
+        endif()
 
         unset(FXT_WORKS CACHE)
         include(CheckFunctionExists)
diff --git a/cmake_modules/morse/find/FindHWLOC.cmake b/cmake_modules/morse/find/FindHWLOC.cmake
index 20ad8ea79e95d06d903bd0037ee39250430a552e..0455f16d0e0f20f85c4a7bca4afc75a81f135997 100644
--- a/cmake_modules/morse/find/FindHWLOC.cmake
+++ b/cmake_modules/morse/find/FindHWLOC.cmake
@@ -211,7 +211,9 @@ if(NOT HWLOC_FOUND OR NOT HWLOC_LIBRARIES)
         # check a function to validate the find
         set(CMAKE_REQUIRED_INCLUDES  "${HWLOC_INCLUDE_DIRS}")
         set(CMAKE_REQUIRED_LIBRARIES "${HWLOC_LIBRARIES}")
-        set(CMAKE_REQUIRED_FLAGS     "-L${HWLOC_LIBRARY_DIRS}")
+        if (HWLOC_LIBRARY_DIRS)
+            set(CMAKE_REQUIRED_FLAGS     "-L${HWLOC_LIBRARY_DIRS}")
+        endif()
 
         unset(HWLOC_WORKS CACHE)
         include(CheckFunctionExists)
diff --git a/cmake_modules/morse/find/FindLAPACKE.cmake b/cmake_modules/morse/find/FindLAPACKE.cmake
index b3e6465ccf6afa5cd2a0ffccd806babdb69b11fc..112faafbba7b79ba2ff6b3624e76d4561a962a80 100644
--- a/cmake_modules/morse/find/FindLAPACKE.cmake
+++ b/cmake_modules/morse/find/FindLAPACKE.cmake
@@ -241,7 +241,12 @@ if (LAPACK_FOUND)
             elseif (CMAKE_Fortran_COMPILER MATCHES ".+ifort.*")
                 list(APPEND CMAKE_REQUIRED_LIBRARIES "-lifcore")
             endif()
-            set(CMAKE_REQUIRED_FLAGS "-L${LAPACKE_LIBRARY_DIRS} -L${LAPACK_LIBRARY_DIRS}")
+            if (LAPACKE_LIBRARY_DIRS)
+                set(CMAKE_REQUIRED_FLAGS "-L${LAPACKE_LIBRARY_DIRS}")
+                if(LAPACK_LIBRARY_DIRS)
+                    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${LAPACK_LIBRARY_DIRS}")
+                endif()
+            endif()
 
             unset(LAPACKE_WORKS CACHE)
             include(CheckFunctionExists)
diff --git a/cmake_modules/morse/find/FindMAGMA.cmake b/cmake_modules/morse/find/FindMAGMA.cmake
index 0fdd189af37d39046cfbaf48f75b4c40009624b3..b1c999acbb7e336c1a11dc4d6bf7654b3c53357e 100644
--- a/cmake_modules/morse/find/FindMAGMA.cmake
+++ b/cmake_modules/morse/find/FindMAGMA.cmake
@@ -278,7 +278,18 @@ if(NOT MAGMA_FOUND OR NOT MAGMA_LIBRARIES)
         # check a function to validate the find
         set(CMAKE_REQUIRED_INCLUDES "${MAGMA_INCLUDE_DIRS};${CBLAS_INCLUDE_DIRS};${CUDA_INCLUDE_DIRS}")
         set(CMAKE_REQUIRED_LIBRARIES "${MAGMA_LIBRARIES};${CBLAS_LIBRARIES};${CUDA_CUBLAS_LIBRARIES};${CUDA_LIBRARIES};${LAPACK_LIBRARIES}")
-        set(CMAKE_REQUIRED_FLAGS     "-L${MAGMA_LIBRARY_DIRS} -L${CBLAS_LIBRARY_DIRS} -L${CUDA_LIBRARY_DIRS} -L${LAPACK_LIBRARY_DIRS}")
+        if (MAGMA_LIBRARY_DIRS)
+            set(CMAKE_REQUIRED_FLAGS "-L${MAGMA_LIBRARY_DIRS}")
+            if (CBLAS_LIBRARY_DIRS)
+                set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${CBLAS_LIBRARY_DIRS}")
+                if(CUDA_LIBRARY_DIRS)
+                    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${CUDA_LIBRARY_DIRS}")
+                    if(LAPACK_LIBRARY_DIRS)
+                        set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${LAPACK_LIBRARY_DIRS}")
+                    endif()
+                endif()
+            endif()
+        endif()
 
         unset(MAGMA_WORKS CACHE)
         include(CheckFunctionExists)
diff --git a/cmake_modules/morse/find/FindQUARK.cmake b/cmake_modules/morse/find/FindQUARK.cmake
index c6dbe604ade2cc83c0de8294d42d8b14fed7c249..55005c53846ff8a5dcbe3363d286b2a71754f6e7 100644
--- a/cmake_modules/morse/find/FindQUARK.cmake
+++ b/cmake_modules/morse/find/FindQUARK.cmake
@@ -191,11 +191,15 @@ if(QUARK_LIBRARIES)
     # check a function to validate the find
     set(CMAKE_REQUIRED_INCLUDES  "${QUARK_INCLUDE_DIRS}")
     set(CMAKE_REQUIRED_LIBRARIES "${QUARK_LIBRARIES};${CMAKE_THREAD_LIBS_INIT}")
-    set(CMAKE_REQUIRED_FLAGS     "-L${QUARK_LIBRARY_DIRS}")
+    if (QUARK_LIBRARY_DIRS)
+        set(CMAKE_REQUIRED_FLAGS "-L${QUARK_LIBRARY_DIRS}")
+    endif()
     if (HWLOC_FOUND)
         list(APPEND CMAKE_REQUIRED_INCLUDES "${HWLOC_INCLUDE_DIRS}")
         list(APPEND CMAKE_REQUIRED_LIBRARIES "${HWLOC_LIBRARIES}")
-        list(APPEND CMAKE_REQUIRED_FLAGS "-L${HWLOC_LIBRARIES}")
+        if (HWLOC_LIBRARY_DIRS)
+            set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${HWLOC_LIBRARY_DIRS}")
+        endif()
     endif()
 
     unset(QUARK_WORKS CACHE)
diff --git a/cmake_modules/morse/find/FindSTARPU.cmake b/cmake_modules/morse/find/FindSTARPU.cmake
index 00efba5ccb486167edde4af9051c06c3b8191ae9..7717fa7e77870a82947d76835f2c038d2fc35c6d 100644
--- a/cmake_modules/morse/find/FindSTARPU.cmake
+++ b/cmake_modules/morse/find/FindSTARPU.cmake
@@ -532,22 +532,37 @@ if( (NOT STARPU_SHM_FOUND) OR (NOT STARPU_SHM_LIBRARIES) OR
         set(CMAKE_REQUIRED_INCLUDES "${STARPU_INCLUDE_DIRS}")
         set(CMAKE_REQUIRED_FLAGS)
         foreach(libdir ${STARPU_LIBRARY_DIRS})
+            if(libdir)
+                set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${libdir}")
+            endif()
         endforeach()
         set(CMAKE_REQUIRED_LIBRARIES "${STARPU_LIBRARIES}")
         if (HWLOC_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${HWLOC_INCLUDE_DIRS}")
+            if (HWLOC_LIBRARY_DIRS)
+                set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${HWLOC_LIBRARY_DIRS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${HWLOC_LIBRARIES}")
         endif()
         if (MPI_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${MPI_C_INCLUDE_PATH}")
+            if (MPI_C_LINK_FLAGS)
+                set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${MPI_C_LINK_FLAGS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${MPI_C_LIBRARIES}")
         endif()
         if (CUDA_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${CUDA_INCLUDE_DIRS}")
+            if (CUDA_LIBRARY_DIRS)
+                set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${CUDA_LIBRARY_DIRS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${CUDA_CUBLAS_LIBRARIES};${CUDA_LIBRARIES}")
         endif()
         if (MAGMA_FOUND)
             list(APPEND CMAKE_REQUIRED_INCLUDES "${MAGMA_INCLUDE_DIRS}")
+            if (MAGMA_LIBRARY_DIRS)
+                set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${MAGMA_LIBRARY_DIRS}")
+            endif()
             list(APPEND CMAKE_REQUIRED_LIBRARIES "${${MAGMA_LIBRARIES}}")
         endif()
 
diff --git a/cmake_modules/morse/find/FindTMG.cmake b/cmake_modules/morse/find/FindTMG.cmake
index 892bce9977b25ebde7818bba00e9ff45956ce3ab..8c2886daf5fa04af12226ebbcec481f6effd388d 100644
--- a/cmake_modules/morse/find/FindTMG.cmake
+++ b/cmake_modules/morse/find/FindTMG.cmake
@@ -191,7 +191,12 @@ if (LAPACK_FOUND)
         # check a function to validate the find
         set(CMAKE_REQUIRED_INCLUDES "${TMG_INCLUDE_DIRS};${LAPACK_INCLUDE_DIRS}")
         set(CMAKE_REQUIRED_LIBRARIES "${TMG_LIBRARIES};${LAPACK_LIBRARIES}")
-        set(CMAKE_REQUIRED_FLAGS "-L${TMG_LIBRARY_DIRS} -L${LAPACK_LIBRARY_DIRS}")
+        if (TMG_LIBRARY_DIRS)
+            set(CMAKE_REQUIRED_FLAGS "-L${TMG_LIBRARY_DIRS}")
+            if (LAPACK_LIBRARY_DIRS)
+                set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -L${LAPACK_LIBRARY_DIRS}")
+            endif()
+        endif()
 
         if(TMG_LIBRARIES)
             unset(TMG_WORKS CACHE)