From 97fdacc3c90df185a225bab9208f5a776063472b Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Mon, 23 Apr 2018 17:23:07 +0200
Subject: [PATCH] update the cmake module

---
 CMakeLists.txt            | 53 +++++++++++++++++++++++++--------------
 cmake_modules/morse_cmake |  2 +-
 include/spm_config.h.in   |  3 +++
 tests/CMakeLists.txt      |  4 +--
 4 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8f565e9b..471495fe 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,7 +13,7 @@ project (SPM C Fortran)
 
 # Check if compiled independently or within another project
 if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
-  set( BUILD_SUBPROJECT OFF )
+  set( BUILD_AS_SUBPROJECT OFF )
 
   option(BUILD_SHARED_LIBS
     "Build shared libraries" OFF)
@@ -34,7 +34,13 @@ if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
   include(CTest)
 
 else()
-  set( BUILD_SUBPROJECT ON )
+  set( BUILD_AS_SUBPROJECT ON )
+
+  # Check if within pastix which provides Scotch
+  if (PASTIX_ORDERING_SCOTCH)
+    set(HAVE_SCOTCH ON)
+  endif()
+
 endif()
 
 # Define a subproject name fr ctest
@@ -84,22 +90,33 @@ include(RulesPrecisions)
 ### System parameter detection
 include(CheckSystem)
 
-# PaStiX depends on CBLAS
-#----------------------------
-find_package(CBLAS) # Should be REQUIRED for BLAS sequential only
-if(CBLAS_FOUND)
-    message(STATUS "cblas: ${CBLAS_INCLUDE_DIRS}")
-    include_directories(${CBLAS_INCLUDE_DIRS})
-endif()
-
-find_package(LAPACKE) # Should be also REQUIRED
+# SPM depends on Lapacke and CBLAS
+#---------------------------------
+find_package(LAPACKE REQUIRED)
 if(LAPACKE_FOUND)
   message(STATUS "lapacke: ${LAPACKE_INCLUDE_DIRS}")
   include_directories(${LAPACKE_INCLUDE_DIRS})
 endif()
 
-#Configuration header
-#--------------------
+find_package(CBLAS REQUIRED)
+if(CBLAS_FOUND)
+  message(STATUS "cblas: ${CBLAS_INCLUDE_DIRS}")
+  include_directories(${CBLAS_INCLUDE_DIRS})
+endif()
+
+### Store dependencies not handled with pkg-config
+set( DEPS_LIBRARIES
+  ${LAPACKE_LIBRARIES_DEP}
+  ${CBLAS_LIBRARIES_DEP}
+  )
+
+list(APPEND CMAKE_INSTALL_RPATH
+  ${LAPACKE_LIBRARY_DIRS_DEP}
+  ${CBLAS_LIBRARY_DIRS_DEP}
+  )
+
+# Configuration header
+#---------------------
 configure_file (
   "${CMAKE_CURRENT_SOURCE_DIR}/include/spm_config.h.in"
   "${CMAKE_CURRENT_BINARY_DIR}/src/spm_config.h")
@@ -108,10 +125,8 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/src/spm_config.h" DESTINATION include
 include_directories(include)
 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
 include_directories("${CMAKE_CURRENT_BINARY_DIR}/src")
-include_directories("${CMAKE_CURRENT_SOURCE_DIR}/drivers")
 
 ### reset variables
-set(generated_sources "")
 set(generated_headers "")
 
 ### Generate the headers in all precisions
@@ -134,6 +149,8 @@ add_custom_target(spm_headers_tgt
   DEPENDS ${spm_headers} )
 
 ### Generate the sources in all precisions
+set(generated_sources "")
+
 set(SOURCES
   src/z_spm.c
   src/z_spm_2dense.c
@@ -186,10 +203,8 @@ add_library(spm
   )
 
 target_link_libraries(spm
-  ${LAPACKE_LIBRARIES}
-  ${LAPACK_SEQ_LIBRARIES}
-  ${CBLAS_LIBRARIES}
-  ${BLAS_SEQ_LIBRARIES}
+  ${LAPACKE_LIBRARIES_DEP}
+  ${CBLAS_LIBRARIES_DEP}
   )
 
 add_dependencies(spm
diff --git a/cmake_modules/morse_cmake b/cmake_modules/morse_cmake
index f4ead635..0e9c7a8f 160000
--- a/cmake_modules/morse_cmake
+++ b/cmake_modules/morse_cmake
@@ -1 +1 @@
-Subproject commit f4ead635e331c6a43b81d9e0a56b082fe47be36c
+Subproject commit 0e9c7a8fe39c4a728c2a8346007e1afa207cd9b5
diff --git a/include/spm_config.h.in b/include/spm_config.h.in
index 3301b6c0..64116e78 100644
--- a/include/spm_config.h.in
+++ b/include/spm_config.h.in
@@ -44,6 +44,9 @@
 /* Datatypes used */
 #cmakedefine SPM_INT64
 
+/* Exploit the scotch version from the library compiling spm */
+#cmakedefine HAVE_SCOTCH
+
 #if defined(HAVE_FALLTHROUGH)
 #define spm_attr_fallthrough __attribute__((fallthrough))
 #else
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index ff6480bc..608ab0ab 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -34,8 +34,8 @@ add_library(spm_test
 
 target_link_libraries( spm_test
   spm
-  ${LAPACKE_LIBRARIES}
-  ${LAPACK_SEQ_LIBRARIES} )
+  ${LAPACKE_LIBRARIES_DEP}
+  ${CBLAS_LIBRARIES_DEP} )
 
 ## Generate all test executables
 set (TESTS
-- 
GitLab