From ed62a6edcea8aeef4c85d81c5d496f929b350e83 Mon Sep 17 00:00:00 2001
From: Florent Pruvost <florent.pruvost@inria.fr>
Date: Wed, 25 Feb 2015 15:25:11 +0000
Subject: [PATCH] remove duplicate dirs in _DEP vars of Finds

---
 cmake_modules/morse/find/FindCBLAS.cmake     |  2 ++
 cmake_modules/morse/find/FindCHAMELEON.cmake |  2 ++
 cmake_modules/morse/find/FindFFTW.cmake      |  2 ++
 cmake_modules/morse/find/FindLAPACKE.cmake   |  2 ++
 cmake_modules/morse/find/FindMAGMA.cmake     |  2 ++
 cmake_modules/morse/find/FindMUMPS.cmake     |  8 +++++-
 cmake_modules/morse/find/FindPASTIX.cmake    | 30 ++++++++++++++------
 cmake_modules/morse/find/FindPTSCOTCH.cmake  |  2 ++
 cmake_modules/morse/find/FindQUARK.cmake     |  2 ++
 cmake_modules/morse/find/FindSCOTCH.cmake    |  2 +-
 cmake_modules/morse/find/FindSTARPU.cmake    |  8 ++++--
 cmake_modules/morse/find/FindTMG.cmake       |  8 ++++--
 12 files changed, 54 insertions(+), 16 deletions(-)

diff --git a/cmake_modules/morse/find/FindCBLAS.cmake b/cmake_modules/morse/find/FindCBLAS.cmake
index f85c66348..bbf09d276 100644
--- a/cmake_modules/morse/find/FindCBLAS.cmake
+++ b/cmake_modules/morse/find/FindCBLAS.cmake
@@ -297,6 +297,8 @@ if (BLAS_FOUND)
                 set(CBLAS_LIBRARIES_DEP "${REQUIRED_LIBS}")
                 set(CBLAS_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
                 set(CBLAS_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+                list(REMOVE_DUPLICATES CBLAS_LIBRARY_DIRS_DEP)
+                list(REMOVE_DUPLICATES CBLAS_INCLUDE_DIRS_DEP)
             else()
                 if(NOT CBLAS_FIND_QUIETLY)
                     message(STATUS "Looking for cblas : test of cblas_dscal with cblas and blas libraries fails")
diff --git a/cmake_modules/morse/find/FindCHAMELEON.cmake b/cmake_modules/morse/find/FindCHAMELEON.cmake
index b89658472..815452956 100644
--- a/cmake_modules/morse/find/FindCHAMELEON.cmake
+++ b/cmake_modules/morse/find/FindCHAMELEON.cmake
@@ -701,6 +701,8 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR NOT CHAMELEON_FOUND )
             endif()
             set(CHAMELEON_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
             set(CHAMELEON_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+            list(REMOVE_DUPLICATES CHAMELEON_LIBRARY_DIRS_DEP)
+            list(REMOVE_DUPLICATES CHAMELEON_INCLUDE_DIRS_DEP)
         else()
             if(NOT CHAMELEON_FIND_QUIETLY)
                 message(STATUS "Looking for chameleon : test of MORSE_Init fails")
diff --git a/cmake_modules/morse/find/FindFFTW.cmake b/cmake_modules/morse/find/FindFFTW.cmake
index 6df493eb5..0d7622c9a 100644
--- a/cmake_modules/morse/find/FindFFTW.cmake
+++ b/cmake_modules/morse/find/FindFFTW.cmake
@@ -390,6 +390,8 @@ if( NOT FFTW_FOUND )
             set(FFTW_LIBRARIES_DEP "${REQUIRED_LIBS}")
             set(FFTW_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
             set(FFTW_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+            list(REMOVE_DUPLICATES FFTW_LIBRARY_DIRS_DEP)
+            list(REMOVE_DUPLICATES FFTW_INCLUDE_DIRS_DEP)
         else()
             if(NOT FFTW_FIND_QUIETLY)
                 message(STATUS "Looking for FFTW : test of ${FFTW_PREC_TESTFUNC}fftw_execute_ with fftw library fails")
diff --git a/cmake_modules/morse/find/FindLAPACKE.cmake b/cmake_modules/morse/find/FindLAPACKE.cmake
index 894a18c09..6ef70b8dc 100644
--- a/cmake_modules/morse/find/FindLAPACKE.cmake
+++ b/cmake_modules/morse/find/FindLAPACKE.cmake
@@ -300,6 +300,8 @@ if (LAPACK_FOUND)
                 set(LAPACKE_LIBRARIES_DEP "${REQUIRED_LIBS}")
                 set(LAPACKE_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
                 set(LAPACKE_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+                list(REMOVE_DUPLICATES LAPACKE_LIBRARY_DIRS_DEP)
+                list(REMOVE_DUPLICATES LAPACKE_INCLUDE_DIRS_DEP)
             else()
                 if(NOT LAPACKE_FIND_QUIETLY)
                     message(STATUS "Looking for lapacke: test of LAPACKE_dgeqrf with lapacke and lapack libraries fails")
diff --git a/cmake_modules/morse/find/FindMAGMA.cmake b/cmake_modules/morse/find/FindMAGMA.cmake
index 2c0734128..343891174 100644
--- a/cmake_modules/morse/find/FindMAGMA.cmake
+++ b/cmake_modules/morse/find/FindMAGMA.cmake
@@ -342,6 +342,8 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT MAGMA_FOUND) OR NOT MAGMA_FOUND )
             set(MAGMA_LIBRARIES_DEP    "${REQUIRED_LIBS}")
             set(MAGMA_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
             set(MAGMA_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+            list(REMOVE_DUPLICATES MAGMA_LIBRARY_DIRS_DEP)
+            list(REMOVE_DUPLICATES MAGMA_INCLUDE_DIRS_DEP)
         else()
             if(NOT MAGMA_FIND_QUIETLY)
                 message(STATUS "Looking for magma : test of magma_dgetrf with
diff --git a/cmake_modules/morse/find/FindMUMPS.cmake b/cmake_modules/morse/find/FindMUMPS.cmake
index 081c59cb1..3c0c79fd9 100644
--- a/cmake_modules/morse/find/FindMUMPS.cmake
+++ b/cmake_modules/morse/find/FindMUMPS.cmake
@@ -299,6 +299,7 @@ else ()
     endif()
 endif()
 
+
 # Looking for lib
 # ---------------
 
@@ -405,7 +406,7 @@ else ()
         message(STATUS "Looking for mumps -- libzmumps.a not found")
     endif()
 endif()
-list(REMOVE_DUPLICATES MUMPS_LIBRARY_DIRS)
+
 # check that one precision arithmetic at least has been discovered
 if (NOT MUMPS_PREC_S AND NOT MUMPS_PREC_D AND NOT MUMPS_PREC_C AND NOT MUMPS_PREC_S)
     if (MUMPS_FIND_REQUIRED)
@@ -439,6 +440,7 @@ if (MUMPS_mpiseq_LIBRARY)
         list(APPEND MUMPS_LIBRARIES "${MUMPS_mpiseq_LIBRARY}")
         get_filename_component(mpiseq_lib_path ${MUMPS_mpiseq_LIBRARY} PATH)
         list(APPEND MUMPS_LIBRARY_DIRS "${mpiseq_lib_path}")
+        list(APPEND MUMPS_INCLUDE_DIRS "${mpiseq_lib_path}")
     endif()
 else ()
     if (MUMPS_FIND_REQUIRED AND MUMPS_LOOK_FOR_SEQ)
@@ -465,6 +467,8 @@ else ()
         endif()
     endif()
 endif()
+list(REMOVE_DUPLICATES MUMPS_LIBRARY_DIRS)
+list(REMOVE_DUPLICATES MUMPS_INCLUDE_DIRS)
 
 # check a function to validate the find
 if(MUMPS_LIBRARIES)
@@ -583,6 +587,8 @@ if(MUMPS_LIBRARIES)
         set(MUMPS_LIBRARIES_DEP "${REQUIRED_LIBS}")
         set(MUMPS_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
         set(MUMPS_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+        list(REMOVE_DUPLICATES MUMPS_LIBRARY_DIRS_DEP)
+        list(REMOVE_DUPLICATES MUMPS_INCLUDE_DIRS_DEP)
     else()
         if(NOT MUMPS_FIND_QUIETLY)
             message(STATUS "Looking for MUMPS : test of [sdcz]mumps() fails")
diff --git a/cmake_modules/morse/find/FindPASTIX.cmake b/cmake_modules/morse/find/FindPASTIX.cmake
index d7e0505e3..ff72836cd 100644
--- a/cmake_modules/morse/find/FindPASTIX.cmake
+++ b/cmake_modules/morse/find/FindPASTIX.cmake
@@ -95,8 +95,8 @@ if( PASTIX_FIND_COMPONENTS )
         endif()
         if (${component} STREQUAL "MPI")
             # means we look for the MPI version of PaStiX (default)
-            set(PASTIX_LOOK_FOR_SEQ ON)
-            set(PASTIX_LOOK_FOR_MPI OFF)
+            set(PASTIX_LOOK_FOR_SEQ OFF)
+            set(PASTIX_LOOK_FOR_MPI ON)
         endif()
         if (${component} STREQUAL "STARPU")
             # means we look for PaStiX with StarPU
@@ -480,13 +480,25 @@ if(PASTIX_LIBRARIES)
     if (PASTIX_LOOK_FOR_STARPU AND STARPU_FOUND)
         if (STARPU_INCLUDE_DIRS_DEP)
             list(APPEND REQUIRED_INCDIRS "${STARPU_INCLUDE_DIRS_DEP}")
+        elseif (STARPU_INCLUDE_DIRS)
+            list(APPEND REQUIRED_INCDIRS "${STARPU_INCLUDE_DIRS}")
+        endif()
+        if(STARPU_LIBRARY_DIRS_DEP)
+            list(APPEND REQUIRED_LIBDIRS "${STARPU_LIBRARY_DIRS_DEP}")
+        elseif(STARPU_LIBRARY_DIRS)
+            list(APPEND REQUIRED_LIBDIRS "${STARPU_LIBRARY_DIRS}")
+        endif()
+        if (STARPU_LIBRARIES_DEP)
+            list(APPEND REQUIRED_LIBS "${STARPU_LIBRARIES_DEP}")
+        elseif (STARPU_LIBRARIES)
+            foreach(lib ${STARPU_LIBRARIES})
+                if (EXISTS ${lib} OR ${lib} MATCHES "^-")
+                    list(APPEND REQUIRED_LIBS "${lib}")
+                else()
+                    list(APPEND REQUIRED_LIBS "-l${lib}")
+                endif()
+            endforeach()
         endif()
-        foreach(libdir ${STARPU_LIBRARY_DIRS_DEP})
-            if (libdir)
-                list(APPEND REQUIRED_LIBDIRS "${libdir}")
-            endif()
-        endforeach()
-        list(APPEND REQUIRED_LIBS "${STARPU_LIBRARIES_DEP}")
     endif()
     # CUDA
     if (PASTIX_LOOK_FOR_STARPU_CUDA AND CUDA_FOUND)
@@ -603,6 +615,8 @@ if(PASTIX_LIBRARIES)
         endif()
         set(PASTIX_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
         set(PASTIX_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+        list(REMOVE_DUPLICATES PASTIX_LIBRARY_DIRS_DEP)
+        list(REMOVE_DUPLICATES PASTIX_INCLUDE_DIRS_DEP)
     else()
         if(NOT PASTIX_FIND_QUIETLY)
             message(STATUS "Looking for PASTIX : test of pastix() fails")
diff --git a/cmake_modules/morse/find/FindPTSCOTCH.cmake b/cmake_modules/morse/find/FindPTSCOTCH.cmake
index 1f70a3aae..b9fac6d55 100644
--- a/cmake_modules/morse/find/FindPTSCOTCH.cmake
+++ b/cmake_modules/morse/find/FindPTSCOTCH.cmake
@@ -264,6 +264,8 @@ if(PTSCOTCH_LIBRARIES)
         endif()
         set(PTSCOTCH_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
         set(PTSCOTCH_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+        list(REMOVE_DUPLICATES PTSCOTCH_LIBRARY_DIRS_DEP)
+        list(REMOVE_DUPLICATES PTSCOTCH_INCLUDE_DIRS_DEP)
     else()
         if(NOT PTSCOTCH_FIND_QUIETLY)
             message(STATUS "Looking for PTSCOTCH : test of SCOTCH_dgraphInit with PTSCOTCH library fails")
diff --git a/cmake_modules/morse/find/FindQUARK.cmake b/cmake_modules/morse/find/FindQUARK.cmake
index 306fc0339..5ac3a64bb 100644
--- a/cmake_modules/morse/find/FindQUARK.cmake
+++ b/cmake_modules/morse/find/FindQUARK.cmake
@@ -265,6 +265,8 @@ if(QUARK_LIBRARIES)
         set(QUARK_LIBRARIES_DEP "${REQUIRED_LIBS}")
         set(QUARK_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
         set(QUARK_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+        list(REMOVE_DUPLICATES QUARK_LIBRARY_DIRS_DEP)
+        list(REMOVE_DUPLICATES QUARK_INCLUDE_DIRS_DEP)
     else()
         if(NOT QUARK_FIND_QUIETLY)
             message(STATUS "Looking for QUARK : test of QUARK_New with QUARK library fails")
diff --git a/cmake_modules/morse/find/FindSCOTCH.cmake b/cmake_modules/morse/find/FindSCOTCH.cmake
index fa67623b8..1be823578 100644
--- a/cmake_modules/morse/find/FindSCOTCH.cmake
+++ b/cmake_modules/morse/find/FindSCOTCH.cmake
@@ -227,7 +227,7 @@ if(SCOTCH_LIBRARIES)
     check_function_exists(SCOTCH_graphInit SCOTCH_WORKS)
     mark_as_advanced(SCOTCH_WORKS)
 
-    if(NOT SCOTCH_WORKS)
+    if(SCOTCH_WORKS)
         # save link with dependencies
         set(SCOTCH_LIBRARIES "${REQUIRED_LIBS}")
     else()
diff --git a/cmake_modules/morse/find/FindSTARPU.cmake b/cmake_modules/morse/find/FindSTARPU.cmake
index 65053fce5..195fce882 100644
--- a/cmake_modules/morse/find/FindSTARPU.cmake
+++ b/cmake_modules/morse/find/FindSTARPU.cmake
@@ -33,9 +33,9 @@
 #  STARPU_LIBRARIES              - starpu libraries
 #  STARPU_SHM_LIBRARIES          - starpu libraries without libstarpumpi
 #  STARPU_MPI_LIBRARIES          - starpu libraries with libstarpumpi
-#  MAGMA_INCLUDE_DIRS_DEP        - starpu + dependencies include directories
-#  MAGMA_LIBRARY_DIRS_DEP        - starpu + dependencies link directories
-#  MAGMA_LIBRARIES_DEP           - starpu libraries + dependencies
+#  STARPU_INCLUDE_DIRS_DEP        - starpu + dependencies include directories
+#  STARPU_LIBRARY_DIRS_DEP        - starpu + dependencies link directories
+#  STARPU_LIBRARIES_DEP           - starpu libraries + dependencies
 #  STARPU_VERSION_STRING         - A human-readable string containing the version of the package found
 #  STARPU_VERSION_MAJOR          - The major version of the package found
 #  STARPU_VERSION_MINOR          - The minor version of the package found
@@ -736,6 +736,8 @@ if( (NOT PKG_CONFIG_EXECUTABLE AND NOT STARPU_FOUND) OR
             endif()
             set(STARPU_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
             set(STARPU_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+            list(REMOVE_DUPLICATES STARPU_LIBRARY_DIRS_DEP)
+            list(REMOVE_DUPLICATES STARPU_INCLUDE_DIRS_DEP)
         else()
             if(NOT STARPU_FIND_QUIETLY)
                 message(STATUS "Looking for starpu : test of starpu_init fails")
diff --git a/cmake_modules/morse/find/FindTMG.cmake b/cmake_modules/morse/find/FindTMG.cmake
index 20ef9a877..d781da409 100644
--- a/cmake_modules/morse/find/FindTMG.cmake
+++ b/cmake_modules/morse/find/FindTMG.cmake
@@ -141,19 +141,19 @@ if (LAPACK_FOUND)
         if(TMG_LIBDIR)
             set(TMG_tmg_LIBRARY "TMG_tmg_LIBRARY-NOTFOUND")
             find_library(TMG_tmg_LIBRARY
-                NAMES tmg
+                NAMES tmglib
                 HINTS ${TMG_LIBDIR} )
         else()
             if(TMG_DIR)
                 set(TMG_tmg_LIBRARY "TMG_tmg_LIBRARY-NOTFOUND")
                 find_library(TMG_tmg_LIBRARY
-                    NAMES tmg
+                    NAMES tmglib
                     HINTS ${TMG_DIR}
                     PATH_SUFFIXES lib lib32 lib64 )
             else()
                 set(TMG_tmg_LIBRARY "TMG_tmg_LIBRARY-NOTFOUND")
                 find_library(TMG_tmg_LIBRARY
-                    NAMES tmg
+                    NAMES tmglib
                     HINTS ${_lib_env} )
             endif()
         endif()
@@ -234,6 +234,8 @@ if (LAPACK_FOUND)
                 set(TMG_LIBRARIES_DEP "${REQUIRED_LIBS}")
                 set(TMG_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
                 set(TMG_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+                list(REMOVE_DUPLICATES TMG_LIBRARY_DIRS_DEP)
+                list(REMOVE_DUPLICATES TMG_INCLUDE_DIRS_DEP)
             else()
                 if(NOT TMG_FIND_QUIETLY)
                     message(STATUS "Looking for tmg: test of dlarnv and dlagsy with tmg and lapack libraries fails")
-- 
GitLab