From cd0d395d23a4038da6556d35ae0a71b073d9df47 Mon Sep 17 00:00:00 2001
From: Florent Pruvost <florent.pruvost@inria.fr>
Date: Tue, 21 Nov 2017 15:45:43 +0100
Subject: [PATCH] add TMG as a component of LAPACKE to check whether lapacke
 provides the tmglib interface or not

---
 .gitlab-ci.yml                    |  2 +-
 modules/find/FindLAPACKE.cmake    | 23 +++++++++++++++++++++--
 modules/find/tests/CMakeLists.txt |  1 +
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6d5a875..1890ae4 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -10,5 +10,5 @@ Find:
     - cd modules/find/tests
     - mkdir -p build
     - cd build
-    - cmake .. -DENABLE_CTEST=ON -DQUARK_COMPONENTS="HWLOC" -DPASTIX_COMPONENTS="PARSEC;STARPU"
+    - cmake .. -DENABLE_CTEST=ON -DLAPACKE_COMPONENTS="TMG" -DQUARK_COMPONENTS="HWLOC" -DPASTIX_COMPONENTS="PARSEC;STARPU"
     - ctest -V
diff --git a/modules/find/FindLAPACKE.cmake b/modules/find/FindLAPACKE.cmake
index 55fc87e..860e50f 100644
--- a/modules/find/FindLAPACKE.cmake
+++ b/modules/find/FindLAPACKE.cmake
@@ -3,7 +3,7 @@
 # @copyright (c) 2009-2014 The University of Tennessee and The University
 #                          of Tennessee Research Foundation.
 #                          All rights reserved.
-# @copyright (c) 2012-2016 Inria. All rights reserved.
+# @copyright (c) 2012-2017 Inria. All rights reserved.
 # @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
 #
 ###
@@ -18,6 +18,11 @@
 #  LAPACKE depends on the following libraries:
 #   - LAPACK
 #
+#  COMPONENTS are optional libraries CHAMELEON could be linked with,
+#  Use it to drive detection of a specific compilation chain
+#  COMPONENTS can be some of the following:
+#   - TMG: to check that LAPACKE provides the tmglib interface
+#
 # This module finds headers and lapacke library.
 # Results are reported in variables:
 #  LAPACKE_FOUND            - True if headers and requested libraries were found
@@ -49,7 +54,7 @@
 # Copyright 2012-2013 Emmanuel Agullo
 # Copyright 2012-2013 Mathieu Faverge
 # Copyright 2012      Cedric Castagnede
-# Copyright 2013-2016 Florent Pruvost
+# Copyright 2013-2017 Florent Pruvost
 #
 # Distributed under the OSI-approved BSD License (the "License");
 # see accompanying file MORSE-Copyright.txt for details.
@@ -68,6 +73,16 @@ if (NOT LAPACKE_FOUND)
   endif()
 endif()
 
+# to check that LAPACKE provides the tmglib interface
+set(LAPACKE_WITH_TMG OFF)
+if( LAPACKE_FIND_COMPONENTS )
+  foreach( component ${LAPACKE_FIND_COMPONENTS} )
+    if (${component} STREQUAL "TMG")
+      set(LAPACKE_WITH_TMG ON)
+    endif()
+  endforeach()
+endif()
+
 # LAPACKE depends on LAPACK anyway, try to find it
 if (NOT LAPACK_FOUND)
   if(LAPACKE_FIND_REQUIRED)
@@ -324,6 +339,10 @@ if (LAPACK_FOUND)
       unset(LAPACKE_WORKS CACHE)
       include(CheckFunctionExists)
       check_function_exists(LAPACKE_dgeqrf LAPACKE_WORKS)
+      if (LAPACKE_WORKS AND LAPACKE_WITH_TMG)
+        unset(LAPACKE_WORKS CACHE)
+        check_function_exists(LAPACKE_dlatms_work LAPACKE_WORKS)
+      endif()
       mark_as_advanced(LAPACKE_WORKS)
 
       if(LAPACKE_WORKS)
diff --git a/modules/find/tests/CMakeLists.txt b/modules/find/tests/CMakeLists.txt
index 8cf0090..edb3ae8 100644
--- a/modules/find/tests/CMakeLists.txt
+++ b/modules/find/tests/CMakeLists.txt
@@ -9,6 +9,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../")
 set(PACKAGES "" CACHE STRING "List of packages to find, ex: BLAS;STARPU;PASTIX")
 
 # specific components to look for with packages
+set(LAPACKE_COMPONENTS "" CACHE STRING "List of specific dependencies to look for with LAPACKE, ex: TMG")
 set(QUARK_COMPONENTS "" CACHE STRING "List of specific dependencies to look for with QUARK, ex: HWLOC")
 set(PASTIX_COMPONENTS "" CACHE STRING "List of specific dependencies to look for with PASTIX, ex: MPI;SEQ;STARPU;STARPU_CUDA;STARPU_FXT;SCOTCH;PTSCOTCH;METIS")
 set(PETSC_COMPONENTS "" CACHE STRING "List of specific dependencies to look for with PETSc, ex: CXX|C")
-- 
GitLab