Squashed 'third_party/eigen/' changes from 61d72f6..cf794d3


Change-Id: I9b814151b01f49af6337a8605d0c42a3a1ed4c72
git-subtree-dir: third_party/eigen
git-subtree-split: cf794d3b741a6278df169e58461f8529f43bce5d
diff --git a/cmake/Eigen3Config.cmake.in b/cmake/Eigen3Config.cmake.in
new file mode 100644
index 0000000..c5c5468
--- /dev/null
+++ b/cmake/Eigen3Config.cmake.in
@@ -0,0 +1,21 @@
+# This file exports the Eigen3::Eigen CMake target which should be passed to the
+# target_link_libraries command.
+
+@PACKAGE_INIT@
+
+include ("${CMAKE_CURRENT_LIST_DIR}/Eigen3Targets.cmake")
+
+# Legacy variables, do *not* use. May be removed in the future.
+
+set (EIGEN3_FOUND 1)
+set (EIGEN3_USE_FILE    "${CMAKE_CURRENT_LIST_DIR}/UseEigen3.cmake")
+
+set (EIGEN3_DEFINITIONS  "@EIGEN_DEFINITIONS@")
+set (EIGEN3_INCLUDE_DIR  "@PACKAGE_EIGEN_INCLUDE_DIR@")
+set (EIGEN3_INCLUDE_DIRS "@PACKAGE_EIGEN_INCLUDE_DIR@")
+set (EIGEN3_ROOT_DIR     "@PACKAGE_EIGEN_ROOT_DIR@")
+
+set (EIGEN3_VERSION_STRING "@EIGEN_VERSION_STRING@")
+set (EIGEN3_VERSION_MAJOR  "@EIGEN_VERSION_MAJOR@")
+set (EIGEN3_VERSION_MINOR  "@EIGEN_VERSION_MINOR@")
+set (EIGEN3_VERSION_PATCH  "@EIGEN_VERSION_PATCH@")
diff --git a/cmake/Eigen3ConfigLegacy.cmake.in b/cmake/Eigen3ConfigLegacy.cmake.in
new file mode 100644
index 0000000..62d7224
--- /dev/null
+++ b/cmake/Eigen3ConfigLegacy.cmake.in
@@ -0,0 +1,30 @@
+#                                               -*- cmake -*-
+#
+#  Eigen3Config.cmake(.in)
+
+# Use the following variables to compile and link against Eigen:
+#  EIGEN3_FOUND              - True if Eigen was found on your system
+#  EIGEN3_USE_FILE           - The file making Eigen usable
+#  EIGEN3_DEFINITIONS        - Definitions needed to build with Eigen
+#  EIGEN3_INCLUDE_DIR        - Directory where signature_of_eigen3_matrix_library can be found
+#  EIGEN3_INCLUDE_DIRS       - List of directories of Eigen and it's dependencies
+#  EIGEN3_ROOT_DIR           - The base directory of Eigen
+#  EIGEN3_VERSION_STRING     - A human-readable string containing the version
+#  EIGEN3_VERSION_MAJOR      - The major version of Eigen
+#  EIGEN3_VERSION_MINOR      - The minor version of Eigen
+#  EIGEN3_VERSION_PATCH      - The patch version of Eigen
+
+@PACKAGE_INIT@
+
+set ( EIGEN3_FOUND 1 )
+set ( EIGEN3_USE_FILE     "${CMAKE_CURRENT_LIST_DIR}/UseEigen3.cmake" )
+
+set ( EIGEN3_DEFINITIONS  "@EIGEN_DEFINITIONS@" )
+set ( EIGEN3_INCLUDE_DIR  "@PACKAGE_EIGEN_INCLUDE_DIR@" )
+set ( EIGEN3_INCLUDE_DIRS "@PACKAGE_EIGEN_INCLUDE_DIR@" )
+set ( EIGEN3_ROOT_DIR     "@PACKAGE_EIGEN_ROOT_DIR@" )
+
+set ( EIGEN3_VERSION_STRING "@EIGEN_VERSION_STRING@" )
+set ( EIGEN3_VERSION_MAJOR  "@EIGEN_VERSION_MAJOR@" )
+set ( EIGEN3_VERSION_MINOR  "@EIGEN_VERSION_MINOR@" )
+set ( EIGEN3_VERSION_PATCH  "@EIGEN_VERSION_PATCH@" )
diff --git a/cmake/EigenConfigureTesting.cmake b/cmake/EigenConfigureTesting.cmake
index 11ecc95..3a82439 100644
--- a/cmake/EigenConfigureTesting.cmake
+++ b/cmake/EigenConfigureTesting.cmake
@@ -11,44 +11,28 @@
 add_custom_target(check COMMAND "ctest")
 add_dependencies(check buildtests)
 
-# check whether /bin/bash exists
-find_file(EIGEN_BIN_BASH_EXISTS "/bin/bash" PATHS "/" NO_DEFAULT_PATH)
-
-# CMake/Ctest does not allow us to change the build command,
-# so we have to workaround by directly editing the generated DartConfiguration.tcl file
-# save CMAKE_MAKE_PROGRAM
-set(CMAKE_MAKE_PROGRAM_SAVE ${CMAKE_MAKE_PROGRAM})
-# and set a fake one
-set(CMAKE_MAKE_PROGRAM "@EIGEN_MAKECOMMAND_PLACEHOLDER@")
+# check whether /bin/bash exists (disabled as not used anymore)
+# find_file(EIGEN_BIN_BASH_EXISTS "/bin/bash" PATHS "/" NO_DEFAULT_PATH)
 
 # This call activates testing and generates the DartConfiguration.tcl
 include(CTest)
 
-set(EIGEN_TEST_BUILD_FLAGS " " CACHE STRING "Options passed to the build command of unit tests")
+set(EIGEN_TEST_BUILD_FLAGS "" CACHE STRING "Options passed to the build command of unit tests")
+set(EIGEN_DASHBOARD_BUILD_TARGET "buildtests" CACHE STRING "Target to be built in dashboard mode, default is buildtests")
+set(EIGEN_CTEST_ERROR_EXCEPTION "" CACHE STRING "Regular expression for build error messages to be filtered out")
 
-# overwrite default DartConfiguration.tcl
-# The worarounds are different for each version of the MSVC IDE
-if(MSVC_IDE)
-  if(CMAKE_MAKE_PROGRAM_SAVE MATCHES "devenv") # devenv
-    set(EIGEN_MAKECOMMAND_PLACEHOLDER "${CMAKE_MAKE_PROGRAM_SAVE} Eigen.sln /build \"Release\" /project buildtests ${EIGEN_TEST_BUILD_FLAGS} \n# ")    
-  else() # msbuild
-    set(EIGEN_MAKECOMMAND_PLACEHOLDER "${CMAKE_MAKE_PROGRAM_SAVE} buildtests.vcxproj /p:Configuration=\${CTEST_CONFIGURATION_TYPE}  ${EIGEN_TEST_BUILD_FLAGS}\n# ")
-  endif()
-else()
-  # for make and nmake
-  set(EIGEN_MAKECOMMAND_PLACEHOLDER "${CMAKE_MAKE_PROGRAM_SAVE} buildtests ${EIGEN_TEST_BUILD_FLAGS}")
+# Overwrite default DartConfiguration.tcl such that ctest can build our unit tests.
+# Recall that our unit tests are not in the "all" target, so we have to explicitely ask ctest to build our custom 'buildtests' target.
+# At this stage, we can also add custom flags to the build tool through the user defined EIGEN_TEST_BUILD_FLAGS variable.
+file(READ  "${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl" EIGEN_DART_CONFIG_FILE)
+# try to grab the default flags
+string(REGEX MATCH "MakeCommand:.*-- (.*)\nDefaultCTestConfigurationType" EIGEN_DUMMY ${EIGEN_DART_CONFIG_FILE})
+if(NOT CMAKE_MATCH_1)
+string(REGEX MATCH "MakeCommand:.*[^c]make (.*)\nDefaultCTestConfigurationType" EIGEN_DUMMY ${EIGEN_DART_CONFIG_FILE})
 endif()
-
-# copy ctest properties, which currently
-# o raise the warning levels
-configure_file(${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl ${CMAKE_BINARY_DIR}/DartConfiguration.tcl)
-
-# restore default CMAKE_MAKE_PROGRAM
-set(CMAKE_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM_SAVE})
-# un-set temporary variables so that it is like they never existed. 
-# CMake 2.6.3 introduces the more logical unset() syntax for this.
-set(CMAKE_MAKE_PROGRAM_SAVE) 
-set(EIGEN_MAKECOMMAND_PLACEHOLDER)
+string(REGEX REPLACE "MakeCommand:.*DefaultCTestConfigurationType" "MakeCommand: ${CMAKE_COMMAND} --build . --target ${EIGEN_DASHBOARD_BUILD_TARGET} --config \"\${CTEST_CONFIGURATION_TYPE}\" -- ${CMAKE_MATCH_1} ${EIGEN_TEST_BUILD_FLAGS}\nDefaultCTestConfigurationType"
+       EIGEN_DART_CONFIG_FILE2 ${EIGEN_DART_CONFIG_FILE})
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl" ${EIGEN_DART_CONFIG_FILE2})
 
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake)
 
@@ -64,18 +48,11 @@
   if(EIGEN_COVERAGE_TESTING)
     set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage")
     set(CTEST_CUSTOM_COVERAGE_EXCLUDE "/test/")
-  else(EIGEN_COVERAGE_TESTING)
-    set(COVERAGE_FLAGS "")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS}")
   endif(EIGEN_COVERAGE_TESTING)
-  if(EIGEN_TEST_C++0x)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
-  endif(EIGEN_TEST_C++0x)
-  if(CMAKE_SYSTEM_NAME MATCHES Linux)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS} -g2")
-    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COVERAGE_FLAGS} -O2 -g2")
-    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COVERAGE_FLAGS} -fno-inline-functions")
-    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS} -O0 -g3")
-  endif(CMAKE_SYSTEM_NAME MATCHES Linux)
+  
 elseif(MSVC)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS")
 endif(CMAKE_COMPILER_IS_GNUCXX)
+
+
diff --git a/cmake/EigenDetermineOSVersion.cmake b/cmake/EigenDetermineOSVersion.cmake
index 3c48d4c..9246fa6 100644
--- a/cmake/EigenDetermineOSVersion.cmake
+++ b/cmake/EigenDetermineOSVersion.cmake
@@ -26,7 +26,7 @@
 endfunction()
 
 function(DetermineOSVersion OS_VERSION)
-  if (WIN32)
+  if (WIN32 AND CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
     file (TO_NATIVE_PATH "$ENV{COMSPEC}" SHELL)
     exec_program( ${SHELL} ARGS "/c" "ver" OUTPUT_VARIABLE ver_output)
 				
diff --git a/cmake/EigenDetermineVSServicePack.cmake b/cmake/EigenDetermineVSServicePack.cmake
index 8e5546a..fed7819 100644
--- a/cmake/EigenDetermineVSServicePack.cmake
+++ b/cmake/EigenDetermineVSServicePack.cmake
@@ -4,7 +4,6 @@
 # _DetermineVSServicePack_FastCheckVersionWithCompiler which lead to errors on some systems.
 function(EigenDetermineVSServicePack _pack)
     if(NOT DETERMINED_VS_SERVICE_PACK OR NOT ${_pack})
-
         if(NOT DETERMINED_VS_SERVICE_PACK)
             _DetermineVSServicePack_CheckVersionWithTryCompile(DETERMINED_VS_SERVICE_PACK _cl_version)
             if(NOT DETERMINED_VS_SERVICE_PACK)
@@ -13,10 +12,25 @@
         endif()
 
         if(DETERMINED_VS_SERVICE_PACK)
-
             if(_cl_version)
                 # Call helper function to determine VS version
                 _DetermineVSServicePackFromCompiler(_sp "${_cl_version}")
+              
+                # temporary fix, until CMake catches up
+                if (NOT _sp)
+                    if(${_cl_version} VERSION_EQUAL "17.00.50727.1")
+                        set(_sp "vc110")
+                    elseif(${_cl_version} VERSION_EQUAL "17.00.51106.1")
+                        set(_sp "vc110sp1")
+                    elseif(${_cl_version} VERSION_EQUAL "17.00.60315.1")
+                        set(_sp "vc110sp2")
+                    elseif(${_cl_version} VERSION_EQUAL "17.00.60610.1")
+                        set(_sp "vc110sp3")
+                    else()
+                        set(_sp ${CMAKE_CXX_COMPILER_VERSION})
+                    endif()
+                endif()
+                
                 if(_sp)
                     set(${_pack} ${_sp} CACHE INTERNAL
                         "The Visual Studio Release with Service Pack")
diff --git a/cmake/EigenTesting.cmake b/cmake/EigenTesting.cmake
index f4796ca..a92a297 100644
--- a/cmake/EigenTesting.cmake
+++ b/cmake/EigenTesting.cmake
@@ -1,19 +1,48 @@
 
 macro(ei_add_property prop value)
-  get_property(previous GLOBAL PROPERTY ${prop})  
+  get_property(previous GLOBAL PROPERTY ${prop})
   if ((NOT previous) OR (previous STREQUAL ""))
     set_property(GLOBAL PROPERTY ${prop} "${value}")
   else()
     set_property(GLOBAL PROPERTY ${prop} "${previous} ${value}")
-  endif()  
+  endif()
 endmacro(ei_add_property)
 
 #internal. See documentation of ei_add_test for details.
 macro(ei_add_test_internal testname testname_with_suffix)
   set(targetname ${testname_with_suffix})
 
-  set(filename ${testname}.cpp)
-  add_executable(${targetname} ${filename})
+  if(EIGEN_ADD_TEST_FILENAME_EXTENSION)
+    set(filename ${testname}.${EIGEN_ADD_TEST_FILENAME_EXTENSION})
+  else()
+    set(filename ${testname}.cpp)
+  endif()
+
+  if(EIGEN_ADD_TEST_FILENAME_EXTENSION STREQUAL cu)
+    if(EIGEN_TEST_CUDA_CLANG)
+      set_source_files_properties(${filename} PROPERTIES LANGUAGE CXX)
+      if(CUDA_64_BIT_DEVICE_CODE)
+        link_directories("${CUDA_TOOLKIT_ROOT_DIR}/lib64")
+      else()
+        link_directories("${CUDA_TOOLKIT_ROOT_DIR}/lib")
+      endif()
+      if (${ARGC} GREATER 2)
+        add_executable(${targetname} ${filename})
+      else()
+        add_executable(${targetname} ${filename} OPTIONS ${ARGV2})
+      endif()
+      target_link_libraries(${targetname} "cudart_static" "cuda" "dl" "rt" "pthread")
+    else()
+      if (${ARGC} GREATER 2)
+        cuda_add_executable(${targetname} ${filename} OPTIONS ${ARGV2})
+      else()
+        cuda_add_executable(${targetname} ${filename})
+      endif()
+    endif()
+  else()
+    add_executable(${targetname} ${filename})
+  endif()
+
   if (targetname MATCHES "^eigen2_")
     add_dependencies(eigen2_buildtests ${targetname})
   else()
@@ -27,20 +56,20 @@
       ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_DEBUG_ASSERTS=1")
     endif(EIGEN_DEBUG_ASSERTS)
   endif(EIGEN_NO_ASSERTION_CHECKING)
-  
+
   ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_TEST_MAX_SIZE=${EIGEN_TEST_MAX_SIZE}")
 
   ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_TEST_FUNC=${testname}")
-  
-  if(MSVC AND NOT EIGEN_SPLIT_LARGE_TESTS)
+
+  if(MSVC)
     ei_add_target_property(${targetname} COMPILE_FLAGS "/bigobj")
-  endif()  
+  endif()
 
   # let the user pass flags.
   if(${ARGC} GREATER 2)
     ei_add_target_property(${targetname} COMPILE_FLAGS "${ARGV2}")
   endif(${ARGC} GREATER 2)
-  
+
   if(EIGEN_TEST_CUSTOM_CXX_FLAGS)
     ei_add_target_property(${targetname} COMPILE_FLAGS "${EIGEN_TEST_CUSTOM_CXX_FLAGS}")
   endif()
@@ -66,16 +95,12 @@
       # notice: no double quotes around ${libs_to_link} here. It may be a list.
       target_link_libraries(${targetname} ${libs_to_link})
     endif()
-  endif() 
-
-  if(EIGEN_BIN_BASH_EXISTS)
-    add_test(${testname_with_suffix} "${Eigen_SOURCE_DIR}/test/runtest.sh" "${testname_with_suffix}")
-  else()
-    add_test(${testname_with_suffix} "${targetname}")
   endif()
-  
+
+  add_test(${testname_with_suffix} "${targetname}")
+
   # Specify target and test labels accoirding to EIGEN_CURRENT_SUBPROJECT
-  get_property(current_subproject GLOBAL PROPERTY EIGEN_CURRENT_SUBPROJECT)  
+  get_property(current_subproject GLOBAL PROPERTY EIGEN_CURRENT_SUBPROJECT)
   if ((current_subproject) AND (NOT (current_subproject STREQUAL "")))
     set_property(TARGET ${targetname} PROPERTY LABELS "Build${current_subproject}")
     add_dependencies("Build${current_subproject}" ${targetname})
@@ -84,6 +109,103 @@
 
 endmacro(ei_add_test_internal)
 
+# SYCL
+macro(ei_add_test_internal_sycl testname testname_with_suffix)
+  include_directories( SYSTEM ${COMPUTECPP_PACKAGE_ROOT_DIR}/include)
+  set(targetname ${testname_with_suffix})
+
+  if(EIGEN_ADD_TEST_FILENAME_EXTENSION)
+    set(filename ${testname}.${EIGEN_ADD_TEST_FILENAME_EXTENSION})
+  else()
+    set(filename ${testname}.cpp)
+  endif()
+
+  set( include_file ${CMAKE_CURRENT_BINARY_DIR}/inc_${filename})
+  set( bc_file ${CMAKE_CURRENT_BINARY_DIR}/${filename})
+  set( host_file ${CMAKE_CURRENT_SOURCE_DIR}/${filename})
+
+  ADD_CUSTOM_COMMAND(
+    OUTPUT ${include_file}
+    COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\\"${host_file}\\\"" > ${include_file}
+    COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\\"${bc_file}.sycl\\\"" >> ${include_file}
+    DEPENDS ${filename} ${bc_file}.sycl
+    COMMENT "Building ComputeCpp integration header file ${include_file}"
+  )
+  # Add a custom target for the generated integration header
+  add_custom_target(${testname}_integration_header_sycl DEPENDS ${include_file})
+
+  add_executable(${targetname} ${include_file})
+  add_dependencies(${targetname} ${testname}_integration_header_sycl)
+  add_sycl_to_target(${targetname} ${filename} ${CMAKE_CURRENT_BINARY_DIR})
+
+  if (targetname MATCHES "^eigen2_")
+    add_dependencies(eigen2_buildtests ${targetname})
+  else()
+    add_dependencies(buildtests ${targetname})
+  endif()
+
+  if(EIGEN_NO_ASSERTION_CHECKING)
+    ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_NO_ASSERTION_CHECKING=1")
+  else(EIGEN_NO_ASSERTION_CHECKING)
+    if(EIGEN_DEBUG_ASSERTS)
+      ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_DEBUG_ASSERTS=1")
+    endif(EIGEN_DEBUG_ASSERTS)
+  endif(EIGEN_NO_ASSERTION_CHECKING)
+
+  ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_TEST_MAX_SIZE=${EIGEN_TEST_MAX_SIZE}")
+
+  ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_TEST_FUNC=${testname}")
+
+  if(MSVC AND NOT EIGEN_SPLIT_LARGE_TESTS)
+    ei_add_target_property(${targetname} COMPILE_FLAGS "/bigobj")
+  endif()
+
+  # let the user pass flags.
+  if(${ARGC} GREATER 2)
+    ei_add_target_property(${targetname} COMPILE_FLAGS "${ARGV2}")
+  endif(${ARGC} GREATER 2)
+
+  if(EIGEN_TEST_CUSTOM_CXX_FLAGS)
+    ei_add_target_property(${targetname} COMPILE_FLAGS "${EIGEN_TEST_CUSTOM_CXX_FLAGS}")
+  endif()
+
+  if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
+    target_link_libraries(${targetname} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO})
+  endif()
+  if(EXTERNAL_LIBS)
+    target_link_libraries(${targetname} ${EXTERNAL_LIBS})
+  endif()
+  if(EIGEN_TEST_CUSTOM_LINKER_FLAGS)
+    target_link_libraries(${targetname} ${EIGEN_TEST_CUSTOM_LINKER_FLAGS})
+  endif()
+
+  if(${ARGC} GREATER 3)
+    set(libs_to_link ${ARGV3})
+    # it could be that some cmake module provides a bad library string " "  (just spaces),
+    # and that severely breaks target_link_libraries ("can't link to -l-lstdc++" errors).
+    # so we check for strings containing only spaces.
+    string(STRIP "${libs_to_link}" libs_to_link_stripped)
+    string(LENGTH "${libs_to_link_stripped}" libs_to_link_stripped_length)
+    if(${libs_to_link_stripped_length} GREATER 0)
+      # notice: no double quotes around ${libs_to_link} here. It may be a list.
+      target_link_libraries(${targetname} ${libs_to_link})
+    endif()
+  endif()
+
+  add_test(${testname_with_suffix} "${targetname}")
+
+  # Specify target and test labels according to EIGEN_CURRENT_SUBPROJECT
+  get_property(current_subproject GLOBAL PROPERTY EIGEN_CURRENT_SUBPROJECT)
+  if ((current_subproject) AND (NOT (current_subproject STREQUAL "")))
+    set_property(TARGET ${targetname} PROPERTY LABELS "Build${current_subproject}")
+    add_dependencies("Build${current_subproject}" ${targetname})
+    set_property(TEST ${testname_with_suffix} PROPERTY LABELS "${current_subproject}")
+  endif()
+
+
+endmacro(ei_add_test_internal_sycl)
+
+
 # Macro to add a test
 #
 # the unique mandatory parameter testname must correspond to a file
@@ -131,7 +253,13 @@
   set(EIGEN_TESTS_LIST "${EIGEN_TESTS_LIST}${testname}\n")
   set_property(GLOBAL PROPERTY EIGEN_TESTS_LIST "${EIGEN_TESTS_LIST}")
 
-  file(READ "${testname}.cpp" test_source)
+  if(EIGEN_ADD_TEST_FILENAME_EXTENSION)
+    set(filename ${testname}.${EIGEN_ADD_TEST_FILENAME_EXTENSION})
+  else()
+    set(filename ${testname}.cpp)
+  endif()
+
+  file(READ "${filename}" test_source)
   set(parts 0)
   string(REGEX MATCHALL "CALL_SUBTEST_[0-9]+|EIGEN_TEST_PART_[0-9]+|EIGEN_SUFFIXES(;[0-9]+)+"
          occurences "${test_source}")
@@ -154,6 +282,39 @@
   endif(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
 endmacro(ei_add_test)
 
+macro(ei_add_test_sycl testname)
+  get_property(EIGEN_TESTS_LIST GLOBAL PROPERTY EIGEN_TESTS_LIST)
+  set(EIGEN_TESTS_LIST "${EIGEN_TESTS_LIST}${testname}\n")
+  set_property(GLOBAL PROPERTY EIGEN_TESTS_LIST "${EIGEN_TESTS_LIST}")
+
+  if(EIGEN_ADD_TEST_FILENAME_EXTENSION)
+    set(filename ${testname}.${EIGEN_ADD_TEST_FILENAME_EXTENSION})
+  else()
+    set(filename ${testname}.cpp)
+  endif()
+
+  file(READ "${filename}" test_source)
+  set(parts 0)
+  string(REGEX MATCHALL "CALL_SUBTEST_[0-9]+|EIGEN_TEST_PART_[0-9]+|EIGEN_SUFFIXES(;[0-9]+)+"
+         occurences "${test_source}")
+  string(REGEX REPLACE "CALL_SUBTEST_|EIGEN_TEST_PART_|EIGEN_SUFFIXES" "" suffixes "${occurences}")
+  list(REMOVE_DUPLICATES suffixes)
+  if(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
+    add_custom_target(${testname})
+    foreach(suffix ${suffixes})
+      ei_add_test_internal_sycl(${testname} ${testname}_${suffix}
+        "${ARGV1} -DEIGEN_TEST_PART_${suffix}=1" "${ARGV2}")
+      add_dependencies(${testname} ${testname}_${suffix})
+    endforeach(suffix)
+  else(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
+    set(symbols_to_enable_all_parts "")
+    foreach(suffix ${suffixes})
+      set(symbols_to_enable_all_parts
+        "${symbols_to_enable_all_parts} -DEIGEN_TEST_PART_${suffix}=1")
+    endforeach(suffix)
+    ei_add_test_internal_sycl(${testname} ${testname} "${ARGV1} ${symbols_to_enable_all_parts}" "${ARGV2}")
+  endif(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
+endmacro(ei_add_test_sycl)
 
 # adds a failtest, i.e. a test that succeed if the program fails to compile
 # note that the test runner for these is CMake itself, when passed -DEIGEN_FAILTEST=ON
@@ -218,7 +379,7 @@
   elseif(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
     message(STATUS "Explicit vectorization disabled (alignment kept enabled)")
   else()
-  
+
   message(STATUS "Maximal matrix/vector size: ${EIGEN_TEST_MAX_SIZE}")
 
     if(EIGEN_TEST_SSE2)
@@ -251,18 +412,75 @@
       message(STATUS "SSE4.2:            Using architecture defaults")
     endif()
 
+    if(EIGEN_TEST_AVX)
+      message(STATUS "AVX:               ON")
+    else()
+      message(STATUS "AVX:               Using architecture defaults")
+    endif()
+
+    if(EIGEN_TEST_FMA)
+      message(STATUS "FMA:               ON")
+    else()
+      message(STATUS "FMA:               Using architecture defaults")
+    endif()
+
+    if(EIGEN_TEST_AVX512)
+      message(STATUS "AVX512:            ON")
+    else()
+      message(STATUS "AVX512:            Using architecture defaults")
+    endif()
+
     if(EIGEN_TEST_ALTIVEC)
       message(STATUS "Altivec:           ON")
     else()
       message(STATUS "Altivec:           Using architecture defaults")
     endif()
 
+    if(EIGEN_TEST_VSX)
+      message(STATUS "VSX:               ON")
+    else()
+      message(STATUS "VSX:               Using architecture defaults")
+    endif()
+
     if(EIGEN_TEST_NEON)
       message(STATUS "ARM NEON:          ON")
     else()
       message(STATUS "ARM NEON:          Using architecture defaults")
     endif()
 
+    if(EIGEN_TEST_NEON64)
+      message(STATUS "ARMv8 NEON:        ON")
+    else()
+      message(STATUS "ARMv8 NEON:        Using architecture defaults")
+    endif()
+
+    if(EIGEN_TEST_ZVECTOR)
+      message(STATUS "S390X ZVECTOR:     ON")
+    else()
+      message(STATUS "S390X ZVECTOR:     Using architecture defaults")
+    endif()
+
+    if(EIGEN_TEST_CXX11)
+      message(STATUS "C++11:             ON")
+    else()
+      message(STATUS "C++11:             OFF")
+    endif()
+
+    if(EIGEN_TEST_SYCL)
+      message(STATUS "SYCL:              ON")
+    else()
+      message(STATUS "SYCL:              OFF")
+    endif()
+    if(EIGEN_TEST_CUDA)
+      if(EIGEN_TEST_CUDA_CLANG)
+        message(STATUS "CUDA:              ON (using clang)")
+      else()
+        message(STATUS "CUDA:              ON (using nvcc)")
+      endif()
+    else()
+      message(STATUS "CUDA:              OFF")
+    endif()
+
   endif() # vectorization / alignment options
 
   message(STATUS "\n${EIGEN_TESTING_SUMMARY}")
@@ -287,7 +505,7 @@
 
   set_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT "0")
   set_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT "0")
-  
+
   # uncomment anytime you change the ei_get_compilerver_from_cxx_version_string macro
   # ei_test_get_compilerver_from_cxx_version_string()
 endmacro(ei_init_testing)
@@ -296,55 +514,47 @@
   # if the sitename is not yet set, try to set it
   if(NOT ${SITE} OR ${SITE} STREQUAL "")
     set(eigen_computername $ENV{COMPUTERNAME})
-	set(eigen_hostname $ENV{HOSTNAME})
+    set(eigen_hostname $ENV{HOSTNAME})
     if(eigen_hostname)
       set(SITE ${eigen_hostname})
-	elseif(eigen_computername)
-	  set(SITE ${eigen_computername})
+    elseif(eigen_computername)
+      set(SITE ${eigen_computername})
     endif()
   endif()
   # in case it is already set, enforce lower case
   if(SITE)
     string(TOLOWER ${SITE} SITE)
-  endif()  
+  endif()
 endmacro(ei_set_sitename)
 
 macro(ei_get_compilerver VAR)
-  if(MSVC)
-    # on windows system, we use a modified CMake script  
-    include(EigenDetermineVSServicePack)
-    EigenDetermineVSServicePack( my_service_pack )
+    if(MSVC)
+      # on windows system, we use a modified CMake script
+      include(EigenDetermineVSServicePack)
+      EigenDetermineVSServicePack( my_service_pack )
 
-    if( my_service_pack )
-      set(${VAR} ${my_service_pack})
+      if( my_service_pack )
+        set(${VAR} ${my_service_pack})
+      else()
+        set(${VAR} "na")
+      endif()
     else()
-      set(${VAR} "na")
-    endif()
-  else()
     # on all other system we rely on ${CMAKE_CXX_COMPILER}
     # supporting a "--version" or "/version" flag
-    
-    if(WIN32 AND NOT CYGWIN)
+
+    if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} EQUAL "Intel")
       set(EIGEN_CXX_FLAG_VERSION "/version")
     else()
       set(EIGEN_CXX_FLAG_VERSION "--version")
     endif()
-    
-    # check whether the head command exists
-    find_program(HEAD_EXE head NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_PATH NO_CMAKE_SYSTEM_PATH)
-    if(HEAD_EXE)
-      execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${EIGEN_CXX_FLAG_VERSION}
-                      COMMAND head -n 1
-                      OUTPUT_VARIABLE eigen_cxx_compiler_version_string OUTPUT_STRIP_TRAILING_WHITESPACE)
-    else()
-      execute_process(COMMAND ${CMAKE_CXX_COMPILER}  ${EIGEN_CXX_FLAG_VERSION}
-                      OUTPUT_VARIABLE eigen_cxx_compiler_version_string OUTPUT_STRIP_TRAILING_WHITESPACE)
-      string(REGEX REPLACE "[\n\r].*"  ""  eigen_cxx_compiler_version_string  ${eigen_cxx_compiler_version_string})
-    endif()
-    
+
+    execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${EIGEN_CXX_FLAG_VERSION}
+                    OUTPUT_VARIABLE eigen_cxx_compiler_version_string OUTPUT_STRIP_TRAILING_WHITESPACE)
+    string(REGEX REPLACE "[\n\r].*"  ""  eigen_cxx_compiler_version_string  ${eigen_cxx_compiler_version_string})
+
     ei_get_compilerver_from_cxx_version_string("${eigen_cxx_compiler_version_string}" CNAME CVER)
     set(${VAR} "${CNAME}-${CVER}")
-    
+
   endif()
 endmacro(ei_get_compilerver)
 
@@ -353,18 +563,20 @@
 # the testing macro call in ei_init_testing() of the EigenTesting.cmake file.
 # See also the ei_test_get_compilerver_from_cxx_version_string macro at the end of the file
 macro(ei_get_compilerver_from_cxx_version_string VERSTRING CNAME CVER)
-  # extract possible compiler names  
+  # extract possible compiler names
   string(REGEX MATCH "g\\+\\+"      ei_has_gpp    ${VERSTRING})
   string(REGEX MATCH "llvm|LLVM"    ei_has_llvm   ${VERSTRING})
   string(REGEX MATCH "gcc|GCC"      ei_has_gcc    ${VERSTRING})
   string(REGEX MATCH "icpc|ICC"     ei_has_icpc   ${VERSTRING})
   string(REGEX MATCH "clang|CLANG"  ei_has_clang  ${VERSTRING})
-  
+
   # combine them
   if((ei_has_llvm) AND (ei_has_gpp OR ei_has_gcc))
     set(${CNAME} "llvm-g++")
   elseif((ei_has_llvm) AND (ei_has_clang))
     set(${CNAME} "llvm-clang++")
+  elseif(ei_has_clang)
+    set(${CNAME} "clang++")
   elseif(ei_has_icpc)
     set(${CNAME} "icpc")
   elseif(ei_has_gpp OR ei_has_gcc)
@@ -372,7 +584,7 @@
   else()
     set(${CNAME} "_")
   endif()
-  
+
   # extract possible version numbers
   # first try to extract 3 isolated numbers:
   string(REGEX MATCH " [0-9]+\\.[0-9]+\\.[0-9]+" eicver ${VERSTRING})
@@ -390,9 +602,9 @@
       endif()
     endif()
   endif()
-  
+
   string(REGEX REPLACE ".(.*)" "\\1" ${CVER} ${eicver})
-  
+
 endmacro(ei_get_compilerver_from_cxx_version_string)
 
 macro(ei_get_cxxflags VAR)
@@ -400,8 +612,18 @@
   ei_is_64bit_env(IS_64BIT_ENV)
   if(EIGEN_TEST_NEON)
     set(${VAR} NEON)
+  elseif(EIGEN_TEST_NEON64)
+    set(${VAR} NEON)
+  elseif(EIGEN_TEST_ZVECTOR)
+    set(${VAR} ZVECTOR)
+  elseif(EIGEN_TEST_VSX)
+    set(${VAR} VSX)
   elseif(EIGEN_TEST_ALTIVEC)
     set(${VAR} ALVEC)
+  elseif(EIGEN_TEST_FMA)
+    set(${VAR} FMA)
+  elseif(EIGEN_TEST_AVX)
+    set(${VAR} AVX)
   elseif(EIGEN_TEST_SSE4_2)
     set(${VAR} SSE42)
   elseif(EIGEN_TEST_SSE4_1)
@@ -411,30 +633,30 @@
   elseif(EIGEN_TEST_SSE3)
     set(${VAR} SSE3)
   elseif(EIGEN_TEST_SSE2 OR IS_64BIT_ENV)
-    set(${VAR} SSE2)  
+    set(${VAR} SSE2)
   endif()
 
   if(EIGEN_TEST_OPENMP)
     if (${VAR} STREQUAL "")
-	  set(${VAR} OMP)
-	else()
-	  set(${VAR} ${${VAR}}-OMP)
-	endif()
+      set(${VAR} OMP)
+    else()
+      set(${VAR} ${${VAR}}-OMP)
+    endif()
   endif()
-  
+
   if(EIGEN_DEFAULT_TO_ROW_MAJOR)
     if (${VAR} STREQUAL "")
-	  set(${VAR} ROW)
-	else()
-	  set(${VAR} ${${VAR}}-ROWMAJ)
-	endif()  
+      set(${VAR} ROW)
+    else()
+      set(${VAR} ${${VAR}}-ROWMAJ)
+    endif()
   endif()
 endmacro(ei_get_cxxflags)
 
 macro(ei_set_build_string)
   ei_get_compilerver(LOCAL_COMPILER_VERSION)
   ei_get_cxxflags(LOCAL_COMPILER_FLAGS)
-  
+
   include(EigenDetermineOSVersion)
   DetermineOSVersion(OS_VERSION)
 
@@ -450,7 +672,11 @@
   else()
     set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-64bit)
   endif()
-  
+
+  if(EIGEN_TEST_CXX11)
+    set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-cxx11)
+  endif()
+
   if(EIGEN_BUILD_STRING_SUFFIX)
     set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-${EIGEN_BUILD_STRING_SUFFIX})
   endif()
diff --git a/cmake/EigenUninstall.cmake b/cmake/EigenUninstall.cmake
new file mode 100644
index 0000000..4dae8c8
--- /dev/null
+++ b/cmake/EigenUninstall.cmake
@@ -0,0 +1,40 @@
+################ CMake Uninstall Template #######################
+# CMake Template file for uninstallation of files
+# mentioned in 'install_manifest.txt'
+#
+# Used by uinstall target
+#################################################################
+
+set(MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt")
+
+if(EXISTS ${MANIFEST})
+  message(STATUS "============== Uninstalling Eigen  ===================")
+
+  file(STRINGS ${MANIFEST} files)
+  foreach(file ${files})
+    if(EXISTS ${file})
+      message(STATUS "Removing file: '${file}'")
+
+      execute_process(
+        COMMAND ${CMAKE_COMMAND} -E remove ${file}
+        OUTPUT_VARIABLE rm_out
+        RESULT_VARIABLE rm_retval
+        )
+
+      if(NOT "${rm_retval}" STREQUAL 0)
+        message(FATAL_ERROR "Failed to remove file: '${file}'.")
+      endif()
+    else()
+      message(STATUS "File '${file}' does not exist.")
+    endif()
+  endforeach(file)
+
+  message(STATUS "========== Finished Uninstalling Eigen  ==============")
+else()
+  message(STATUS "Cannot find install manifest: '${MANIFEST}'")
+  message(STATUS "Probably make install has not been performed")
+  message(STATUS "   or install_manifest.txt has been deleted.")
+endif()
+
+
+
diff --git a/cmake/FindAdolc.cmake b/cmake/FindAdolc.cmake
index 1a7ff36..937e549 100644
--- a/cmake/FindAdolc.cmake
+++ b/cmake/FindAdolc.cmake
@@ -5,7 +5,7 @@
 
 find_path(ADOLC_INCLUDES
   NAMES
-  adolc/adouble.h
+  adolc/adtl.h
   PATHS
   $ENV{ADOLCDIR}
   ${INCLUDE_INSTALL_DIR}
diff --git a/cmake/FindBLAS.cmake b/cmake/FindBLAS.cmake
index 68c4e07..e3395bc 100644
--- a/cmake/FindBLAS.cmake
+++ b/cmake/FindBLAS.cmake
@@ -1,385 +1,1363 @@
-# Find BLAS library
+###
 #
-# This module finds an installed library that implements the BLAS
+# @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-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
+#
+###
+#
+# - Find BLAS library
+# This module finds an installed fortran library that implements the BLAS
 # linear-algebra interface (see http://www.netlib.org/blas/).
-# The list of libraries searched for is mainly taken
+# The list of libraries searched for is taken
 # from the autoconf macro file, acx_blas.m4 (distributed at
 # http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
 #
 # This module sets the following variables:
 #  BLAS_FOUND - set to true if a library implementing the BLAS interface
 #    is found
-#  BLAS_INCLUDE_DIR - Directories containing the BLAS header files
-#  BLAS_DEFINITIONS - Compilation options to use BLAS
-#  BLAS_LINKER_FLAGS - Linker flags to use BLAS (excluding -l
+#  BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l
 #    and -L).
-#  BLAS_LIBRARIES_DIR - Directories containing the BLAS libraries.
-#     May be null if BLAS_LIBRARIES contains libraries name using full path.
-#  BLAS_LIBRARIES - List of libraries to link against BLAS interface.
-#     May be null if the compiler supports auto-link (e.g. VC++).
-#  BLAS_USE_FILE - The name of the cmake module to include to compile
-#     applications or libraries using BLAS.
+#  BLAS_COMPILER_FLAGS - uncached list of required compiler flags (including -I for mkl headers).
+#  BLAS_LIBRARIES - uncached list of libraries (using full path name) to
+#    link against to use BLAS
+#  BLAS95_LIBRARIES - uncached list of libraries (using full path name)
+#    to link against to use BLAS95 interface
+#  BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface
+#    is found
+#  BLA_STATIC  if set on this determines what kind of linkage we do (static)
+#  BLA_VENDOR  if set checks only the specified vendor, if not set checks
+#     all the possibilities
+#  BLAS_VENDOR_FOUND stores the BLAS vendor found 
+#  BLA_F95     if set on tries to find the f95 interfaces for BLAS/LAPACK
+# The user can give specific paths where to find the libraries adding cmake
+# options at configure (ex: cmake path/to/project -DBLAS_DIR=path/to/blas):
+#  BLAS_DIR            - Where to find the base directory of blas
+#  BLAS_INCDIR         - Where to find the header files
+#  BLAS_LIBDIR         - Where to find the library files
+# The module can also look for the following environment variables if paths
+# are not given as cmake variable: BLAS_DIR, BLAS_INCDIR, BLAS_LIBDIR
+# For MKL case and if no paths are given as hints, we will try to use the MKLROOT
+# environment variable
+#  BLAS_VERBOSE Print some additional information during BLAS libraries detection
+##########
+### List of vendors (BLA_VENDOR) valid in this module
+########## List of vendors (BLA_VENDOR) valid in this module
+##  Open (for OpenBlas), Eigen (for EigenBlas), Goto, ATLAS PhiPACK,
+##  CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, IBMESSLMT
+##  Intel10_32 (intel mkl v10 32 bit), Intel10_64lp (intel mkl v10 64 bit,lp thread model, lp64 model),
+##  Intel10_64lp_seq (intel mkl v10 64 bit,sequential code, lp64 model),
+##  Intel( older versions of mkl 32 and 64 bit),
+##  ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic
+# C/CXX should be enabled to use Intel mkl
+###
+# We handle different modes to find the dependency
 #
-# This module was modified by CGAL team:
-# - find libraries for a C++ compiler, instead of Fortran
-# - added BLAS_INCLUDE_DIR, BLAS_DEFINITIONS and BLAS_LIBRARIES_DIR
-# - removed BLAS95_LIBRARIES
+# - Detection if already installed on the system
+#   - BLAS libraries can be detected from different ways
+#     Here is the order of precedence:
+#     1) we look in cmake variable BLAS_LIBDIR or BLAS_DIR (we guess the libdirs) if defined
+#     2) we look in environment variable BLAS_LIBDIR or BLAS_DIR (we guess the libdirs) if defined
+#     3) we look in common environnment variables depending on the system (INCLUDE, C_INCLUDE_PATH, CPATH - LIB, DYLD_LIBRARY_PATH, LD_LIBRARY_PATH)
+#     4) we look in common system paths depending on the system, see for example paths contained in the following cmake variables:
+#       - CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES, CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
+#       - CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES, CMAKE_C_IMPLICIT_LINK_DIRECTORIES
+#
+
+#=============================================================================
+# Copyright 2007-2009 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+## Some macros to print status when search for headers and libs
+# This macro informs why the _lib_to_find file has not been found
+macro(Print_Find_Library_Blas_Status _libname _lib_to_find)
+
+  # save _libname upper/lower case
+  string(TOUPPER ${_libname} LIBNAME)
+  string(TOLOWER ${_libname} libname)
+
+  # print status
+  #message(" ")
+  if(${LIBNAME}_LIBDIR)
+    message("${Yellow}${LIBNAME}_LIBDIR is defined but ${_lib_to_find}"
+      "has not been found in ${ARGN}${ColourReset}")
+  else()
+    if(${LIBNAME}_DIR)
+      message("${Yellow}${LIBNAME}_DIR is defined but ${_lib_to_find}"
+	"has not been found in ${ARGN}${ColourReset}")
+    else()
+      message("${Yellow}${_lib_to_find} not found."
+	"Nor ${LIBNAME}_DIR neither ${LIBNAME}_LIBDIR"
+	"are defined so that we look for ${_lib_to_find} in"
+	"system paths (Linux: LD_LIBRARY_PATH, Windows: LIB,"
+	"Mac: DYLD_LIBRARY_PATH,"
+	"CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES,"
+	"CMAKE_C_IMPLICIT_LINK_DIRECTORIES)${ColourReset}")
+      if(_lib_env)
+	message("${Yellow}${_lib_to_find} has not been found in"
+	  "${_lib_env}${ColourReset}")
+      endif()
+    endif()
+  endif()
+  message("${BoldYellow}Please indicate where to find ${_lib_to_find}. You have three options:\n"
+    "- Option 1: Provide the Installation directory of BLAS library with cmake option: -D${LIBNAME}_DIR=your/path/to/${libname}/\n"
+    "- Option 2: Provide the directory where to find the library with cmake option: -D${LIBNAME}_LIBDIR=your/path/to/${libname}/lib/\n"
+    "- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
+    "- Option 4: If your library provides a PkgConfig file, make sure pkg-config finds your library${ColourReset}")
+
+endmacro()
+
+# This macro informs why the _lib_to_find file has not been found
+macro(Print_Find_Library_Blas_CheckFunc_Status _name)
+
+  # save _libname upper/lower case
+  string(TOUPPER ${_name} FUNCNAME)
+  string(TOLOWER ${_name} funcname)
+
+  # print status
+  #message(" ")
+  message("${Red}Libs have been found but check of symbol ${_name} failed "
+    "with following libraries ${ARGN}${ColourReset}")
+  message("${BoldRed}Please open your error file CMakeFiles/CMakeError.log"
+    "to figure out why it fails${ColourReset}")
+  #message(" ")
+
+endmacro()
+
+if (NOT BLAS_FOUND)
+  set(BLAS_DIR "" CACHE PATH "Installation directory of BLAS library")
+  if (NOT BLAS_FIND_QUIETLY)
+    message(STATUS "A cache variable, namely BLAS_DIR, has been set to specify the install directory of BLAS")
+  endif()
+endif()
+
+option(BLAS_VERBOSE "Print some additional information during BLAS libraries detection" OFF)
+mark_as_advanced(BLAS_VERBOSE)
 
 include(CheckFunctionExists)
+include(CheckFortranFunctionExists)
 
+set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
 
-# This macro checks for the existence of the combination of fortran libraries
-# given by _list.  If the combination is found, this macro checks (using the
-# check_function_exists macro) whether can link against that library
-# combination using the name of a routine given by _name using the linker
-# flags given by _flags.  If the combination of libraries is found and passes
-# the link test, LIBRARIES is set to the list of complete library paths that
-# have been found and DEFINITIONS to the required definitions.
-# Otherwise, LIBRARIES is set to FALSE.
-# N.B. _prefix is the prefix applied to the names of all cached variables that
-# are generated internally and marked advanced by this macro.
-macro(check_fortran_libraries DEFINITIONS LIBRARIES _prefix _name _flags _list _path)
-  #message("DEBUG: check_fortran_libraries(${_list} in ${_path})")
+# Check the language being used
+get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES )
+if( _LANGUAGES_ MATCHES Fortran AND CMAKE_Fortran_COMPILER)
+  set( _CHECK_FORTRAN TRUE )
+elseif( (_LANGUAGES_ MATCHES C) OR (_LANGUAGES_ MATCHES CXX) )
+  set( _CHECK_FORTRAN FALSE )
+else()
+  if(BLAS_FIND_REQUIRED)
+    message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
+  else()
+    message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
+    return()
+  endif()
+endif()
 
-  # Check for the existence of the libraries given by _list
-  set(_libraries_found TRUE)
-  set(_libraries_work FALSE)
-  set(${DEFINITIONS} "")
-  set(${LIBRARIES} "")
+macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread)
+  # This macro checks for the existence of the combination of fortran libraries
+  # given by _list.  If the combination is found, this macro checks (using the
+  # Check_Fortran_Function_Exists macro) whether can link against that library
+  # combination using the name of a routine given by _name using the linker
+  # flags given by _flags.  If the combination of libraries is found and passes
+  # the link test, LIBRARIES is set to the list of complete library paths that
+  # have been found.  Otherwise, LIBRARIES is set to FALSE.
+
+  # N.B. _prefix is the prefix applied to the names of all cached variables that
+  # are generated internally and marked advanced by this macro.
+
+  set(_libdir ${ARGN})
+
+  set(_libraries_work TRUE)
+  set(${LIBRARIES})
   set(_combined_name)
+  set(ENV_MKLROOT "$ENV{MKLROOT}")
+  set(ENV_BLAS_DIR "$ENV{BLAS_DIR}")
+  set(ENV_BLAS_LIBDIR "$ENV{BLAS_LIBDIR}")
+  if (NOT _libdir)
+    if (BLAS_LIBDIR)
+      list(APPEND _libdir "${BLAS_LIBDIR}")
+    elseif (BLAS_DIR)
+      list(APPEND _libdir "${BLAS_DIR}")
+      list(APPEND _libdir "${BLAS_DIR}/lib")
+      if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
+	list(APPEND _libdir "${BLAS_DIR}/lib64")
+	list(APPEND _libdir "${BLAS_DIR}/lib/intel64")
+      else()
+	list(APPEND _libdir "${BLAS_DIR}/lib32")
+	list(APPEND _libdir "${BLAS_DIR}/lib/ia32")
+      endif()
+    elseif(ENV_BLAS_LIBDIR)
+      list(APPEND _libdir "${ENV_BLAS_LIBDIR}")
+    elseif(ENV_BLAS_DIR)
+      list(APPEND _libdir "${ENV_BLAS_DIR}")
+      list(APPEND _libdir "${ENV_BLAS_DIR}/lib")
+      if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
+	list(APPEND _libdir "${ENV_BLAS_DIR}/lib64")
+	list(APPEND _libdir "${ENV_BLAS_DIR}/lib/intel64")
+      else()
+	list(APPEND _libdir "${ENV_BLAS_DIR}/lib32")
+	list(APPEND _libdir "${ENV_BLAS_DIR}/lib/ia32")
+      endif()
+    else()
+      if (ENV_MKLROOT)
+	list(APPEND _libdir "${ENV_MKLROOT}/lib")
+	if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
+	  list(APPEND _libdir "${ENV_MKLROOT}/lib64")
+	  list(APPEND _libdir "${ENV_MKLROOT}/lib/intel64")
+	else()
+	  list(APPEND _libdir "${ENV_MKLROOT}/lib32")
+	  list(APPEND _libdir "${ENV_MKLROOT}/lib/ia32")
+	endif()
+      endif()
+      if (WIN32)
+	string(REPLACE ":" ";" _libdir2 "$ENV{LIB}")
+      elseif (APPLE)
+	string(REPLACE ":" ";" _libdir2 "$ENV{DYLD_LIBRARY_PATH}")
+      else ()
+	string(REPLACE ":" ";" _libdir2 "$ENV{LD_LIBRARY_PATH}")
+      endif ()
+      list(APPEND _libdir "${_libdir2}")
+      list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
+      list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
+    endif()
+  endif ()
+
+  if (BLAS_VERBOSE)
+    message("${Cyan}Try to find BLAS libraries: ${_list}")
+  endif ()
+
   foreach(_library ${_list})
     set(_combined_name ${_combined_name}_${_library})
 
-    if(_libraries_found)
-      # search first in ${_path}
-      find_library(${_prefix}_${_library}_LIBRARY
-                  NAMES ${_library}
-                  PATHS ${_path} NO_DEFAULT_PATH
-                  )
-      # if not found, search in environment variables and system
-      if ( WIN32 )
-        find_library(${_prefix}_${_library}_LIBRARY
-                    NAMES ${_library}
-                    PATHS ENV LIB
-                    )
-      elseif ( APPLE )
-        find_library(${_prefix}_${_library}_LIBRARY
-                    NAMES ${_library}
-                    PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
-                    )
+    if(_libraries_work)
+      if (BLA_STATIC)
+	if (WIN32)
+	  set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
+	endif ()
+	if (APPLE)
+	  set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
+	else ()
+	  set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+	endif ()
       else ()
-        find_library(${_prefix}_${_library}_LIBRARY
-                    NAMES ${_library}
-                    PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
-                    )
-      endif()
+	if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+	  # for ubuntu's libblas3gf and liblapack3gf packages
+	  set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
+	endif ()
+      endif ()
+      find_library(${_prefix}_${_library}_LIBRARY
+	NAMES ${_library}
+	HINTS ${_libdir}
+	NO_DEFAULT_PATH
+	)
       mark_as_advanced(${_prefix}_${_library}_LIBRARY)
+      # Print status if not found
+      # -------------------------
+      if (NOT ${_prefix}_${_library}_LIBRARY AND NOT BLAS_FIND_QUIETLY AND BLAS_VERBOSE)
+	Print_Find_Library_Blas_Status(blas ${_library} ${_libdir})
+      endif ()
       set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
-      set(_libraries_found ${${_prefix}_${_library}_LIBRARY})
-    endif(_libraries_found)
+      set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
+    endif(_libraries_work)
   endforeach(_library ${_list})
-  if(_libraries_found)
-    set(_libraries_found ${${LIBRARIES}})
-  endif()
 
-  # Test this combination of libraries with the Fortran/f2c interface.
-  # We test the Fortran interface first as it is well standardized.
-  if(_libraries_found AND NOT _libraries_work)
-    set(${DEFINITIONS}  "-D${_prefix}_USE_F2C")
-    set(${LIBRARIES}    ${_libraries_found})
-    # Some C++ linkers require the f2c library to link with Fortran libraries.
-    # I do not know which ones, thus I just add the f2c library if it is available.
-    find_package( F2C QUIET )
-    if ( F2C_FOUND )
-      set(${DEFINITIONS}  ${${DEFINITIONS}} ${F2C_DEFINITIONS})
-      set(${LIBRARIES}    ${${LIBRARIES}} ${F2C_LIBRARIES})
+  if(_libraries_work)
+    # Test this combination of libraries.
+    if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BLA_STATIC)
+      list(INSERT ${LIBRARIES} 0 "-Wl,--start-group")
+      list(APPEND ${LIBRARIES} "-Wl,--end-group")
     endif()
-    set(CMAKE_REQUIRED_DEFINITIONS  ${${DEFINITIONS}})
-    set(CMAKE_REQUIRED_LIBRARIES    ${_flags} ${${LIBRARIES}})
-    #message("DEBUG: CMAKE_REQUIRED_DEFINITIONS = ${CMAKE_REQUIRED_DEFINITIONS}")
-    #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
-    # Check if function exists with f2c calling convention (ie a trailing underscore)
-    check_function_exists(${_name}_ ${_prefix}_${_name}_${_combined_name}_f2c_WORKS)
-    set(CMAKE_REQUIRED_DEFINITIONS} "")
-    set(CMAKE_REQUIRED_LIBRARIES    "")
-    mark_as_advanced(${_prefix}_${_name}_${_combined_name}_f2c_WORKS)
-    set(_libraries_work ${${_prefix}_${_name}_${_combined_name}_f2c_WORKS})
-  endif(_libraries_found AND NOT _libraries_work)
-
-  # If not found, test this combination of libraries with a C interface.
-  # A few implementations (ie ACML) provide a C interface. Unfortunately, there is no standard.
-  if(_libraries_found AND NOT _libraries_work)
-    set(${DEFINITIONS} "")
-    set(${LIBRARIES}   ${_libraries_found})
-    set(CMAKE_REQUIRED_DEFINITIONS "")
-    set(CMAKE_REQUIRED_LIBRARIES   ${_flags} ${${LIBRARIES}})
-    #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
-    check_function_exists(${_name} ${_prefix}_${_name}${_combined_name}_WORKS)
-    set(CMAKE_REQUIRED_LIBRARIES "")
-    mark_as_advanced(${_prefix}_${_name}${_combined_name}_WORKS)
-    set(_libraries_work ${${_prefix}_${_name}${_combined_name}_WORKS})
-  endif(_libraries_found AND NOT _libraries_work)
-
-  # on failure
-  if(NOT _libraries_work)
-    set(${DEFINITIONS} "")
-    set(${LIBRARIES}   FALSE)
+    set(CMAKE_REQUIRED_LIBRARIES "${_flags};${${LIBRARIES}};${_thread}")
+    set(CMAKE_REQUIRED_FLAGS "${BLAS_COMPILER_FLAGS}")
+    if (BLAS_VERBOSE)
+      message("${Cyan}BLAS libs found for BLA_VENDOR ${BLA_VENDOR}."
+	"Try to compile symbol ${_name} with following libraries:"
+	"${CMAKE_REQUIRED_LIBRARIES}")
+    endif ()
+    if(NOT BLAS_FOUND)
+      unset(${_prefix}${_combined_name}_WORKS CACHE)
+    endif()
+    if (_CHECK_FORTRAN)
+      if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
+	string(REPLACE "mkl_intel_lp64" "mkl_gf_lp64" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
+	string(REPLACE "mkl_intel_ilp64" "mkl_gf_ilp64" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
+      endif()
+      check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
+    else()
+      check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
+    endif()
+    mark_as_advanced(${_prefix}${_combined_name}_WORKS)
+    set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
+    # Print status if not found
+    # -------------------------
+    if (NOT _libraries_work AND NOT BLAS_FIND_QUIETLY AND BLAS_VERBOSE)
+      Print_Find_Library_Blas_CheckFunc_Status(${_name} ${CMAKE_REQUIRED_LIBRARIES})
+    endif ()
+    set(CMAKE_REQUIRED_LIBRARIES)
   endif()
-  #message("DEBUG: ${DEFINITIONS} = ${${DEFINITIONS}}")
-  #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
-endmacro(check_fortran_libraries)
+
+  if(_libraries_work)
+    set(${LIBRARIES} ${${LIBRARIES}} ${_thread})
+  else(_libraries_work)
+    set(${LIBRARIES} FALSE)
+  endif(_libraries_work)
+
+endmacro(Check_Fortran_Libraries)
 
 
-#
-# main
-#
+set(BLAS_LINKER_FLAGS)
+set(BLAS_LIBRARIES)
+set(BLAS95_LIBRARIES)
+if ($ENV{BLA_VENDOR} MATCHES ".+")
+  set(BLA_VENDOR $ENV{BLA_VENDOR})
+else ()
+  if(NOT BLA_VENDOR)
+    set(BLA_VENDOR "All")
+  endif()
+endif ()
 
-# Is it already configured?
-if (BLAS_LIBRARIES_DIR OR BLAS_LIBRARIES)
+#BLAS in intel mkl 10 library? (em64t 64bit)
+if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
 
-  set(BLAS_FOUND TRUE)
+  if(NOT BLAS_LIBRARIES OR BLA_VENDOR MATCHES "Intel*")
+    # Looking for include
+    # -------------------
 
-else()
+    # Add system include paths to search include
+    # ------------------------------------------
+    unset(_inc_env)
+    set(ENV_MKLROOT "$ENV{MKLROOT}")
+    set(ENV_BLAS_DIR "$ENV{BLAS_DIR}")
+    set(ENV_BLAS_INCDIR "$ENV{BLAS_INCDIR}")
+    if(ENV_BLAS_INCDIR)
+      list(APPEND _inc_env "${ENV_BLAS_INCDIR}")
+    elseif(ENV_BLAS_DIR)
+      list(APPEND _inc_env "${ENV_BLAS_DIR}")
+      list(APPEND _inc_env "${ENV_BLAS_DIR}/include")
+    else()
+      if (ENV_MKLROOT)
+	list(APPEND _inc_env "${ENV_MKLROOT}/include")
+      endif()
+      # system variables
+      if(WIN32)
+	string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
+	list(APPEND _inc_env "${_path_env}")
+      else()
+	string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
+	list(APPEND _inc_env "${_path_env}")
+	string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
+	list(APPEND _inc_env "${_path_env}")
+	string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
+	list(APPEND _inc_env "${_path_env}")
+	string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
+	list(APPEND _inc_env "${_path_env}")
+      endif()
+    endif()
+    list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
+    list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
+    list(REMOVE_DUPLICATES _inc_env)
 
-  # reset variables
-  set( BLAS_INCLUDE_DIR "" )
-  set( BLAS_DEFINITIONS "" )
-  set( BLAS_LINKER_FLAGS "" )
-  set( BLAS_LIBRARIES "" )
-  set( BLAS_LIBRARIES_DIR "" )
+    # set paths where to look for
+    set(PATH_TO_LOOK_FOR "${_inc_env}")
 
-    #
-    # If Unix, search for BLAS function in possible libraries
-    #
+    # Try to find the fftw header in the given paths
+    # -------------------------------------------------
+    # call cmake macro to find the header path
+    if(BLAS_INCDIR)
+      set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
+      find_path(BLAS_mkl.h_DIRS
+	NAMES mkl.h
+	HINTS ${BLAS_INCDIR})
+    else()
+      if(BLAS_DIR)
+	set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
+	find_path(BLAS_mkl.h_DIRS
+	  NAMES mkl.h
+	  HINTS ${BLAS_DIR}
+	  PATH_SUFFIXES "include")
+      else()
+	set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
+	find_path(BLAS_mkl.h_DIRS
+	  NAMES mkl.h
+	  HINTS ${PATH_TO_LOOK_FOR})
+      endif()
+    endif()
+    mark_as_advanced(BLAS_mkl.h_DIRS)
 
-    # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+    # If found, add path to cmake variable
+    # ------------------------------------
+    if (BLAS_mkl.h_DIRS)
+      set(BLAS_INCLUDE_DIRS "${BLAS_mkl.h_DIRS}")
+    else ()
+      set(BLAS_INCLUDE_DIRS "BLAS_INCLUDE_DIRS-NOTFOUND")
+      if(NOT BLAS_FIND_QUIETLY)
+	message(STATUS "Looking for BLAS -- mkl.h not found")
+      endif()
+    endif()
+
+    if (WIN32)
+      string(REPLACE ":" ";" _libdir "$ENV{LIB}")
+    elseif (APPLE)
+      string(REPLACE ":" ";" _libdir "$ENV{DYLD_LIBRARY_PATH}")
+    else ()
+      string(REPLACE ":" ";" _libdir "$ENV{LD_LIBRARY_PATH}")
+    endif ()
+    list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
+    list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
+    # libiomp5
+    # --------
+    set(OMP_iomp5_LIBRARY "OMP_iomp5_LIBRARY-NOTFOUND")
+    find_library(OMP_iomp5_LIBRARY
+      NAMES iomp5
+      HINTS ${_libdir}
+      )
+    mark_as_advanced(OMP_iomp5_LIBRARY)
+    set(OMP_LIB "")
+    # libgomp
+    # -------
+    set(OMP_gomp_LIBRARY "OMP_gomp_LIBRARY-NOTFOUND")
+    find_library(OMP_gomp_LIBRARY
+      NAMES gomp
+      HINTS ${_libdir}
+      )
+    mark_as_advanced(OMP_gomp_LIBRARY)
+    # choose one or another depending on the compilo
+    if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+      if (OMP_gomp_LIBRARY)
+	set(OMP_LIB "${OMP_gomp_LIBRARY}")
+      endif()
+    else(CMAKE_C_COMPILER_ID STREQUAL "Intel")
+      if (OMP_iomp5_LIBRARY)
+	set(OMP_LIB "${OMP_iomp5_LIBRARY}")
+      endif()
+    endif()
+
+    if (UNIX AND NOT WIN32)
+      # m
+      find_library(M_LIBRARY
+	NAMES m
+	HINTS ${_libdir})
+      mark_as_advanced(M_LIBRARY)
+      if(M_LIBRARY)
+	set(LM "-lm")
+      else()
+	set(LM "")
+      endif()
+      # Fortran
+      set(LGFORTRAN "")
+      if (CMAKE_C_COMPILER_ID MATCHES "GNU")
+	find_library(
+	  FORTRAN_gfortran_LIBRARY
+	  NAMES gfortran
+	  HINTS ${_libdir}
+	  )
+	mark_as_advanced(FORTRAN_gfortran_LIBRARY)
+	if (FORTRAN_gfortran_LIBRARY)
+	  set(LGFORTRAN "${FORTRAN_gfortran_LIBRARY}")
+	endif()
+      elseif (CMAKE_C_COMPILER_ID MATCHES "Intel")
+	find_library(
+	  FORTRAN_ifcore_LIBRARY
+	  NAMES ifcore
+	  HINTS ${_libdir}
+	  )
+	mark_as_advanced(FORTRAN_ifcore_LIBRARY)
+	if (FORTRAN_ifcore_LIBRARY)
+	  set(LGFORTRAN "{FORTRAN_ifcore_LIBRARY}")
+	endif()
+      endif()
+      set(BLAS_COMPILER_FLAGS "")
+      if (NOT BLA_VENDOR STREQUAL "Intel10_64lp_seq")
+	if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
+	  list(APPEND BLAS_COMPILER_FLAGS "-openmp")
+	endif()
+	if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+	  list(APPEND BLAS_COMPILER_FLAGS "-fopenmp")
+	endif()
+      endif()
+      if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+	if (BLA_VENDOR STREQUAL "Intel10_32")
+	  list(APPEND BLAS_COMPILER_FLAGS "-m32")
+	else()
+	  list(APPEND BLAS_COMPILER_FLAGS "-m64")
+	endif()
+	if (NOT BLA_VENDOR STREQUAL "Intel10_64lp_seq")
+	  list(APPEND OMP_LIB "-ldl")
+	endif()
+	if (ENV_MKLROOT)
+	  list(APPEND BLAS_COMPILER_FLAGS "-I${ENV_MKLROOT}/include")
+	endif()
+      endif()
+
+      set(additional_flags "")
+      if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
+	set(additional_flags "-Wl,--no-as-needed")
+      endif()
+    endif ()
+
+    if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
+      if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
+	find_package(Threads)
+      else()
+	find_package(Threads REQUIRED)
+      endif()
+
+      set(BLAS_SEARCH_LIBS "")
+
+      if(BLA_F95)
+
+	set(BLAS_mkl_SEARCH_SYMBOL SGEMM)
+	set(_LIBRARIES BLAS95_LIBRARIES)
+	if (WIN32)
+	  if (BLA_STATIC)
+	    set(BLAS_mkl_DLL_SUFFIX "")
+	  else()
+	    set(BLAS_mkl_DLL_SUFFIX "_dll")
+	  endif()
+
+	  # Find the main file (32-bit or 64-bit)
+	  set(BLAS_SEARCH_LIBS_WIN_MAIN "")
+	  if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
+	    list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
+	      "mkl_blas95${BLAS_mkl_DLL_SUFFIX} mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
+	  endif()
+	  if (BLA_VENDOR STREQUAL "Intel10_64lp*" OR BLA_VENDOR STREQUAL "All")
+	    list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
+	      "mkl_blas95_lp64${BLAS_mkl_DLL_SUFFIX} mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
+	  endif ()
+
+	  # Add threading/sequential libs
+	  set(BLAS_SEARCH_LIBS_WIN_THREAD "")
+	  if (BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
+	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+	      "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
+	  endif()
+	  if (NOT BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
+	    # old version
+	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+	      "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
+	    # mkl >= 10.3
+	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+	      "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
+	  endif()
+
+	  # Cartesian product of the above
+	  foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
+	    foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
+	      list(APPEND BLAS_SEARCH_LIBS
+		"${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
+	    endforeach()
+	  endforeach()
+	else (WIN32)
+	  if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
+	    list(APPEND BLAS_SEARCH_LIBS
+	      "mkl_blas95 mkl_intel mkl_intel_thread mkl_core guide")
+	  endif ()
+	  if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
+	    # old version
+	    list(APPEND BLAS_SEARCH_LIBS
+	      "mkl_blas95 mkl_intel_lp64 mkl_intel_thread mkl_core guide")
+	    # mkl >= 10.3
+	    if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
+	      list(APPEND BLAS_SEARCH_LIBS
+		"mkl_blas95_lp64 mkl_intel_lp64 mkl_intel_thread mkl_core")
+	    endif()
+	    if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+	      list(APPEND BLAS_SEARCH_LIBS
+		"mkl_blas95_lp64 mkl_intel_lp64 mkl_gnu_thread mkl_core")
+	    endif()
+	  endif ()
+	  if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
+	    list(APPEND BLAS_SEARCH_LIBS
+	      "mkl_intel_lp64 mkl_sequential mkl_core")
+	    if (BLA_VENDOR STREQUAL "Intel10_64lp_seq")
+	      set(OMP_LIB "")
+	    endif()
+	  endif ()
+	endif (WIN32)
+
+      else (BLA_F95)
+
+	set(BLAS_mkl_SEARCH_SYMBOL sgemm)
+	set(_LIBRARIES BLAS_LIBRARIES)
+	if (WIN32)
+	  if (BLA_STATIC)
+	    set(BLAS_mkl_DLL_SUFFIX "")
+	  else()
+	    set(BLAS_mkl_DLL_SUFFIX "_dll")
+	  endif()
+
+	  # Find the main file (32-bit or 64-bit)
+	  set(BLAS_SEARCH_LIBS_WIN_MAIN "")
+	  if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
+	    list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
+	      "mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
+	  endif()
+	  if (BLA_VENDOR STREQUAL "Intel10_64lp*" OR BLA_VENDOR STREQUAL "All")
+	    list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
+	      "mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
+	  endif ()
+
+	  # Add threading/sequential libs
+	  set(BLAS_SEARCH_LIBS_WIN_THREAD "")
+	  if (NOT BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
+	    # old version
+	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+	      "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
+	    # mkl >= 10.3
+	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+	      "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
+	  endif()
+	  if (BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
+	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+	      "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
+	  endif()
+
+	  # Cartesian product of the above
+	  foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
+	    foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
+	      list(APPEND BLAS_SEARCH_LIBS
+		"${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
+	    endforeach()
+	  endforeach()
+	else (WIN32)
+	  if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
+	    list(APPEND BLAS_SEARCH_LIBS
+	      "mkl_intel mkl_intel_thread mkl_core guide")
+	  endif ()
+	  if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
+	    # old version
+	    list(APPEND BLAS_SEARCH_LIBS
+	      "mkl_intel_lp64 mkl_intel_thread mkl_core guide")
+	    # mkl >= 10.3
+	    if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
+	      list(APPEND BLAS_SEARCH_LIBS
+		"mkl_intel_lp64 mkl_intel_thread mkl_core")
+	    endif()
+	    if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+	      list(APPEND BLAS_SEARCH_LIBS
+		"mkl_intel_lp64 mkl_gnu_thread mkl_core")
+	    endif()
+	  endif ()
+	  if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
+	    list(APPEND BLAS_SEARCH_LIBS
+	      "mkl_intel_lp64 mkl_sequential mkl_core")
+	    if (BLA_VENDOR STREQUAL "Intel10_64lp_seq")
+	      set(OMP_LIB "")
+	    endif()
+	  endif ()
+	  #older vesions of intel mkl libs
+	  if (BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
+	    list(APPEND BLAS_SEARCH_LIBS
+	      "mkl")
+	    list(APPEND BLAS_SEARCH_LIBS
+	      "mkl_ia32")
+	    list(APPEND BLAS_SEARCH_LIBS
+	      "mkl_em64t")
+	  endif ()
+	endif (WIN32)
+
+      endif (BLA_F95)
+
+      foreach (IT ${BLAS_SEARCH_LIBS})
+	string(REPLACE " " ";" SEARCH_LIBS ${IT})
+	if (${_LIBRARIES})
+	else ()
+	  check_fortran_libraries(
+	    ${_LIBRARIES}
+	    BLAS
+	    ${BLAS_mkl_SEARCH_SYMBOL}
+	    "${additional_flags}"
+	    "${SEARCH_LIBS}"
+	    "${OMP_LIB};${CMAKE_THREAD_LIBS_INIT};${LM}"
+	    )
+	  if(_LIBRARIES)
+	    set(BLAS_LINKER_FLAGS "${additional_flags}")
+	  endif()
+	endif()
+      endforeach ()
+      if(NOT BLAS_FIND_QUIETLY)
+        if(${_LIBRARIES})
+          message(STATUS "Looking for MKL BLAS: found")
+        else()
+          message(STATUS "Looking for MKL BLAS: not found")
+        endif()
+      endif()
+      if (${_LIBRARIES} AND NOT BLAS_VENDOR_FOUND)
+          set (BLAS_VENDOR_FOUND "Intel MKL")
+      endif()
+    endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
+  endif(NOT BLAS_LIBRARIES OR BLA_VENDOR MATCHES "Intel*")
+endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
+
+
+if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    # gotoblas (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       ""
-      "cblas;f77blas;atlas"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
+      "goto2"
+      ""
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for Goto BLAS: found")
+      else()
+	message(STATUS "Looking for Goto BLAS: not found")
+      endif()
     endif()
+  endif()
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "Goto")
+  endif()
 
-    # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
+
+
+# OpenBlas
+if (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    # openblas (http://www.openblas.net/)
+    check_fortran_libraries(
+      BLAS_LIBRARIES
+      BLAS
+      sgemm
+      ""
+      "openblas"
+      ""
+      )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for Open BLAS: found")
+      else()
+	message(STATUS "Looking for Open BLAS: not found")
+      endif()
+    endif()
+  endif()
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "Openblas")
+  endif()
+
+endif (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All")
+
+
+# EigenBlas
+if (BLA_VENDOR STREQUAL "Eigen" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    # eigenblas (http://eigen.tuxfamily.org/index.php?title=Main_Page)
+    check_fortran_libraries(
+      BLAS_LIBRARIES
+      BLAS
+      sgemm
+      ""
+      "eigen_blas"
+      ""
+      )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+	message(STATUS "Looking for Eigen BLAS: found")
+      else()
+	message(STATUS "Looking for Eigen BLAS: not found")
+      endif()
+    endif()
+  endif()
+
+  if(NOT BLAS_LIBRARIES)
+    # eigenblas (http://eigen.tuxfamily.org/index.php?title=Main_Page)
+    check_fortran_libraries(
+      BLAS_LIBRARIES
+      BLAS
+      sgemm
+      ""
+      "eigen_blas_static"
+      ""
+      )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for Eigen BLAS: found")
+      else()
+	message(STATUS "Looking for Eigen BLAS: not found")
+      endif()
+    endif()
+  endif()
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "Eigen")
+  endif()
+
+endif (BLA_VENDOR STREQUAL "Eigen" OR BLA_VENDOR STREQUAL "All")
+
+
+if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
+    check_fortran_libraries(
+      BLAS_LIBRARIES
+      BLAS
+      dgemm
+      ""
+      "f77blas;atlas"
+      ""
+      )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for Atlas BLAS: found")
+      else()
+	message(STATUS "Looking for Atlas BLAS: not found")
+      endif()
+    endif()
+  endif()
+
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "Atlas")
+  endif()
+
+endif (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
+
+
+# BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
+if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       ""
       "sgemm;dgemm;blas"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
+      ""
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for PhiPACK BLAS: found")
+      else()
+	message(STATUS "Looking for PhiPACK BLAS: not found")
+      endif()
     endif()
+  endif()
 
-    # BLAS in Alpha CXML library?
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "PhiPACK")
+  endif()
+
+endif (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
+
+
+# BLAS in Alpha CXML library?
+if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       ""
       "cxml"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
+      ""
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for CXML BLAS: found")
+      else()
+	message(STATUS "Looking for CXML BLAS: not found")
+      endif()
     endif()
+  endif()
 
-    # BLAS in Alpha DXML library? (now called CXML, see above)
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "CXML")
+  endif()
+
+endif (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
+
+
+# BLAS in Alpha DXML library? (now called CXML, see above)
+if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       ""
       "dxml"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
+      ""
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for DXML BLAS: found")
+      else()
+	message(STATUS "Looking for DXML BLAS: not found")
+      endif()
     endif()
+  endif()
 
-    # BLAS in Sun Performance library?
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "DXML")
+  endif()
+  
+endif (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
+
+
+# BLAS in Sun Performance library?
+if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       "-xlic_lib=sunperf"
       "sunperf;sunmath"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
+      ""
       )
+    if(BLAS_LIBRARIES)
+      set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
+    endif()
+    if(NOT BLAS_FIND_QUIETLY)
       if(BLAS_LIBRARIES)
-        # Extra linker flag
-        set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
+	message(STATUS "Looking for SunPerf BLAS: found")
+      else()
+	message(STATUS "Looking for SunPerf BLAS: not found")
       endif()
     endif()
+  endif()
 
-    # BLAS in SCSL library?  (SGI/Cray Scientific Library)
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "SunPerf")
+  endif()
+
+endif ()
+
+
+# BLAS in SCSL library?  (SGI/Cray Scientific Library)
+if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       ""
       "scsl"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
+      ""
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for SCSL BLAS: found")
+      else()
+	message(STATUS "Looking for SCSL BLAS: not found")
+      endif()
     endif()
+  endif()
 
-    # BLAS in SGIMATH library?
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "SunPerf")
+  endif()
+
+endif ()
+
+
+# BLAS in SGIMATH library?
+if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       ""
       "complib.sgimath"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
+      ""
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for SGIMATH BLAS: found")
+      else()
+	message(STATUS "Looking for SGIMATH BLAS: not found")
+      endif()
     endif()
+  endif()
 
-    # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "SGIMATH")
+  endif()
+
+endif ()
+
+
+# BLAS in IBM ESSL library (requires generic BLAS lib, too)
+if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       ""
-      "essl;blas"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
+      "essl;xlfmath;xlf90_r;blas"
+      ""
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for IBM ESSL BLAS: found")
+      else()
+	message(STATUS "Looking for IBM ESSL BLAS: not found")
+      endif()
     endif()
+  endif()
 
-    #BLAS in intel mkl 10 library? (em64t 64bit)
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "IBM ESSL")
+  endif()
+
+endif ()
+
+# BLAS in IBM ESSL_MT library (requires generic BLAS lib, too)
+if (BLA_VENDOR STREQUAL "IBMESSLMT" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       ""
-      "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide;pthread"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
-      )
-    endif()
-
-    ### windows version of intel mkl 10?
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
-      BLAS_LIBRARIES
-      BLAS
-      SGEMM
+      "esslsmp;xlsmp;xlfmath;xlf90_r;blas"
       ""
-      "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for IBM ESSL MT BLAS: found")
+      else()
+	message(STATUS "Looking for IBM ESSL MT BLAS: not found")
+      endif()
     endif()
+  endif()
 
-    #older versions of intel mkl libs
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "IBM ESSL MT")
+  endif()
 
-    # BLAS in intel mkl library? (shared)
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+endif ()
+
+
+#BLAS in acml library?
+if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All")
+
+  if( ((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
+      ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
+      ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS)))
+
+    # try to find acml in "standard" paths
+    if( WIN32 )
+      file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" )
+    else()
+      file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
+    endif()
+    if( WIN32 )
+      file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
+    else()
+      file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" )
+    endif()
+    list(GET _ACML_ROOT 0 _ACML_ROOT)
+    list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
+
+    if( _ACML_ROOT )
+
+      get_filename_component( _ACML_ROOT ${_ACML_ROOT} PATH )
+      if( SIZEOF_INTEGER EQUAL 8 )
+	set( _ACML_PATH_SUFFIX "_int64" )
+      else()
+	set( _ACML_PATH_SUFFIX "" )
+      endif()
+      if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
+	set( _ACML_COMPILER32 "ifort32" )
+	set( _ACML_COMPILER64 "ifort64" )
+      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
+	set( _ACML_COMPILER32 "sun32" )
+	set( _ACML_COMPILER64 "sun64" )
+      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
+	set( _ACML_COMPILER32 "pgi32" )
+	if( WIN32 )
+	  set( _ACML_COMPILER64 "win64" )
+	else()
+	  set( _ACML_COMPILER64 "pgi64" )
+	endif()
+      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Open64" )
+	# 32 bit builds not supported on Open64 but for code simplicity
+	# We'll just use the same directory twice
+	set( _ACML_COMPILER32 "open64_64" )
+	set( _ACML_COMPILER64 "open64_64" )
+      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
+	set( _ACML_COMPILER32 "nag32" )
+	set( _ACML_COMPILER64 "nag64" )
+      else()
+	set( _ACML_COMPILER32 "gfortran32" )
+	set( _ACML_COMPILER64 "gfortran64" )
+      endif()
+
+      if( BLA_VENDOR STREQUAL "ACML_MP" )
+	set(_ACML_MP_LIB_DIRS
+	  "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
+	  "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib" )
+      else()
+	set(_ACML_LIB_DIRS
+	  "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
+	  "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib" )
+      endif()
+
+    endif(_ACML_ROOT)
+
+  elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
+
+    set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
+
+  endif()
+
+  if( BLA_VENDOR STREQUAL "ACML_MP" )
+    foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
+      check_fortran_libraries (
+	BLAS_LIBRARIES
+	BLAS
+	sgemm
+	"" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS}
+	)
+      if( BLAS_LIBRARIES )
+	break()
+      endif()
+    endforeach()
+  elseif( BLA_VENDOR STREQUAL "ACML_GPU" )
+    foreach( BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
+      check_fortran_libraries (
+	BLAS_LIBRARIES
+	BLAS
+	sgemm
+	"" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS}
+	)
+      if( BLAS_LIBRARIES )
+	break()
+      endif()
+    endforeach()
+  else()
+    foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} )
+      check_fortran_libraries (
+	BLAS_LIBRARIES
+	BLAS
+	sgemm
+	"" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS}
+	)
+      if( BLAS_LIBRARIES )
+	break()
+      endif()
+    endforeach()
+  endif()
+
+  # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       ""
-      "mkl;guide;pthread"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
+      "acml;acml_mv"
+      ""
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for ACML BLAS: found")
+      else()
+	message(STATUS "Looking for ACML BLAS: not found")
+      endif()
     endif()
+  endif()
 
-    #BLAS in intel mkl library? (static, 32bit)
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       ""
-      "mkl_ia32;guide;pthread"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
+      "acml_mp;acml_mv"
+      ""
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for ACML BLAS: found")
+      else()
+	message(STATUS "Looking for ACML BLAS: not found")
+      endif()
     endif()
+  endif()
 
-    #BLAS in intel mkl library? (static, em64t 64bit)
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
       sgemm
       ""
-      "mkl_em64t;guide;pthread"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
-      )
-    endif()
-
-    #BLAS in acml library?
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
-      BLAS_LIBRARIES
-      BLAS
-      sgemm
+      "acml;acml_mv;CALBLAS"
       ""
-      "acml"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for ACML BLAS: found")
+      else()
+	message(STATUS "Looking for ACML BLAS: not found")
+      endif()
     endif()
+  endif()
 
-    # Apple BLAS library?
-    if(NOT BLAS_LIBRARIES)
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "ACML")
+  endif()
+
+endif (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All") # ACML
+
+
+# Apple BLAS library?
+if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
+
+  if(NOT BLAS_LIBRARIES)
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
-      sgemm
+      dgemm
       ""
       "Accelerate"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
+      ""
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for Apple BLAS: found")
+      else()
+	message(STATUS "Looking for Apple BLAS: not found")
+      endif()
     endif()
+  endif()
 
-    if ( NOT BLAS_LIBRARIES )
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "Apple Accelerate")
+  endif()
+
+endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
+
+
+if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
+
+  if ( NOT BLAS_LIBRARIES )
+    check_fortran_libraries(
       BLAS_LIBRARIES
       BLAS
-      sgemm
+      dgemm
       ""
       "vecLib"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
-      )
-    endif ( NOT BLAS_LIBRARIES )
-
-    # Generic BLAS library?
-    # This configuration *must* be the last try as this library is notably slow.
-    if ( NOT BLAS_LIBRARIES )
-      check_fortran_libraries(
-      BLAS_DEFINITIONS
-      BLAS_LIBRARIES
-      BLAS
-      sgemm
       ""
-      "blas"
-      "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
       )
+    if(NOT BLAS_FIND_QUIETLY)
+      if(BLAS_LIBRARIES)
+	message(STATUS "Looking for NAS BLAS: found")
+      else()
+	message(STATUS "Looking for NAS BLAS: not found")
+      endif()
     endif()
+  endif ()
 
-  if(BLAS_LIBRARIES_DIR OR BLAS_LIBRARIES)
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "NAS")
+  endif()
+
+endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
+
+
+# Generic BLAS library?
+if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
+
+  set(BLAS_SEARCH_LIBS "blas;blas_LINUX;blas_MAC;blas_WINDOWS;refblas")
+  foreach (SEARCH_LIB ${BLAS_SEARCH_LIBS})
+    if (BLAS_LIBRARIES)
+    else ()
+      check_fortran_libraries(
+	BLAS_LIBRARIES
+	BLAS
+	sgemm
+	""
+	"${SEARCH_LIB}"
+	"${LGFORTRAN}"
+	)
+      if(NOT BLAS_FIND_QUIETLY)
+	if(BLAS_LIBRARIES)
+	  message(STATUS "Looking for Generic BLAS: found")
+	else()
+	  message(STATUS "Looking for Generic BLAS: not found")
+	endif()
+      endif()
+    endif()
+  endforeach ()
+
+  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
+      set (BLAS_VENDOR_FOUND "Netlib or other Generic libblas")
+  endif()
+
+endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
+
+
+if(BLA_F95)
+
+  if(BLAS95_LIBRARIES)
+    set(BLAS95_FOUND TRUE)
+  else()
+    set(BLAS95_FOUND FALSE)
+  endif()
+
+  if(NOT BLAS_FIND_QUIETLY)
+    if(BLAS95_FOUND)
+      message(STATUS "A library with BLAS95 API found.")
+      message(STATUS "BLAS_LIBRARIES ${BLAS_LIBRARIES}")
+    else(BLAS95_FOUND)
+      message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas 95 libraries could not be found or check of symbols failed."
+	"\nPlease indicate where to find blas libraries. You have three options:\n"
+	"- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
+	"- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
+	"- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
+	"\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
+	"\nYou could also specify a BLAS vendor to look for by setting -DBLA_VENDOR=blas_vendor_name."
+	"\nList of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, Intel10_32 (intel mkl v10 32 bit),"
+	"Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model), Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),"
+	"Intel( older versions of mkl 32 and 64 bit), ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
+      if(BLAS_FIND_REQUIRED)
+	message(FATAL_ERROR
+	  "A required library with BLAS95 API not found. Please specify library location.")
+      else()
+	message(STATUS
+	  "A library with BLAS95 API not found. Please specify library location.")
+      endif()
+    endif(BLAS95_FOUND)
+  endif(NOT BLAS_FIND_QUIETLY)
+
+  set(BLAS_FOUND TRUE)
+  set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
+
+else(BLA_F95)
+
+  if(BLAS_LIBRARIES)
     set(BLAS_FOUND TRUE)
   else()
     set(BLAS_FOUND FALSE)
@@ -388,32 +1366,41 @@
   if(NOT BLAS_FIND_QUIETLY)
     if(BLAS_FOUND)
       message(STATUS "A library with BLAS API found.")
+      message(STATUS "BLAS_LIBRARIES ${BLAS_LIBRARIES}")
     else(BLAS_FOUND)
+      message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas libraries could not be found or check of symbols failed."
+	"\nPlease indicate where to find blas libraries. You have three options:\n"
+	"- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
+	"- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
+	"- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
+	"\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
+	"\nYou could also specify a BLAS vendor to look for by setting -DBLA_VENDOR=blas_vendor_name."
+	"\nList of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, Intel10_32 (intel mkl v10 32 bit),"
+	"Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model), Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),"
+	"Intel( older versions of mkl 32 and 64 bit), ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
       if(BLAS_FIND_REQUIRED)
-        message(FATAL_ERROR "A required library with BLAS API not found. Please specify library location.")
+	message(FATAL_ERROR
+	  "A required library with BLAS API not found. Please specify library location.")
       else()
-        message(STATUS "A library with BLAS API not found. Please specify library location.")
+	message(STATUS
+	  "A library with BLAS API not found. Please specify library location.")
       endif()
     endif(BLAS_FOUND)
   endif(NOT BLAS_FIND_QUIETLY)
 
-  # Add variables to cache
-  set( BLAS_INCLUDE_DIR   "${BLAS_INCLUDE_DIR}"
-                          CACHE PATH "Directories containing the BLAS header files" FORCE )
-  set( BLAS_DEFINITIONS   "${BLAS_DEFINITIONS}"
-                          CACHE STRING "Compilation options to use BLAS" FORCE )
-  set( BLAS_LINKER_FLAGS  "${BLAS_LINKER_FLAGS}"
-                          CACHE STRING "Linker flags to use BLAS" FORCE )
-  set( BLAS_LIBRARIES     "${BLAS_LIBRARIES}"
-                          CACHE FILEPATH "BLAS libraries name" FORCE )
-  set( BLAS_LIBRARIES_DIR "${BLAS_LIBRARIES_DIR}"
-                          CACHE PATH "Directories containing the BLAS libraries" FORCE )
+endif(BLA_F95)
 
-  #message("DEBUG: BLAS_INCLUDE_DIR = ${BLAS_INCLUDE_DIR}")
-  #message("DEBUG: BLAS_DEFINITIONS = ${BLAS_DEFINITIONS}")
-  #message("DEBUG: BLAS_LINKER_FLAGS = ${BLAS_LINKER_FLAGS}")
-  #message("DEBUG: BLAS_LIBRARIES = ${BLAS_LIBRARIES}")
-  #message("DEBUG: BLAS_LIBRARIES_DIR = ${BLAS_LIBRARIES_DIR}")
-  #message("DEBUG: BLAS_FOUND = ${BLAS_FOUND}")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
 
-endif(BLAS_LIBRARIES_DIR OR BLAS_LIBRARIES)
+if (BLAS_FOUND)
+  list(GET BLAS_LIBRARIES 0 first_lib)
+  get_filename_component(first_lib_path "${first_lib}" PATH)
+  if (${first_lib_path} MATCHES "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)")
+    string(REGEX REPLACE "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)" "" not_cached_dir "${first_lib_path}")
+    set(BLAS_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of BLAS library" FORCE)
+  else()
+    set(BLAS_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of BLAS library" FORCE)
+  endif()
+endif()
+mark_as_advanced(BLAS_DIR)
+mark_as_advanced(BLAS_DIR_FOUND)
diff --git a/cmake/FindBLASEXT.cmake b/cmake/FindBLASEXT.cmake
new file mode 100644
index 0000000..0fe7fb8
--- /dev/null
+++ b/cmake/FindBLASEXT.cmake
@@ -0,0 +1,380 @@
+###
+#
+# @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-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
+#
+###
+#
+# - Find BLAS EXTENDED for MORSE projects: find include dirs and libraries
+#
+# This module allows to find BLAS libraries by calling the official FindBLAS module
+# and handles the creation of different library lists whether the user wishes to link
+# with a sequential BLAS or a multihreaded (BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES).
+# BLAS is detected with a FindBLAS call then if the BLAS vendor is Intel10_64lp, ACML
+# or IBMESSLMT then the module attempts to find the corresponding multithreaded libraries.
+#
+# The following variables have been added to manage links with sequential or multithreaded
+# versions:
+#  BLAS_INCLUDE_DIRS  - BLAS include directories
+#  BLAS_LIBRARY_DIRS  - Link directories for BLAS libraries
+#  BLAS_SEQ_LIBRARIES - BLAS component libraries to be linked (sequential)
+#  BLAS_PAR_LIBRARIES - BLAS component libraries to be linked (multithreaded)
+
+#=============================================================================
+# Copyright 2012-2013 Inria
+# Copyright 2012-2013 Emmanuel Agullo
+# Copyright 2012-2013 Mathieu Faverge
+# Copyright 2012      Cedric Castagnede
+# Copyright 2013-2016 Florent Pruvost
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file MORSE-Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of Morse, substitute the full
+#  License text for the above reference.)
+
+# macro to factorize this call
+macro(find_package_blas)
+  if(BLASEXT_FIND_REQUIRED)
+    if(BLASEXT_FIND_QUIETLY)
+      find_package(BLAS REQUIRED QUIET)
+    else()
+      find_package(BLAS REQUIRED)
+    endif()
+  else()
+    if(BLASEXT_FIND_QUIETLY)
+      find_package(BLAS QUIET)
+    else()
+      find_package(BLAS)
+    endif()
+  endif()
+endmacro()
+
+# add a cache variable to let the user specify the BLAS vendor
+set(BLA_VENDOR "" CACHE STRING "list of possible BLAS vendor:
+    Open, Eigen, Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, IBMESSLMT,
+    Intel10_32 (intel mkl v10 32 bit),
+    Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model),
+    Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),
+    Intel( older versions of mkl 32 and 64 bit),
+    ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
+
+if(NOT BLASEXT_FIND_QUIETLY)
+  message(STATUS "In FindBLASEXT")
+  message(STATUS "If you want to force the use of one specific library, "
+    "\n   please specify the BLAS vendor by setting -DBLA_VENDOR=blas_vendor_name"
+    "\n   at cmake configure.")
+  message(STATUS "List of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, "
+    "\n   DXML, SunPerf, SCSL, SGIMATH, IBMESSL, IBMESSLMT, Intel10_32 (intel mkl v10 32 bit),"
+    "\n   Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model),"
+    "\n   Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),"
+    "\n   Intel( older versions of mkl 32 and 64 bit),"
+    "\n   ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
+endif()
+
+if (NOT BLAS_FOUND)
+  # First try to detect two cases:
+  # 1: only SEQ libs are handled
+  # 2: both SEQ and PAR libs are handled
+  find_package_blas()
+endif ()
+
+# detect the cases where SEQ and PAR libs are handled
+if(BLA_VENDOR STREQUAL "All" AND
+    (BLAS_mkl_core_LIBRARY OR BLAS_mkl_core_dll_LIBRARY)
+    )
+  set(BLA_VENDOR "Intel")
+  if(BLAS_mkl_intel_LIBRARY)
+    set(BLA_VENDOR "Intel10_32")
+  endif()
+  if(BLAS_mkl_intel_lp64_LIBRARY)
+    set(BLA_VENDOR "Intel10_64lp")
+  endif()
+  if(NOT BLASEXT_FIND_QUIETLY)
+    message(STATUS "A BLAS library has been found (${BLAS_LIBRARIES}) but we"
+      "\n   have also potentially detected some multithreaded BLAS libraries from the MKL."
+      "\n   We try to find both libraries lists (Sequential/Multithreaded).")
+  endif()
+  set(BLAS_FOUND "")
+elseif(BLA_VENDOR STREQUAL "All" AND BLAS_acml_LIBRARY)
+  set(BLA_VENDOR "ACML")
+  if(NOT BLASEXT_FIND_QUIETLY)
+    message(STATUS "A BLAS library has been found (${BLAS_LIBRARIES}) but we"
+      "\n   have also potentially detected some multithreaded BLAS libraries from the ACML."
+      "\n   We try to find both libraries lists (Sequential/Multithreaded).")
+  endif()
+  set(BLAS_FOUND "")
+elseif(BLA_VENDOR STREQUAL "All" AND BLAS_essl_LIBRARY)
+  set(BLA_VENDOR "IBMESSL")
+  if(NOT BLASEXT_FIND_QUIETLY)
+    message(STATUS "A BLAS library has been found (${BLAS_LIBRARIES}) but we"
+      "\n   have also potentially detected some multithreaded BLAS libraries from the ESSL."
+      "\n   We try to find both libraries lists (Sequential/Multithreaded).")
+  endif()
+  set(BLAS_FOUND "")
+endif()
+
+# Intel case
+if(BLA_VENDOR MATCHES "Intel*")
+
+  ###
+  # look for include path if the BLAS vendor is Intel
+  ###
+
+  # gather system include paths
+  unset(_inc_env)
+  if(WIN32)
+    string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
+  else()
+    string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
+    list(APPEND _inc_env "${_path_env}")
+  endif()
+  list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
+  list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
+  set(ENV_MKLROOT "$ENV{MKLROOT}")
+  if (ENV_MKLROOT)
+    list(APPEND _inc_env "${ENV_MKLROOT}/include")
+  endif()
+  list(REMOVE_DUPLICATES _inc_env)
+
+  # find mkl.h inside known include paths
+  set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
+  if(BLAS_INCDIR)
+    set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
+    find_path(BLAS_mkl.h_INCLUDE_DIRS
+      NAMES mkl.h
+      HINTS ${BLAS_INCDIR})
+  else()
+    if(BLAS_DIR)
+      set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
+      find_path(BLAS_mkl.h_INCLUDE_DIRS
+	NAMES mkl.h
+	HINTS ${BLAS_DIR}
+	PATH_SUFFIXES include)
+    else()
+      set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
+      find_path(BLAS_mkl.h_INCLUDE_DIRS
+	NAMES mkl.h
+	HINTS ${_inc_env})
+    endif()
+  endif()
+  mark_as_advanced(BLAS_mkl.h_INCLUDE_DIRS)
+  ## Print status if not found
+  ## -------------------------
+  #if (NOT BLAS_mkl.h_INCLUDE_DIRS AND MORSE_VERBOSE)
+  #    Print_Find_Header_Status(blas mkl.h)
+  #endif ()
+  set(BLAS_INCLUDE_DIRS "")
+  if(BLAS_mkl.h_INCLUDE_DIRS)
+    list(APPEND BLAS_INCLUDE_DIRS "${BLAS_mkl.h_INCLUDE_DIRS}" )
+  endif()
+
+  ###
+  # look for libs
+  ###
+  # if Intel 10 64 bit -> look for sequential and multithreaded versions
+  if(BLA_VENDOR MATCHES "Intel10_64lp*")
+
+    ## look for the sequential version
+    set(BLA_VENDOR "Intel10_64lp_seq")
+    if(NOT BLASEXT_FIND_QUIETLY)
+      message(STATUS "Look for the sequential version Intel10_64lp_seq")
+    endif()
+    find_package_blas()
+    if(BLAS_FOUND)
+      set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
+    else()
+      set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
+    endif()
+
+    ## look for the multithreaded version
+    set(BLA_VENDOR "Intel10_64lp")
+    if(NOT BLASEXT_FIND_QUIETLY)
+      message(STATUS "Look for the multithreaded version Intel10_64lp")
+    endif()
+    find_package_blas()
+    if(BLAS_FOUND)
+      set(BLAS_PAR_LIBRARIES "${BLAS_LIBRARIES}")
+    else()
+      set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
+    endif()
+
+  else()
+
+    if(BLAS_FOUND)
+      set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
+    else()
+      set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
+    endif()
+
+  endif()
+
+  # ACML case
+elseif(BLA_VENDOR MATCHES "ACML*")
+
+  ## look for the sequential version
+  set(BLA_VENDOR "ACML")
+  find_package_blas()
+  if(BLAS_FOUND)
+    set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
+  else()
+    set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
+  endif()
+
+  ## look for the multithreaded version
+  set(BLA_VENDOR "ACML_MP")
+  find_package_blas()
+  if(BLAS_FOUND)
+    set(BLAS_PAR_LIBRARIES "${BLAS_LIBRARIES}")
+  else()
+    set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
+  endif()
+
+  # IBMESSL case
+elseif(BLA_VENDOR MATCHES "IBMESSL*")
+
+  ## look for the sequential version
+  set(BLA_VENDOR "IBMESSL")
+  find_package_blas()
+  if(BLAS_FOUND)
+    set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
+  else()
+    set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
+  endif()
+
+  ## look for the multithreaded version
+  set(BLA_VENDOR "IBMESSLMT")
+  find_package_blas()
+  if(BLAS_FOUND)
+    set(BLAS_PAR_LIBRARIES "${BLAS_LIBRARIES}")
+  else()
+    set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
+  endif()
+
+else()
+
+  if(BLAS_FOUND)
+    # define the SEQ libs as the BLAS_LIBRARIES
+    set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
+  else()
+    set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
+  endif()
+  set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
+
+endif()
+
+
+if(BLAS_SEQ_LIBRARIES)
+  set(BLAS_LIBRARIES "${BLAS_SEQ_LIBRARIES}")
+endif()
+
+# extract libs paths
+# remark: because it is not given by find_package(BLAS)
+set(BLAS_LIBRARY_DIRS "")
+string(REPLACE " " ";" BLAS_LIBRARIES "${BLAS_LIBRARIES}")
+foreach(blas_lib ${BLAS_LIBRARIES})
+  if (EXISTS "${blas_lib}")
+    get_filename_component(a_blas_lib_dir "${blas_lib}" PATH)
+    list(APPEND BLAS_LIBRARY_DIRS "${a_blas_lib_dir}" )
+  else()
+    string(REPLACE "-L" "" blas_lib "${blas_lib}")
+    if (EXISTS "${blas_lib}")
+      list(APPEND BLAS_LIBRARY_DIRS "${blas_lib}" )
+    else()
+      get_filename_component(a_blas_lib_dir "${blas_lib}" PATH)
+      if (EXISTS "${a_blas_lib_dir}")
+	list(APPEND BLAS_LIBRARY_DIRS "${a_blas_lib_dir}" )
+      endif()
+    endif()
+  endif()
+endforeach()
+if (BLAS_LIBRARY_DIRS)
+  list(REMOVE_DUPLICATES BLAS_LIBRARY_DIRS)
+endif ()
+
+# check that BLAS has been found
+# ---------------------------------
+include(FindPackageHandleStandardArgs)
+if(BLA_VENDOR MATCHES "Intel*")
+  if(BLA_VENDOR MATCHES "Intel10_64lp*")
+    if(NOT BLASEXT_FIND_QUIETLY)
+      message(STATUS "BLAS found is Intel MKL:"
+	"\n   we manage two lists of libs, one sequential and one parallel if found"
+	"\n   (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)")
+      message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
+    endif()
+    find_package_handle_standard_args(BLAS DEFAULT_MSG
+      BLAS_SEQ_LIBRARIES
+      BLAS_LIBRARY_DIRS
+      BLAS_INCLUDE_DIRS)
+    if(BLAS_PAR_LIBRARIES)
+      if(NOT BLASEXT_FIND_QUIETLY)
+	message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES")
+      endif()
+      find_package_handle_standard_args(BLAS DEFAULT_MSG
+	BLAS_PAR_LIBRARIES)
+    endif()
+  else()
+    if(NOT BLASEXT_FIND_QUIETLY)
+      message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
+    endif()
+    find_package_handle_standard_args(BLAS DEFAULT_MSG
+      BLAS_SEQ_LIBRARIES
+      BLAS_LIBRARY_DIRS
+      BLAS_INCLUDE_DIRS)
+  endif()
+elseif(BLA_VENDOR MATCHES "ACML*")
+  if(NOT BLASEXT_FIND_QUIETLY)
+    message(STATUS "BLAS found is ACML:"
+      "\n   we manage two lists of libs, one sequential and one parallel if found"
+      "\n   (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)")
+    message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
+  endif()
+  find_package_handle_standard_args(BLAS DEFAULT_MSG
+    BLAS_SEQ_LIBRARIES
+    BLAS_LIBRARY_DIRS)
+  if(BLAS_PAR_LIBRARIES)
+    if(NOT BLASEXT_FIND_QUIETLY)
+      message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES")
+    endif()
+    find_package_handle_standard_args(BLAS DEFAULT_MSG
+      BLAS_PAR_LIBRARIES)
+  endif()
+elseif(BLA_VENDOR MATCHES "IBMESSL*")
+  if(NOT BLASEXT_FIND_QUIETLY)
+    message(STATUS "BLAS found is ESSL:"
+      "\n   we manage two lists of libs, one sequential and one parallel if found"
+      "\n   (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)")
+    message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
+  endif()
+  find_package_handle_standard_args(BLAS DEFAULT_MSG
+    BLAS_SEQ_LIBRARIES
+    BLAS_LIBRARY_DIRS)
+  if(BLAS_PAR_LIBRARIES)
+    if(NOT BLASEXT_FIND_QUIETLY)
+      message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES")
+    endif()
+    find_package_handle_standard_args(BLAS DEFAULT_MSG
+      BLAS_PAR_LIBRARIES)
+  endif()
+else()
+  if(NOT BLASEXT_FIND_QUIETLY)
+    message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
+  endif()
+  find_package_handle_standard_args(BLAS DEFAULT_MSG
+    BLAS_SEQ_LIBRARIES
+    BLAS_LIBRARY_DIRS)
+endif()
diff --git a/cmake/FindComputeCpp.cmake b/cmake/FindComputeCpp.cmake
new file mode 100644
index 0000000..07ebed6
--- /dev/null
+++ b/cmake/FindComputeCpp.cmake
@@ -0,0 +1,245 @@
+#.rst:
+# FindComputeCpp
+#---------------
+#
+#   Copyright 2016 Codeplay Software Ltd.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use these files except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+#########################
+#  FindComputeCpp.cmake
+#########################
+#
+#  Tools for finding and building with ComputeCpp.
+#
+#  User must define COMPUTECPP_PACKAGE_ROOT_DIR pointing to the ComputeCpp
+#   installation.
+#
+#  Latest version of this file can be found at:
+#    https://github.com/codeplaysoftware/computecpp-sdk
+
+# Require CMake version 3.2.2 or higher
+cmake_minimum_required(VERSION 3.2.2)
+
+# Check that a supported host compiler can be found
+if(CMAKE_COMPILER_IS_GNUCXX)
+    # Require at least gcc 4.8
+    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
+      message(FATAL_ERROR
+        "host compiler - Not found! (gcc version must be at least 4.8)")
+    # Require the GCC dual ABI to be disabled for 5.1 or higher
+    elseif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.1)
+      set(COMPUTECPP_DISABLE_GCC_DUAL_ABI "True")
+      message(STATUS
+        "host compiler - gcc ${CMAKE_CXX_COMPILER_VERSION} (note pre 5.1 gcc ABI enabled)")
+    else()
+      message(STATUS "host compiler - gcc ${CMAKE_CXX_COMPILER_VERSION}")
+    endif()
+elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+    # Require at least clang 3.6
+    if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.6)
+      message(FATAL_ERROR
+        "host compiler - Not found! (clang version must be at least 3.6)")
+    else()
+      message(STATUS "host compiler - clang ${CMAKE_CXX_COMPILER_VERSION}")
+    endif()
+else()
+  message(WARNING
+    "host compiler - Not found! (ComputeCpp supports GCC and Clang, see readme)")
+endif()
+
+set(COMPUTECPP_64_BIT_DEFAULT ON)
+option(COMPUTECPP_64_BIT_CODE "Compile device code in 64 bit mode"
+        ${COMPUTECPP_64_BIT_DEFAULT})
+mark_as_advanced(COMPUTECPP_64_BIT_CODE)
+
+# Find OpenCL package
+find_package(OpenCL REQUIRED)
+
+# Find ComputeCpp packagee
+if(NOT COMPUTECPP_PACKAGE_ROOT_DIR)
+  message(FATAL_ERROR
+    "ComputeCpp package - Not found! (please set COMPUTECPP_PACKAGE_ROOT_DIR")
+else()
+  message(STATUS "ComputeCpp package - Found")
+endif()
+option(COMPUTECPP_PACKAGE_ROOT_DIR "Path to the ComputeCpp Package")
+
+# Obtain the path to compute++
+find_program(COMPUTECPP_DEVICE_COMPILER compute++ PATHS
+  ${COMPUTECPP_PACKAGE_ROOT_DIR} PATH_SUFFIXES bin)
+if (EXISTS ${COMPUTECPP_DEVICE_COMPILER})
+  mark_as_advanced(COMPUTECPP_DEVICE_COMPILER)
+  message(STATUS "compute++ - Found")
+else()
+  message(FATAL_ERROR "compute++ - Not found! (${COMPUTECPP_DEVICE_COMPILER})")
+endif()
+
+# Obtain the path to computecpp_info
+find_program(COMPUTECPP_INFO_TOOL computecpp_info PATHS
+  ${COMPUTECPP_PACKAGE_ROOT_DIR} PATH_SUFFIXES bin)
+if (EXISTS ${COMPUTECPP_INFO_TOOL})
+  mark_as_advanced(${COMPUTECPP_INFO_TOOL})
+  message(STATUS "computecpp_info - Found")
+else()
+  message(FATAL_ERROR "computecpp_info - Not found! (${COMPUTECPP_INFO_TOOL})")
+endif()
+
+# Obtain the path to the ComputeCpp runtime library
+find_library(COMPUTECPP_RUNTIME_LIBRARY ComputeCpp PATHS ${COMPUTECPP_PACKAGE_ROOT_DIR}
+  HINTS ${COMPUTECPP_PACKAGE_ROOT_DIR}/lib PATH_SUFFIXES lib
+  DOC "ComputeCpp Runtime Library" NO_DEFAULT_PATH)
+
+if (EXISTS ${COMPUTECPP_RUNTIME_LIBRARY})
+  mark_as_advanced(COMPUTECPP_RUNTIME_LIBRARY)
+  message(STATUS "libComputeCpp.so - Found")
+else()
+  message(FATAL_ERROR "libComputeCpp.so - Not found!")
+endif()
+
+# Obtain the ComputeCpp include directory
+set(COMPUTECPP_INCLUDE_DIRECTORY ${COMPUTECPP_PACKAGE_ROOT_DIR}/include/)
+if (NOT EXISTS ${COMPUTECPP_INCLUDE_DIRECTORY})
+  message(FATAL_ERROR "ComputeCpp includes - Not found!")
+else()
+  message(STATUS "ComputeCpp includes - Found")
+endif()
+
+# Obtain the package version
+execute_process(COMMAND ${COMPUTECPP_INFO_TOOL} "--dump-version"
+  OUTPUT_VARIABLE COMPUTECPP_PACKAGE_VERSION
+  RESULT_VARIABLE COMPUTECPP_INFO_TOOL_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
+if(NOT COMPUTECPP_INFO_TOOL_RESULT EQUAL "0")
+  message(FATAL_ERROR "Package version - Error obtaining version!")
+else()
+  mark_as_advanced(COMPUTECPP_PACKAGE_VERSION)
+  message(STATUS "Package version - ${COMPUTECPP_PACKAGE_VERSION}")
+endif()
+
+# Obtain the device compiler flags
+execute_process(COMMAND ${COMPUTECPP_INFO_TOOL} "--dump-device-compiler-flags"
+  OUTPUT_VARIABLE COMPUTECPP_DEVICE_COMPILER_FLAGS
+  RESULT_VARIABLE COMPUTECPP_INFO_TOOL_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
+if(NOT COMPUTECPP_INFO_TOOL_RESULT EQUAL "0")
+  message(FATAL_ERROR "compute++ flags - Error obtaining compute++ flags!")
+else()
+  mark_as_advanced(COMPUTECPP_COMPILER_FLAGS)
+  message(STATUS "compute++ flags - ${COMPUTECPP_DEVICE_COMPILER_FLAGS}")
+endif()
+
+set(COMPUTECPP_DEVICE_COMPILER_FLAGS ${COMPUTECPP_DEVICE_COMPILER_FLAGS} -sycl-compress-name -no-serial-memop -DEIGEN_NO_ASSERTION_CHECKING=1)
+
+# Check if the platform is supported
+execute_process(COMMAND ${COMPUTECPP_INFO_TOOL} "--dump-is-supported"
+  OUTPUT_VARIABLE COMPUTECPP_PLATFORM_IS_SUPPORTED
+  RESULT_VARIABLE COMPUTECPP_INFO_TOOL_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
+if(NOT COMPUTECPP_INFO_TOOL_RESULT EQUAL "0")
+  message(FATAL_ERROR "platform - Error checking platform support!")
+else()
+  mark_as_advanced(COMPUTECPP_PLATFORM_IS_SUPPORTED)
+  if (COMPUTECPP_PLATFORM_IS_SUPPORTED)
+    message(STATUS "platform - your system can support ComputeCpp")
+  else()
+    message(STATUS "platform - your system CANNOT support ComputeCpp")
+  endif()
+endif()
+
+####################
+#   __build_sycl
+####################
+#
+#  Adds a custom target for running compute++ and adding a dependency for the
+#  resulting integration header.
+#
+#  targetName : Name of the target.
+#  sourceFile : Source file to be compiled.
+#  binaryDir : Intermediate directory to output the integration header.
+#
+function(__build_spir targetName sourceFile binaryDir)
+
+  # Retrieve source file name.
+  get_filename_component(sourceFileName ${sourceFile} NAME)
+
+  # Set the path to the Sycl file.
+  set(outputSyclFile ${binaryDir}/${sourceFileName}.sycl)
+
+  # Add any user-defined include to the device compiler
+  get_property(includeDirectories DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY
+    INCLUDE_DIRECTORIES)
+  set(device_compiler_includes "")
+  foreach(directory ${includeDirectories})
+    set(device_compiler_includes "-I${directory}" ${device_compiler_includes})
+  endforeach()
+  if (CMAKE_INCLUDE_PATH)
+    foreach(directory ${CMAKE_INCLUDE_PATH})
+      set(device_compiler_includes "-I${directory}"
+        ${device_compiler_includes})
+    endforeach()
+  endif()
+
+  # Convert argument list format
+  separate_arguments(COMPUTECPP_DEVICE_COMPILER_FLAGS)
+
+  # Add custom command for running compute++
+  add_custom_command(
+    OUTPUT ${outputSyclFile}
+    COMMAND ${COMPUTECPP_DEVICE_COMPILER}
+            ${COMPUTECPP_DEVICE_COMPILER_FLAGS}
+            -isystem ${COMPUTECPP_INCLUDE_DIRECTORY}
+            ${COMPUTECPP_PLATFORM_SPECIFIC_ARGS}
+            ${device_compiler_includes}
+            -o ${outputSyclFile}
+            -c ${CMAKE_CURRENT_SOURCE_DIR}/${sourceFile}
+    DEPENDS ${sourceFile}
+    WORKING_DIRECTORY ${binaryDir}
+  COMMENT "Building ComputeCpp integration header file ${outputSyclFile}")
+
+  # Add a custom target for the generated integration header
+  add_custom_target(${targetName}_integration_header DEPENDS ${outputSyclFile})
+
+  # Add a dependency on the integration header
+  add_dependencies(${targetName} ${targetName}_integration_header)
+
+  # Set the host compiler C++ standard to C++11
+  set_property(TARGET ${targetName} PROPERTY CXX_STANDARD 11)
+
+  # Disable GCC dual ABI on GCC 5.1 and higher
+  if(COMPUTECPP_DISABLE_GCC_DUAL_ABI)
+    set_property(TARGET ${targetName} APPEND PROPERTY COMPILE_DEFINITIONS
+      "_GLIBCXX_USE_CXX11_ABI=0")
+  endif()
+
+endfunction()
+
+#######################
+#  add_sycl_to_target
+#######################
+#
+#  Adds a SYCL compilation custom command associated with an existing
+#  target and sets a dependancy on that new command.
+#
+#  targetName : Name of the target to add a SYCL to.
+#  sourceFile : Source file to be compiled for SYCL.
+#  binaryDir : Intermediate directory to output the integration header.
+#
+function(add_sycl_to_target targetName sourceFile binaryDir)
+
+  # Add custom target to run compute++ and generate the integration header
+  __build_spir(${targetName} ${sourceFile} ${binaryDir})
+
+  # Link with the ComputeCpp runtime library
+  target_link_libraries(${targetName} PUBLIC ${COMPUTECPP_RUNTIME_LIBRARY}
+                        PUBLIC ${OpenCL_LIBRARIES})
+
+endfunction(add_sycl_to_target)
diff --git a/cmake/FindEigen3.cmake b/cmake/FindEigen3.cmake
index 9c546a0..9e96978 100644
--- a/cmake/FindEigen3.cmake
+++ b/cmake/FindEigen3.cmake
@@ -9,6 +9,12 @@
 #  EIGEN3_FOUND - system has eigen lib with correct version
 #  EIGEN3_INCLUDE_DIR - the eigen include directory
 #  EIGEN3_VERSION - eigen version
+#
+# This module reads hints about search locations from 
+# the following enviroment variables:
+#
+# EIGEN3_ROOT
+# EIGEN3_ROOT_DIR
 
 # Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
 # Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
@@ -60,13 +66,23 @@
   set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
 
 else (EIGEN3_INCLUDE_DIR)
+  
+  # search first if an Eigen3Config.cmake is available in the system,
+  # if successful this would set EIGEN3_INCLUDE_DIR and the rest of
+  # the script will work as usual
+  find_package(Eigen3 ${Eigen3_FIND_VERSION} NO_MODULE QUIET)
 
-  find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
-      PATHS
-      ${CMAKE_INSTALL_PREFIX}/include
-      ${KDE4_INCLUDE_DIR}
-      PATH_SUFFIXES eigen3 eigen
-    )
+  if(NOT EIGEN3_INCLUDE_DIR)
+    find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
+        HINTS
+        ENV EIGEN3_ROOT 
+        ENV EIGEN3_ROOT_DIR
+        PATHS
+        ${CMAKE_INSTALL_PREFIX}/include
+        ${KDE4_INCLUDE_DIR}
+        PATH_SUFFIXES eigen3 eigen
+      )
+  endif(NOT EIGEN3_INCLUDE_DIR)
 
   if(EIGEN3_INCLUDE_DIR)
     _eigen3_check_version()
diff --git a/cmake/FindHWLOC.cmake b/cmake/FindHWLOC.cmake
new file mode 100644
index 0000000..a831b5c
--- /dev/null
+++ b/cmake/FindHWLOC.cmake
@@ -0,0 +1,331 @@
+###
+#
+# @copyright (c) 2009-2014 The University of Tennessee and The University
+#                          of Tennessee Research Foundation.
+#                          All rights reserved.
+# @copyright (c) 2012-2014 Inria. All rights reserved.
+# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
+#
+###
+#
+# - Find HWLOC include dirs and libraries
+# Use this module by invoking find_package with the form:
+#  find_package(HWLOC
+#               [REQUIRED]) # Fail with error if hwloc is not found
+#
+# This module finds headers and hwloc library.
+# Results are reported in variables:
+#  HWLOC_FOUND           - True if headers and requested libraries were found
+#  HWLOC_INCLUDE_DIRS    - hwloc include directories
+#  HWLOC_LIBRARY_DIRS    - Link directories for hwloc libraries
+#  HWLOC_LIBRARIES       - hwloc component libraries to be linked
+#
+# The user can give specific paths where to find the libraries adding cmake
+# options at configure (ex: cmake path/to/project -DHWLOC_DIR=path/to/hwloc):
+#  HWLOC_DIR             - Where to find the base directory of hwloc
+#  HWLOC_INCDIR          - Where to find the header files
+#  HWLOC_LIBDIR          - Where to find the library files
+# The module can also look for the following environment variables if paths
+# are not given as cmake variable: HWLOC_DIR, HWLOC_INCDIR, HWLOC_LIBDIR
+
+#=============================================================================
+# Copyright 2012-2013 Inria
+# Copyright 2012-2013 Emmanuel Agullo
+# Copyright 2012-2013 Mathieu Faverge
+# Copyright 2012      Cedric Castagnede
+# Copyright 2013      Florent Pruvost
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file MORSE-Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of Morse, substitute the full
+#  License text for the above reference.)
+
+include(CheckStructHasMember)
+include(CheckCSourceCompiles)
+
+if (NOT HWLOC_FOUND)
+  set(HWLOC_DIR "" CACHE PATH "Installation directory of HWLOC library")
+  if (NOT HWLOC_FIND_QUIETLY)
+    message(STATUS "A cache variable, namely HWLOC_DIR, has been set to specify the install directory of HWLOC")
+  endif()
+endif()
+
+set(ENV_HWLOC_DIR "$ENV{HWLOC_DIR}")
+set(ENV_HWLOC_INCDIR "$ENV{HWLOC_INCDIR}")
+set(ENV_HWLOC_LIBDIR "$ENV{HWLOC_LIBDIR}")
+set(HWLOC_GIVEN_BY_USER "FALSE")
+if ( HWLOC_DIR OR ( HWLOC_INCDIR AND HWLOC_LIBDIR) OR ENV_HWLOC_DIR OR (ENV_HWLOC_INCDIR AND ENV_HWLOC_LIBDIR) )
+  set(HWLOC_GIVEN_BY_USER "TRUE")
+endif()
+
+# Optionally use pkg-config to detect include/library dirs (if pkg-config is available)
+# -------------------------------------------------------------------------------------
+include(FindPkgConfig)
+find_package(PkgConfig QUIET)
+if( PKG_CONFIG_EXECUTABLE AND NOT HWLOC_GIVEN_BY_USER )
+
+  pkg_search_module(HWLOC hwloc)
+  if (NOT HWLOC_FIND_QUIETLY)
+    if (HWLOC_FOUND AND HWLOC_LIBRARIES)
+      message(STATUS "Looking for HWLOC - found using PkgConfig")
+      #if(NOT HWLOC_INCLUDE_DIRS)
+      #    message("${Magenta}HWLOC_INCLUDE_DIRS is empty using PkgConfig."
+      #        "Perhaps the path to hwloc headers is already present in your"
+      #        "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}")
+      #endif()
+    else()
+      message(STATUS "${Magenta}Looking for HWLOC - not found using PkgConfig."
+	"\n   Perhaps you should add the directory containing hwloc.pc to"
+	"\n   the PKG_CONFIG_PATH environment variable.${ColourReset}")
+    endif()
+  endif()
+
+endif( PKG_CONFIG_EXECUTABLE AND NOT HWLOC_GIVEN_BY_USER )
+
+if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT HWLOC_FOUND) OR (HWLOC_GIVEN_BY_USER) )
+
+  if (NOT HWLOC_FIND_QUIETLY)
+    message(STATUS "Looking for HWLOC - PkgConfig not used")
+  endif()
+
+  # Looking for include
+  # -------------------
+
+  # Add system include paths to search include
+  # ------------------------------------------
+  unset(_inc_env)
+  if(ENV_HWLOC_INCDIR)
+    list(APPEND _inc_env "${ENV_HWLOC_INCDIR}")
+  elseif(ENV_HWLOC_DIR)
+    list(APPEND _inc_env "${ENV_HWLOC_DIR}")
+    list(APPEND _inc_env "${ENV_HWLOC_DIR}/include")
+    list(APPEND _inc_env "${ENV_HWLOC_DIR}/include/hwloc")
+  else()
+    if(WIN32)
+      string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
+    else()
+      string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
+      list(APPEND _inc_env "${_path_env}")
+      string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
+      list(APPEND _inc_env "${_path_env}")
+      string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
+      list(APPEND _inc_env "${_path_env}")
+      string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
+      list(APPEND _inc_env "${_path_env}")
+    endif()
+  endif()
+  list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
+  list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
+  list(REMOVE_DUPLICATES _inc_env)
+
+  # set paths where to look for
+  set(PATH_TO_LOOK_FOR "${_inc_env}")
+
+  # Try to find the hwloc header in the given paths
+  # -------------------------------------------------
+  # call cmake macro to find the header path
+  if(HWLOC_INCDIR)
+    set(HWLOC_hwloc.h_DIRS "HWLOC_hwloc.h_DIRS-NOTFOUND")
+    find_path(HWLOC_hwloc.h_DIRS
+      NAMES hwloc.h
+      HINTS ${HWLOC_INCDIR})
+  else()
+    if(HWLOC_DIR)
+      set(HWLOC_hwloc.h_DIRS "HWLOC_hwloc.h_DIRS-NOTFOUND")
+      find_path(HWLOC_hwloc.h_DIRS
+	NAMES hwloc.h
+	HINTS ${HWLOC_DIR}
+	PATH_SUFFIXES "include" "include/hwloc")
+    else()
+      set(HWLOC_hwloc.h_DIRS "HWLOC_hwloc.h_DIRS-NOTFOUND")
+      find_path(HWLOC_hwloc.h_DIRS
+	NAMES hwloc.h
+	HINTS ${PATH_TO_LOOK_FOR}
+	PATH_SUFFIXES "hwloc")
+    endif()
+  endif()
+  mark_as_advanced(HWLOC_hwloc.h_DIRS)
+
+  # Add path to cmake variable
+  # ------------------------------------
+  if (HWLOC_hwloc.h_DIRS)
+    set(HWLOC_INCLUDE_DIRS "${HWLOC_hwloc.h_DIRS}")
+  else ()
+    set(HWLOC_INCLUDE_DIRS "HWLOC_INCLUDE_DIRS-NOTFOUND")
+    if(NOT HWLOC_FIND_QUIETLY)
+      message(STATUS "Looking for hwloc -- hwloc.h not found")
+    endif()
+  endif ()
+
+  if (HWLOC_INCLUDE_DIRS)
+    list(REMOVE_DUPLICATES HWLOC_INCLUDE_DIRS)
+  endif ()
+
+
+  # Looking for lib
+  # ---------------
+
+  # Add system library paths to search lib
+  # --------------------------------------
+  unset(_lib_env)
+  if(ENV_HWLOC_LIBDIR)
+    list(APPEND _lib_env "${ENV_HWLOC_LIBDIR}")
+  elseif(ENV_HWLOC_DIR)
+    list(APPEND _lib_env "${ENV_HWLOC_DIR}")
+    list(APPEND _lib_env "${ENV_HWLOC_DIR}/lib")
+  else()
+    if(WIN32)
+      string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
+    else()
+      if(APPLE)
+	string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
+      else()
+	string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
+      endif()
+      list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
+      list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
+    endif()
+  endif()
+  list(REMOVE_DUPLICATES _lib_env)
+
+  # set paths where to look for
+  set(PATH_TO_LOOK_FOR "${_lib_env}")
+
+  # Try to find the hwloc lib in the given paths
+  # ----------------------------------------------
+
+  # call cmake macro to find the lib path
+  if(HWLOC_LIBDIR)
+    set(HWLOC_hwloc_LIBRARY "HWLOC_hwloc_LIBRARY-NOTFOUND")
+    find_library(HWLOC_hwloc_LIBRARY
+      NAMES hwloc
+      HINTS ${HWLOC_LIBDIR})
+  else()
+    if(HWLOC_DIR)
+      set(HWLOC_hwloc_LIBRARY "HWLOC_hwloc_LIBRARY-NOTFOUND")
+      find_library(HWLOC_hwloc_LIBRARY
+	NAMES hwloc
+	HINTS ${HWLOC_DIR}
+	PATH_SUFFIXES lib lib32 lib64)
+    else()
+      set(HWLOC_hwloc_LIBRARY "HWLOC_hwloc_LIBRARY-NOTFOUND")
+      find_library(HWLOC_hwloc_LIBRARY
+	NAMES hwloc
+	HINTS ${PATH_TO_LOOK_FOR})
+    endif()
+  endif()
+  mark_as_advanced(HWLOC_hwloc_LIBRARY)
+
+  # If found, add path to cmake variable
+  # ------------------------------------
+  if (HWLOC_hwloc_LIBRARY)
+    get_filename_component(hwloc_lib_path ${HWLOC_hwloc_LIBRARY} PATH)
+    # set cmake variables (respects naming convention)
+    set(HWLOC_LIBRARIES    "${HWLOC_hwloc_LIBRARY}")
+    set(HWLOC_LIBRARY_DIRS "${hwloc_lib_path}")
+  else ()
+    set(HWLOC_LIBRARIES    "HWLOC_LIBRARIES-NOTFOUND")
+    set(HWLOC_LIBRARY_DIRS "HWLOC_LIBRARY_DIRS-NOTFOUND")
+    if(NOT HWLOC_FIND_QUIETLY)
+      message(STATUS "Looking for hwloc -- lib hwloc not found")
+    endif()
+  endif ()
+
+  if (HWLOC_LIBRARY_DIRS)
+    list(REMOVE_DUPLICATES HWLOC_LIBRARY_DIRS)
+  endif ()
+
+  # check a function to validate the find
+  if(HWLOC_LIBRARIES)
+
+    set(REQUIRED_INCDIRS)
+    set(REQUIRED_LIBDIRS)
+    set(REQUIRED_LIBS)
+
+    # HWLOC
+    if (HWLOC_INCLUDE_DIRS)
+      set(REQUIRED_INCDIRS "${HWLOC_INCLUDE_DIRS}")
+    endif()
+    if (HWLOC_LIBRARY_DIRS)
+      set(REQUIRED_LIBDIRS "${HWLOC_LIBRARY_DIRS}")
+    endif()
+    set(REQUIRED_LIBS "${HWLOC_LIBRARIES}")
+
+    # set required libraries for link
+    set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
+    set(CMAKE_REQUIRED_LIBRARIES)
+    foreach(lib_dir ${REQUIRED_LIBDIRS})
+      list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
+    endforeach()
+    list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
+    string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
+
+    # test link
+    unset(HWLOC_WORKS CACHE)
+    include(CheckFunctionExists)
+    check_function_exists(hwloc_topology_init HWLOC_WORKS)
+    mark_as_advanced(HWLOC_WORKS)
+
+    if(NOT HWLOC_WORKS)
+      if(NOT HWLOC_FIND_QUIETLY)
+	message(STATUS "Looking for hwloc : test of hwloc_topology_init with hwloc library fails")
+	message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
+	message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
+	message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
+      endif()
+    endif()
+    set(CMAKE_REQUIRED_INCLUDES)
+    set(CMAKE_REQUIRED_FLAGS)
+    set(CMAKE_REQUIRED_LIBRARIES)
+  endif(HWLOC_LIBRARIES)
+
+endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT HWLOC_FOUND) OR (HWLOC_GIVEN_BY_USER) )
+
+if (HWLOC_LIBRARIES)
+  if (HWLOC_LIBRARY_DIRS)
+    list(GET HWLOC_LIBRARY_DIRS 0 first_lib_path)
+  else()
+    list(GET HWLOC_LIBRARIES 0 first_lib)
+    get_filename_component(first_lib_path "${first_lib}" PATH)
+  endif()
+  if (${first_lib_path} MATCHES "/lib(32|64)?$")
+    string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
+    set(HWLOC_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of HWLOC library" FORCE)
+  else()
+    set(HWLOC_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of HWLOC library" FORCE)
+  endif()
+endif()
+mark_as_advanced(HWLOC_DIR)
+mark_as_advanced(HWLOC_DIR_FOUND)
+
+# check that HWLOC has been found
+# -------------------------------
+include(FindPackageHandleStandardArgs)
+if (PKG_CONFIG_EXECUTABLE AND HWLOC_FOUND)
+  find_package_handle_standard_args(HWLOC DEFAULT_MSG
+    HWLOC_LIBRARIES)
+else()
+  find_package_handle_standard_args(HWLOC DEFAULT_MSG
+    HWLOC_LIBRARIES
+    HWLOC_WORKS)
+endif()
+
+if (HWLOC_FOUND)
+  set(HWLOC_SAVE_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
+  list(APPEND CMAKE_REQUIRED_INCLUDES ${HWLOC_INCLUDE_DIRS})
+
+  # test headers to guess the version
+  check_struct_has_member( "struct hwloc_obj" parent hwloc.h HAVE_HWLOC_PARENT_MEMBER )
+  check_struct_has_member( "struct hwloc_cache_attr_s" size hwloc.h HAVE_HWLOC_CACHE_ATTR )
+  check_c_source_compiles( "#include <hwloc.h>
+	    int main(void) { hwloc_obj_t o; o->type = HWLOC_OBJ_PU; return 0;}" HAVE_HWLOC_OBJ_PU)
+  include(CheckLibraryExists)
+  check_library_exists(${HWLOC_LIBRARIES} hwloc_bitmap_free "" HAVE_HWLOC_BITMAP)
+
+  set(CMAKE_REQUIRED_INCLUDES ${HWLOC_SAVE_CMAKE_REQUIRED_INCLUDES})
+endif()
diff --git a/cmake/FindMetis.cmake b/cmake/FindMetis.cmake
index 6a0ce79..da2f1f1 100644
--- a/cmake/FindMetis.cmake
+++ b/cmake/FindMetis.cmake
@@ -1,59 +1,264 @@
-# Pastix requires METIS or METIS (partitioning and reordering tools)
+###
+#
+# @copyright (c) 2009-2014 The University of Tennessee and The University
+#                          of Tennessee Research Foundation.
+#                          All rights reserved.
+# @copyright (c) 2012-2014 Inria. All rights reserved.
+# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
+#
+###
+#
+# - Find METIS include dirs and libraries
+# Use this module by invoking find_package with the form:
+#  find_package(METIS
+#               [REQUIRED]             # Fail with error if metis is not found
+#              )
+#
+# This module finds headers and metis library.
+# Results are reported in variables:
+#  METIS_FOUND           - True if headers and requested libraries were found
+#  METIS_INCLUDE_DIRS    - metis include directories
+#  METIS_LIBRARY_DIRS    - Link directories for metis libraries
+#  METIS_LIBRARIES       - metis component libraries to be linked
+#
+# The user can give specific paths where to find the libraries adding cmake
+# options at configure (ex: cmake path/to/project -DMETIS_DIR=path/to/metis):
+#  METIS_DIR             - Where to find the base directory of metis
+#  METIS_INCDIR          - Where to find the header files
+#  METIS_LIBDIR          - Where to find the library files
+# The module can also look for the following environment variables if paths
+# are not given as cmake variable: METIS_DIR, METIS_INCDIR, METIS_LIBDIR
 
-if (METIS_INCLUDES AND METIS_LIBRARIES)
-  set(METIS_FIND_QUIETLY TRUE)
-endif (METIS_INCLUDES AND METIS_LIBRARIES)
+#=============================================================================
+# Copyright 2012-2013 Inria
+# Copyright 2012-2013 Emmanuel Agullo
+# Copyright 2012-2013 Mathieu Faverge
+# Copyright 2012      Cedric Castagnede
+# Copyright 2013      Florent Pruvost
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file MORSE-Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of Morse, substitute the full
+#  License text for the above reference.)
 
-find_path(METIS_INCLUDES 
-  NAMES 
-  metis.h 
-  PATHS 
-  $ENV{METISDIR} 
-  ${INCLUDE_INSTALL_DIR} 
-  PATH_SUFFIXES
-  .
-  metis
-  include
-)
-
-macro(_metis_check_version)
-  file(READ "${METIS_INCLUDES}/metis.h" _metis_version_header)
-
-  string(REGEX MATCH "define[ \t]+METIS_VER_MAJOR[ \t]+([0-9]+)" _metis_major_version_match "${_metis_version_header}")
-  set(METIS_MAJOR_VERSION "${CMAKE_MATCH_1}")
-  string(REGEX MATCH "define[ \t]+METIS_VER_MINOR[ \t]+([0-9]+)" _metis_minor_version_match "${_metis_version_header}")
-  set(METIS_MINOR_VERSION "${CMAKE_MATCH_1}")
-  string(REGEX MATCH "define[ \t]+METIS_VER_SUBMINOR[ \t]+([0-9]+)" _metis_subminor_version_match "${_metis_version_header}")
-  set(METIS_SUBMINOR_VERSION "${CMAKE_MATCH_1}")
-  if(NOT METIS_MAJOR_VERSION)
-    message(STATUS "Could not determine Metis version. Assuming version 4.0.0")
-    set(METIS_VERSION 4.0.0)
-  else()
-    set(METIS_VERSION ${METIS_MAJOR_VERSION}.${METIS_MINOR_VERSION}.${METIS_SUBMINOR_VERSION})
+if (NOT METIS_FOUND)
+  set(METIS_DIR "" CACHE PATH "Installation directory of METIS library")
+  if (NOT METIS_FIND_QUIETLY)
+    message(STATUS "A cache variable, namely METIS_DIR, has been set to specify the install directory of METIS")
   endif()
-  if(${METIS_VERSION} VERSION_LESS ${Metis_FIND_VERSION})
-    set(METIS_VERSION_OK FALSE)
+endif()
+
+# Looking for include
+# -------------------
+
+# Add system include paths to search include
+# ------------------------------------------
+unset(_inc_env)
+set(ENV_METIS_DIR "$ENV{METIS_DIR}")
+set(ENV_METIS_INCDIR "$ENV{METIS_INCDIR}")
+if(ENV_METIS_INCDIR)
+  list(APPEND _inc_env "${ENV_METIS_INCDIR}")
+elseif(ENV_METIS_DIR)
+  list(APPEND _inc_env "${ENV_METIS_DIR}")
+  list(APPEND _inc_env "${ENV_METIS_DIR}/include")
+  list(APPEND _inc_env "${ENV_METIS_DIR}/include/metis")
+else()
+  if(WIN32)
+    string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
   else()
-    set(METIS_VERSION_OK TRUE)
+    string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
+    list(APPEND _inc_env "${_path_env}")
+  endif()
+endif()
+list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
+list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
+list(REMOVE_DUPLICATES _inc_env)
+
+
+# Try to find the metis header in the given paths
+# -------------------------------------------------
+# call cmake macro to find the header path
+if(METIS_INCDIR)
+  set(METIS_metis.h_DIRS "METIS_metis.h_DIRS-NOTFOUND")
+  find_path(METIS_metis.h_DIRS
+    NAMES metis.h
+    HINTS ${METIS_INCDIR})
+else()
+  if(METIS_DIR)
+    set(METIS_metis.h_DIRS "METIS_metis.h_DIRS-NOTFOUND")
+    find_path(METIS_metis.h_DIRS
+      NAMES metis.h
+      HINTS ${METIS_DIR}
+      PATH_SUFFIXES "include" "include/metis")
+  else()
+    set(METIS_metis.h_DIRS "METIS_metis.h_DIRS-NOTFOUND")
+    find_path(METIS_metis.h_DIRS
+      NAMES metis.h
+      HINTS ${_inc_env})
+  endif()
+endif()
+mark_as_advanced(METIS_metis.h_DIRS)
+
+
+# If found, add path to cmake variable
+# ------------------------------------
+if (METIS_metis.h_DIRS)
+  set(METIS_INCLUDE_DIRS "${METIS_metis.h_DIRS}")
+else ()
+  set(METIS_INCLUDE_DIRS "METIS_INCLUDE_DIRS-NOTFOUND")
+  if(NOT METIS_FIND_QUIETLY)
+    message(STATUS "Looking for metis -- metis.h not found")
+  endif()
+endif()
+
+
+# Looking for lib
+# ---------------
+
+# Add system library paths to search lib
+# --------------------------------------
+unset(_lib_env)
+set(ENV_METIS_LIBDIR "$ENV{METIS_LIBDIR}")
+if(ENV_METIS_LIBDIR)
+  list(APPEND _lib_env "${ENV_METIS_LIBDIR}")
+elseif(ENV_METIS_DIR)
+  list(APPEND _lib_env "${ENV_METIS_DIR}")
+  list(APPEND _lib_env "${ENV_METIS_DIR}/lib")
+else()
+  if(WIN32)
+    string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
+  else()
+    if(APPLE)
+      string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
+    else()
+      string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
+    endif()
+    list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
+    list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
+  endif()
+endif()
+list(REMOVE_DUPLICATES _lib_env)
+
+# Try to find the metis lib in the given paths
+# ----------------------------------------------
+# call cmake macro to find the lib path
+if(METIS_LIBDIR)
+  set(METIS_metis_LIBRARY "METIS_metis_LIBRARY-NOTFOUND")
+  find_library(METIS_metis_LIBRARY
+    NAMES metis
+    HINTS ${METIS_LIBDIR})
+else()
+  if(METIS_DIR)
+    set(METIS_metis_LIBRARY "METIS_metis_LIBRARY-NOTFOUND")
+    find_library(METIS_metis_LIBRARY
+      NAMES metis
+      HINTS ${METIS_DIR}
+      PATH_SUFFIXES lib lib32 lib64)
+  else()
+    set(METIS_metis_LIBRARY "METIS_metis_LIBRARY-NOTFOUND")
+    find_library(METIS_metis_LIBRARY
+      NAMES metis
+      HINTS ${_lib_env})
+  endif()
+endif()
+mark_as_advanced(METIS_metis_LIBRARY)
+
+
+# If found, add path to cmake variable
+# ------------------------------------
+if (METIS_metis_LIBRARY)
+  get_filename_component(metis_lib_path "${METIS_metis_LIBRARY}" PATH)
+  # set cmake variables
+  set(METIS_LIBRARIES    "${METIS_metis_LIBRARY}")
+  set(METIS_LIBRARY_DIRS "${metis_lib_path}")
+else ()
+  set(METIS_LIBRARIES    "METIS_LIBRARIES-NOTFOUND")
+  set(METIS_LIBRARY_DIRS "METIS_LIBRARY_DIRS-NOTFOUND")
+  if(NOT METIS_FIND_QUIETLY)
+    message(STATUS "Looking for metis -- lib metis not found")
+  endif()
+endif ()
+
+# check a function to validate the find
+if(METIS_LIBRARIES)
+
+  set(REQUIRED_INCDIRS)
+  set(REQUIRED_LIBDIRS)
+  set(REQUIRED_LIBS)
+
+  # METIS
+  if (METIS_INCLUDE_DIRS)
+    set(REQUIRED_INCDIRS  "${METIS_INCLUDE_DIRS}")
+  endif()
+  if (METIS_LIBRARY_DIRS)
+    set(REQUIRED_LIBDIRS "${METIS_LIBRARY_DIRS}")
+  endif()
+  set(REQUIRED_LIBS "${METIS_LIBRARIES}")
+  # m
+  find_library(M_LIBRARY NAMES m)
+  mark_as_advanced(M_LIBRARY)
+  if(M_LIBRARY)
+    list(APPEND REQUIRED_LIBS "-lm")
   endif()
 
-  if(NOT METIS_VERSION_OK)
-    message(STATUS "Metis version ${METIS_VERSION} found in ${METIS_INCLUDES}, "
-                   "but at least version ${Metis_FIND_VERSION} is required")
-  endif(NOT METIS_VERSION_OK)
-endmacro(_metis_check_version)
+  # set required libraries for link
+  set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
+  set(CMAKE_REQUIRED_LIBRARIES)
+  foreach(lib_dir ${REQUIRED_LIBDIRS})
+    list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
+  endforeach()
+  list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
+  string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
 
-  if(METIS_INCLUDES AND Metis_FIND_VERSION)
-    _metis_check_version()
-  else()
-    set(METIS_VERSION_OK TRUE)
+  # test link
+  unset(METIS_WORKS CACHE)
+  include(CheckFunctionExists)
+  check_function_exists(METIS_NodeND METIS_WORKS)
+  mark_as_advanced(METIS_WORKS)
+
+  if(NOT METIS_WORKS)
+    if(NOT METIS_FIND_QUIETLY)
+      message(STATUS "Looking for METIS : test of METIS_NodeND with METIS library fails")
+      message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
+      message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
+      message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
+    endif()
   endif()
+  set(CMAKE_REQUIRED_INCLUDES)
+  set(CMAKE_REQUIRED_FLAGS)
+  set(CMAKE_REQUIRED_LIBRARIES)
+endif(METIS_LIBRARIES)
 
+if (METIS_LIBRARIES)
+  list(GET METIS_LIBRARIES 0 first_lib)
+  get_filename_component(first_lib_path "${first_lib}" PATH)
+  if (${first_lib_path} MATCHES "/lib(32|64)?$")
+    string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
+    set(METIS_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of METIS library" FORCE)
+  else()
+    set(METIS_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of METIS library" FORCE)
+  endif()
+endif()
+mark_as_advanced(METIS_DIR)
+mark_as_advanced(METIS_DIR_FOUND)
 
-find_library(METIS_LIBRARIES metis PATHS $ENV{METISDIR} ${LIB_INSTALL_DIR} PATH_SUFFIXES lib)
-
+# check that METIS has been found
+# ---------------------------------
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(METIS DEFAULT_MSG
-                                  METIS_INCLUDES METIS_LIBRARIES METIS_VERSION_OK)
-
-mark_as_advanced(METIS_INCLUDES METIS_LIBRARIES)
+  METIS_LIBRARIES
+  METIS_WORKS)
+#
+# TODO: Add possibility to check for specific functions in the library
+#
diff --git a/cmake/FindPTSCOTCH.cmake b/cmake/FindPTSCOTCH.cmake
new file mode 100644
index 0000000..1396d05
--- /dev/null
+++ b/cmake/FindPTSCOTCH.cmake
@@ -0,0 +1,423 @@
+###
+#
+# @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-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
+#
+###
+#
+# - Find PTSCOTCH include dirs and libraries
+# Use this module by invoking find_package with the form:
+#  find_package(PTSCOTCH
+#               [REQUIRED]             # Fail with error if ptscotch is not found
+#               [COMPONENTS <comp1> <comp2> ...] # dependencies
+#              )
+#
+#  PTSCOTCH depends on the following libraries:
+#   - Threads
+#   - MPI
+#
+#  COMPONENTS can be some of the following:
+#   - ESMUMPS: to activate detection of PT-Scotch with the esmumps interface
+#
+# This module finds headers and ptscotch library.
+# Results are reported in variables:
+#  PTSCOTCH_FOUND            - True if headers and requested libraries were found
+#  PTSCOTCH_LINKER_FLAGS     - list of required linker flags (excluding -l and -L)
+#  PTSCOTCH_INCLUDE_DIRS     - ptscotch include directories
+#  PTSCOTCH_LIBRARY_DIRS     - Link directories for ptscotch libraries
+#  PTSCOTCH_LIBRARIES        - ptscotch component libraries to be linked
+#  PTSCOTCH_INCLUDE_DIRS_DEP - ptscotch + dependencies include directories
+#  PTSCOTCH_LIBRARY_DIRS_DEP - ptscotch + dependencies link directories
+#  PTSCOTCH_LIBRARIES_DEP    - ptscotch libraries + dependencies
+#  PTSCOTCH_INTSIZE          - Number of octets occupied by a SCOTCH_Num
+#
+# The user can give specific paths where to find the libraries adding cmake
+# options at configure (ex: cmake path/to/project -DPTSCOTCH=path/to/ptscotch):
+#  PTSCOTCH_DIR              - Where to find the base directory of ptscotch
+#  PTSCOTCH_INCDIR           - Where to find the header files
+#  PTSCOTCH_LIBDIR           - Where to find the library files
+# The module can also look for the following environment variables if paths
+# are not given as cmake variable: PTSCOTCH_DIR, PTSCOTCH_INCDIR, PTSCOTCH_LIBDIR
+
+#=============================================================================
+# Copyright 2012-2013 Inria
+# Copyright 2012-2013 Emmanuel Agullo
+# Copyright 2012-2013 Mathieu Faverge
+# Copyright 2012      Cedric Castagnede
+# Copyright 2013-2016 Florent Pruvost
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file MORSE-Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of Morse, substitute the full
+#  License text for the above reference.)
+
+if (NOT PTSCOTCH_FOUND)
+  set(PTSCOTCH_DIR "" CACHE PATH "Installation directory of PTSCOTCH library")
+  if (NOT PTSCOTCH_FIND_QUIETLY)
+    message(STATUS "A cache variable, namely PTSCOTCH_DIR, has been set to specify the install directory of PTSCOTCH")
+  endif()
+endif()
+
+# Set the version to find
+set(PTSCOTCH_LOOK_FOR_ESMUMPS OFF)
+
+if( PTSCOTCH_FIND_COMPONENTS )
+  foreach( component ${PTSCOTCH_FIND_COMPONENTS} )
+    if (${component} STREQUAL "ESMUMPS")
+      # means we look for esmumps library
+      set(PTSCOTCH_LOOK_FOR_ESMUMPS ON)
+    endif()
+  endforeach()
+endif()
+
+# PTSCOTCH depends on Threads, try to find it
+if (NOT THREADS_FOUND)
+  if (PTSCOTCH_FIND_REQUIRED)
+    find_package(Threads REQUIRED)
+  else()
+    find_package(Threads)
+  endif()
+endif()
+
+# PTSCOTCH depends on MPI, try to find it
+if (NOT MPI_FOUND)
+  if (PTSCOTCH_FIND_REQUIRED)
+    find_package(MPI REQUIRED)
+  else()
+    find_package(MPI)
+  endif()
+endif()
+
+# Looking for include
+# -------------------
+
+# Add system include paths to search include
+# ------------------------------------------
+unset(_inc_env)
+set(ENV_PTSCOTCH_DIR "$ENV{PTSCOTCH_DIR}")
+set(ENV_PTSCOTCH_INCDIR "$ENV{PTSCOTCH_INCDIR}")
+if(ENV_PTSCOTCH_INCDIR)
+  list(APPEND _inc_env "${ENV_PTSCOTCH_INCDIR}")
+elseif(ENV_PTSCOTCH_DIR)
+  list(APPEND _inc_env "${ENV_PTSCOTCH_DIR}")
+  list(APPEND _inc_env "${ENV_PTSCOTCH_DIR}/include")
+  list(APPEND _inc_env "${ENV_PTSCOTCH_DIR}/include/ptscotch")
+else()
+  if(WIN32)
+    string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
+  else()
+    string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
+    list(APPEND _inc_env "${_path_env}")
+  endif()
+endif()
+list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
+list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
+list(REMOVE_DUPLICATES _inc_env)
+
+
+# Try to find the ptscotch header in the given paths
+# -------------------------------------------------
+
+set(PTSCOTCH_hdrs_to_find "ptscotch.h;scotch.h")
+
+# call cmake macro to find the header path
+if(PTSCOTCH_INCDIR)
+  foreach(ptscotch_hdr ${PTSCOTCH_hdrs_to_find})
+    set(PTSCOTCH_${ptscotch_hdr}_DIRS "PTSCOTCH_${ptscotch_hdr}_DIRS-NOTFOUND")
+    find_path(PTSCOTCH_${ptscotch_hdr}_DIRS
+      NAMES ${ptscotch_hdr}
+      HINTS ${PTSCOTCH_INCDIR})
+    mark_as_advanced(PTSCOTCH_${ptscotch_hdr}_DIRS)
+  endforeach()
+else()
+  if(PTSCOTCH_DIR)
+    foreach(ptscotch_hdr ${PTSCOTCH_hdrs_to_find})
+      set(PTSCOTCH_${ptscotch_hdr}_DIRS "PTSCOTCH_${ptscotch_hdr}_DIRS-NOTFOUND")
+      find_path(PTSCOTCH_${ptscotch_hdr}_DIRS
+	NAMES ${ptscotch_hdr}
+	HINTS ${PTSCOTCH_DIR}
+	PATH_SUFFIXES "include" "include/scotch")
+      mark_as_advanced(PTSCOTCH_${ptscotch_hdr}_DIRS)
+    endforeach()
+  else()
+    foreach(ptscotch_hdr ${PTSCOTCH_hdrs_to_find})
+      set(PTSCOTCH_${ptscotch_hdr}_DIRS "PTSCOTCH_${ptscotch_hdr}_DIRS-NOTFOUND")
+      find_path(PTSCOTCH_${ptscotch_hdr}_DIRS
+	NAMES ${ptscotch_hdr}
+	HINTS ${_inc_env}
+	PATH_SUFFIXES "scotch")
+      mark_as_advanced(PTSCOTCH_${ptscotch_hdr}_DIRS)
+    endforeach()
+  endif()
+endif()
+
+# If found, add path to cmake variable
+# ------------------------------------
+foreach(ptscotch_hdr ${PTSCOTCH_hdrs_to_find})
+  if (PTSCOTCH_${ptscotch_hdr}_DIRS)
+    list(APPEND PTSCOTCH_INCLUDE_DIRS "${PTSCOTCH_${ptscotch_hdr}_DIRS}")
+  else ()
+    set(PTSCOTCH_INCLUDE_DIRS "PTSCOTCH_INCLUDE_DIRS-NOTFOUND")
+    if (NOT PTSCOTCH_FIND_QUIETLY)
+      message(STATUS "Looking for ptscotch -- ${ptscotch_hdr} not found")
+    endif()
+  endif()
+endforeach()
+list(REMOVE_DUPLICATES PTSCOTCH_INCLUDE_DIRS)
+
+# Looking for lib
+# ---------------
+
+# Add system library paths to search lib
+# --------------------------------------
+unset(_lib_env)
+set(ENV_PTSCOTCH_LIBDIR "$ENV{PTSCOTCH_LIBDIR}")
+if(ENV_PTSCOTCH_LIBDIR)
+  list(APPEND _lib_env "${ENV_PTSCOTCH_LIBDIR}")
+elseif(ENV_PTSCOTCH_DIR)
+  list(APPEND _lib_env "${ENV_PTSCOTCH_DIR}")
+  list(APPEND _lib_env "${ENV_PTSCOTCH_DIR}/lib")
+else()
+  if(WIN32)
+    string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
+  else()
+    if(APPLE)
+      string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
+    else()
+      string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
+    endif()
+    list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
+    list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
+  endif()
+endif()
+list(REMOVE_DUPLICATES _lib_env)
+
+# Try to find the ptscotch lib in the given paths
+# ----------------------------------------------
+
+set(PTSCOTCH_libs_to_find "ptscotch;ptscotcherr")
+if (PTSCOTCH_LOOK_FOR_ESMUMPS)
+  list(INSERT PTSCOTCH_libs_to_find 0 "ptesmumps")
+  list(APPEND PTSCOTCH_libs_to_find   "esmumps"  )
+endif()
+list(APPEND PTSCOTCH_libs_to_find "scotch;scotcherr")
+
+# call cmake macro to find the lib path
+if(PTSCOTCH_LIBDIR)
+  foreach(ptscotch_lib ${PTSCOTCH_libs_to_find})
+    set(PTSCOTCH_${ptscotch_lib}_LIBRARY "PTSCOTCH_${ptscotch_lib}_LIBRARY-NOTFOUND")
+    find_library(PTSCOTCH_${ptscotch_lib}_LIBRARY
+      NAMES ${ptscotch_lib}
+      HINTS ${PTSCOTCH_LIBDIR})
+  endforeach()
+else()
+  if(PTSCOTCH_DIR)
+    foreach(ptscotch_lib ${PTSCOTCH_libs_to_find})
+      set(PTSCOTCH_${ptscotch_lib}_LIBRARY "PTSCOTCH_${ptscotch_lib}_LIBRARY-NOTFOUND")
+      find_library(PTSCOTCH_${ptscotch_lib}_LIBRARY
+	NAMES ${ptscotch_lib}
+	HINTS ${PTSCOTCH_DIR}
+	PATH_SUFFIXES lib lib32 lib64)
+    endforeach()
+  else()
+    foreach(ptscotch_lib ${PTSCOTCH_libs_to_find})
+      set(PTSCOTCH_${ptscotch_lib}_LIBRARY "PTSCOTCH_${ptscotch_lib}_LIBRARY-NOTFOUND")
+      find_library(PTSCOTCH_${ptscotch_lib}_LIBRARY
+	NAMES ${ptscotch_lib}
+	HINTS ${_lib_env})
+    endforeach()
+  endif()
+endif()
+
+set(PTSCOTCH_LIBRARIES "")
+set(PTSCOTCH_LIBRARY_DIRS "")
+# If found, add path to cmake variable
+# ------------------------------------
+foreach(ptscotch_lib ${PTSCOTCH_libs_to_find})
+
+  if (PTSCOTCH_${ptscotch_lib}_LIBRARY)
+    get_filename_component(${ptscotch_lib}_lib_path "${PTSCOTCH_${ptscotch_lib}_LIBRARY}" PATH)
+    # set cmake variables
+    list(APPEND PTSCOTCH_LIBRARIES "${PTSCOTCH_${ptscotch_lib}_LIBRARY}")
+    list(APPEND PTSCOTCH_LIBRARY_DIRS "${${ptscotch_lib}_lib_path}")
+  else ()
+    list(APPEND PTSCOTCH_LIBRARIES "${PTSCOTCH_${ptscotch_lib}_LIBRARY}")
+    if (NOT PTSCOTCH_FIND_QUIETLY)
+      message(STATUS "Looking for ptscotch -- lib ${ptscotch_lib} not found")
+    endif()
+  endif ()
+
+  mark_as_advanced(PTSCOTCH_${ptscotch_lib}_LIBRARY)
+
+endforeach()
+list(REMOVE_DUPLICATES PTSCOTCH_LIBRARY_DIRS)
+
+# check a function to validate the find
+if(PTSCOTCH_LIBRARIES)
+
+  set(REQUIRED_LDFLAGS)
+  set(REQUIRED_INCDIRS)
+  set(REQUIRED_LIBDIRS)
+  set(REQUIRED_LIBS)
+
+  # PTSCOTCH
+  if (PTSCOTCH_INCLUDE_DIRS)
+    set(REQUIRED_INCDIRS  "${PTSCOTCH_INCLUDE_DIRS}")
+  endif()
+  if (PTSCOTCH_LIBRARY_DIRS)
+    set(REQUIRED_LIBDIRS "${PTSCOTCH_LIBRARY_DIRS}")
+  endif()
+  set(REQUIRED_LIBS "${PTSCOTCH_LIBRARIES}")
+  # MPI
+  if (MPI_FOUND)
+    if (MPI_C_INCLUDE_PATH)
+      list(APPEND CMAKE_REQUIRED_INCLUDES "${MPI_C_INCLUDE_PATH}")
+    endif()
+    if (MPI_C_LINK_FLAGS)
+      if (${MPI_C_LINK_FLAGS} MATCHES "  -")
+	string(REGEX REPLACE " -" "-" MPI_C_LINK_FLAGS ${MPI_C_LINK_FLAGS})
+      endif()
+      list(APPEND REQUIRED_LDFLAGS "${MPI_C_LINK_FLAGS}")
+    endif()
+    list(APPEND REQUIRED_LIBS "${MPI_C_LIBRARIES}")
+  endif()
+  # THREADS
+  if(CMAKE_THREAD_LIBS_INIT)
+    list(APPEND REQUIRED_LIBS "${CMAKE_THREAD_LIBS_INIT}")
+  endif()
+  set(Z_LIBRARY "Z_LIBRARY-NOTFOUND")
+  find_library(Z_LIBRARY NAMES z)
+  mark_as_advanced(Z_LIBRARY)
+  if(Z_LIBRARY)
+    list(APPEND REQUIRED_LIBS "-lz")
+  endif()
+  set(M_LIBRARY "M_LIBRARY-NOTFOUND")
+  find_library(M_LIBRARY NAMES m)
+  mark_as_advanced(M_LIBRARY)
+  if(M_LIBRARY)
+    list(APPEND REQUIRED_LIBS "-lm")
+  endif()
+  set(RT_LIBRARY "RT_LIBRARY-NOTFOUND")
+  find_library(RT_LIBRARY NAMES rt)
+  mark_as_advanced(RT_LIBRARY)
+  if(RT_LIBRARY)
+    list(APPEND REQUIRED_LIBS "-lrt")
+  endif()
+
+  # set required libraries for link
+  set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
+  set(CMAKE_REQUIRED_LIBRARIES)
+  list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}")
+  foreach(lib_dir ${REQUIRED_LIBDIRS})
+    list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
+  endforeach()
+  list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
+  list(APPEND CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}")
+  string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
+
+  # test link
+  unset(PTSCOTCH_WORKS CACHE)
+  include(CheckFunctionExists)
+  check_function_exists(SCOTCH_dgraphInit PTSCOTCH_WORKS)
+  mark_as_advanced(PTSCOTCH_WORKS)
+
+  if(PTSCOTCH_WORKS)
+    # save link with dependencies
+    set(PTSCOTCH_LIBRARIES_DEP "${REQUIRED_LIBS}")
+    set(PTSCOTCH_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
+    set(PTSCOTCH_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+    set(PTSCOTCH_LINKER_FLAGS "${REQUIRED_LDFLAGS}")
+    list(REMOVE_DUPLICATES PTSCOTCH_LIBRARY_DIRS_DEP)
+    list(REMOVE_DUPLICATES PTSCOTCH_INCLUDE_DIRS_DEP)
+    list(REMOVE_DUPLICATES PTSCOTCH_LINKER_FLAGS)
+  else()
+    if(NOT PTSCOTCH_FIND_QUIETLY)
+      message(STATUS "Looking for PTSCOTCH : test of SCOTCH_dgraphInit with PTSCOTCH library fails")
+      message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
+      message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
+      message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
+    endif()
+  endif()
+  set(CMAKE_REQUIRED_INCLUDES)
+  set(CMAKE_REQUIRED_FLAGS)
+  set(CMAKE_REQUIRED_LIBRARIES)
+endif(PTSCOTCH_LIBRARIES)
+
+if (PTSCOTCH_LIBRARIES)
+  list(GET PTSCOTCH_LIBRARIES 0 first_lib)
+  get_filename_component(first_lib_path "${first_lib}" PATH)
+  if (${first_lib_path} MATCHES "/lib(32|64)?$")
+    string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
+    set(PTSCOTCH_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of PTSCOTCH library" FORCE)
+  else()
+    set(PTSCOTCH_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of PTSCOTCH library" FORCE)
+  endif()
+endif()
+mark_as_advanced(PTSCOTCH_DIR)
+mark_as_advanced(PTSCOTCH_DIR_FOUND)
+
+# Check the size of SCOTCH_Num
+# ---------------------------------
+set(CMAKE_REQUIRED_INCLUDES ${PTSCOTCH_INCLUDE_DIRS})
+
+include(CheckCSourceRuns)
+#stdio.h and stdint.h should be included by scotch.h directly
+set(PTSCOTCH_C_TEST_SCOTCH_Num_4 "
+#include <stdio.h>
+#include <stdint.h>
+#include <ptscotch.h>
+int main(int argc, char **argv) {
+  if (sizeof(SCOTCH_Num) == 4)
+    return 0;
+  else
+    return 1;
+}
+")
+
+set(PTSCOTCH_C_TEST_SCOTCH_Num_8 "
+#include <stdio.h>
+#include <stdint.h>
+#include <ptscotch.h>
+int main(int argc, char **argv) {
+  if (sizeof(SCOTCH_Num) == 8)
+    return 0;
+  else
+    return 1;
+}
+")
+check_c_source_runs("${PTSCOTCH_C_TEST_SCOTCH_Num_4}" PTSCOTCH_Num_4)
+if(NOT PTSCOTCH_Num_4)
+  check_c_source_runs("${PTSCOTCH_C_TEST_SCOTCH_Num_8}" PTSCOTCH_Num_8)
+  if(NOT PTSCOTCH_Num_8)
+    set(PTSCOTCH_INTSIZE -1)
+  else()
+    set(PTSCOTCH_INTSIZE 8)
+  endif()
+else()
+  set(PTSCOTCH_INTSIZE 4)
+endif()
+set(CMAKE_REQUIRED_INCLUDES "")
+
+# check that PTSCOTCH has been found
+# ---------------------------------
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(PTSCOTCH DEFAULT_MSG
+  PTSCOTCH_LIBRARIES
+  PTSCOTCH_WORKS)
+#
+# TODO: Add possibility to check for specific functions in the library
+#
diff --git a/cmake/FindPastix.cmake b/cmake/FindPastix.cmake
index e2e6c81..470477f 100644
--- a/cmake/FindPastix.cmake
+++ b/cmake/FindPastix.cmake
@@ -1,25 +1,704 @@
-# Pastix lib requires linking to a blas library.
-# It is up to the user of this module to find a BLAS and link to it.
-# Pastix requires SCOTCH or METIS (partitioning and reordering tools) as well
+###
+#
+# @copyright (c) 2009-2014 The University of Tennessee and The University
+#                          of Tennessee Research Foundation.
+#                          All rights reserved.
+# @copyright (c) 2012-2014 Inria. All rights reserved.
+# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
+#
+###
+#
+# - Find PASTIX include dirs and libraries
+# Use this module by invoking find_package with the form:
+#  find_package(PASTIX
+#               [REQUIRED] # Fail with error if pastix is not found
+#               [COMPONENTS <comp1> <comp2> ...] # dependencies
+#              )
+#
+#  PASTIX depends on the following libraries:
+#   - Threads, m, rt
+#   - MPI
+#   - HWLOC
+#   - BLAS
+#
+#  COMPONENTS are optional libraries PASTIX could be linked with,
+#  Use it to drive detection of a specific compilation chain
+#  COMPONENTS can be some of the following:
+#   - MPI: to activate detection of the parallel MPI version (default)
+#        it looks for Threads, HWLOC, BLAS, MPI and ScaLAPACK libraries
+#   - SEQ: to activate detection of the sequential version (exclude MPI version)
+#   - STARPU: to activate detection of StarPU version
+#   it looks for MPI version of StarPU (default behaviour)
+#   if SEQ and STARPU are given, it looks for a StarPU without MPI
+#   - STARPU_CUDA: to activate detection of StarPU with CUDA
+#   - STARPU_FXT: to activate detection of StarPU with FxT
+#   - SCOTCH: to activate detection of PASTIX linked with SCOTCH
+#   - PTSCOTCH: to activate detection of PASTIX linked with SCOTCH
+#   - METIS: to activate detection of PASTIX linked with SCOTCH
+#
+# This module finds headers and pastix library.
+# Results are reported in variables:
+#  PASTIX_FOUND            - True if headers and requested libraries were found
+#  PASTIX_LINKER_FLAGS     - list of required linker flags (excluding -l and -L)
+#  PASTIX_INCLUDE_DIRS     - pastix include directories
+#  PASTIX_LIBRARY_DIRS     - Link directories for pastix libraries
+#  PASTIX_LIBRARIES        - pastix libraries
+#  PASTIX_INCLUDE_DIRS_DEP - pastix + dependencies include directories
+#  PASTIX_LIBRARY_DIRS_DEP - pastix + dependencies link directories
+#  PASTIX_LIBRARIES_DEP    - pastix libraries + dependencies
+#
+# The user can give specific paths where to find the libraries adding cmake
+# options at configure (ex: cmake path/to/project -DPASTIX_DIR=path/to/pastix):
+#  PASTIX_DIR              - Where to find the base directory of pastix
+#  PASTIX_INCDIR           - Where to find the header files
+#  PASTIX_LIBDIR           - Where to find the library files
+# The module can also look for the following environment variables if paths
+# are not given as cmake variable: PASTIX_DIR, PASTIX_INCDIR, PASTIX_LIBDIR
 
-if (PASTIX_INCLUDES AND PASTIX_LIBRARIES)
-  set(PASTIX_FIND_QUIETLY TRUE)
-endif (PASTIX_INCLUDES AND PASTIX_LIBRARIES)
-
-find_path(PASTIX_INCLUDES
-  NAMES
-  pastix_nompi.h
-  PATHS
-  $ENV{PASTIXDIR}
-  ${INCLUDE_INSTALL_DIR}
-)
-
-find_library(PASTIX_LIBRARIES pastix PATHS $ENV{PASTIXDIR} ${LIB_INSTALL_DIR})
+#=============================================================================
+# Copyright 2012-2013 Inria
+# Copyright 2012-2013 Emmanuel Agullo
+# Copyright 2012-2013 Mathieu Faverge
+# Copyright 2012      Cedric Castagnede
+# Copyright 2013      Florent Pruvost
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file MORSE-Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of Morse, substitute the full
+#  License text for the above reference.)
 
 
+if (NOT PASTIX_FOUND)
+  set(PASTIX_DIR "" CACHE PATH "Installation directory of PASTIX library")
+  if (NOT PASTIX_FIND_QUIETLY)
+    message(STATUS "A cache variable, namely PASTIX_DIR, has been set to specify the install directory of PASTIX")
+  endif()
+endif()
 
+# Set the version to find
+set(PASTIX_LOOK_FOR_MPI ON)
+set(PASTIX_LOOK_FOR_SEQ OFF)
+set(PASTIX_LOOK_FOR_STARPU OFF)
+set(PASTIX_LOOK_FOR_STARPU_CUDA OFF)
+set(PASTIX_LOOK_FOR_STARPU_FXT OFF)
+set(PASTIX_LOOK_FOR_SCOTCH ON)
+set(PASTIX_LOOK_FOR_PTSCOTCH OFF)
+set(PASTIX_LOOK_FOR_METIS OFF)
+
+if( PASTIX_FIND_COMPONENTS )
+  foreach( component ${PASTIX_FIND_COMPONENTS} )
+    if (${component} STREQUAL "SEQ")
+      # means we look for the sequential version of PaStiX (without MPI)
+      set(PASTIX_LOOK_FOR_SEQ ON)
+      set(PASTIX_LOOK_FOR_MPI OFF)
+    endif()
+    if (${component} STREQUAL "MPI")
+      # means we look for the MPI version of PaStiX (default)
+      set(PASTIX_LOOK_FOR_SEQ OFF)
+      set(PASTIX_LOOK_FOR_MPI ON)
+    endif()
+    if (${component} STREQUAL "STARPU")
+      # means we look for PaStiX with StarPU
+      set(PASTIX_LOOK_FOR_STARPU ON)
+    endif()
+    if (${component} STREQUAL "STARPU_CUDA")
+      # means we look for PaStiX with StarPU + CUDA
+      set(PASTIX_LOOK_FOR_STARPU ON)
+      set(PASTIX_LOOK_FOR_STARPU_CUDA ON)
+    endif()
+    if (${component} STREQUAL "STARPU_FXT")
+      # means we look for PaStiX with StarPU + FxT
+      set(PASTIX_LOOK_FOR_STARPU_FXT ON)
+    endif()
+    if (${component} STREQUAL "SCOTCH")
+      set(PASTIX_LOOK_FOR_SCOTCH ON)
+    endif()
+    if (${component} STREQUAL "SCOTCH")
+      set(PASTIX_LOOK_FOR_PTSCOTCH ON)
+    endif()
+    if (${component} STREQUAL "METIS")
+      set(PASTIX_LOOK_FOR_METIS ON)
+    endif()
+  endforeach()
+endif()
+
+# Dependencies detection
+# ----------------------
+
+
+# Required dependencies
+# ---------------------
+
+if (NOT PASTIX_FIND_QUIETLY)
+  message(STATUS "Looking for PASTIX - Try to detect pthread")
+endif()
+if (PASTIX_FIND_REQUIRED)
+  find_package(Threads REQUIRED QUIET)
+else()
+  find_package(Threads QUIET)
+endif()
+set(PASTIX_EXTRA_LIBRARIES "")
+if( THREADS_FOUND )
+  list(APPEND PASTIX_EXTRA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
+endif ()
+
+# Add math library to the list of extra
+# it normally exists on all common systems provided with a C compiler
+if (NOT PASTIX_FIND_QUIETLY)
+  message(STATUS "Looking for PASTIX - Try to detect libm")
+endif()
+set(PASTIX_M_LIBRARIES "")
+if(UNIX OR WIN32)
+  find_library(
+    PASTIX_M_m_LIBRARY
+    NAMES m
+    )
+  mark_as_advanced(PASTIX_M_m_LIBRARY)
+  if (PASTIX_M_m_LIBRARY)
+    list(APPEND PASTIX_M_LIBRARIES "${PASTIX_M_m_LIBRARY}")
+    list(APPEND PASTIX_EXTRA_LIBRARIES "${PASTIX_M_m_LIBRARY}")
+  else()
+    if (PASTIX_FIND_REQUIRED)
+      message(FATAL_ERROR "Could NOT find libm on your system."
+	"Are you sure to a have a C compiler installed?")
+    endif()
+  endif()
+endif()
+
+# Try to find librt (libposix4 - POSIX.1b Realtime Extensions library)
+# on Unix systems except Apple ones because it does not exist on it
+if (NOT PASTIX_FIND_QUIETLY)
+  message(STATUS "Looking for PASTIX - Try to detect librt")
+endif()
+set(PASTIX_RT_LIBRARIES "")
+if(UNIX AND NOT APPLE)
+  find_library(
+    PASTIX_RT_rt_LIBRARY
+    NAMES rt
+    )
+  mark_as_advanced(PASTIX_RT_rt_LIBRARY)
+  if (PASTIX_RT_rt_LIBRARY)
+    list(APPEND PASTIX_RT_LIBRARIES "${PASTIX_RT_rt_LIBRARY}")
+    list(APPEND PASTIX_EXTRA_LIBRARIES "${PASTIX_RT_rt_LIBRARY}")
+  else()
+    if (PASTIX_FIND_REQUIRED)
+      message(FATAL_ERROR "Could NOT find librt on your system")
+    endif()
+  endif()
+endif()
+
+# PASTIX depends on HWLOC
+#------------------------
+if (NOT PASTIX_FIND_QUIETLY)
+  message(STATUS "Looking for PASTIX - Try to detect HWLOC")
+endif()
+if (PASTIX_FIND_REQUIRED)
+  find_package(HWLOC REQUIRED QUIET)
+else()
+  find_package(HWLOC QUIET)
+endif()
+
+# PASTIX depends on BLAS
+#-----------------------
+if (NOT PASTIX_FIND_QUIETLY)
+  message(STATUS "Looking for PASTIX - Try to detect BLAS")
+endif()
+if (PASTIX_FIND_REQUIRED)
+  find_package(BLASEXT REQUIRED QUIET)
+else()
+  find_package(BLASEXT QUIET)
+endif()
+
+# Optional dependencies
+# ---------------------
+
+# PASTIX may depend on MPI
+#-------------------------
+if (NOT MPI_FOUND AND PASTIX_LOOK_FOR_MPI)
+  if (NOT PASTIX_FIND_QUIETLY)
+    message(STATUS "Looking for PASTIX - Try to detect MPI")
+  endif()
+  # allows to use an external mpi compilation by setting compilers with
+  # -DMPI_C_COMPILER=path/to/mpicc -DMPI_Fortran_COMPILER=path/to/mpif90
+  # at cmake configure
+  if(NOT MPI_C_COMPILER)
+    set(MPI_C_COMPILER mpicc)
+  endif()
+  if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_MPI)
+    find_package(MPI REQUIRED QUIET)
+  else()
+    find_package(MPI QUIET)
+  endif()
+  if (MPI_FOUND)
+    mark_as_advanced(MPI_LIBRARY)
+    mark_as_advanced(MPI_EXTRA_LIBRARY)
+  endif()
+endif (NOT MPI_FOUND AND PASTIX_LOOK_FOR_MPI)
+
+# PASTIX may depend on STARPU
+#----------------------------
+if( NOT STARPU_FOUND AND PASTIX_LOOK_FOR_STARPU)
+
+  if (NOT PASTIX_FIND_QUIETLY)
+    message(STATUS "Looking for PASTIX - Try to detect StarPU")
+  endif()
+
+  set(PASTIX_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
+
+  # create list of components in order to make a single call to find_package(starpu...)
+  # we explicitly need a StarPU version built with hwloc
+  set(STARPU_COMPONENT_LIST "HWLOC")
+
+  # StarPU may depend on MPI
+  # allows to use an external mpi compilation by setting compilers with
+  # -DMPI_C_COMPILER=path/to/mpicc -DMPI_Fortran_COMPILER=path/to/mpif90
+  # at cmake configure
+  if (PASTIX_LOOK_FOR_MPI)
+    if(NOT MPI_C_COMPILER)
+      set(MPI_C_COMPILER mpicc)
+    endif()
+    list(APPEND STARPU_COMPONENT_LIST "MPI")
+  endif()
+  if (PASTIX_LOOK_FOR_STARPU_CUDA)
+    list(APPEND STARPU_COMPONENT_LIST "CUDA")
+  endif()
+  if (PASTIX_LOOK_FOR_STARPU_FXT)
+    list(APPEND STARPU_COMPONENT_LIST "FXT")
+  endif()
+  # set the list of optional dependencies we may discover
+  if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_STARPU)
+    find_package(STARPU ${PASTIX_STARPU_VERSION} REQUIRED
+      COMPONENTS ${STARPU_COMPONENT_LIST})
+  else()
+    find_package(STARPU ${PASTIX_STARPU_VERSION}
+      COMPONENTS ${STARPU_COMPONENT_LIST})
+  endif()
+
+endif( NOT STARPU_FOUND AND PASTIX_LOOK_FOR_STARPU)
+
+# PASTIX may depends on SCOTCH
+#-----------------------------
+if (NOT SCOTCH_FOUND AND PASTIX_LOOK_FOR_SCOTCH)
+  if (NOT PASTIX_FIND_QUIETLY)
+    message(STATUS "Looking for PASTIX - Try to detect SCOTCH")
+  endif()
+  if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_SCOTCH)
+    find_package(SCOTCH REQUIRED QUIET)
+  else()
+    find_package(SCOTCH QUIET)
+  endif()
+endif()
+
+# PASTIX may depends on PTSCOTCH
+#-------------------------------
+if (NOT PTSCOTCH_FOUND AND PASTIX_LOOK_FOR_PTSCOTCH)
+  if (NOT PASTIX_FIND_QUIETLY)
+    message(STATUS "Looking for PASTIX - Try to detect PTSCOTCH")
+  endif()
+  if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_PTSCOTCH)
+    find_package(PTSCOTCH REQUIRED QUIET)
+  else()
+    find_package(PTSCOTCH QUIET)
+  endif()
+endif()
+
+# PASTIX may depends on METIS
+#----------------------------
+if (NOT METIS_FOUND AND PASTIX_LOOK_FOR_METIS)
+  if (NOT PASTIX_FIND_QUIETLY)
+    message(STATUS "Looking for PASTIX - Try to detect METIS")
+  endif()
+  if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_METIS)
+    find_package(METIS REQUIRED QUIET)
+  else()
+    find_package(METIS QUIET)
+  endif()
+endif()
+
+# Error if pastix required and no partitioning lib found
+if (PASTIX_FIND_REQUIRED AND NOT SCOTCH_FOUND AND NOT PTSCOTCH_FOUND AND NOT METIS_FOUND)
+  message(FATAL_ERROR "Could NOT find any partitioning library on your system"
+    " (install scotch, ptscotch or metis)")
+endif()
+
+
+# Looking for PaStiX
+# ------------------
+
+# Looking for include
+# -------------------
+
+# Add system include paths to search include
+# ------------------------------------------
+unset(_inc_env)
+set(ENV_PASTIX_DIR "$ENV{PASTIX_DIR}")
+set(ENV_PASTIX_INCDIR "$ENV{PASTIX_INCDIR}")
+if(ENV_PASTIX_INCDIR)
+  list(APPEND _inc_env "${ENV_PASTIX_INCDIR}")
+elseif(ENV_PASTIX_DIR)
+  list(APPEND _inc_env "${ENV_PASTIX_DIR}")
+  list(APPEND _inc_env "${ENV_PASTIX_DIR}/include")
+  list(APPEND _inc_env "${ENV_PASTIX_DIR}/include/pastix")
+else()
+  if(WIN32)
+    string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
+  else()
+    string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
+    list(APPEND _inc_env "${_path_env}")
+  endif()
+endif()
+list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
+list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
+list(REMOVE_DUPLICATES _inc_env)
+
+
+# Try to find the pastix header in the given paths
+# ---------------------------------------------------
+# call cmake macro to find the header path
+if(PASTIX_INCDIR)
+  set(PASTIX_pastix.h_DIRS "PASTIX_pastix.h_DIRS-NOTFOUND")
+  find_path(PASTIX_pastix.h_DIRS
+    NAMES pastix.h
+    HINTS ${PASTIX_INCDIR})
+else()
+  if(PASTIX_DIR)
+    set(PASTIX_pastix.h_DIRS "PASTIX_pastix.h_DIRS-NOTFOUND")
+    find_path(PASTIX_pastix.h_DIRS
+      NAMES pastix.h
+      HINTS ${PASTIX_DIR}
+      PATH_SUFFIXES "include" "include/pastix")
+  else()
+    set(PASTIX_pastix.h_DIRS "PASTIX_pastix.h_DIRS-NOTFOUND")
+    find_path(PASTIX_pastix.h_DIRS
+      NAMES pastix.h
+      HINTS ${_inc_env}
+      PATH_SUFFIXES "pastix")
+  endif()
+endif()
+mark_as_advanced(PASTIX_pastix.h_DIRS)
+
+# If found, add path to cmake variable
+# ------------------------------------
+if (PASTIX_pastix.h_DIRS)
+  set(PASTIX_INCLUDE_DIRS "${PASTIX_pastix.h_DIRS}")
+else ()
+  set(PASTIX_INCLUDE_DIRS "PASTIX_INCLUDE_DIRS-NOTFOUND")
+  if(NOT PASTIX_FIND_QUIETLY)
+    message(STATUS "Looking for pastix -- pastix.h not found")
+  endif()
+endif()
+
+
+# Looking for lib
+# ---------------
+
+# Add system library paths to search lib
+# --------------------------------------
+unset(_lib_env)
+set(ENV_PASTIX_LIBDIR "$ENV{PASTIX_LIBDIR}")
+if(ENV_PASTIX_LIBDIR)
+  list(APPEND _lib_env "${ENV_PASTIX_LIBDIR}")
+elseif(ENV_PASTIX_DIR)
+  list(APPEND _lib_env "${ENV_PASTIX_DIR}")
+  list(APPEND _lib_env "${ENV_PASTIX_DIR}/lib")
+else()
+  if(WIN32)
+    string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
+  else()
+    if(APPLE)
+      string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
+    else()
+      string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
+    endif()
+    list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
+    list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
+  endif()
+endif()
+list(REMOVE_DUPLICATES _lib_env)
+
+# Try to find the pastix lib in the given paths
+# ------------------------------------------------
+
+# create list of libs to find
+set(PASTIX_libs_to_find "pastix_murge;pastix")
+
+# call cmake macro to find the lib path
+if(PASTIX_LIBDIR)
+  foreach(pastix_lib ${PASTIX_libs_to_find})
+    set(PASTIX_${pastix_lib}_LIBRARY "PASTIX_${pastix_lib}_LIBRARY-NOTFOUND")
+    find_library(PASTIX_${pastix_lib}_LIBRARY
+      NAMES ${pastix_lib}
+      HINTS ${PASTIX_LIBDIR})
+  endforeach()
+else()
+  if(PASTIX_DIR)
+    foreach(pastix_lib ${PASTIX_libs_to_find})
+      set(PASTIX_${pastix_lib}_LIBRARY "PASTIX_${pastix_lib}_LIBRARY-NOTFOUND")
+      find_library(PASTIX_${pastix_lib}_LIBRARY
+	NAMES ${pastix_lib}
+	HINTS ${PASTIX_DIR}
+	PATH_SUFFIXES lib lib32 lib64)
+    endforeach()
+  else()
+    foreach(pastix_lib ${PASTIX_libs_to_find})
+      set(PASTIX_${pastix_lib}_LIBRARY "PASTIX_${pastix_lib}_LIBRARY-NOTFOUND")
+      find_library(PASTIX_${pastix_lib}_LIBRARY
+	NAMES ${pastix_lib}
+	HINTS ${_lib_env})
+    endforeach()
+  endif()
+endif()
+
+# If found, add path to cmake variable
+# ------------------------------------
+foreach(pastix_lib ${PASTIX_libs_to_find})
+
+  get_filename_component(${pastix_lib}_lib_path ${PASTIX_${pastix_lib}_LIBRARY} PATH)
+  # set cmake variables (respects naming convention)
+  if (PASTIX_LIBRARIES)
+    list(APPEND PASTIX_LIBRARIES "${PASTIX_${pastix_lib}_LIBRARY}")
+  else()
+    set(PASTIX_LIBRARIES "${PASTIX_${pastix_lib}_LIBRARY}")
+  endif()
+  if (PASTIX_LIBRARY_DIRS)
+    list(APPEND PASTIX_LIBRARY_DIRS "${${pastix_lib}_lib_path}")
+  else()
+    set(PASTIX_LIBRARY_DIRS "${${pastix_lib}_lib_path}")
+  endif()
+  mark_as_advanced(PASTIX_${pastix_lib}_LIBRARY)
+
+endforeach(pastix_lib ${PASTIX_libs_to_find})
+
+# check a function to validate the find
+if(PASTIX_LIBRARIES)
+
+  set(REQUIRED_LDFLAGS)
+  set(REQUIRED_INCDIRS)
+  set(REQUIRED_LIBDIRS)
+  set(REQUIRED_LIBS)
+
+  # PASTIX
+  if (PASTIX_INCLUDE_DIRS)
+    set(REQUIRED_INCDIRS "${PASTIX_INCLUDE_DIRS}")
+  endif()
+  foreach(libdir ${PASTIX_LIBRARY_DIRS})
+    if (libdir)
+      list(APPEND REQUIRED_LIBDIRS "${libdir}")
+    endif()
+  endforeach()
+  set(REQUIRED_LIBS "${PASTIX_LIBRARIES}")
+  # STARPU
+  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()
+  endif()
+  # CUDA
+  if (PASTIX_LOOK_FOR_STARPU_CUDA AND CUDA_FOUND)
+    if (CUDA_INCLUDE_DIRS)
+      list(APPEND REQUIRED_INCDIRS "${CUDA_INCLUDE_DIRS}")
+    endif()
+    foreach(libdir ${CUDA_LIBRARY_DIRS})
+      if (libdir)
+	list(APPEND REQUIRED_LIBDIRS "${libdir}")
+      endif()
+    endforeach()
+    list(APPEND REQUIRED_LIBS "${CUDA_CUBLAS_LIBRARIES};${CUDA_LIBRARIES}")
+  endif()
+  # MPI
+  if (PASTIX_LOOK_FOR_MPI AND MPI_FOUND)
+    if (MPI_C_INCLUDE_PATH)
+      list(APPEND REQUIRED_INCDIRS "${MPI_C_INCLUDE_PATH}")
+    endif()
+    if (MPI_C_LINK_FLAGS)
+      if (${MPI_C_LINK_FLAGS} MATCHES "  -")
+	string(REGEX REPLACE " -" "-" MPI_C_LINK_FLAGS ${MPI_C_LINK_FLAGS})
+      endif()
+      list(APPEND REQUIRED_LDFLAGS "${MPI_C_LINK_FLAGS}")
+    endif()
+    list(APPEND REQUIRED_LIBS "${MPI_C_LIBRARIES}")
+  endif()
+  # HWLOC
+  if (HWLOC_FOUND)
+    if (HWLOC_INCLUDE_DIRS)
+      list(APPEND REQUIRED_INCDIRS "${HWLOC_INCLUDE_DIRS}")
+    endif()
+    foreach(libdir ${HWLOC_LIBRARY_DIRS})
+      if (libdir)
+	list(APPEND REQUIRED_LIBDIRS "${libdir}")
+      endif()
+    endforeach()
+    foreach(lib ${HWLOC_LIBRARIES})
+      if (EXISTS ${lib} OR ${lib} MATCHES "^-")
+	list(APPEND REQUIRED_LIBS "${lib}")
+      else()
+	list(APPEND REQUIRED_LIBS "-l${lib}")
+      endif()
+    endforeach()
+  endif()
+  # BLAS
+  if (BLAS_FOUND)
+    if (BLAS_INCLUDE_DIRS)
+      list(APPEND REQUIRED_INCDIRS "${BLAS_INCLUDE_DIRS}")
+    endif()
+    foreach(libdir ${BLAS_LIBRARY_DIRS})
+      if (libdir)
+	list(APPEND REQUIRED_LIBDIRS "${libdir}")
+      endif()
+    endforeach()
+    list(APPEND REQUIRED_LIBS "${BLAS_LIBRARIES}")
+    if (BLAS_LINKER_FLAGS)
+      list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}")
+    endif()
+  endif()
+  # SCOTCH
+  if (PASTIX_LOOK_FOR_SCOTCH AND SCOTCH_FOUND)
+    if (SCOTCH_INCLUDE_DIRS)
+      list(APPEND REQUIRED_INCDIRS "${SCOTCH_INCLUDE_DIRS}")
+    endif()
+    foreach(libdir ${SCOTCH_LIBRARY_DIRS})
+      if (libdir)
+	list(APPEND REQUIRED_LIBDIRS "${libdir}")
+      endif()
+    endforeach()
+    list(APPEND REQUIRED_LIBS "${SCOTCH_LIBRARIES}")
+  endif()
+  # PTSCOTCH
+  if (PASTIX_LOOK_FOR_PTSCOTCH AND PTSCOTCH_FOUND)
+    if (PTSCOTCH_INCLUDE_DIRS)
+      list(APPEND REQUIRED_INCDIRS "${PTSCOTCH_INCLUDE_DIRS}")
+    endif()
+    foreach(libdir ${PTSCOTCH_LIBRARY_DIRS})
+      if (libdir)
+	list(APPEND REQUIRED_LIBDIRS "${libdir}")
+      endif()
+    endforeach()
+    list(APPEND REQUIRED_LIBS "${PTSCOTCH_LIBRARIES}")
+  endif()
+  # METIS
+  if (PASTIX_LOOK_FOR_METIS AND METIS_FOUND)
+    if (METIS_INCLUDE_DIRS)
+      list(APPEND REQUIRED_INCDIRS "${METIS_INCLUDE_DIRS}")
+    endif()
+    foreach(libdir ${METIS_LIBRARY_DIRS})
+      if (libdir)
+	list(APPEND REQUIRED_LIBDIRS "${libdir}")
+      endif()
+    endforeach()
+    list(APPEND REQUIRED_LIBS "${METIS_LIBRARIES}")
+  endif()
+  # Fortran
+  if (CMAKE_C_COMPILER_ID MATCHES "GNU")
+    find_library(
+      FORTRAN_gfortran_LIBRARY
+      NAMES gfortran
+      HINTS ${_lib_env}
+      )
+    mark_as_advanced(FORTRAN_gfortran_LIBRARY)
+    if (FORTRAN_gfortran_LIBRARY)
+      list(APPEND REQUIRED_LIBS "${FORTRAN_gfortran_LIBRARY}")
+    endif()
+  elseif (CMAKE_C_COMPILER_ID MATCHES "Intel")
+    find_library(
+      FORTRAN_ifcore_LIBRARY
+      NAMES ifcore
+      HINTS ${_lib_env}
+      )
+    mark_as_advanced(FORTRAN_ifcore_LIBRARY)
+    if (FORTRAN_ifcore_LIBRARY)
+      list(APPEND REQUIRED_LIBS "${FORTRAN_ifcore_LIBRARY}")
+    endif()
+  endif()
+  # EXTRA LIBS such that pthread, m, rt
+  list(APPEND REQUIRED_LIBS ${PASTIX_EXTRA_LIBRARIES})
+
+  # set required libraries for link
+  set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
+  set(CMAKE_REQUIRED_LIBRARIES)
+  list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}")
+  foreach(lib_dir ${REQUIRED_LIBDIRS})
+    list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
+  endforeach()
+  list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
+  list(APPEND CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}")
+  string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
+
+  # test link
+  unset(PASTIX_WORKS CACHE)
+  include(CheckFunctionExists)
+  check_function_exists(pastix PASTIX_WORKS)
+  mark_as_advanced(PASTIX_WORKS)
+
+  if(PASTIX_WORKS)
+    # save link with dependencies
+    set(PASTIX_LIBRARIES_DEP "${REQUIRED_LIBS}")
+    set(PASTIX_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
+    set(PASTIX_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
+    set(PASTIX_LINKER_FLAGS "${REQUIRED_LDFLAGS}")
+    list(REMOVE_DUPLICATES PASTIX_LIBRARY_DIRS_DEP)
+    list(REMOVE_DUPLICATES PASTIX_INCLUDE_DIRS_DEP)
+    list(REMOVE_DUPLICATES PASTIX_LINKER_FLAGS)
+  else()
+    if(NOT PASTIX_FIND_QUIETLY)
+      message(STATUS "Looking for PASTIX : test of pastix() fails")
+      message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
+      message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
+      message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
+      message(STATUS "Maybe PASTIX is linked with specific libraries. "
+	"Have you tried with COMPONENTS (MPI/SEQ, STARPU, STARPU_CUDA, SCOTCH, PTSCOTCH, METIS)? "
+	"See the explanation in FindPASTIX.cmake.")
+    endif()
+  endif()
+  set(CMAKE_REQUIRED_INCLUDES)
+  set(CMAKE_REQUIRED_FLAGS)
+  set(CMAKE_REQUIRED_LIBRARIES)
+endif(PASTIX_LIBRARIES)
+
+if (PASTIX_LIBRARIES)
+  list(GET PASTIX_LIBRARIES 0 first_lib)
+  get_filename_component(first_lib_path "${first_lib}" PATH)
+  if (${first_lib_path} MATCHES "/lib(32|64)?$")
+    string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
+    set(PASTIX_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of PASTIX library" FORCE)
+  else()
+    set(PASTIX_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of PASTIX library" FORCE)
+  endif()
+endif()
+mark_as_advanced(PASTIX_DIR)
+mark_as_advanced(PASTIX_DIR_FOUND)
+
+# check that PASTIX has been found
+# ---------------------------------
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(PASTIX DEFAULT_MSG
-                                  PASTIX_INCLUDES PASTIX_LIBRARIES)
-
-mark_as_advanced(PASTIX_INCLUDES PASTIX_LIBRARIES)
+  PASTIX_LIBRARIES
+  PASTIX_WORKS)
diff --git a/cmake/FindSPQR.cmake b/cmake/FindSPQR.cmake
index 794c212..1e958c3 100644
--- a/cmake/FindSPQR.cmake
+++ b/cmake/FindSPQR.cmake
@@ -26,7 +26,12 @@
   find_library(SUITESPARSE_LIBRARY SuiteSparse PATHS $ENV{SPQRDIR} ${LIB_INSTALL_DIR})
   if (SUITESPARSE_LIBRARY)
     set(SPQR_LIBRARIES ${SPQR_LIBRARIES} ${SUITESPARSE_LIBRARY})
-  endif (SUITESPARSE_LIBRARY)
+  endif()
+
+  find_library(CHOLMOD_LIBRARY cholmod PATHS $ENV{UMFPACK_LIBDIR} $ENV{UMFPACKDIR} ${LIB_INSTALL_DIR})
+  if(CHOLMOD_LIBRARY)
+    set(SPQR_LIBRARIES ${SPQR_LIBRARIES} ${CHOLMOD_LIBRARY})
+  endif()
   
 endif(SPQR_LIBRARIES)
 
diff --git a/cmake/FindScotch.cmake b/cmake/FindScotch.cmake
index 530340b..89d295a 100644
--- a/cmake/FindScotch.cmake
+++ b/cmake/FindScotch.cmake
@@ -1,24 +1,369 @@
-# Pastix requires SCOTCH or METIS (partitioning and reordering tools)
+###
+#
+# @copyright (c) 2009-2014 The University of Tennessee and The University
+#                          of Tennessee Research Foundation.
+#                          All rights reserved.
+# @copyright (c) 2012-2014 Inria. All rights reserved.
+# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
+#
+###
+#
+# - Find SCOTCH include dirs and libraries
+# Use this module by invoking find_package with the form:
+#  find_package(SCOTCH
+#               [REQUIRED]             # Fail with error if scotch is not found
+#               [COMPONENTS <comp1> <comp2> ...] # dependencies
+#              )
+#
+#  COMPONENTS can be some of the following:
+#   - ESMUMPS: to activate detection of Scotch with the esmumps interface
+#
+# This module finds headers and scotch library.
+# Results are reported in variables:
+#  SCOTCH_FOUND           - True if headers and requested libraries were found
+#  SCOTCH_INCLUDE_DIRS    - scotch include directories
+#  SCOTCH_LIBRARY_DIRS    - Link directories for scotch libraries
+#  SCOTCH_LIBRARIES       - scotch component libraries to be linked
+#  SCOTCH_INTSIZE         - Number of octets occupied by a SCOTCH_Num
+#
+# The user can give specific paths where to find the libraries adding cmake
+# options at configure (ex: cmake path/to/project -DSCOTCH=path/to/scotch):
+#  SCOTCH_DIR             - Where to find the base directory of scotch
+#  SCOTCH_INCDIR          - Where to find the header files
+#  SCOTCH_LIBDIR          - Where to find the library files
+# The module can also look for the following environment variables if paths
+# are not given as cmake variable: SCOTCH_DIR, SCOTCH_INCDIR, SCOTCH_LIBDIR
 
-if (SCOTCH_INCLUDES AND SCOTCH_LIBRARIES)
-  set(SCOTCH_FIND_QUIETLY TRUE)
-endif (SCOTCH_INCLUDES AND SCOTCH_LIBRARIES)
+#=============================================================================
+# Copyright 2012-2013 Inria
+# Copyright 2012-2013 Emmanuel Agullo
+# Copyright 2012-2013 Mathieu Faverge
+# Copyright 2012      Cedric Castagnede
+# Copyright 2013      Florent Pruvost
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file MORSE-Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of Morse, substitute the full
+#  License text for the above reference.)
 
-find_path(SCOTCH_INCLUDES 
-  NAMES 
-  scotch.h 
-  PATHS 
-  $ENV{SCOTCHDIR} 
-  ${INCLUDE_INSTALL_DIR} 
-  PATH_SUFFIXES 
-  scotch
-)
+if (NOT SCOTCH_FOUND)
+  set(SCOTCH_DIR "" CACHE PATH "Installation directory of SCOTCH library")
+  if (NOT SCOTCH_FIND_QUIETLY)
+    message(STATUS "A cache variable, namely SCOTCH_DIR, has been set to specify the install directory of SCOTCH")
+  endif()
+endif()
+
+# Set the version to find
+set(SCOTCH_LOOK_FOR_ESMUMPS OFF)
+
+if( SCOTCH_FIND_COMPONENTS )
+  foreach( component ${SCOTCH_FIND_COMPONENTS} )
+    if (${component} STREQUAL "ESMUMPS")
+      # means we look for esmumps library
+      set(SCOTCH_LOOK_FOR_ESMUMPS ON)
+    endif()
+  endforeach()
+endif()
+
+# SCOTCH may depend on Threads, try to find it
+if (NOT THREADS_FOUND)
+  if (SCOTCH_FIND_REQUIRED)
+    find_package(Threads REQUIRED)
+  else()
+    find_package(Threads)
+  endif()
+endif()
+
+# Looking for include
+# -------------------
+
+# Add system include paths to search include
+# ------------------------------------------
+unset(_inc_env)
+set(ENV_SCOTCH_DIR "$ENV{SCOTCH_DIR}")
+set(ENV_SCOTCH_INCDIR "$ENV{SCOTCH_INCDIR}")
+if(ENV_SCOTCH_INCDIR)
+  list(APPEND _inc_env "${ENV_SCOTCH_INCDIR}")
+elseif(ENV_SCOTCH_DIR)
+  list(APPEND _inc_env "${ENV_SCOTCH_DIR}")
+  list(APPEND _inc_env "${ENV_SCOTCH_DIR}/include")
+  list(APPEND _inc_env "${ENV_SCOTCH_DIR}/include/scotch")
+else()
+  if(WIN32)
+    string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
+  else()
+    string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
+    list(APPEND _inc_env "${_path_env}")
+    string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
+    list(APPEND _inc_env "${_path_env}")
+  endif()
+endif()
+list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
+list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
+list(REMOVE_DUPLICATES _inc_env)
 
 
-find_library(SCOTCH_LIBRARIES scotch PATHS $ENV{SCOTCHDIR} ${LIB_INSTALL_DIR})
+# Try to find the scotch header in the given paths
+# -------------------------------------------------
+# call cmake macro to find the header path
+if(SCOTCH_INCDIR)
+  set(SCOTCH_scotch.h_DIRS "SCOTCH_scotch.h_DIRS-NOTFOUND")
+  find_path(SCOTCH_scotch.h_DIRS
+    NAMES scotch.h
+    HINTS ${SCOTCH_INCDIR})
+else()
+  if(SCOTCH_DIR)
+    set(SCOTCH_scotch.h_DIRS "SCOTCH_scotch.h_DIRS-NOTFOUND")
+    find_path(SCOTCH_scotch.h_DIRS
+      NAMES scotch.h
+      HINTS ${SCOTCH_DIR}
+      PATH_SUFFIXES "include" "include/scotch")
+  else()
+    set(SCOTCH_scotch.h_DIRS "SCOTCH_scotch.h_DIRS-NOTFOUND")
+    find_path(SCOTCH_scotch.h_DIRS
+      NAMES scotch.h
+      HINTS ${_inc_env}
+      PATH_SUFFIXES "scotch")
+  endif()
+endif()
+mark_as_advanced(SCOTCH_scotch.h_DIRS)
 
+# If found, add path to cmake variable
+# ------------------------------------
+if (SCOTCH_scotch.h_DIRS)
+  set(SCOTCH_INCLUDE_DIRS "${SCOTCH_scotch.h_DIRS}")
+else ()
+  set(SCOTCH_INCLUDE_DIRS "SCOTCH_INCLUDE_DIRS-NOTFOUND")
+  if (NOT SCOTCH_FIND_QUIETLY)
+    message(STATUS "Looking for scotch -- scotch.h not found")
+  endif()
+endif()
+list(REMOVE_DUPLICATES SCOTCH_INCLUDE_DIRS)
+
+# Looking for lib
+# ---------------
+
+# Add system library paths to search lib
+# --------------------------------------
+unset(_lib_env)
+set(ENV_SCOTCH_LIBDIR "$ENV{SCOTCH_LIBDIR}")
+if(ENV_SCOTCH_LIBDIR)
+  list(APPEND _lib_env "${ENV_SCOTCH_LIBDIR}")
+elseif(ENV_SCOTCH_DIR)
+  list(APPEND _lib_env "${ENV_SCOTCH_DIR}")
+  list(APPEND _lib_env "${ENV_SCOTCH_DIR}/lib")
+else()
+  if(WIN32)
+    string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
+  else()
+    if(APPLE)
+      string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
+    else()
+      string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
+    endif()
+    list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
+    list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
+  endif()
+endif()
+list(REMOVE_DUPLICATES _lib_env)
+
+# Try to find the scotch lib in the given paths
+# ----------------------------------------------
+
+set(SCOTCH_libs_to_find "scotch;scotcherrexit")
+if (SCOTCH_LOOK_FOR_ESMUMPS)
+  list(INSERT SCOTCH_libs_to_find 0 "esmumps")
+endif()
+
+# call cmake macro to find the lib path
+if(SCOTCH_LIBDIR)
+  foreach(scotch_lib ${SCOTCH_libs_to_find})
+    set(SCOTCH_${scotch_lib}_LIBRARY "SCOTCH_${scotch_lib}_LIBRARY-NOTFOUND")
+    find_library(SCOTCH_${scotch_lib}_LIBRARY
+      NAMES ${scotch_lib}
+      HINTS ${SCOTCH_LIBDIR})
+  endforeach()
+else()
+  if(SCOTCH_DIR)
+    foreach(scotch_lib ${SCOTCH_libs_to_find})
+      set(SCOTCH_${scotch_lib}_LIBRARY "SCOTCH_${scotch_lib}_LIBRARY-NOTFOUND")
+      find_library(SCOTCH_${scotch_lib}_LIBRARY
+	NAMES ${scotch_lib}
+	HINTS ${SCOTCH_DIR}
+	PATH_SUFFIXES lib lib32 lib64)
+    endforeach()
+  else()
+    foreach(scotch_lib ${SCOTCH_libs_to_find})
+      set(SCOTCH_${scotch_lib}_LIBRARY "SCOTCH_${scotch_lib}_LIBRARY-NOTFOUND")
+      find_library(SCOTCH_${scotch_lib}_LIBRARY
+	NAMES ${scotch_lib}
+	HINTS ${_lib_env})
+    endforeach()
+  endif()
+endif()
+
+set(SCOTCH_LIBRARIES "")
+set(SCOTCH_LIBRARY_DIRS "")
+# If found, add path to cmake variable
+# ------------------------------------
+foreach(scotch_lib ${SCOTCH_libs_to_find})
+
+  if (SCOTCH_${scotch_lib}_LIBRARY)
+    get_filename_component(${scotch_lib}_lib_path "${SCOTCH_${scotch_lib}_LIBRARY}" PATH)
+    # set cmake variables
+    list(APPEND SCOTCH_LIBRARIES "${SCOTCH_${scotch_lib}_LIBRARY}")
+    list(APPEND SCOTCH_LIBRARY_DIRS "${${scotch_lib}_lib_path}")
+  else ()
+    list(APPEND SCOTCH_LIBRARIES "${SCOTCH_${scotch_lib}_LIBRARY}")
+    if (NOT SCOTCH_FIND_QUIETLY)
+      message(STATUS "Looking for scotch -- lib ${scotch_lib} not found")
+    endif()
+  endif ()
+
+  mark_as_advanced(SCOTCH_${scotch_lib}_LIBRARY)
+
+endforeach()
+list(REMOVE_DUPLICATES SCOTCH_LIBRARY_DIRS)
+
+# check a function to validate the find
+if(SCOTCH_LIBRARIES)
+
+  set(REQUIRED_INCDIRS)
+  set(REQUIRED_LIBDIRS)
+  set(REQUIRED_LIBS)
+
+  # SCOTCH
+  if (SCOTCH_INCLUDE_DIRS)
+    set(REQUIRED_INCDIRS  "${SCOTCH_INCLUDE_DIRS}")
+  endif()
+  if (SCOTCH_LIBRARY_DIRS)
+    set(REQUIRED_LIBDIRS "${SCOTCH_LIBRARY_DIRS}")
+  endif()
+  set(REQUIRED_LIBS "${SCOTCH_LIBRARIES}")
+  # THREADS
+  if(CMAKE_THREAD_LIBS_INIT)
+    list(APPEND REQUIRED_LIBS "${CMAKE_THREAD_LIBS_INIT}")
+  endif()
+  set(Z_LIBRARY "Z_LIBRARY-NOTFOUND")
+  find_library(Z_LIBRARY NAMES z)
+  mark_as_advanced(Z_LIBRARY)
+  if(Z_LIBRARY)
+    list(APPEND REQUIRED_LIBS "-lz")
+  endif()
+  set(M_LIBRARY "M_LIBRARY-NOTFOUND")
+  find_library(M_LIBRARY NAMES m)
+  mark_as_advanced(M_LIBRARY)
+  if(M_LIBRARY)
+    list(APPEND REQUIRED_LIBS "-lm")
+  endif()
+  set(RT_LIBRARY "RT_LIBRARY-NOTFOUND")
+  find_library(RT_LIBRARY NAMES rt)
+  mark_as_advanced(RT_LIBRARY)
+  if(RT_LIBRARY)
+    list(APPEND REQUIRED_LIBS "-lrt")
+  endif()
+
+  # set required libraries for link
+  set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
+  set(CMAKE_REQUIRED_LIBRARIES)
+  foreach(lib_dir ${REQUIRED_LIBDIRS})
+    list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
+  endforeach()
+  list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
+  string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
+
+  # test link
+  unset(SCOTCH_WORKS CACHE)
+  include(CheckFunctionExists)
+  check_function_exists(SCOTCH_graphInit SCOTCH_WORKS)
+  mark_as_advanced(SCOTCH_WORKS)
+
+  if(SCOTCH_WORKS)
+    # save link with dependencies
+    set(SCOTCH_LIBRARIES "${REQUIRED_LIBS}")
+  else()
+    if(NOT SCOTCH_FIND_QUIETLY)
+      message(STATUS "Looking for SCOTCH : test of SCOTCH_graphInit with SCOTCH library fails")
+      message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
+      message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
+      message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
+    endif()
+  endif()
+  set(CMAKE_REQUIRED_INCLUDES)
+  set(CMAKE_REQUIRED_FLAGS)
+  set(CMAKE_REQUIRED_LIBRARIES)
+endif(SCOTCH_LIBRARIES)
+
+if (SCOTCH_LIBRARIES)
+  list(GET SCOTCH_LIBRARIES 0 first_lib)
+  get_filename_component(first_lib_path "${first_lib}" PATH)
+  if (${first_lib_path} MATCHES "/lib(32|64)?$")
+    string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
+    set(SCOTCH_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of SCOTCH library" FORCE)
+  else()
+    set(SCOTCH_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of SCOTCH library" FORCE)
+  endif()
+endif()
+mark_as_advanced(SCOTCH_DIR)
+mark_as_advanced(SCOTCH_DIR_FOUND)
+
+# Check the size of SCOTCH_Num
+# ---------------------------------
+set(CMAKE_REQUIRED_INCLUDES ${SCOTCH_INCLUDE_DIRS})
+
+include(CheckCSourceRuns)
+#stdio.h and stdint.h should be included by scotch.h directly
+set(SCOTCH_C_TEST_SCOTCH_Num_4 "
+#include <stdio.h>
+#include <stdint.h>
+#include <scotch.h>
+int main(int argc, char **argv) {
+  if (sizeof(SCOTCH_Num) == 4)
+    return 0;
+  else
+    return 1;
+}
+")
+
+set(SCOTCH_C_TEST_SCOTCH_Num_8 "
+#include <stdio.h>
+#include <stdint.h>
+#include <scotch.h>
+int main(int argc, char **argv) {
+  if (sizeof(SCOTCH_Num) == 8)
+    return 0;
+  else
+    return 1;
+}
+")
+check_c_source_runs("${SCOTCH_C_TEST_SCOTCH_Num_4}" SCOTCH_Num_4)
+if(NOT SCOTCH_Num_4)
+  check_c_source_runs("${SCOTCH_C_TEST_SCOTCH_Num_8}" SCOTCH_Num_8)
+  if(NOT SCOTCH_Num_8)
+    set(SCOTCH_INTSIZE -1)
+  else()
+    set(SCOTCH_INTSIZE 8)
+  endif()
+else()
+  set(SCOTCH_INTSIZE 4)
+endif()
+set(CMAKE_REQUIRED_INCLUDES "")
+
+# check that SCOTCH has been found
+# ---------------------------------
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(SCOTCH DEFAULT_MSG
-                                  SCOTCH_INCLUDES SCOTCH_LIBRARIES)
-
-mark_as_advanced(SCOTCH_INCLUDES SCOTCH_LIBRARIES)
+  SCOTCH_LIBRARIES
+  SCOTCH_WORKS)
+#
+# TODO: Add possibility to check for specific functions in the library
+#
diff --git a/cmake/FindSuperLU.cmake b/cmake/FindSuperLU.cmake
index 8a3df36..f38146e 100644
--- a/cmake/FindSuperLU.cmake
+++ b/cmake/FindSuperLU.cmake
@@ -17,10 +17,81 @@
   SRC
 )
 
-find_library(SUPERLU_LIBRARIES superlu PATHS $ENV{SUPERLUDIR} ${LIB_INSTALL_DIR} PATH_SUFFIXES lib)
-  
+find_library(SUPERLU_LIBRARIES
+  NAMES "superlu_5.2.1" "superlu_5.2" "superlu_5.1.1" "superlu_5.1" "superlu_5.0" "superlu_4.3" "superlu_4.2" "superlu_4.1" "superlu_4.0" "superlu_3.1" "superlu_3.0" "superlu"
+  PATHS $ENV{SUPERLUDIR} ${LIB_INSTALL_DIR}
+  PATH_SUFFIXES lib)
+
+if(SUPERLU_INCLUDES AND SUPERLU_LIBRARIES)
+
+include(CheckCXXSourceCompiles)
+include(CMakePushCheckState)
+cmake_push_check_state()
+
+set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${SUPERLU_INCLUDES})
+
+# check whether struct mem_usage_t is globally defined
+check_cxx_source_compiles("
+typedef int int_t;
+#include <supermatrix.h>
+#include <slu_util.h>
+int main() {
+  mem_usage_t mem;
+  return 0;
+}"
+SUPERLU_HAS_GLOBAL_MEM_USAGE_T)
+
+
+check_cxx_source_compiles("
+typedef int int_t;
+#include <supermatrix.h>
+#include <superlu_enum_consts.h>
+int main() {
+  return SLU_SINGLE;
+}"
+SUPERLU_HAS_CLEAN_ENUMS)
+
+check_cxx_source_compiles("
+typedef int int_t;
+#include <supermatrix.h>
+#include <slu_util.h>
+int main(void)
+{
+  GlobalLU_t glu;
+  return 0;
+}"
+SUPERLU_HAS_GLOBALLU_T)
+
+if(SUPERLU_HAS_GLOBALLU_T)
+  # at least 5.0
+  set(SUPERLU_VERSION_VAR "5.0")
+elseif(SUPERLU_HAS_CLEAN_ENUMS)
+  # at least 4.3
+  set(SUPERLU_VERSION_VAR "4.3")
+elseif(SUPERLU_HAS_GLOBAL_MEM_USAGE_T)
+  # at least 4.0
+  set(SUPERLU_VERSION_VAR "4.0")
+else()
+  set(SUPERLU_VERSION_VAR "3.0")
+endif()
+
+cmake_pop_check_state()
+
+if(SuperLU_FIND_VERSION)
+  if(${SUPERLU_VERSION_VAR} VERSION_LESS ${SuperLU_FIND_VERSION})
+    set(SUPERLU_VERSION_OK FALSE)
+  else()
+    set(SUPERLU_VERSION_OK TRUE)
+  endif()
+else()
+  set(SUPERLU_VERSION_OK TRUE)
+endif()
+
+endif()
+
 include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(SUPERLU DEFAULT_MSG
-                                  SUPERLU_INCLUDES SUPERLU_LIBRARIES)
+find_package_handle_standard_args(SUPERLU
+                                  REQUIRED_VARS SUPERLU_INCLUDES SUPERLU_LIBRARIES SUPERLU_VERSION_OK
+                                  VERSION_VAR SUPERLU_VERSION_VAR)
 
 mark_as_advanced(SUPERLU_INCLUDES SUPERLU_LIBRARIES)
diff --git a/cmake/FindUmfpack.cmake b/cmake/FindUmfpack.cmake
index 16b046c..53cf0b4 100644
--- a/cmake/FindUmfpack.cmake
+++ b/cmake/FindUmfpack.cmake
@@ -20,24 +20,29 @@
 
 if(UMFPACK_LIBRARIES)
 
-  if (NOT UMFPACK_LIBDIR)
+  if(NOT UMFPACK_LIBDIR)
     get_filename_component(UMFPACK_LIBDIR ${UMFPACK_LIBRARIES} PATH)
   endif(NOT UMFPACK_LIBDIR)
 
   find_library(COLAMD_LIBRARY colamd PATHS ${UMFPACK_LIBDIR} $ENV{UMFPACKDIR} ${LIB_INSTALL_DIR})
-  if (COLAMD_LIBRARY)
+  if(COLAMD_LIBRARY)
     set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES} ${COLAMD_LIBRARY})
-  endif (COLAMD_LIBRARY)
+  endif ()
   
   find_library(AMD_LIBRARY amd PATHS ${UMFPACK_LIBDIR} $ENV{UMFPACKDIR} ${LIB_INSTALL_DIR})
-  if (AMD_LIBRARY)
+  if(AMD_LIBRARY)
     set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES} ${AMD_LIBRARY})
-  endif (AMD_LIBRARY)
+  endif ()
 
   find_library(SUITESPARSE_LIBRARY SuiteSparse PATHS ${UMFPACK_LIBDIR} $ENV{UMFPACKDIR} ${LIB_INSTALL_DIR})
-  if (SUITESPARSE_LIBRARY)
+  if(SUITESPARSE_LIBRARY)
     set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES} ${SUITESPARSE_LIBRARY})
-  endif (SUITESPARSE_LIBRARY)
+  endif ()
+
+  find_library(CHOLMOD_LIBRARY cholmod PATHS $ENV{UMFPACK_LIBDIR} $ENV{UMFPACKDIR} ${LIB_INSTALL_DIR})
+  if(CHOLMOD_LIBRARY)
+    set(UMFPACK_LIBRARIES ${UMFPACK_LIBRARIES} ${CHOLMOD_LIBRARY})
+  endif()
 
 endif(UMFPACK_LIBRARIES)
 
@@ -45,4 +50,4 @@
 find_package_handle_standard_args(UMFPACK DEFAULT_MSG
                                   UMFPACK_INCLUDES UMFPACK_LIBRARIES)
 
-mark_as_advanced(UMFPACK_INCLUDES UMFPACK_LIBRARIES AMD_LIBRARY COLAMD_LIBRARY SUITESPARSE_LIBRARY)
+mark_as_advanced(UMFPACK_INCLUDES UMFPACK_LIBRARIES AMD_LIBRARY COLAMD_LIBRARY CHOLMOD_LIBRARY SUITESPARSE_LIBRARY)
diff --git a/cmake/UseEigen3.cmake b/cmake/UseEigen3.cmake
new file mode 100644
index 0000000..a38bac8
--- /dev/null
+++ b/cmake/UseEigen3.cmake
@@ -0,0 +1,6 @@
+#                                               -*- cmake -*-
+#
+#  UseEigen3.cmake
+
+add_definitions     ( ${EIGEN3_DEFINITIONS} )
+include_directories ( ${EIGEN3_INCLUDE_DIRS} )
diff --git a/cmake/language_support.cmake b/cmake/language_support.cmake
index 231f7ff..ddba509 100644
--- a/cmake/language_support.cmake
+++ b/cmake/language_support.cmake
@@ -26,7 +26,7 @@
     cmake_minimum_required(VERSION 2.8.0)
     set (CMAKE_Fortran_FLAGS \"${CMAKE_Fortran_FLAGS}\")
     set (CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS}\")
-    enable_language(${language} OPTIONAL)
+    enable_language(${language})
   ")
   file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/language_tests/${language})
   file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/language_tests/${language})
@@ -43,7 +43,7 @@
   if(return_code EQUAL 0)
     # Second run
     execute_process (
-      COMMAND ${CMAKE_COMMAND} .
+      COMMAND ${CMAKE_COMMAND} . -G "${CMAKE_GENERATOR}"
       WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/language_tests/${language}
       RESULT_VARIABLE return_code
       OUTPUT_QUIET
@@ -64,3 +64,4 @@
 #message("CXX_language_works = ${CXX_language_works}")
 #workaround_9220(CXXp CXXp_language_works)
 #message("CXXp_language_works = ${CXXp_language_works}")
+