From 355b57e796c26bd3f946b510648d5c3eed65a81d Mon Sep 17 00:00:00 2001
From: Florent Pruvost <florent.pruvost@inria.fr>
Date: Fri, 21 Nov 2014 15:32:16 +0000
Subject: [PATCH] add a condition to MAGMA version we are depending on (with
 pkg-config)

---
 CMakeLists.txt                           |  3 ++-
 cmake_modules/morse/find/FindMAGMA.cmake | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 891a7d509..540e998b5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -306,8 +306,9 @@ if(NOT CHAMELEON_SIMULATION)
         #----------------------------------------------
         if ( CUDA_FOUND )
             if ( CHAMELEON_USE_MAGMA )
+                set(CHAMELEON_CACHE_VERSION "1.4" CACHE STRING "oldest MAGMA version desired")
                 set(MAGMA_DIR "" CACHE PATH "Root directory of MAGMA library")
-                find_package(MAGMA REQUIRED COMPONENTS CBLAS LAPACK CUDA)
+                find_package(MAGMA ${CHAMELEON_CACHE_VERSION} REQUIRED COMPONENTS CBLAS LAPACK CUDA)
 
                 set(HAVE_MAGMA ${MAGMA_FOUND})
                 if ( MAGMA_FOUND )
diff --git a/cmake_modules/morse/find/FindMAGMA.cmake b/cmake_modules/morse/find/FindMAGMA.cmake
index 315cf87c7..bd1f44a0d 100644
--- a/cmake_modules/morse/find/FindMAGMA.cmake
+++ b/cmake_modules/morse/find/FindMAGMA.cmake
@@ -94,6 +94,27 @@ if(PKG_CONFIG_EXECUTABLE)
         endif()
     endif()
 
+    if (MAGMA_FIND_VERSION_EXACT STREQUAL 1)
+        if( NOT (MAGMA_FIND_VERSION_MAJOR STREQUAL MAGMA_VERSION_MAJOR) OR
+            NOT (MAGMA_FIND_VERSION_MINOR STREQUAL MAGMA_VERSION_MINOR) )
+            if(NOT MAGMA_FIND_QUIETLY)
+                message(FATAL_ERROR
+                        "MAGMA version found is ${MAGMA_VERSION_STRING}"
+                        "when required is ${MAGMA_FIND_VERSION}")
+            endif()
+        endif()
+    else()
+        # if the version found is older than the required then error
+        if( (MAGMA_FIND_VERSION_MAJOR STRGREATER MAGMA_VERSION_MAJOR) OR
+            (MAGMA_FIND_VERSION_MINOR STRGREATER MAGMA_VERSION_MINOR) )
+            if(NOT MAGMA_FIND_QUIETLY)
+                message(FATAL_ERROR
+                        "MAGMA version found is ${MAGMA_VERSION_STRING}"
+                        "when required is ${MAGMA_FIND_VERSION} or newer")
+            endif()
+        endif()
+    endif()
+
 endif(PKG_CONFIG_EXECUTABLE)
 
 if(NOT MAGMA_FOUND OR NOT MAGMA_LIBRARIES)
-- 
GitLab