From 0ae0534e1fe18fde1de298344f5d2948caa02a74 Mon Sep 17 00:00:00 2001
From: Florent Pruvost <florent.pruvost@inria.fr>
Date: Thu, 26 Mar 2015 17:23:13 +0000
Subject: [PATCH] begin macro to install packages generically

---
 CMakeLists.txt                           | 9 ++++++++-
 cmake_modules/morse/MorseInit.cmake      | 3 +++
 cmake_modules/morse/find/FindCBLAS.cmake | 4 +++-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 25343e9d0..b0202f4ff 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -303,7 +303,14 @@ if (MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_SOURCE_DIR}/cmake_modules/")
                 list(APPEND CMAKE_EXE_LINKER_FLAGS "${BLAS_LINKER_FLAGS}")
             endif()
         else()
-            message(FATAL_ERROR "A BLAS library is required but has not been found")
+            message(FATAL_ERROR "BLAS library has not been found")
+            #install_package(BLAS DOWNLOAD)
+            #find_package(BLASEXT)
+            #if (BLAS_FOUND)
+            #    message(STATUS "BLAS library has been found after automatic installation")
+            #else()
+            #    message(FATAL_ERROR "BLAS library has not been found after automatic installation")
+            #endif()
         endif()
         if(CBLAS_FOUND)
             include_directories(${CBLAS_INCLUDE_DIRS})
diff --git a/cmake_modules/morse/MorseInit.cmake b/cmake_modules/morse/MorseInit.cmake
index ccb528762..6e24ceaa7 100644
--- a/cmake_modules/morse/MorseInit.cmake
+++ b/cmake_modules/morse/MorseInit.cmake
@@ -46,6 +46,9 @@ include(AuxilaryFlags)
 # Add the path where we handle our FindFOO.cmake to seek for liraries
 list(APPEND CMAKE_MODULE_PATH ${MORSE_CMAKE_MODULE_PATH}/find)
 
+# Install libraries if not discovered on the system
+include(InstallPackage)
+
 option(MORSE_VERBOSE_FIND_PACKAGE "Add additional messages concerning no found packages" OFF)
 #message("-- ${BoldGreen}MORSE_VERBOSE_FIND_PACKAGE is set to OFF, turn it ON to get"
 #        "information about packages not found${ColourReset}")
diff --git a/cmake_modules/morse/find/FindCBLAS.cmake b/cmake_modules/morse/find/FindCBLAS.cmake
index 15994828f..c3945f718 100644
--- a/cmake_modules/morse/find/FindCBLAS.cmake
+++ b/cmake_modules/morse/find/FindCBLAS.cmake
@@ -102,7 +102,9 @@ endif()
 if (CBLAS_FIND_COMPONENTS)
     foreach( component ${CBLAS_FIND_COMPONENTS} )
         if(CBLAS_FIND_REQUIRED_${component})
-            find_package(${component} REQUIRED)
+            if (CBLAS_FIND_REQUIRED)
+                find_package(${component} REQUIRED)
+            endif()
         else()
             find_package(${component})
         endif()
-- 
GitLab