From 64472303d9064792a69211f89ca120ad829345cb Mon Sep 17 00:00:00 2001 From: Florent Pruvost <florent.pruvost@inria.fr> Date: Tue, 13 Dec 2016 11:50:02 +0100 Subject: [PATCH] add morse modules --- modules/AuxilaryFlags.cmake | 91 ++ modules/ColorizeMessage.cmake | 79 + modules/FindHeadersAndLibs.cmake | 100 ++ modules/MorseInit.cmake | 60 + modules/ParseArguments.cmake | 71 + modules/PrintFindStatus.cmake | 210 +++ modules/Ressources.cmake | 56 + modules/RulesPrecisions.cmake | 256 +++ modules/find/FindBLAS.cmake | 1409 +++++++++++++++++ modules/find/FindBLASEXT.cmake | 380 +++++ modules/find/FindCBLAS.cmake | 388 +++++ modules/find/FindCHAMELEON.cmake | 800 ++++++++++ modules/find/FindEZTRACE.cmake | 355 +++++ modules/find/FindFFTW.cmake | 806 ++++++++++ modules/find/FindFXT.cmake | 310 ++++ modules/find/FindHWLOC.cmake | 331 ++++ modules/find/FindHYPRE.cmake | 273 ++++ modules/find/FindLAPACK.cmake | 730 +++++++++ modules/find/FindLAPACKE.cmake | 378 +++++ modules/find/FindLAPACKEXT.cmake | 350 ++++ modules/find/FindMAGMA.cmake | 438 +++++ modules/find/FindMETIS.cmake | 264 +++ modules/find/FindMPIEXT.cmake | 120 ++ modules/find/FindMUMPS.cmake | 753 +++++++++ modules/find/FindPAMPA.cmake | 383 +++++ modules/find/FindPAPI.cmake | 310 ++++ modules/find/FindPARMETIS.cmake | 264 +++ modules/find/FindPARSEC.cmake | 660 ++++++++ modules/find/FindPASTIX.cmake | 704 ++++++++ modules/find/FindPETSc.cmake | 318 ++++ modules/find/FindPTSCOTCH.cmake | 423 +++++ modules/find/FindQUARK.cmake | 325 ++++ modules/find/FindSCALAPACK.cmake | 489 ++++++ modules/find/FindSCOTCH.cmake | 369 +++++ modules/find/FindSIMGRID.cmake | 310 ++++ modules/find/FindSTARPU.cmake | 948 +++++++++++ modules/find/FindSUITESPARSE.cmake | 433 +++++ modules/find/FindTMG.cmake | 306 ++++ modules/find/MORSE-Copyright.txt | 41 + modules/find/RulesJDF.cmake | 54 + modules/find/css | 1 + modules/find/morse_cmakefind_doc.html | 284 ++++ modules/find/morse_cmakefind_doc.org | 135 ++ modules/precision_generator/Conversion.py | 266 ++++ modules/precision_generator/codegen.py | 120 ++ .../precision_generator/genDependencies.py | 211 +++ modules/precision_generator/subs.py | 1003 ++++++++++++ 47 files changed, 17365 insertions(+) create mode 100644 modules/AuxilaryFlags.cmake create mode 100644 modules/ColorizeMessage.cmake create mode 100644 modules/FindHeadersAndLibs.cmake create mode 100644 modules/MorseInit.cmake create mode 100644 modules/ParseArguments.cmake create mode 100644 modules/PrintFindStatus.cmake create mode 100644 modules/Ressources.cmake create mode 100644 modules/RulesPrecisions.cmake create mode 100644 modules/find/FindBLAS.cmake create mode 100644 modules/find/FindBLASEXT.cmake create mode 100644 modules/find/FindCBLAS.cmake create mode 100644 modules/find/FindCHAMELEON.cmake create mode 100644 modules/find/FindEZTRACE.cmake create mode 100644 modules/find/FindFFTW.cmake create mode 100644 modules/find/FindFXT.cmake create mode 100644 modules/find/FindHWLOC.cmake create mode 100644 modules/find/FindHYPRE.cmake create mode 100644 modules/find/FindLAPACK.cmake create mode 100644 modules/find/FindLAPACKE.cmake create mode 100644 modules/find/FindLAPACKEXT.cmake create mode 100644 modules/find/FindMAGMA.cmake create mode 100644 modules/find/FindMETIS.cmake create mode 100644 modules/find/FindMPIEXT.cmake create mode 100644 modules/find/FindMUMPS.cmake create mode 100644 modules/find/FindPAMPA.cmake create mode 100644 modules/find/FindPAPI.cmake create mode 100644 modules/find/FindPARMETIS.cmake create mode 100644 modules/find/FindPARSEC.cmake create mode 100644 modules/find/FindPASTIX.cmake create mode 100644 modules/find/FindPETSc.cmake create mode 100644 modules/find/FindPTSCOTCH.cmake create mode 100644 modules/find/FindQUARK.cmake create mode 100644 modules/find/FindSCALAPACK.cmake create mode 100644 modules/find/FindSCOTCH.cmake create mode 100644 modules/find/FindSIMGRID.cmake create mode 100644 modules/find/FindSTARPU.cmake create mode 100644 modules/find/FindSUITESPARSE.cmake create mode 100644 modules/find/FindTMG.cmake create mode 100644 modules/find/MORSE-Copyright.txt create mode 100644 modules/find/RulesJDF.cmake create mode 120000 modules/find/css create mode 100644 modules/find/morse_cmakefind_doc.html create mode 100644 modules/find/morse_cmakefind_doc.org create mode 100644 modules/precision_generator/Conversion.py create mode 100755 modules/precision_generator/codegen.py create mode 100755 modules/precision_generator/genDependencies.py create mode 100644 modules/precision_generator/subs.py diff --git a/modules/AuxilaryFlags.cmake b/modules/AuxilaryFlags.cmake new file mode 100644 index 0000000..9744d57 --- /dev/null +++ b/modules/AuxilaryFlags.cmake @@ -0,0 +1,91 @@ +### +# +# @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. +# +### +# +# @file AuxilaryFlags.cmake +# +# @project MORSE +# MORSE is a software package provided by: +# Inria Bordeaux - Sud-Ouest, +# Univ. of Tennessee, +# King Abdullah Univesity of Science and Technology +# Univ. of California Berkeley, +# Univ. of Colorado Denver. +# +# @version 0.9.0 +# @author Xavier Lacoste +# @author Florent Pruvost +# @date 30-01-2015 +# +# Update CMAKE auxilary variables: +# - CMAKE_C_FLAGS: C compiler flags +# - CMAKE_CXX_FLAGS: CXX compiler flags +# - CMAKE_Fortran_FLAGS: Fortran compiler flags +# - CMAKE_Fortran_PREPROCESS_FLAGS : force C preprocessor. +# - CMAKE_Fortran_FREEFORM_FLAG : Force free format. +### + +if (MORSE_ENABLE_WARNING) + + if(CMAKE_C_COMPILER_ID MATCHES GNU) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + elseif(CMAKE_C_COMPILER_ID MATCHES Intel) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w3 -diag-disable:remark") + endif() + + if(CMAKE_CXX_COMPILER_ID MATCHES GNU) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + elseif(CMAKE_CXX_COMPILER_ID MATCHES Intel) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w3 -diag-disable:remark") + endif() + + if(CMAKE_Fortran_COMPILER_ID MATCHES GNU) + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall") + elseif(CMAKE_Fortran_COMPILER_ID MATCHES Intel) + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -warn all -diag-disable:remark") + endif() + +endif(MORSE_ENABLE_WARNING) + +if (MORSE_ENABLE_COVERAGE) + + if(CMAKE_C_COMPILER_ID MATCHES GNU) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") + else() + message(FATAL_ERROR "Code coverage is only available with the GNU C (gcc)" + "\n compiler, please turn MORSE_ENABLE_COVERAGE OFF\n.") + endif() + + if(CMAKE_CXX_COMPILER_ID MATCHES GNU) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") + else() + message(FATAL_ERROR "Code coverage is only available with the GNU CXX" + "\n (g++) compiler, please turn MORSE_ENABLE_COVERAGE OFF\n.") + endif() + + if(CMAKE_Fortran_COMPILER_ID MATCHES GNU) + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} --coverage") + else() + message(FATAL_ERROR "Code coverage is only available with the GNU" + "\n Fortran (gfortran) compiler, please turn MORSE_ENABLE_COVERAGE" + "\n OFF\n.") + endif() + + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") + +endif(MORSE_ENABLE_COVERAGE) + + +if(CMAKE_Fortran_COMPILER_ID MATCHES GNU) + list(APPEND CMAKE_Fortran_PREPROCESS_FLAGS "-cpp") + list(APPEND CMAKE_Fortran_FREEFORM_FLAG "-ffree-form") +elseif(CMAKE_Fortran_COMPILER_ID MATCHES Intel) + list(APPEND CMAKE_Fortran_PREPROCESS_FLAG "-fpp") + list(APPEND CMAKE_Fortran_FREEFORM_FLAG "") +endif() diff --git a/modules/ColorizeMessage.cmake b/modules/ColorizeMessage.cmake new file mode 100644 index 0000000..e0e4d2b --- /dev/null +++ b/modules/ColorizeMessage.cmake @@ -0,0 +1,79 @@ +### +# +# @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. +# +### +# +# @file ColorizeMessage.cmake +# +# @project MORSE +# MORSE is a software package provided by: +# Inria Bordeaux - Sud-Ouest, +# Univ. of Tennessee, +# King Abdullah Univesity of Science and Technology +# Univ. of California Berkeley, +# Univ. of Colorado Denver. +# +# @version 0.9.0 +# @author Cedric Castagnede +# @author Emmanuel Agullo +# @author Mathieu Faverge +# @author Florent Pruvost +# @date 13-07-2012 +# +### + +# Set some colors +#if(NOT WIN32) +# string(ASCII 27 Esc) +# set(ColourReset "${Esc}[m") +# set(ColourBold "${Esc}[1m") +# set(Red "${Esc}[31m") +# set(Green "${Esc}[32m") +# set(Yellow "${Esc}[33m") +# set(Blue "${Esc}[34m") +# set(Magenta "${Esc}[35m") +# set(Cyan "${Esc}[36m") +# set(White "${Esc}[37m") +# set(BoldRed "${Esc}[1;31m") +# set(BoldGreen "${Esc}[1;32m") +# set(BoldYellow "${Esc}[1;33m") +# set(BoldBlue "${Esc}[1;34m") +# set(BoldMagenta "${Esc}[1;35m") +# set(BoldCyan "${Esc}[1;36m") +# set(BoldWhite "${Esc}[1;37m") +#endif() + +# Colorize cmake messages during configure +function(message) + list(GET ARGV 0 MessageType) + if(MessageType STREQUAL FATAL_ERROR OR MessageType STREQUAL SEND_ERROR) + list(REMOVE_AT ARGV 0) + string (REPLACE ";" " " ARGV_STR "${ARGV}") + _message(${MessageType} "${BoldRed}${ARGV_STR}${ColourReset}") + elseif(MessageType STREQUAL WARNING) + list(REMOVE_AT ARGV 0) + string (REPLACE ";" " " ARGV_STR "${ARGV}") + _message(${MessageType} "${BoldYellow}${ARGV_STR}${ColourReset}") + elseif(MessageType STREQUAL AUTHOR_WARNING) + list(REMOVE_AT ARGV 0) + string (REPLACE ";" " " ARGV_STR "${ARGV}") + _message(${MessageType} "${BoldCyan}${ARGV_STR}${ColourReset}") + elseif(MessageType STREQUAL STATUS) + list(REMOVE_AT ARGV 0) + string (REPLACE ";" " " ARGV_STR "${ARGV}") + _message(${MessageType} "${Green}${ARGV_STR}${ColourReset}") + else() + string (REPLACE ";" " " ARGV_STR "${ARGV}") + string (REPLACE "${Esc}[1 " "${Esc}[1;" ARGV_STR "${ARGV_STR}") + _message("${ARGV_STR}") + endif() +endfunction() + +## +## @end file ColorizeMessage.cmake +## diff --git a/modules/FindHeadersAndLibs.cmake b/modules/FindHeadersAndLibs.cmake new file mode 100644 index 0000000..d0919dc --- /dev/null +++ b/modules/FindHeadersAndLibs.cmake @@ -0,0 +1,100 @@ +### +# +# @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. +# +### +# +# @file FindHeadersAndLibs.cmake +# +# @project MORSE +# MORSE is a software package provided by: +# Inria Bordeaux - Sud-Ouest, +# Univ. of Tennessee, +# King Abdullah Univesity of Science and Technology +# Univ. of California Berkeley, +# Univ. of Colorado Denver. +# +# @version 0.9.0 +# @author Cedric Castagnede +# @author Emmanuel Agullo +# @author Mathieu Faverge +# @author Florent Pruvost +# @date 13-07-2012 +# +### + +# Add the path where we handle our FindFOO.cmake to seek for liraries +list(APPEND CMAKE_MODULE_PATH ${MORSE_CMAKE_MODULE_PATH}/find) + +# Some macros to print status when search for headers and libs +# PrintFindStatus.cmake is in cmake_modules/morse/find directory +include(PrintFindStatus) + + +function(FindHeader _libname _header_to_find) + + # save _libname upper and lower case + string(TOUPPER ${_libname} LIBNAME) + string(TOLOWER ${_libname} libname) + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + 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}") + list(REMOVE_DUPLICATES _inc_env) + + + # Try to find the _header_to_find in the given paths + # -------------------------------------------------- + # call cmake macro to find the header path + if(${LIBNAME}_INCDIR) + set(${LIBNAME}_${_header_to_find}_DIRS "${LIBNAME}_${_header_to_find}_DIRS-NOTFOUND") + find_path(${LIBNAME}_${_header_to_find}_DIRS + NAMES ${_header_to_find} + HINTS ${${LIBNAME}_INCDIR}) + elseif(${LIBNAME}_DIR) + set(${LIBNAME}_${_header_to_find}_DIRS "${LIBNAME}_${_header_to_find}_DIRS-NOTFOUND") + find_path(${LIBNAME}_${_header_to_find}_DIRS + NAMES ${_header_to_find} + HINTS ${${LIBNAME}_DIR} + PATH_SUFFIXES include) + else() + set(${LIBNAME}_${_header_to_find}_DIRS "${LIBNAME}_${_header_to_find}_DIRS-NOTFOUND") + find_path(${LIBNAME}_${_header_to_find}_DIRS + NAMES ${_header_to_find} + HINTS ${_inc_env}) + endif() + mark_as_advanced(${LIBNAME}_${_header_to_find}_DIRS) + + # Print status if not found + # ------------------------- + if (NOT ${LIBNAME}_${_header_to_find}_DIRS) + Print_Find_Header_Status(${libname} ${_header_to_find}) + endif () + +endfunction(FindHeader) + + +## +## @end file FindHeadersAndLibs.cmake +## diff --git a/modules/MorseInit.cmake b/modules/MorseInit.cmake new file mode 100644 index 0000000..1fd1794 --- /dev/null +++ b/modules/MorseInit.cmake @@ -0,0 +1,60 @@ +### +# +# @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. +# +### +# +# @file MorseInit.cmake +# +# @project MORSE +# MORSE is a software package provided by: +# Inria Bordeaux - Sud-Ouest, +# Univ. of Tennessee, +# King Abdullah Univesity of Science and Technology +# Univ. of California Berkeley, +# Univ. of Colorado Denver. +# +# @version 0.9.0 +# @author Cedric Castagnede +# @author Emmanuel Agullo +# @author Mathieu Faverge +# @author Florent Pruvost +# @date 13-07-2012 +# +### + +# This include is required to check symbols of libs in the main CMakeLists.txt +include(CheckFunctionExists) + +# To colorize messages +#include(ColorizeMessage) + +# To find headers and libs +include(FindHeadersAndLibs) + +# Some macros to print status when search for headers and libs +# PrintFindStatus.cmake is in cmake_modules/morse/find directory +include(PrintFindStatus) + +# Define some auxilary flags +include(AuxilaryFlags) + +# Define some variables to et info about ressources +include(Ressources) + +# Add the path where we handle our FindFOO.cmake to seek for liraries +list(APPEND CMAKE_MODULE_PATH ${MORSE_CMAKE_MODULE_PATH}/find) + +option(MORSE_ENABLE_WARNING "Enable warning messages" OFF) +option(MORSE_ENABLE_COVERAGE "Enable flags for coverage test" OFF) +#option(MORSE_VERBOSE_FIND_PACKAGE "Add additional messages concerning packages not found" OFF) +#message(STATUS "MORSE_VERBOSE_FIND_PACKAGE is set to OFF, turn it ON to get" +# " information about packages not found") + +## +## @end file MorseInit.cmake +## diff --git a/modules/ParseArguments.cmake b/modules/ParseArguments.cmake new file mode 100644 index 0000000..23a5ce6 --- /dev/null +++ b/modules/ParseArguments.cmake @@ -0,0 +1,71 @@ +### +# +# @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. +# +### +# +# @file ParseArguments.cmake +# +# @project MORSE +# MORSE is a software package provided by: +# Inria Bordeaux - Sud-Ouest, +# Univ. of Tennessee, +# King Abdullah Univesity of Science and Technology +# Univ. of California Berkeley, +# Univ. of Colorado Denver. +# +# @version 0.9.0 +# @author Cedric Castagnede +# @author Emmanuel Agullo +# @author Mathieu Faverge +# @date 13-07-2012 +# +### + +MACRO(PARSE_ARGUMENTS prefix arg_names option_names) + set(DEFAULT_ARGS) + foreach(arg_name ${arg_names}) + set(${prefix}_${arg_name}) + endforeach(arg_name) + foreach(option ${option_names}) + set(${prefix}_${option} FALSE) + endforeach(option) + + set(current_arg_name DEFAULT_ARGS) + set(current_arg_list) + foreach(arg ${ARGN}) + set(larg_names ${arg_names}) + list(FIND larg_names "${arg}" is_arg_name) + if(is_arg_name GREATER -1) + set(${prefix}_${current_arg_name} ${current_arg_list}) + set(current_arg_name ${arg}) + set(current_arg_list) + else(is_arg_name GREATER -1) + set(loption_names ${option_names}) + list(FIND loption_names "${arg}" is_option) + if(is_option GREATER -1) + set(${prefix}_${arg} TRUE) + else(is_option GREATER -1) + set(current_arg_list ${current_arg_list} ${arg}) + endif(is_option GREATER -1) + endif(is_arg_name GREATER -1) + endforeach(arg) + set(${prefix}_${current_arg_name} ${current_arg_list}) + +ENDMACRO(PARSE_ARGUMENTS) + +MACRO(CAR var) + set(${var} ${ARGV1}) +ENDMACRO(CAR) + +MACRO(CDR var junk) + set(${var} ${ARGN}) +ENDMACRO(CDR) + +## +## @end file ParseArguments.cmake +## diff --git a/modules/PrintFindStatus.cmake b/modules/PrintFindStatus.cmake new file mode 100644 index 0000000..54e33a7 --- /dev/null +++ b/modules/PrintFindStatus.cmake @@ -0,0 +1,210 @@ +### +# +# @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. +# +### +# +# - Some macros to print status when search for headers and libs +# Main parameters of macros +# _libname: name of the lib you seek, foo for example +# _header_to_find: name of the header you seek, foo.h for example +# _lib_to_find: name of the library you seek, libfoo for example +# _pc_to_find: name of the pkg-config file zyou seek, foo.pc for example + + +#============================================================================= +# 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.) + + +# Set some colors +#if(NOT WIN32) +# string(ASCII 27 Esc) +# set(ColourReset "${Esc}[m") +# set(ColourBold "${Esc}[1m") +# set(Red "${Esc}[31m") +# set(Green "${Esc}[32m") +# set(Yellow "${Esc}[33m") +# set(Blue "${Esc}[34m") +# set(Magenta "${Esc}[35m") +# set(Cyan "${Esc}[36m") +# set(White "${Esc}[37m") +# set(BoldRed "${Esc}[1;31m") +# set(BoldGreen "${Esc}[1;32m") +# set(BoldYellow "${Esc}[1;33m") +# set(BoldBlue "${Esc}[1;34m") +# set(BoldMagenta "${Esc}[1;35m") +# set(BoldCyan "${Esc}[1;36m") +# set(BoldWhite "${Esc}[1;37m") +#endif() + + +# This macro informs why the _header_to_find file has not been found +macro(Print_Find_Header_Status _libname _header_to_find) + + # save _libname upper and lower case + string(TOUPPER ${_libname} LIBNAME) + string(TOLOWER ${_libname} libname) + + # print status + #message(" ") + if(${LIBNAME}_INCDIR) + message("${Blue}${LIBNAME}_INCDIR is defined but ${_header_to_find}" + "has not been found in ${${LIBNAME}_INCDIR}${ColourReset}") + else() + if(${LIBNAME}_DIR) + message("${Blue}${LIBNAME}_DIR is defined but" + "${_header_to_find} has not been found in" + "${${LIBNAME}_DIR}/include${ColourReset}") + else() + message("${Blue}${_header_to_find} not found." + "Nor ${LIBNAME}_DIR neither ${LIBNAME}_INCDIR" + "are defined so that we looked for ${_header_to_find} in" + "system paths (INCLUDE, CPATH, C_INCLUDE_PATH," + "INCLUDE_PATH, CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES" + ", CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES)${ColourReset}") + if(_inc_env) + message("${Blue}${_header_to_find} has not been found in" + "${_inc_env}${ColourReset}") + endif() + endif() + endif() + message("${BoldBlue}Please indicate where to find ${_header_to_find}. You have three options:\n" + "- Option 1: Provide the root directory of the library with cmake option: -D${LIBNAME}_DIR=your/path/to/${libname}/\n" + "- Option 2: Provide the directory where to find the headers with cmake option: -D${LIBNAME}_INCDIR=your/path/to/${libname}/include/\n" + "- Option 3: Update your environment variable (INCLUDE or CPATH)\n" + "- Option 4: If your library provides a PkgConfig file, make sure pkg-config finds your library${ColourReset}") + #message(" ") + +endmacro() + +# This macro informs why the _lib_to_find file has not been found +macro(Print_Find_Library_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 ${${LIBNAME}_LIBDIR}${ColourReset}") + else() + if(${LIBNAME}_DIR) + message("${Yellow}${LIBNAME}_DIR is defined but ${_lib_to_find}" + "has not been found in ${${LIBNAME}_DIR}/lib(or /lib32 or" + "/lib64)${ColourReset}") + else() + message("${Yellow}${_lib_to_find} not found." + "Nor ${LIBNAME}_DIR neither ${LIBNAME}_LIBDIR" + "are defined so that we looked 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 root directory of the 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_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 root directory of the 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() + +# This macro informs that _pc_to_find file has not been found in the list +# path you give as last argument (read in ${ARGN}) +# ex: Print_Find_Pkgconfig_Status(foo foo.pc ${PATHLIST} +macro(Print_Find_Pkgconfig_Status _libname _pc_to_find) + + # save _libname lower case + string(TOLOWER ${_libname} libname) + + # print status + #message(" ") + message("${Magenta}${_pc_to_find} has not been found in" + "${ARGN}${ColourReset}") + message("${BoldMagenta}If you really want to use the pkg-config file of" + "${libname}, please update your PKG_CONFIG_PATH with the path" + "where ${_pc_to_find} states${ColourReset}") + #message(" ") + +endmacro() diff --git a/modules/Ressources.cmake b/modules/Ressources.cmake new file mode 100644 index 0000000..cd5e2a1 --- /dev/null +++ b/modules/Ressources.cmake @@ -0,0 +1,56 @@ +### +# +# @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. +# +### +# +# @file Ressources.cmake +# +# @project MORSE +# MORSE is a software package provided by: +# Inria Bordeaux - Sud-Ouest, +# Univ. of Tennessee, +# King Abdullah Univesity of Science and Technology +# Univ. of California Berkeley, +# Univ. of Colorado Denver. +# +# @version 0.9.0 +# @author Florent Pruvost +# @date 13-05-2015 +# +# Define variables for hardware ressources: +# - NUMBER_OF_CPU. +# - TODO: NUMBER_OF_CUDA. +### + + +if(NOT DEFINED PROCESSOR_COUNT) + # Unknown: + set(NUMBER_OF_CPU 0) + + # Linux: + set(cpuinfo_file "/proc/cpuinfo") + if(EXISTS "${cpuinfo_file}") + file(STRINGS "${cpuinfo_file}" procs REGEX "^processor.: [0-9]+$") + list(LENGTH procs NUMBER_OF_CPU) + endif() + + # Mac: + if(APPLE) + find_program(cmd_sys_pro "system_profiler") + if(cmd_sys_pro) + execute_process(COMMAND ${cmd_sys_pro} SPHardwareDataType OUTPUT_VARIABLE info) + string(REGEX REPLACE "^.*Total Number of Cores: ([0-9]+).*$" "\\1" + NUMBER_OF_CPU "${info}") + endif() + endif() + + # Windows: + if(WIN32) + set(NUMBER_OF_CPU "$ENV{NUMBER_OF_PROCESSORS}") + endif() +endif() diff --git a/modules/RulesPrecisions.cmake b/modules/RulesPrecisions.cmake new file mode 100644 index 0000000..5fb8224 --- /dev/null +++ b/modules/RulesPrecisions.cmake @@ -0,0 +1,256 @@ +### +# +# @copyright (c) 2009-2014 The University of Tennessee and The University +# of Tennessee Research Foundation. +# All rights reserved. +# @copyright (c) 2012-2016 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved. +# +### +# +# @file RulesPrecisions.cmake +# +# @project MORSE +# MORSE is a software package provided by: +# Inria Bordeaux - Sud-Ouest, +# Univ. of Tennessee, +# King Abdullah Univesity of Science and Technology +# Univ. of California Berkeley, +# Univ. of Colorado Denver. +# +# @version 0.9.0 +# @author Thomas Herault +# @author George Bosilca +# @author Aurelien Bouteiller +# @author Mathieu Faverge +# @author Florent Puvost +# @date 13-07-2012 +# +### +cmake_minimum_required(VERSION 2.8) +include(CMakeDependentOption) + +set(RP_GENDEPENDENCIES ${MORSE_CMAKE_MODULE_PATH}/precision_generator/genDependencies.py) +set(RP_CODEGEN ${MORSE_CMAKE_MODULE_PATH}/precision_generator/codegen.py) + +# Dictionnary +# ----------- +if( NOT DEFINED RP_${CMAKE_PROJECT_NAME}_DICTIONNARY ) + message( WARNING "RulesPrecisions included before RP_${CMAKE_PROJECT_NAME}_DICTIONNARY was defined (Default is used)" ) + set(RP_${CMAKE_PROJECT_NAME}_DICTIONNARY ${MORSE_CMAKE_MODULE_PATH}/precision_generator/subs.py + CACHE INTERNAL "Dictionnary used for precision generation" ) +else() + set(RP_${CMAKE_PROJECT_NAME}_DICTIONNARY ${RP_${CMAKE_PROJECT_NAME}_DICTIONNARY} + CACHE INTERNAL "Dictionnary used for precision generation" ) +endif() + +# Default Precisions +# ------------------ +if( NOT DEFINED RP_${CMAKE_PROJECT_NAME}_PRECISIONS ) + message( WARNING "RulesPrecisions included before RP_${CMAKE_PROJECT_NAME}_PRECISIONS was defined (\"s;d;c;z\" is used)" ) + set(RP_${CMAKE_PROJECT_NAME}_PRECISIONS "s;d;c;z" + CACHE INTERNAL "Set of available precisions for the project" ) +else() + set(RP_${CMAKE_PROJECT_NAME}_PRECISIONS ${RP_${CMAKE_PROJECT_NAME}_PRECISIONS} + CACHE INTERNAL "Set of available precisions for the project" ) +endif() + +# Detect if compilation is done in or out of place +# ------------------------------------------------ +string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" __inplace) +set( ${CMAKE_PROJECT_NAME}_COMPILE_INPLACE ${__inplace} + CACHE INTERNAL "Defines if the project compilation is made inplace or not" ) + +# Detect default settings +# ----------------------- +set( _prec_S OFF ) +set( _prec_D OFF ) +set( _prec_DS OFF ) +set( _prec_C OFF ) +set( _prec_Z OFF ) +set( _prec_ZC OFF ) +foreach(_prec ${RP_${CMAKE_PROJECT_NAME}_PRECISIONS}) + if ( ${_prec} STREQUAL zc ) + set( _prec_S ON ) + set( _prec_D ON ) + set( _prec_C ON ) + set( _prec_Z ON ) + set( _prec_ZC ON ) + elseif( ${_prec} STREQUAL z ) + set( _prec_D ON ) + set( _prec_Z ON ) + elseif( ${_prec} STREQUAL c ) + set( _prec_S ON ) + set( _prec_C ON ) + elseif( ${_prec} STREQUAL ds ) + set( _prec_S ON ) + set( _prec_D ON ) + set( _prec_DS ON ) + elseif( ${_prec} STREQUAL d ) + set( _prec_S ON ) + elseif( ${_prec} STREQUAL s ) + set( _prec_S ON ) + endif() +endforeach() + +# set computed precisions +# ----------------------- +if( ${_prec_S} ) + option(${PROJECT_NAME}_PREC_S + "Build ${PROJECT_NAME} real single precision" ON) +endif() +if( ${_prec_D} ) + option(${PROJECT_NAME}_PREC_D + "Build ${PROJECT_NAME} real double precision" ON) +endif() + +if( ${_prec_C} ) + cmake_dependent_option(${PROJECT_NAME}_PREC_C + "Build ${PROJECT_NAME} complex single precision" ON "${PROJECT_NAME}_PREC_S" OFF) +endif() +if( ${_prec_Z} ) + cmake_dependent_option(${PROJECT_NAME}_PREC_Z + "Build ${PROJECT_NAME} complex double precision" ON "${PROJECT_NAME}_PREC_D" OFF) +endif() + +if( ${_prec_DS} ) + cmake_dependent_option(${PROJECT_NAME}_PREC_DS + "Build ${PROJECT_NAME} real mixed precision" ON "${PROJECT_NAME}_PREC_S;${PROJECT_NAME}_PREC_D" OFF) +endif() +if( ${_prec_ZC} ) + cmake_dependent_option(${PROJECT_NAME}_PREC_ZC + "Build ${PROJECT_NAME} complex mixed precision" ON "${PROJECT_NAME}_PREC_C;${PROJECT_NAME}_PREC_Z" OFF) +endif() + +# Define precision supported by the project +# ----------------------------------------- +set( ${CMAKE_PROJECT_NAME}_PRECISION "" ) +if(${CMAKE_PROJECT_NAME}_PREC_S) + list(APPEND ${CMAKE_PROJECT_NAME}_PRECISION "s") +endif() + +if(${CMAKE_PROJECT_NAME}_PREC_D) + list(APPEND ${CMAKE_PROJECT_NAME}_PRECISION "d") +endif() + +if(${CMAKE_PROJECT_NAME}_PREC_DS) + list(APPEND ${CMAKE_PROJECT_NAME}_PRECISION "ds") +endif() + +if(${CMAKE_PROJECT_NAME}_PREC_C) + list(APPEND ${CMAKE_PROJECT_NAME}_PRECISION "c") +endif() + +if(${CMAKE_PROJECT_NAME}_PREC_Z) + list(APPEND ${CMAKE_PROJECT_NAME}_PRECISION "z") +endif() + +if(${CMAKE_PROJECT_NAME}_PREC_ZC) + list(APPEND ${CMAKE_PROJECT_NAME}_PRECISION "zc") +endif() + +# +# Generates a rule for every SOURCES file, to create the precisions in PRECISIONS. If TARGETDIR +# is not empty then all generated files will be prepended with the $TARGETDIR/. +# A new file is created, from a copy by default +# If the first precision is "/", all occurences of the basename in the file are remplaced by +# "pbasename" where p is the selected precision. +# the target receives a -DPRECISION_p in its cflags. +# +include(ParseArguments) +find_package(PythonInterp REQUIRED) + +MACRO(precisions_rules_py) + PARSE_ARGUMENTS(PREC_RULE "TARGETDIR;PRECISIONS" "" ${ARGN}) + + message(STATUS "Generate precision dependencies in ${CMAKE_CURRENT_SOURCE_DIR}") + + # The first is the output variable list + CAR(OUTPUTLIST ${PREC_RULE_DEFAULT_ARGS}) + # Everything else should be source files. + CDR(SOURCES ${PREC_RULE_DEFAULT_ARGS}) + + if( NOT DEFINED ${CMAKE_PROJECT_NAME}_COMPILE_INPLACE ) + message( FATAL_ERROR "precisions_rules_init must be called before any call to precisions_rules_py" ) + endif() + + if( NOT DEFINED RP_${CMAKE_PROJECT_NAME}_DICTIONNARY ) + message( FATAL_ERROR "precisions_rules_init must be called before any call to precisions_rules_py" ) + endif() + + # By default the TARGETDIR is the current binary directory + if( "${PREC_RULE_TARGETDIR}" STREQUAL "" ) + set(PREC_RULE_TARGETDIR "./") + set(PRECISIONPP_prefix "./") + set(PRECISIONPP_arg "-P") + else( "${PREC_RULE_TARGETDIR}" STREQUAL "" ) + if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${PREC_RULE_TARGETDIR}) + else(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${PREC_RULE_TARGETDIR}) + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PREC_RULE_TARGETDIR}) + endif(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${PREC_RULE_TARGETDIR}) + set(PRECISIONPP_arg "-P") + set(PRECISIONPP_prefix "${PREC_RULE_TARGETDIR}") + endif( "${PREC_RULE_TARGETDIR}" STREQUAL "" ) + + set(options_list "") + foreach(prec_rules_PREC ${PREC_RULE_PRECISIONS}) + set(options_list "${options_list} ${prec_rules_PREC}") + endforeach() + + set(sources_list "") + foreach(_src ${SOURCES}) + set(sources_list "${sources_list} ${_src}") + endforeach() + + set(gencmd ${PYTHON_EXECUTABLE} ${RP_GENDEPENDENCIES} -f "${sources_list}" -p "${options_list}" -s "${CMAKE_CURRENT_SOURCE_DIR}" ${PRECISIONPP_arg} ${PRECISIONPP_prefix}) + EXECUTE_PROCESS(COMMAND ${gencmd} OUTPUT_VARIABLE dependencies_list) + + foreach(_dependency ${dependencies_list}) + + string(STRIP "${_dependency}" _dependency) + string(COMPARE NOTEQUAL "${_dependency}" "" not_empty) + if( not_empty ) + + string(REGEX REPLACE "^(.*),(.*),(.*)$" "\\1" _dependency_INPUT "${_dependency}") + set(_dependency_PREC "${CMAKE_MATCH_2}") + set(_dependency_OUTPUT "${CMAKE_MATCH_3}") + + set(pythoncmd ${PYTHON_EXECUTABLE} ${RP_CODEGEN} -f ${CMAKE_CURRENT_SOURCE_DIR}/${_dependency_INPUT} -p ${_dependency_PREC} ${PRECISIONPP_arg} ${PRECISIONPP_prefix}) + + string(STRIP "${_dependency_OUTPUT}" _dependency_OUTPUT) + string(COMPARE NOTEQUAL "${_dependency_OUTPUT}" "" got_file) + + # Force the copy of the original files in the binary_dir + # for VPATH compilation + if( NOT ${CMAKE_PROJECT_NAME}_COMPILE_INPLACE ) + set(generate_out 1) + else( NOT ${CMAKE_PROJECT_NAME}_COMPILE_INPLACE ) + string(COMPARE NOTEQUAL "${_dependency_OUTPUT}" "${_dependency_INPUT}" generate_out ) + endif() + + # We generate a dependency only if a file will be generated + if( got_file ) + if( generate_out ) + # the custom command is executed in CMAKE_CURRENT_BINARY_DIR + ADD_CUSTOM_COMMAND( + OUTPUT ${_dependency_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E remove -f ${_dependency_OUTPUT} && ${pythoncmd} && chmod a-w ${_dependency_OUTPUT} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_dependency_INPUT} ${RP_CODEGEN} ${RP_${CMAKE_PROJECT_NAME}_DICTIONNARY}) + + set_SOURCE_FILES_PROPERTIES(${_dependency_OUTPUT} PROPERTIES COMPILE_FLAGS "-DPRECISION_${_dependency_PREC}" GENERATED 1 IS_IN_BINARY_DIR 1 ) + + else( generate_out ) + set_SOURCE_FILES_PROPERTIES(${_dependency_OUTPUT} PROPERTIES COMPILE_FLAGS "-DPRECISION_${_dependency_PREC}" GENERATED 0 ) + endif( generate_out ) + + list(APPEND ${OUTPUTLIST} ${_dependency_OUTPUT}) + endif( got_file ) + endif() + endforeach() + + message(STATUS "Generate precision dependencies in ${CMAKE_CURRENT_SOURCE_DIR} - Done") + +ENDMACRO(precisions_rules_py) + +## +## @end file RulesPrecisions.cmake +## diff --git a/modules/find/FindBLAS.cmake b/modules/find/FindBLAS.cmake new file mode 100644 index 0000000..e9efa72 --- /dev/null +++ b/modules/find/FindBLAS.cmake @@ -0,0 +1,1409 @@ +### +# +# @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 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_LINKER_FLAGS - uncached list of required linker flags (excluding -l +# and -L). +# 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 +# +# - 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}) + +# Check the language being used +get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES ) +if( _LANGUAGES_ MATCHES Fortran ) + 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() + +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_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 () + 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_work ${${_prefix}_${_library}_LIBRARY}) + endif(_libraries_work) + endforeach(_library ${_list}) + + 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_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() + + if(_libraries_work) + set(${LIBRARIES} ${${LIBRARIES}} ${_thread}) + else(_libraries_work) + set(${LIBRARIES} FALSE) + endif(_libraries_work) + +endmacro(Check_Fortran_Libraries) + + +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 () + +#BLAS in intel mkl 10 library? (em64t 64bit) +if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All") + + if(NOT BLAS_LIBRARIES OR BLA_VENDOR MATCHES "Intel*") + # Looking for include + # ------------------- + + # 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) + + # set paths where to look for + set(PATH_TO_LOOK_FOR "${_inc_env}") + + # 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) + + # 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 + "" + "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() + +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" + "" + ) + 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() + + 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" + "" + ) + 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() + + 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" + "" + ) + 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() + + 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" + "" + ) + if(BLAS_LIBRARIES) + set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf") + endif() + if(NOT BLAS_FIND_QUIETLY) + if(BLAS_LIBRARIES) + message(STATUS "Looking for SunPerf BLAS: found") + else() + message(STATUS "Looking for SunPerf BLAS: not found") + endif() + endif() + endif() + + 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" + "" + ) + 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() + + 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" + "" + ) + 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() + + 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;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() + + 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 + "" + "esslsmp;xlsmp;xlfmath;xlf90_r;blas" + "" + ) + 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() + + if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND) + set (BLAS_VENDOR_FOUND "IBM ESSL MT") + endif() + +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 + "" + "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() + + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_LIBRARIES + BLAS + sgemm + "" + "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() + + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_LIBRARIES + BLAS + sgemm + "" + "acml;acml_mv;CALBLAS" + "" + ) + 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() + + 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 + dgemm + "" + "Accelerate" + "" + ) + 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 (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 + dgemm + "" + "vecLib" + "" + ) + 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 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}") + if (NOT BLAS_LIBRARIES_DEP) + set(BLAS_LIBRARIES_DEP "${BLAS95_LIBRARIES}") + endif() + +else(BLA_F95) + + if(BLAS_LIBRARIES) + set(BLAS_FOUND TRUE) + else() + set(BLAS_FOUND FALSE) + endif() + + 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.") + else() + message(STATUS + "A library with BLAS API not found. Please specify library location.") + endif() + endif(BLAS_FOUND) + endif(NOT BLAS_FIND_QUIETLY) + +endif(BLA_F95) + +set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) + +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/modules/find/FindBLASEXT.cmake b/modules/find/FindBLASEXT.cmake new file mode 100644 index 0000000..0fe7fb8 --- /dev/null +++ b/modules/find/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/modules/find/FindCBLAS.cmake b/modules/find/FindCBLAS.cmake new file mode 100644 index 0000000..eb10586 --- /dev/null +++ b/modules/find/FindCBLAS.cmake @@ -0,0 +1,388 @@ +### +# +# @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 CBLAS include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(CBLAS +# [REQUIRED] # Fail with error if cblas is not found +# [COMPONENTS <comp1> <comp2> ...] # dependencies +# ) +# +# CBLAS depends on the following libraries: +# - BLAS +# +# This module finds headers and cblas library. +# Results are reported in variables: +# CBLAS_FOUND - True if headers and requested libraries were found +# CBLAS_LINKER_FLAGS - list of required linker flags (excluding -l and -L) +# CBLAS_INCLUDE_DIRS - cblas include directories +# CBLAS_LIBRARY_DIRS - Link directories for cblas libraries +# CBLAS_LIBRARIES - cblas component libraries to be linked +# CBLAS_INCLUDE_DIRS_DEP - cblas + dependencies include directories +# CBLAS_LIBRARY_DIRS_DEP - cblas + dependencies link directories +# CBLAS_LIBRARIES_DEP - cblas libraries + dependencies +# CBLAS_HAS_ZGEMM3M - True if cblas contains zgemm3m fast complex mat-mat product +# +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DCBLAS_DIR=path/to/cblas): +# CBLAS_DIR - Where to find the base directory of cblas +# CBLAS_INCDIR - Where to find the header files +# CBLAS_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: CBLAS_DIR, CBLAS_INCDIR, CBLAS_LIBDIR +# +# CBLAS could be directly embedded in BLAS library (ex: Intel MKL) so that +# we test a cblas function with the blas libraries found and set CBLAS +# variables to BLAS ones if test is successful. To skip this feature and +# look for a stand alone cblas, please add the following in your +# CMakeLists.txt before to call find_package(CBLAS): +# set(CBLAS_STANDALONE TRUE) +### +# We handle different modes to find the dependency +# +# - Detection if already installed on the system +# - CBLAS libraries can be detected from different ways +# Here is the order of precedence: +# 1) we look in cmake variable CBLAS_LIBDIR or CBLAS_DIR (we guess the libdirs) if defined +# 2) we look in environment variable CBLAS_LIBDIR or CBLAS_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 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 CBLAS_FOUND) + set(CBLAS_DIR "" CACHE PATH "Installation directory of CBLAS library") + if (NOT CBLAS_FIND_QUIETLY) + message(STATUS "A cache variable, namely CBLAS_DIR, has been set to specify the install directory of CBLAS") + endif() +endif() + + +# CBLAS depends on BLAS anyway, try to find it +if (NOT BLAS_FOUND) + if(CBLAS_FIND_REQUIRED) + find_package(BLASEXT REQUIRED) + else() + find_package(BLASEXT) + endif() +endif() + + +# find CBLAS +if (BLAS_FOUND) + + if (NOT CBLAS_STANDALONE) + # check if a cblas function exists in the BLAS lib + # this can be the case with libs such as MKL, ACML + include(CheckFunctionExists) + set(CMAKE_REQUIRED_LIBRARIES "${BLAS_LINKER_FLAGS};${BLAS_LIBRARIES}") + set(CMAKE_REQUIRED_FLAGS "${BLAS_COMPILER_FLAGS}") + unset(CBLAS_WORKS CACHE) + check_function_exists(cblas_dscal CBLAS_WORKS) + check_function_exists(cblas_zgemm3m CBLAS_ZGEMM3M_FOUND) + mark_as_advanced(CBLAS_WORKS) + set(CMAKE_REQUIRED_LIBRARIES) + + if(CBLAS_WORKS) + + # Check for faster complex GEMM routine + # (only C/Z, no S/D version) + if ( CBLAS_ZGEMM3M_FOUND ) + add_definitions(-DCBLAS_HAS_ZGEMM3M -DCBLAS_HAS_CGEMM3M) + endif() + + if(NOT CBLAS_FIND_QUIETLY) + message(STATUS "Looking for cblas: test with blas succeeds") + endif() + # test succeeds: CBLAS is in BLAS + set(CBLAS_LIBRARIES "${BLAS_LIBRARIES}") + if (BLAS_LIBRARY_DIRS) + set(CBLAS_LIBRARY_DIRS "${BLAS_LIBRARY_DIRS}") + endif() + if(BLAS_INCLUDE_DIRS) + set(CBLAS_INCLUDE_DIRS "${BLAS_INCLUDE_DIRS}") + endif() + if (BLAS_LINKER_FLAGS) + set(CBLAS_LINKER_FLAGS "${BLAS_LINKER_FLAGS}") + endif() + endif() + endif (NOT CBLAS_STANDALONE) + + if (CBLAS_STANDALONE OR NOT CBLAS_WORKS) + + if(NOT CBLAS_WORKS AND NOT CBLAS_FIND_QUIETLY) + message(STATUS "Looking for cblas : test with blas fails") + endif() + # test fails: try to find CBLAS lib exterior to BLAS + + # Try to find CBLAS lib + ####################### + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + unset(_inc_env) + set(ENV_CBLAS_DIR "$ENV{CBLAS_DIR}") + set(ENV_CBLAS_INCDIR "$ENV{CBLAS_INCDIR}") + if(ENV_CBLAS_INCDIR) + list(APPEND _inc_env "${ENV_CBLAS_INCDIR}") + elseif(ENV_CBLAS_DIR) + list(APPEND _inc_env "${ENV_CBLAS_DIR}") + list(APPEND _inc_env "${ENV_CBLAS_DIR}/include") + list(APPEND _inc_env "${ENV_CBLAS_DIR}/include/cblas") + else() + 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) + + + # Try to find the cblas header in the given paths + # ------------------------------------------------- + # call cmake macro to find the header path + if(CBLAS_INCDIR) + set(CBLAS_cblas.h_DIRS "CBLAS_cblas.h_DIRS-NOTFOUND") + find_path(CBLAS_cblas.h_DIRS + NAMES cblas.h + HINTS ${CBLAS_INCDIR}) + else() + if(CBLAS_DIR) + set(CBLAS_cblas.h_DIRS "CBLAS_cblas.h_DIRS-NOTFOUND") + find_path(CBLAS_cblas.h_DIRS + NAMES cblas.h + HINTS ${CBLAS_DIR} + PATH_SUFFIXES "include" "include/cblas") + else() + set(CBLAS_cblas.h_DIRS "CBLAS_cblas.h_DIRS-NOTFOUND") + find_path(CBLAS_cblas.h_DIRS + NAMES cblas.h + HINTS ${_inc_env} + PATH_SUFFIXES "cblas") + endif() + endif() + mark_as_advanced(CBLAS_cblas.h_DIRS) + + # If found, add path to cmake variable + # ------------------------------------ + if (CBLAS_cblas.h_DIRS) + set(CBLAS_INCLUDE_DIRS "${CBLAS_cblas.h_DIRS}") + else () + set(CBLAS_INCLUDE_DIRS "CBLAS_INCLUDE_DIRS-NOTFOUND") + if(NOT CBLAS_FIND_QUIETLY) + message(STATUS "Looking for cblas -- cblas.h not found") + endif() + endif() + + + # Looking for lib + # --------------- + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_CBLAS_LIBDIR "$ENV{CBLAS_LIBDIR}") + if(ENV_CBLAS_LIBDIR) + list(APPEND _lib_env "${ENV_CBLAS_LIBDIR}") + elseif(ENV_CBLAS_DIR) + list(APPEND _lib_env "${ENV_CBLAS_DIR}") + list(APPEND _lib_env "${ENV_CBLAS_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 cblas lib in the given paths + # ---------------------------------------------- + + # call cmake macro to find the lib path + if(CBLAS_LIBDIR) + set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND") + find_library(CBLAS_cblas_LIBRARY + NAMES cblas + HINTS ${CBLAS_LIBDIR}) + else() + if(CBLAS_DIR) + set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND") + find_library(CBLAS_cblas_LIBRARY + NAMES cblas + HINTS ${CBLAS_DIR} + PATH_SUFFIXES lib lib32 lib64) + else() + set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND") + find_library(CBLAS_cblas_LIBRARY + NAMES cblas + HINTS ${_lib_env}) + endif() + endif() + mark_as_advanced(CBLAS_cblas_LIBRARY) + + # If found, add path to cmake variable + # ------------------------------------ + if (CBLAS_cblas_LIBRARY) + get_filename_component(cblas_lib_path "${CBLAS_cblas_LIBRARY}" PATH) + # set cmake variables + set(CBLAS_LIBRARIES "${CBLAS_cblas_LIBRARY}") + set(CBLAS_LIBRARY_DIRS "${cblas_lib_path}") + else () + set(CBLAS_LIBRARIES "CBLAS_LIBRARIES-NOTFOUND") + set(CBLAS_LIBRARY_DIRS "CBLAS_LIBRARY_DIRS-NOTFOUND") + if (NOT CBLAS_FIND_QUIETLY) + message(STATUS "Looking for cblas -- lib cblas not found") + endif() + endif () + + # check a function to validate the find + if(CBLAS_LIBRARIES) + + set(REQUIRED_INCDIRS) + set(REQUIRED_LDFLAGS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # CBLAS + if (CBLAS_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${CBLAS_INCLUDE_DIRS}") + endif() + if (CBLAS_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${CBLAS_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${CBLAS_LIBRARIES}") + # BLAS + if (BLAS_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${BLAS_INCLUDE_DIRS}") + endif() + if (BLAS_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${BLAS_LIBRARY_DIRS}") + endif() + list(APPEND REQUIRED_LIBS "${BLAS_LIBRARIES}") + if (BLAS_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}") + 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}") + string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + + # test link + unset(CBLAS_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(cblas_dscal CBLAS_WORKS) + mark_as_advanced(CBLAS_WORKS) + + if(CBLAS_WORKS) + + # Check for faster complex GEMM routine + # (only C/Z, no S/D version) + check_function_exists(cblas_zgemm3m CBLAS_ZGEMM3M_FOUND) + if ( CBLAS_ZGEMM3M_FOUND ) + add_definitions(-DCBLAS_HAS_ZGEMM3M -DCBLAS_HAS_CGEMM3M) + endif() + + # save link with dependencies + set(CBLAS_LIBRARIES_DEP "${REQUIRED_LIBS}") + set(CBLAS_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(CBLAS_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(CBLAS_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES CBLAS_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES CBLAS_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES CBLAS_LINKER_FLAGS) + else() + if(NOT CBLAS_FIND_QUIETLY) + message(STATUS "Looking for cblas : test of cblas_dscal with cblas and blas libraries 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(CBLAS_LIBRARIES) + + endif (CBLAS_STANDALONE OR NOT CBLAS_WORKS) + +else(BLAS_FOUND) + + if (NOT CBLAS_FIND_QUIETLY) + message(STATUS "CBLAS requires BLAS but BLAS has not been found." + "Please look for BLAS first.") + endif() + +endif(BLAS_FOUND) + +if (CBLAS_LIBRARIES) + list(GET CBLAS_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(CBLAS_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of CBLAS library" FORCE) + else() + set(CBLAS_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of CBLAS library" FORCE) + endif() +endif() +mark_as_advanced(CBLAS_DIR) +mark_as_advanced(CBLAS_DIR_FOUND) + +# check that CBLAS has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CBLAS DEFAULT_MSG + CBLAS_LIBRARIES + CBLAS_WORKS) diff --git a/modules/find/FindCHAMELEON.cmake b/modules/find/FindCHAMELEON.cmake new file mode 100644 index 0000000..9b581f5 --- /dev/null +++ b/modules/find/FindCHAMELEON.cmake @@ -0,0 +1,800 @@ +### +# +# @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 CHAMELEON include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(CHAMELEON +# [REQUIRED] # Fail with error if chameleon is not found +# [COMPONENTS <comp1> <comp2> ...] # dependencies +# ) +# +# CHAMELEON depends on the following libraries: +# - Threads, m, rt +# - HWLOC +# - CBLAS +# - LAPACKE +# - TMG +# - At least one runtime, default is StarPU +# (For QUARK, use COMPONENTS QUARK) +# +# COMPONENTS are optional libraries CHAMELEON could be linked with, +# Use it to drive detection of a specific compilation chain +# COMPONENTS can be some of the following: +# - STARPU (default): to activate detection of Chameleon linked with StarPU +# - QUARK (STARPU will be deactivated): to activate detection of Chameleon linked with QUARK +# - CUDA (comes with cuBLAS): to activate detection of Chameleon linked with CUDA +# - MAGMA: to activate detection of Chameleon linked with MAGMA +# - MPI: to activate detection of Chameleon linked with MPI +# - FXT: to activate detection of Chameleon linked with StarPU+FXT +# +# This module finds headers and chameleon library. +# Results are reported in variables: +# CHAMELEON_FOUND - True if headers and requested libraries were found +# CHAMELEON_LINKER_FLAGS - list of required linker flags (excluding -l and -L) +# CHAMELEON_INCLUDE_DIRS - chameleon include directories +# CHAMELEON_LIBRARY_DIRS - Link directories for chameleon libraries +# CHAMELEON_INCLUDE_DIRS_DEP - chameleon + dependencies include directories +# CHAMELEON_LIBRARY_DIRS_DEP - chameleon + dependencies link directories +# CHAMELEON_LIBRARIES_DEP - chameleon libraries + dependencies +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DCHAMELEON_DIR=path/to/chameleon): +# CHAMELEON_DIR - Where to find the base directory of chameleon +# CHAMELEON_INCDIR - Where to find the header files +# CHAMELEON_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: CHAMELEON_DIR, CHAMELEON_INCDIR, CHAMELEON_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 CHAMELEON_FOUND) + set(CHAMELEON_DIR "" CACHE PATH "Installation directory of CHAMELEON library") + if (NOT CHAMELEON_FIND_QUIETLY) + message(STATUS "A cache variable, namely CHAMELEON_DIR, has been set to specify the install directory of CHAMELEON") + endif() +endif() + +# Try to find CHAMELEON dependencies if specified as COMPONENTS during the call +set(CHAMELEON_LOOK_FOR_STARPU ON) +set(CHAMELEON_LOOK_FOR_QUARK OFF) +set(CHAMELEON_LOOK_FOR_CUDA OFF) +set(CHAMELEON_LOOK_FOR_MAGMA OFF) +set(CHAMELEON_LOOK_FOR_MPI OFF) +set(CHAMELEON_LOOK_FOR_FXT OFF) + +if( CHAMELEON_FIND_COMPONENTS ) + foreach( component ${CHAMELEON_FIND_COMPONENTS} ) + if (${component} STREQUAL "STARPU") + # means we look for Chameleon with StarPU + set(CHAMELEON_LOOK_FOR_STARPU ON) + set(CHAMELEON_LOOK_FOR_QUARK OFF) + endif() + if (${component} STREQUAL "QUARK") + # means we look for Chameleon with QUARK + set(CHAMELEON_LOOK_FOR_QUARK ON) + set(CHAMELEON_LOOK_FOR_STARPU OFF) + endif() + if (${component} STREQUAL "CUDA") + # means we look for Chameleon with CUDA + set(CHAMELEON_LOOK_FOR_CUDA ON) + endif() + if (${component} STREQUAL "MAGMA") + # means we look for Chameleon with MAGMA + set(CHAMELEON_LOOK_FOR_MAGMA ON) + endif() + if (${component} STREQUAL "MPI") + # means we look for Chameleon with MPI + set(CHAMELEON_LOOK_FOR_MPI ON) + endif() + if (${component} STREQUAL "FXT") + # means we look for Chameleon with FXT + set(CHAMELEON_LOOK_FOR_FXT ON) + endif() + endforeach() +endif() + +set(ENV_CHAMELEON_DIR "$ENV{CHAMELEON_DIR}") +set(ENV_CHAMELEON_INCDIR "$ENV{CHAMELEON_INCDIR}") +set(ENV_CHAMELEON_LIBDIR "$ENV{CHAMELEON_LIBDIR}") +set(CHAMELEON_GIVEN_BY_USER "FALSE") +if ( CHAMELEON_DIR OR ( CHAMELEON_INCDIR AND CHAMELEON_LIBDIR) OR ENV_CHAMELEON_DIR OR (ENV_CHAMELEON_INCDIR AND ENV_CHAMELEON_LIBDIR) ) + set(CHAMELEON_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 CHAMELEON_GIVEN_BY_USER) + + pkg_search_module(CHAMELEON chameleon) + if (NOT CHAMELEON_FIND_QUIETLY) + if (CHAMELEON_FOUND AND CHAMELEON_LIBRARIES) + message(STATUS "Looking for CHAMELEON - found using PkgConfig") + #if(NOT CHAMELEON_INCLUDE_DIRS) + # message("${Magenta}CHAMELEON_INCLUDE_DIRS is empty using PkgConfig." + # "Perhaps the path to chameleon headers is already present in your" + # "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}") + #endif() + else() + message(STATUS "${Magenta}Looking for CHAMELEON - not found using PkgConfig." + "\n Perhaps you should add the directory containing chameleon.pc" + "\n to the PKG_CONFIG_PATH environment variable.${ColourReset}") + endif() + endif() + + if (CHAMELEON_FIND_VERSION_EXACT) + if( NOT (CHAMELEON_FIND_VERSION_MAJOR STREQUAL CHAMELEON_VERSION_MAJOR) OR + NOT (CHAMELEON_FIND_VERSION_MINOR STREQUAL CHAMELEON_VERSION_MINOR) ) + if(NOT CHAMELEON_FIND_QUIETLY) + message(FATAL_ERROR + "CHAMELEON version found is ${CHAMELEON_VERSION_STRING}" + "when required is ${CHAMELEON_FIND_VERSION}") + endif() + endif() + else() + # if the version found is older than the required then error + if( (CHAMELEON_FIND_VERSION_MAJOR STRGREATER CHAMELEON_VERSION_MAJOR) OR + (CHAMELEON_FIND_VERSION_MINOR STRGREATER CHAMELEON_VERSION_MINOR) ) + if(NOT CHAMELEON_FIND_QUIETLY) + message(FATAL_ERROR + "CHAMELEON version found is ${CHAMELEON_VERSION_STRING}" + "when required is ${CHAMELEON_FIND_VERSION} or newer") + endif() + endif() + endif() + + set(CHAMELEON_INCLUDE_DIRS_DEP "${CHAMELEON_INCLUDE_DIRS}") + set(CHAMELEON_LIBRARY_DIRS_DEP "${CHAMELEON_LIBRARY_DIRS}") + set(CHAMELEON_LIBRARIES_DEP "${CHAMELEON_LIBRARIES}") + +endif(PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_GIVEN_BY_USER) + +if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR (CHAMELEON_GIVEN_BY_USER) ) + + if (NOT CHAMELEON_FIND_QUIETLY) + message(STATUS "Looking for CHAMELEON - PkgConfig not used") + endif() + + # Dependencies detection + # ---------------------- + + if (NOT CHAMELEON_FIND_QUIETLY) + message(STATUS "Looking for CHAMELEON - Try to detect pthread") + endif() + if (CHAMELEON_FIND_REQUIRED) + find_package(Threads REQUIRED) + else() + find_package(Threads) + endif() + set(CHAMELEON_EXTRA_LIBRARIES "") + if( THREADS_FOUND ) + list(APPEND CHAMELEON_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 CHAMELEON_FIND_QUIETLY) + message(STATUS "Looking for CHAMELEON - Try to detect libm") + endif() + set(CHAMELEON_M_LIBRARIES "") + if(UNIX OR WIN32) + find_library( + CHAMELEON_M_m_LIBRARY + NAMES m + ) + mark_as_advanced(CHAMELEON_M_m_LIBRARY) + if (CHAMELEON_M_m_LIBRARY) + list(APPEND CHAMELEON_M_LIBRARIES "${CHAMELEON_M_m_LIBRARY}") + list(APPEND CHAMELEON_EXTRA_LIBRARIES "${CHAMELEON_M_m_LIBRARY}") + else() + if (CHAMELEON_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 CHAMELEON_FIND_QUIETLY) + message(STATUS "Looking for CHAMELEON - Try to detect librt") + endif() + set(CHAMELEON_RT_LIBRARIES "") + if(UNIX AND NOT APPLE) + find_library( + CHAMELEON_RT_rt_LIBRARY + NAMES rt + ) + mark_as_advanced(CHAMELEON_RT_rt_LIBRARY) + if (CHAMELEON_RT_rt_LIBRARY) + list(APPEND CHAMELEON_RT_LIBRARIES "${CHAMELEON_RT_rt_LIBRARY}") + list(APPEND CHAMELEON_EXTRA_LIBRARIES "${CHAMELEON_RT_rt_LIBRARY}") + else() + if (CHAMELEON_FIND_REQUIRED) + message(FATAL_ERROR "Could NOT find librt on your system") + endif() + endif() + endif() + + # CHAMELEON depends on CBLAS + #--------------------------- + if (NOT CHAMELEON_FIND_QUIETLY) + message(STATUS "Looking for CHAMELEON - Try to detect CBLAS (depends on BLAS)") + endif() + if (CHAMELEON_FIND_REQUIRED) + find_package(CBLAS REQUIRED) + else() + find_package(CBLAS) + endif() + + # CHAMELEON depends on LAPACKE + #----------------------------- + + # standalone version of lapacke seems useless for now + # let the comment in case we meet some problems of non existing lapacke + # functions in lapack library such as mkl, acml, ... + #set(LAPACKE_STANDALONE TRUE) + if (NOT CHAMELEON_FIND_QUIETLY) + message(STATUS "Looking for CHAMELEON - Try to detect LAPACKE (depends on LAPACK)") + endif() + if (CHAMELEON_FIND_REQUIRED) + find_package(LAPACKE REQUIRED) + else() + find_package(LAPACKE) + endif() + + # CHAMELEON depends on TMG + #------------------------- + if (NOT CHAMELEON_FIND_QUIETLY) + message(STATUS "Looking for CHAMELEON - Try to detect TMG (depends on LAPACK)") + endif() + if (CHAMELEON_FIND_REQUIRED) + find_package(TMG REQUIRED) + else() + find_package(TMG) + endif() + + # CHAMELEON may depend on CUDA/CUBLAS + #------------------------------------ + if (NOT CUDA_FOUND AND CHAMELEON_LOOK_FOR_CUDA) + if (CHAMELEON_FIND_REQUIRED AND CHAMELEON_FIND_REQUIRED_CUDA) + find_package(CUDA REQUIRED) + else() + find_package(CUDA) + endif() + if (CUDA_FOUND) + mark_as_advanced(CUDA_BUILD_CUBIN) + mark_as_advanced(CUDA_BUILD_EMULATION) + mark_as_advanced(CUDA_SDK_ROOT_DIR) + mark_as_advanced(CUDA_TOOLKIT_ROOT_DIR) + mark_as_advanced(CUDA_VERBOSE_BUILD) + endif() + endif() + + # CHAMELEON may depend on MAGMA gpu kernels + # call our cmake module to test (in cmake_modules) + # change this call position if not appropriated + #------------------------------------------------- + if( CUDA_FOUND AND CHAMELEON_LOOK_FOR_MAGMA ) + set(CHAMELEON_MAGMA_VERSION "1.4" CACHE STRING "oldest MAGMA version desired") + if (CHAMELEON_FIND_REQUIRED AND CHAMELEON_FIND_REQUIRED_MAGMA) + find_package(MAGMA ${CHAMELEON_MAGMA_VERSION} REQUIRED) + else() + find_package(MAGMA ${CHAMELEON_MAGMA_VERSION}) + endif() + endif() + + # CHAMELEON depends on MPI + #------------------------- + if( NOT MPI_FOUND AND CHAMELEON_LOOK_FOR_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(NOT MPI_C_COMPILER) + set(MPI_C_COMPILER mpicc) + endif() + if (CHAMELEON_FIND_REQUIRED AND CHAMELEON_FIND_REQUIRED_MPI) + find_package(MPI REQUIRED) + else() + find_package(MPI) + endif() + if (MPI_FOUND) + mark_as_advanced(MPI_LIBRARY) + mark_as_advanced(MPI_EXTRA_LIBRARY) + endif() + + endif() + + if( NOT STARPU_FOUND AND CHAMELEON_LOOK_FOR_STARPU ) + + set(CHAMELEON_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 (CHAMELEON_LOOK_FOR_MPI) + if(NOT MPI_C_COMPILER) + set(MPI_C_COMPILER mpicc) + endif() + list(APPEND STARPU_COMPONENT_LIST "MPI") + endif() + if (CHAMELEON_LOOK_FOR_CUDA) + list(APPEND STARPU_COMPONENT_LIST "CUDA") + endif() + if (CHAMELEON_LOOK_FOR_FXT) + list(APPEND STARPU_COMPONENT_LIST "FXT") + endif() + if (CHAMELEON_FIND_REQUIRED AND CHAMELEON_FIND_REQUIRED_STARPU) + find_package(STARPU ${CHAMELEON_STARPU_VERSION} REQUIRED + COMPONENTS ${STARPU_COMPONENT_LIST}) + else() + find_package(STARPU ${CHAMELEON_STARPU_VERSION} + COMPONENTS ${STARPU_COMPONENT_LIST}) + endif() + + endif() + + if( NOT QUARK_FOUND AND CHAMELEON_LOOK_FOR_QUARK ) + + # try to find quark runtime + if (CHAMELEON_FIND_REQUIRED AND CHAMELEON_FIND_REQUIRED_QUARK) + find_package(QUARK REQUIRED COMPONENTS HWLOC) + else() + find_package(QUARK COMPONENTS HWLOC) + endif() + + endif() + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + unset(_inc_env) + set(ENV_CHAMELEON_DIR "$ENV{CHAMELEON_DIR}") + set(ENV_CHAMELEON_INCDIR "$ENV{CHAMELEON_INCDIR}") + if(ENV_CHAMELEON_INCDIR) + list(APPEND _inc_env "${ENV_CHAMELEON_INCDIR}") + elseif(ENV_CHAMELEON_DIR) + list(APPEND _inc_env "${ENV_CHAMELEON_DIR}") + list(APPEND _inc_env "${ENV_CHAMELEON_DIR}/include") + list(APPEND _inc_env "${ENV_CHAMELEON_DIR}/include/chameleon") + 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 chameleon header in the given paths + # --------------------------------------------------- + # call cmake macro to find the header path + if(CHAMELEON_INCDIR) + set(CHAMELEON_morse.h_DIRS "CHAMELEON_morse.h_DIRS-NOTFOUND") + find_path(CHAMELEON_morse.h_DIRS + NAMES morse.h + HINTS ${CHAMELEON_INCDIR}) + else() + if(CHAMELEON_DIR) + set(CHAMELEON_morse.h_DIRS "CHAMELEON_morse.h_DIRS-NOTFOUND") + find_path(CHAMELEON_morse.h_DIRS + NAMES morse.h + HINTS ${CHAMELEON_DIR} + PATH_SUFFIXES "include" "include/chameleon") + else() + set(CHAMELEON_morse.h_DIRS "CHAMELEON_morse.h_DIRS-NOTFOUND") + find_path(CHAMELEON_morse.h_DIRS + NAMES morse.h + HINTS ${_inc_env} + PATH_SUFFIXES "chameleon") + endif() + endif() + mark_as_advanced(CHAMELEON_morse.h_DIRS) + + # If found, add path to cmake variable + # ------------------------------------ + if (CHAMELEON_morse.h_DIRS) + set(CHAMELEON_INCLUDE_DIRS "${CHAMELEON_morse.h_DIRS}") + else () + set(CHAMELEON_INCLUDE_DIRS "CHAMELEON_INCLUDE_DIRS-NOTFOUND") + if(NOT CHAMELEON_FIND_QUIETLY) + message(STATUS "Looking for chameleon -- morse.h not found") + endif() + endif() + + + # Looking for lib + # --------------- + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_CHAMELEON_LIBDIR "$ENV{CHAMELEON_LIBDIR}") + if(ENV_CHAMELEON_LIBDIR) + list(APPEND _lib_env "${ENV_CHAMELEON_LIBDIR}") + elseif(ENV_CHAMELEON_DIR) + list(APPEND _lib_env "${ENV_CHAMELEON_DIR}") + list(APPEND _lib_env "${ENV_CHAMELEON_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 chameleon lib in the given paths + # ------------------------------------------------ + + # create list of libs to find + set(CHAMELEON_libs_to_find "chameleon") + if (STARPU_FOUND) + list(APPEND CHAMELEON_libs_to_find "chameleon_starpu") + elseif (QUARK_FOUND) + list(APPEND CHAMELEON_libs_to_find "chameleon_quark") + endif() + list(APPEND CHAMELEON_libs_to_find "coreblas") + + # call cmake macro to find the lib path + if(CHAMELEON_LIBDIR) + foreach(chameleon_lib ${CHAMELEON_libs_to_find}) + set(CHAMELEON_${chameleon_lib}_LIBRARY "CHAMELEON_${chameleon_lib}_LIBRARY-NOTFOUND") + find_library(CHAMELEON_${chameleon_lib}_LIBRARY + NAMES ${chameleon_lib} + HINTS ${CHAMELEON_LIBDIR}) + endforeach() + else() + if(CHAMELEON_DIR) + foreach(chameleon_lib ${CHAMELEON_libs_to_find}) + set(CHAMELEON_${chameleon_lib}_LIBRARY "CHAMELEON_${chameleon_lib}_LIBRARY-NOTFOUND") + find_library(CHAMELEON_${chameleon_lib}_LIBRARY + NAMES ${chameleon_lib} + HINTS ${CHAMELEON_DIR} + PATH_SUFFIXES lib lib32 lib64) + endforeach() + else() + foreach(chameleon_lib ${CHAMELEON_libs_to_find}) + set(CHAMELEON_${chameleon_lib}_LIBRARY "CHAMELEON_${chameleon_lib}_LIBRARY-NOTFOUND") + find_library(CHAMELEON_${chameleon_lib}_LIBRARY + NAMES ${chameleon_lib} + HINTS ${_lib_env}) + endforeach() + endif() + endif() + + # If found, add path to cmake variable + # ------------------------------------ + foreach(chameleon_lib ${CHAMELEON_libs_to_find}) + + get_filename_component(${chameleon_lib}_lib_path ${CHAMELEON_${chameleon_lib}_LIBRARY} PATH) + # set cmake variables (respects naming convention) + if (CHAMELEON_LIBRARIES) + list(APPEND CHAMELEON_LIBRARIES "${CHAMELEON_${chameleon_lib}_LIBRARY}") + else() + set(CHAMELEON_LIBRARIES "${CHAMELEON_${chameleon_lib}_LIBRARY}") + endif() + if (CHAMELEON_LIBRARY_DIRS) + list(APPEND CHAMELEON_LIBRARY_DIRS "${${chameleon_lib}_lib_path}") + else() + set(CHAMELEON_LIBRARY_DIRS "${${chameleon_lib}_lib_path}") + endif() + mark_as_advanced(CHAMELEON_${chameleon_lib}_LIBRARY) + + endforeach(chameleon_lib ${CHAMELEON_libs_to_find}) + + # check a function to validate the find + if(CHAMELEON_LIBRARIES) + + set(REQUIRED_LDFLAGS) + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # CHAMELEON + if (CHAMELEON_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${CHAMELEON_INCLUDE_DIRS}") + endif() + foreach(libdir ${CHAMELEON_LIBRARY_DIRS}) + if (libdir) + list(APPEND REQUIRED_LIBDIRS "${libdir}") + endif() + endforeach() + set(REQUIRED_LIBS "${CHAMELEON_LIBRARIES}") + # STARPU + if (STARPU_FOUND AND CHAMELEON_LOOK_FOR_STARPU) + 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() + # QUARK + if (QUARK_FOUND AND CHAMELEON_LOOK_FOR_QUARK) + if (QUARK_INCLUDE_DIRS_DEP) + list(APPEND REQUIRED_INCDIRS "${QUARK_INCLUDE_DIRS_DEP}") + elseif(QUARK_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${QUARK_INCLUDE_DIRS}") + endif() + if(QUARK_LIBRARY_DIRS_DEP) + list(APPEND REQUIRED_LIBDIRS "${QUARK_LIBRARY_DIRS_DEP}") + elseif(QUARK_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${QUARK_LIBRARY_DIRS}") + endif() + if (QUARK_LIBRARY_DIRS_DEP) + list(APPEND REQUIRED_LIBS "${QUARK_LIBRARIES_DEP}") + elseif (QUARK_LIBRARY_DIRS_DEP) + list(APPEND REQUIRED_LIBS "${QUARK_LIBRARIES}") + endif() + endif() + # CUDA + if (CUDA_FOUND AND CHAMELEON_LOOK_FOR_CUDA) + 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() + # MAGMA + if (MAGMA_FOUND AND CHAMELEON_LOOK_FOR_MAGMA) + if (MAGMA_INCLUDE_DIRS_DEP) + list(APPEND REQUIRED_INCDIRS "${MAGMA_INCLUDE_DIRS_DEP}") + elseif(MAGMA_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${MAGMA_INCLUDE_DIRS}") + endif() + if (MAGMA_LIBRARY_DIRS_DEP) + list(APPEND REQUIRED_LIBDIRS "${MAGMA_LIBRARY_DIRS_DEP}") + elseif(MAGMA_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${MAGMA_LIBRARY_DIRS}") + endif() + if (MAGMA_LIBRARIES_DEP) + list(APPEND REQUIRED_LIBS "${MAGMA_LIBRARIES_DEP}") + elseif(MAGMA_LIBRARIES) + foreach(lib ${MAGMA_LIBRARIES}) + if (EXISTS ${lib} OR ${lib} MATCHES "^-") + list(APPEND REQUIRED_LIBS "${lib}") + else() + list(APPEND REQUIRED_LIBS "-l${lib}") + endif() + endforeach() + endif() + endif() + # MPI + if (MPI_FOUND AND CHAMELEON_LOOK_FOR_MPI) + 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() + # TMG + if (TMG_FOUND) + if (TMG_INCLUDE_DIRS_DEP) + list(APPEND REQUIRED_INCDIRS "${TMG_INCLUDE_DIRS_DEP}") + elseif (TMG_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${TMG_INCLUDE_DIRS}") + endif() + if(TMG_LIBRARY_DIRS_DEP) + list(APPEND REQUIRED_LIBDIRS "${TMG_LIBRARY_DIRS_DEP}") + elseif(TMG_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${TMG_LIBRARY_DIRS}") + endif() + if (TMG_LIBRARIES_DEP) + list(APPEND REQUIRED_LIBS "${TMG_LIBRARIES_DEP}") + elseif(TMG_LIBRARIES) + list(APPEND REQUIRED_LIBS "${TMG_LIBRARIES}") + endif() + if (TMG_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${TMG_LINKER_FLAGS}") + endif() + endif() + # LAPACKE + if (LAPACKE_FOUND) + if (LAPACKE_INCLUDE_DIRS_DEP) + list(APPEND REQUIRED_INCDIRS "${LAPACKE_INCLUDE_DIRS_DEP}") + elseif (LAPACKE_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${LAPACKE_INCLUDE_DIRS}") + endif() + if(LAPACKE_LIBRARY_DIRS_DEP) + list(APPEND REQUIRED_LIBDIRS "${LAPACKE_LIBRARY_DIRS_DEP}") + elseif(LAPACKE_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${LAPACKE_LIBRARY_DIRS}") + endif() + if (LAPACKE_LIBRARIES_DEP) + list(APPEND REQUIRED_LIBS "${LAPACKE_LIBRARIES_DEP}") + elseif(LAPACKE_LIBRARIES) + list(APPEND REQUIRED_LIBS "${LAPACKE_LIBRARIES}") + endif() + if (LAPACK_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${LAPACK_LINKER_FLAGS}") + endif() + endif() + # CBLAS + if (CBLAS_FOUND) + if (CBLAS_INCLUDE_DIRS_DEP) + list(APPEND REQUIRED_INCDIRS "${CBLAS_INCLUDE_DIRS_DEP}") + elseif (CBLAS_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${CBLAS_INCLUDE_DIRS}") + endif() + if(CBLAS_LIBRARY_DIRS_DEP) + list(APPEND REQUIRED_LIBDIRS "${CBLAS_LIBRARY_DIRS_DEP}") + elseif(CBLAS_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${CBLAS_LIBRARY_DIRS}") + endif() + if (CBLAS_LIBRARIES_DEP) + list(APPEND REQUIRED_LIBS "${CBLAS_LIBRARIES_DEP}") + elseif(CBLAS_LIBRARIES) + list(APPEND REQUIRED_LIBS "${CBLAS_LIBRARIES}") + endif() + if (BLAS_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}") + endif() + endif() + # EXTRA LIBS such that pthread, m, rt + list(APPEND REQUIRED_LIBS ${CHAMELEON_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}") + string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + + # test link + unset(CHAMELEON_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(MORSE_Init CHAMELEON_WORKS) + mark_as_advanced(CHAMELEON_WORKS) + + if(CHAMELEON_WORKS) + # save link with dependencies + set(CHAMELEON_LIBRARIES_DEP "${REQUIRED_LIBS}") + set(CHAMELEON_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(CHAMELEON_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(CHAMELEON_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES CHAMELEON_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES CHAMELEON_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES CHAMELEON_LINKER_FLAGS) + else() + if(NOT CHAMELEON_FIND_QUIETLY) + message(STATUS "Looking for chameleon : test of MORSE_Init 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 CHAMELEON is linked with specific libraries. " + "Have you tried with COMPONENTS (STARPU/QUARK, CUDA, MAGMA, MPI, FXT)? " + "See the explanation in FindCHAMELEON.cmake.") + endif() + endif() + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_LIBRARIES) + endif(CHAMELEON_LIBRARIES) + +endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT CHAMELEON_FOUND) OR (CHAMELEON_GIVEN_BY_USER) ) + +if (CHAMELEON_LIBRARIES) + if (CHAMELEON_LIBRARY_DIRS) + foreach(dir ${CHAMELEON_LIBRARY_DIRS}) + if ("${dir}" MATCHES "chameleon") + set(first_lib_path "${dir}") + endif() + endforeach() + else() + list(GET CHAMELEON_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(CHAMELEON_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of CHAMELEON library" FORCE) + else() + set(CHAMELEON_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of CHAMELEON library" FORCE) + endif() +endif() +mark_as_advanced(CHAMELEON_DIR) +mark_as_advanced(CHAMELEON_DIR_FOUND) + +# check that CHAMELEON has been found +# --------------------------------- +include(FindPackageHandleStandardArgs) +if (PKG_CONFIG_EXECUTABLE AND CHAMELEON_FOUND) + find_package_handle_standard_args(CHAMELEON DEFAULT_MSG + CHAMELEON_LIBRARIES) +else() + find_package_handle_standard_args(CHAMELEON DEFAULT_MSG + CHAMELEON_LIBRARIES + CHAMELEON_WORKS) +endif() diff --git a/modules/find/FindEZTRACE.cmake b/modules/find/FindEZTRACE.cmake new file mode 100644 index 0000000..7584c5e --- /dev/null +++ b/modules/find/FindEZTRACE.cmake @@ -0,0 +1,355 @@ +### +# +# @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 EZTRACE include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(EZTRACE +# [REQUIRED]) # Fail with error if eztrace is not found +# +# EZTRACE depends on the following libraries: +# - libbfd.so +# - libiberty.so (optional) +# +# This module finds headers and eztrace library. +# Results are reported in variables: +# EZTRACE_FOUND - True if headers and requested libraries were found +# EZTRACE_INCLUDE_DIRS - eztrace include directories +# EZTRACE_LIBRARY_DIRS - Link directories for eztrace libraries +# EZTRACE_LIBRARIES - eztrace 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 -DEZTRACE_DIR=path/to/eztrace): +# EZTRACE_DIR - Where to find the base directory of eztrace +# EZTRACE_INCDIR - Where to find the header files +# EZTRACE_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: EZTRACE_DIR, EZTRACE_INCDIR, EZTRACE_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.) + +if (NOT EZTRACE_FOUND) + set(EZTRACE_DIR "" CACHE PATH "Installation directory of EZTRACE library") + if (NOT EZTRACE_FIND_QUIETLY) + message(STATUS "A cache variable, namely EZTRACE_DIR, has been set to specify the install directory of EZTRACE") + endif() +endif() + +set(ENV_EZTRACE_DIR "$ENV{EZTRACE_DIR}") +set(ENV_EZTRACE_INCDIR "$ENV{EZTRACE_INCDIR}") +set(ENV_EZTRACE_LIBDIR "$ENV{EZTRACE_LIBDIR}") +set(EZTRACE_GIVEN_BY_USER "FALSE") +if ( EZTRACE_DIR OR ( EZTRACE_INCDIR AND EZTRACE_LIBDIR) OR ENV_EZTRACE_DIR OR (ENV_EZTRACE_INCDIR AND ENV_EZTRACE_LIBDIR) ) + set(EZTRACE_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 EZTRACE_GIVEN_BY_USER ) + + pkg_search_module(EZTRACE eztrace) + if (NOT EZTRACE_FIND_QUIETLY) + if (EZTRACE_FOUND AND EZTRACE_LIBRARIES) + message(STATUS "Looking for EZTRACE - found using PkgConfig") + #if(NOT EZTRACE_INCLUDE_DIRS) + # message("${Magenta}EZTRACE_INCLUDE_DIRS is empty using PkgConfig." + # "Perhaps the path to eztrace headers is already present in your" + # "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}") + #endif() + else() + message(STATUS "${Magenta}Looking for EZTRACE - not found using PkgConfig." + "\n Perhaps you should add the directory containing eztrace.pc to" + "\n the PKG_CONFIG_PATH environment variable.${ColourReset}") + endif() + endif() + +endif( PKG_CONFIG_EXECUTABLE AND NOT EZTRACE_GIVEN_BY_USER ) + +if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT EZTRACE_FOUND) OR (EZTRACE_GIVEN_BY_USER) ) + + if (NOT EZTRACE_FIND_QUIETLY) + message(STATUS "Looking for EZTRACE - PkgConfig not used") + endif() + + # Looking for libbfd + # ------------------ + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + 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() + list(REMOVE_DUPLICATES _lib_env) + + # set paths where to look for + set(PATH_TO_LOOK_FOR "${_lib_env}") + + # Try to find the bfd lib in the given paths + # ------------------------------------------ + + # call cmake macro to find the lib path + set(EZTRACE_bfd_LIBRARY "EZTRACE_bfd_LIBRARY-NOTFOUND") + find_library(EZTRACE_bfd_LIBRARY + NAMES bfd + HINTS ${PATH_TO_LOOK_FOR}) + mark_as_advanced(EZTRACE_bfd_LIBRARY) + + if (NOT EZTRACE_bfd_LIBRARY) + if(NOT EZTRACE_FIND_QUIETLY) + message(STATUS "Looking for eztrace -- lib bfd not found") + endif() + endif () + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + unset(_inc_env) + if(ENV_EZTRACE_INCDIR) + list(APPEND _inc_env "${ENV_EZTRACE_INCDIR}") + elseif(ENV_EZTRACE_DIR) + list(APPEND _inc_env "${ENV_EZTRACE_DIR}") + list(APPEND _inc_env "${ENV_EZTRACE_DIR}/include") + list(APPEND _inc_env "${ENV_EZTRACE_DIR}/include/eztrace") + 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 eztrace header in the given paths + # ------------------------------------------------- + # call cmake macro to find the header path + if(EZTRACE_INCDIR) + set(EZTRACE_eztrace.h_DIRS "EZTRACE_eztrace.h_DIRS-NOTFOUND") + find_path(EZTRACE_eztrace.h_DIRS + NAMES eztrace.h + HINTS ${EZTRACE_INCDIR}) + else() + if(EZTRACE_DIR) + set(EZTRACE_eztrace.h_DIRS "EZTRACE_eztrace.h_DIRS-NOTFOUND") + find_path(EZTRACE_eztrace.h_DIRS + NAMES eztrace.h + HINTS ${EZTRACE_DIR} + PATH_SUFFIXES "include" "include/eztrace") + else() + set(EZTRACE_eztrace.h_DIRS "EZTRACE_eztrace.h_DIRS-NOTFOUND") + find_path(EZTRACE_eztrace.h_DIRS + NAMES eztrace.h + HINTS ${PATH_TO_LOOK_FOR} + PATH_SUFFIXES "eztrace") + endif() + endif() + mark_as_advanced(EZTRACE_eztrace.h_DIRS) + + # Add path to cmake variable + # ------------------------------------ + if (EZTRACE_eztrace.h_DIRS) + set(EZTRACE_INCLUDE_DIRS "${EZTRACE_eztrace.h_DIRS}") + else () + set(EZTRACE_INCLUDE_DIRS "EZTRACE_INCLUDE_DIRS-NOTFOUND") + if(NOT EZTRACE_FIND_QUIETLY) + message(STATUS "Looking for eztrace -- eztrace.h not found") + endif() + endif () + + if (EZTRACE_INCLUDE_DIRS) + list(REMOVE_DUPLICATES EZTRACE_INCLUDE_DIRS) + endif () + + + # Looking for lib + # --------------- + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + if(ENV_EZTRACE_LIBDIR) + list(APPEND _lib_env "${ENV_EZTRACE_LIBDIR}") + elseif(ENV_EZTRACE_DIR) + list(APPEND _lib_env "${ENV_EZTRACE_DIR}") + list(APPEND _lib_env "${ENV_EZTRACE_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 eztrace lib in the given paths + # ---------------------------------------------- + + # call cmake macro to find the lib path + if(EZTRACE_LIBDIR) + set(EZTRACE_eztrace_LIBRARY "EZTRACE_eztrace_LIBRARY-NOTFOUND") + find_library(EZTRACE_eztrace_LIBRARY + NAMES eztrace + HINTS ${EZTRACE_LIBDIR}) + else() + if(EZTRACE_DIR) + set(EZTRACE_eztrace_LIBRARY "EZTRACE_eztrace_LIBRARY-NOTFOUND") + find_library(EZTRACE_eztrace_LIBRARY + NAMES eztrace + HINTS ${EZTRACE_DIR} + PATH_SUFFIXES lib lib32 lib64) + else() + set(EZTRACE_eztrace_LIBRARY "EZTRACE_eztrace_LIBRARY-NOTFOUND") + find_library(EZTRACE_eztrace_LIBRARY + NAMES eztrace + HINTS ${PATH_TO_LOOK_FOR}) + endif() + endif() + mark_as_advanced(EZTRACE_eztrace_LIBRARY) + + # If found, add path to cmake variable + # ------------------------------------ + if (EZTRACE_eztrace_LIBRARY) + get_filename_component(eztrace_lib_path ${EZTRACE_eztrace_LIBRARY} PATH) + # set cmake variables (respects naming convention) + set(EZTRACE_LIBRARIES "${EZTRACE_eztrace_LIBRARY}") + set(EZTRACE_LIBRARY_DIRS "${eztrace_lib_path}") + else () + set(EZTRACE_LIBRARIES "EZTRACE_LIBRARIES-NOTFOUND") + set(EZTRACE_LIBRARY_DIRS "EZTRACE_LIBRARY_DIRS-NOTFOUND") + if(NOT EZTRACE_FIND_QUIETLY) + message(STATUS "Looking for eztrace -- lib eztrace not found") + endif() + endif () + + if (EZTRACE_LIBRARY_DIRS) + list(REMOVE_DUPLICATES EZTRACE_LIBRARY_DIRS) + endif () + + # check a function to validate the find + if(EZTRACE_LIBRARIES) + + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # EZTRACE + if (EZTRACE_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${EZTRACE_INCLUDE_DIRS}") + endif() + if (EZTRACE_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${EZTRACE_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${EZTRACE_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(EZTRACE_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(eztrace_start EZTRACE_WORKS) + mark_as_advanced(EZTRACE_WORKS) + + if(NOT EZTRACE_WORKS) + if(NOT EZTRACE_FIND_QUIETLY) + message(STATUS "Looking for eztrace : test of eztrace_topology_init with eztrace 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(EZTRACE_LIBRARIES) + +endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT EZTRACE_FOUND) OR (EZTRACE_GIVEN_BY_USER) ) + +if (EZTRACE_LIBRARIES) + if (EZTRACE_LIBRARY_DIRS) + list(GET EZTRACE_LIBRARY_DIRS 0 first_lib_path) + else() + list(GET EZTRACE_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(EZTRACE_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of EZTRACE library" FORCE) + else() + set(EZTRACE_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of EZTRACE library" FORCE) + endif() +endif() +mark_as_advanced(EZTRACE_DIR) +mark_as_advanced(EZTRACE_DIR_FOUND) + +# check that EZTRACE has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +if (PKG_CONFIG_EXECUTABLE AND EZTRACE_FOUND) + find_package_handle_standard_args(EZTRACE DEFAULT_MSG + EZTRACE_LIBRARIES) +else() + find_package_handle_standard_args(EZTRACE DEFAULT_MSG + EZTRACE_LIBRARIES + EZTRACE_WORKS) +endif() diff --git a/modules/find/FindFFTW.cmake b/modules/find/FindFFTW.cmake new file mode 100644 index 0000000..a9d8b19 --- /dev/null +++ b/modules/find/FindFFTW.cmake @@ -0,0 +1,806 @@ +### +# +# @copyright (c) 2009-2014 The University of Tennessee and The University +# of Tennessee Research Foundation. +# All rights reserved. +# @copyright (c) 2012-2015 Inria. All rights reserved. +# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved. +# +### +# +# - Find FFTW Version 3 include dirs and libraries +# Default configuration will find the real double precision fftw library version +# without THREADS|OMP. +# Use this module by invoking find_package with the form: +# find_package(FFTW +# [REQUIRED] # Fail with error if fftw is not found +# [COMPONENTS MKL] +# +# COMPONENTS can be some of the following: +# - MKL: to detect the FFTW from Intel MKL +# - ESSL: to detect the FFTW from IBM ESSL +# - THREADS: to detect the Threads version of FFTW +# - OMP: to detect the OpenMP version of FFTW +# - SIMPLE: to detect the FFTW simple precision fftw3f +# - LONG: to detect the FFTW long double precision fftw3l +# - QUAD: to detect the FFTW quadruple precision fftw3q +# +# This module finds headers and fftw library. +# Results are reported in variables: +# FFTW_FOUND - True if headers and requested libraries were found +# FFTW_C_FLAGS - list of required compilation flags (excluding -I) +# FFTW_LINKER_FLAGS - list of required linker flags (excluding -l and -L) +# FFTW_INCLUDE_DIRS - fftw include directories +# FFTW_LIBRARY_DIRS - Link directories for fftw libraries +# FFTW_LIBRARIES - fftw component libraries to be linked +# FFTW_INCLUDE_DIRS_DEP - fftw + dependencies include directories +# FFTW_LIBRARY_DIRS_DEP - fftw + dependencies link directories +# FFTW_LIBRARIES_DEP - fftw libraries + dependencies +# +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DFFTW_DIR=path/to/fftw): +# FFTW_DIR - Where to find the base directory of fftw +# FFTW_INCDIR - Where to find the header files +# FFTW_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: FFTW_DIR, FFTW_INCDIR, FFTW_LIBDIR +# For MKL case and if no paths are given as hints, we will try to use the MKLROOT +# environment variable + +#============================================================================= +# 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 FFTW_FOUND) + set(FFTW_DIR "" CACHE PATH "Installation directory of FFTW library given by user") + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "A cache variable, namely FFTW_DIR, has been set to specify the install directory of FFTW") + endif() +endif() + +# Set the version to find +set(FFTW_LOOK_FOR_MKL OFF) +set(FFTW_LOOK_FOR_ESSL OFF) +set(FFTW_LOOK_FOR_THREADS OFF) +set(FFTW_LOOK_FOR_OMP OFF) +set(FFTW_LOOK_FOR_FFTW_SIMPLE OFF) +set(FFTW_LOOK_FOR_FFTW_LONG OFF) +set(FFTW_LOOK_FOR_FFTW_QUAD OFF) + +if( FFTW_FIND_COMPONENTS ) + foreach( component ${FFTW_FIND_COMPONENTS} ) + if (${component} STREQUAL "THREADS") + # means we look for the Threads version of FFTW + set(FFTW_LOOK_FOR_THREADS ON) + endif() + if (${component} STREQUAL "OMP") + # means we look for the OpenMP version of FFTW + set(FFTW_LOOK_FOR_OMP ON) + endif() + if (${component} STREQUAL "SIMPLE") + # means we look for FFTW simple precision (fftw3f) + set(FFTW_LOOK_FOR_FFTW_SIMPLE ON) + set(FFTW_LOOK_FOR_FFTW_LONG OFF) + set(FFTW_LOOK_FOR_FFTW_QUAD OFF) + endif() + if (${component} STREQUAL "LONG") + # means we look for FFTW long double precision (fftw3l) + set(FFTW_LOOK_FOR_FFTW_SIMPLE OFF) + set(FFTW_LOOK_FOR_FFTW_LONG ON) + set(FFTW_LOOK_FOR_FFTW_QUAD OFF) + endif() + if (${component} STREQUAL "QUAD") + # means we look for FFTW quad precision (fftw3q) + set(FFTW_LOOK_FOR_FFTW_SIMPLE OFF) + set(FFTW_LOOK_FOR_FFTW_LONG OFF) + set(FFTW_LOOK_FOR_FFTW_QUAD ON) + endif() + if (${component} STREQUAL "MKL") + # means we look for the Intel MKL version of FFTW + set(FFTW_LOOK_FOR_MKL ON) + if (FFTW_LOOK_FOR_FFTW_LONG) + if (NOT FFTW_FIND_QUIETLY) + message(WARNING "Looking for FFTW -- long precision functions do not exist in MKL FFTW") + endif() + set(FFTW_LOOK_FOR_FFTW_LONG OFF) + endif() + if (FFTW_LOOK_FOR_FFTW_QUAD) + if (NOT FFTW_FIND_QUIETLY) + message(WARNING "Looking for FFTW -- quadruple functions do not exist in MKL FFTW") + endif() + set(FFTW_LOOK_FOR_FFTW_QUAD OFF) + endif() + endif() + if (${component} STREQUAL "ESSL") + # means we look for the Intel MKL version of FFTW + set(FFTW_LOOK_FOR_ESSL ON) + if (FFTW_LOOK_FOR_FFTW_LONG) + if (NOT FFTW_FIND_QUIETLY) + message(WARNING "Looking for FFTW -- long precision functions do not exist in FFTW_ESSL") + endif() + set(FFTW_LOOK_FOR_FFTW_LONG OFF) + endif() + if (FFTW_LOOK_FOR_FFTW_QUAD) + if (NOT FFTW_FIND_QUIETLY) + message(WARNING "Looking for FFTW -- quadruple functions do not exist in FFTW_ESSL") + endif() + set(FFTW_LOOK_FOR_FFTW_QUAD OFF) + endif() + if (FFTW_LOOK_FOR_OMP) + if (NOT FFTW_FIND_QUIETLY) + message(WARNING "Looking for FFTW -- FFTW_ESSL does not use OpenMP") + endif() + set(FFTW_LOOK_FOR_OMP OFF) + endif() + endif() + endforeach() +endif() + +if (FFTW_LOOK_FOR_THREADS) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "FFTW looks for threads") + endif() + if (FFTW_FIND_REQUIRED AND FFTW_FIND_REQUIRED_THREADS) + find_package(Threads REQUIRED) + else() + find_package(Threads) + endif() +endif() + +if (FFTW_LOOK_FOR_OMP) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "FFTW looks for openmp") + endif() + if (FFTW_FIND_REQUIRED AND FFTW_FIND_REQUIRED_OMP) + find_package(OpenMP REQUIRED) + else() + find_package(OpenMP) + endif() +endif() + +if (FFTW_LOOK_FOR_MKL) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "FFTW looks for threads and Intel MKL") + endif() + if (FFTW_LOOK_FOR_THREADS) + set(BLA_VENDOR "Intel10_64lp") + else() + set(BLA_VENDOR "Intel10_64lp_seq") + endif() + if (FFTW_FIND_REQUIRED AND FFTW_FIND_REQUIRED_MKL) + find_package(Threads REQUIRED) + find_package(BLASEXT REQUIRED) + else() + find_package(Threads) + find_package(BLASEXT) + endif() +endif() + +if (FFTW_LOOK_FOR_ESSL) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "FFTW looks for IBM ESSL") + endif() + if (FFTW_LOOK_FOR_THREADS) + set(BLA_VENDOR "IBMESSLMT") + else() + set(BLA_VENDOR "IBMESSL") + endif() + if (FFTW_FIND_REQUIRED AND FFTW_FIND_REQUIRED_ESSL) + find_package(BLASEXT REQUIRED) + else() + find_package(BLASEXT) + endif() +endif() + +set(ENV_FFTW_DIR "$ENV{FFTW_DIR}") +set(ENV_FFTW_INCDIR "$ENV{FFTW_INCDIR}") +set(ENV_FFTW_LIBDIR "$ENV{FFTW_LIBDIR}") +set(FFTW_GIVEN_BY_USER "FALSE") +if ( FFTW_DIR OR ( FFTW_INCDIR AND FFTW_LIBDIR) OR ENV_FFTW_DIR OR (ENV_FFTW_INCDIR AND ENV_FFTW_LIBDIR) ) + set(FFTW_GIVEN_BY_USER "TRUE") +endif() + + +# Optionally use pkg-config to detect include/library dirs (if pkg-config is available) +# ------------------------------------------------------------------------------------- +if (NOT FFTW_LOOK_FOR_MKL AND NOT FFTW_LOOK_FOR_ESSL) + include(FindPkgConfig) + find_package(PkgConfig QUIET) + if( PKG_CONFIG_EXECUTABLE AND NOT FFTW_GIVEN_BY_USER ) + + set(FFTW_INCLUDE_DIRS) + set(FFTW_LIBRARY_DIRS) + set(FFTW_LIBRARIES) + + if(FFTW_LOOK_FOR_FFTW_SIMPLE) + pkg_search_module(FFTW3F fftw3f) + pkg_search_module(FFTW3 fftw3) + if (FFTW3F_FOUND) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "Looking for FFTW3F - found using PkgConfig") + endif() + if (FFTW3F_LIBRARIES) + list(APPEND FFTW_LIBRARIES "${FFTW3F_LIBRARIES}") + endif() + if(FFTW3F_INCLUDE_DIRS) + list(APPEND FFTW_INCLUDE_DIRS "${FFTW3F_INCLUDE_DIRS}") + else() + if (NOT FFTW_FIND_QUIETLY) + message(WARNING "FFTW3F_INCLUDE_DIRS is empty using PkgConfig." + "Perhaps the path to fftw3f headers is already present in your" + "CPATH/C(PLUS)_INCLUDE_PATH environment variables.") + endif() + endif() + if(FFTW3F_LIBRARY_DIRS) + list(APPEND FFTW_LIBRARY_DIRS "${FFTW3F_LIBRARY_DIRS}") + endif() + else(FFTW3F_FOUND) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "Looking for FFTW3F - not found using PkgConfig." + "\n Perhaps you should add the directory containing fftw3f.pc to" + "\n the PKG_CONFIG_PATH environment variable.") + endif() + endif(FFTW3F_FOUND) + elseif(FFTW_LOOK_FOR_FFTW_LONG) + pkg_search_module(FFTW3L fftw3l) + pkg_search_module(FFTW3 fftw3) + if (FFTW3L_FOUND) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "Looking for FFTW3L - found using PkgConfig") + endif() + if (FFTW3L_LIBRARIES) + list(APPEND FFTW_LIBRARIES "${FFTW3L_LIBRARIES}") + endif() + if(FFTW3L_INCLUDE_DIRS) + list(APPEND FFTW_INCLUDE_DIRS "${FFTW3L_INCLUDE_DIRS}") + else() + if (NOT FFTW_FIND_QUIETLY) + message(WARNING "FFTW3L_INCLUDE_DIRS is empty using PkgConfig." + "Perhaps the path to fftw3l headers is already present in your" + "CPATH/C(PLUS)_INCLUDE_PATH environment variables.") + endif() + endif() + if(FFTW3L_LIBRARY_DIRS) + list(APPEND FFTW_LIBRARY_DIRS "${FFTW3L_LIBRARY_DIRS}") + endif() + else(FFTW3L_FOUND) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "Looking for FFTW3L - not found using PkgConfig." + "\n Perhaps you should add the directory containing fftw3l.pc to" + "\n the PKG_CONFIG_PATH environment variable.") + endif() + endif(FFTW3L_FOUND) + elseif(FFTW_LOOK_FOR_FFTW_QUAD) + pkg_search_module(FFTW3Q fftw3q) + pkg_search_module(FFTW3 fftw3) + if (FFTW3Q_FOUND) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "Looking for FFTW3Q - found using PkgConfig") + endif() + if (FFTW3Q_LIBRARIES) + list(APPEND FFTW_LIBRARIES "${FFTW3Q_LIBRARIES}") + endif() + if(FFTW3Q_INCLUDE_DIRS) + list(APPEND FFTW_INCLUDE_DIRS "${FFTW3Q_INCLUDE_DIRS}") + else() + if (NOT FFTW_FIND_QUIETLY) + message(WARNING "FFTW3Q_INCLUDE_DIRS is empty using PkgConfig." + "Perhaps the path to fftw3q headers is already present in your" + "CPATH/C(PLUS)_INCLUDE_PATH environment variables.") + endif() + endif() + if(FFTW3Q_LIBRARY_DIRS) + list(APPEND FFTW_LIBRARY_DIRS "${FFTW3Q_LIBRARY_DIRS}") + endif() + else(FFTW3Q_FOUND) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "Looking for FFTW3Q - not found using PkgConfig." + "\n Perhaps you should add the directory containing fftw3q.pc to" + "\n the PKG_CONFIG_PATH environment variable.") + endif() + endif(FFTW3Q_FOUND) + else() + pkg_search_module(FFTW3 fftw3) + endif() + if (FFTW3_FOUND) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "Looking for FFTW3 - found using PkgConfig") + endif() + if (FFTW3_LIBRARIES) + list(APPEND FFTW_LIBRARIES "${FFTW3_LIBRARIES}") + endif() + if(FFTW3_INCLUDE_DIRS) + list(APPEND FFTW_INCLUDE_DIRS "${FFTW3_INCLUDE_DIRS}") + else() + if (NOT FFTW_FIND_QUIETLY) + message(WARNING "FFTW3_INCLUDE_DIRS is empty using PkgConfig." + "Perhaps the path to fftw3 headers is already present in your" + "CPATH/C(PLUS)_INCLUDE_PATH environment variables.") + endif() + endif() + if(FFTW3_LIBRARY_DIRS) + list(APPEND FFTW_LIBRARY_DIRS "${FFTW3_LIBRARY_DIRS}") + endif() + else(FFTW3_FOUND) + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "Looking for FFTW3 - not found using PkgConfig." + "\n Perhaps you should add the directory containing fftw3.pc to" + "\n the PKG_CONFIG_PATH environment variable.") + endif() + endif(FFTW3_FOUND) + + set(FFTW_INCLUDE_DIRS_DEP "${FFTW_INCLUDE_DIRS}") + set(FFTW_LIBRARY_DIRS_DEP "${FFTW_LIBRARY_DIRS}") + set(FFTW_LIBRARIES_DEP "${FFTW_LIBRARIES}" ) + + if (FFTW_LIBRARIES) + set(FFTW_WORKS TRUE) + endif() + + endif( PKG_CONFIG_EXECUTABLE AND NOT FFTW_GIVEN_BY_USER ) + +endif(NOT FFTW_LOOK_FOR_MKL AND NOT FFTW_LOOK_FOR_ESSL) + +if( (NOT PKG_CONFIG_EXECUTABLE) OR + (PKG_CONFIG_EXECUTABLE AND NOT FFTW_FOUND) OR + FFTW_GIVEN_BY_USER OR + FFTW_LOOK_FOR_MKL OR + FFTW_LOOK_FOR_ESSL + ) + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + unset(_inc_env) + set(ENV_MKLROOT "$ENV{MKLROOT}") + set(ENV_FFTW_DIR "$ENV{FFTW_DIR}") + set(ENV_FFTW_INCDIR "$ENV{FFTW_INCDIR}") + if(ENV_FFTW_INCDIR) + list(APPEND _inc_env "${ENV_FFTW_INCDIR}") + elseif(ENV_FFTW_DIR) + list(APPEND _inc_env "${ENV_FFTW_DIR}") + list(APPEND _inc_env "${ENV_FFTW_DIR}/include") + list(APPEND _inc_env "${ENV_FFTW_DIR}/include/fftw") + else() + if (ENV_MKLROOT) + list(APPEND _inc_env "${ENV_MKLROOT}/include/fftw") + 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) + + # set paths where to look for + set(PATH_TO_LOOK_FOR "${_inc_env}") + + if (FFTW_LOOK_FOR_ESSL) + set(FFTW3_HEADER_TO_FIND "fftw3_essl.h") + else() + set(FFTW3_HEADER_TO_FIND "fftw3.h") + endif() + + # Try to find the fftw header in the given paths + # ------------------------------------------------- + # call cmake macro to find the header path + if(FFTW_INCDIR) + set(FFTW_${FFTW3_HEADER_TO_FIND}_DIRS "FFTW_${FFTW3_HEADER_TO_FIND}_DIRS-NOTFOUND") + find_path(FFTW_${FFTW3_HEADER_TO_FIND}_DIRS + NAMES ${FFTW3_HEADER_TO_FIND} + HINTS ${FFTW_INCDIR}) + else() + if(FFTW_DIR) + set(FFTW_${FFTW3_HEADER_TO_FIND}_DIRS "FFTW_${FFTW3_HEADER_TO_FIND}_DIRS-NOTFOUND") + find_path(FFTW_${FFTW3_HEADER_TO_FIND}_DIRS + NAMES ${FFTW3_HEADER_TO_FIND} + HINTS ${FFTW_DIR} + PATH_SUFFIXES "include" "include/fftw") + else() + set(FFTW_${FFTW3_HEADER_TO_FIND}_DIRS "FFTW_${FFTW3_HEADER_TO_FIND}_DIRS-NOTFOUND") + find_path(FFTW_${FFTW3_HEADER_TO_FIND}_DIRS + NAMES ${FFTW3_HEADER_TO_FIND} + HINTS ${PATH_TO_LOOK_FOR} + PATH_SUFFIXES "fftw") + endif() + endif() + mark_as_advanced(FFTW_${FFTW3_HEADER_TO_FIND}_DIRS) + + # Add path to cmake variable + # ------------------------------------ + if (FFTW_${FFTW3_HEADER_TO_FIND}_DIRS) + set(FFTW_INCLUDE_DIRS "${FFTW_${FFTW3_HEADER_TO_FIND}_DIRS}") + else () + set(FFTW_INCLUDE_DIRS "FFTW_INCLUDE_DIRS-NOTFOUND") + if(NOT FFTW_FIND_QUIETLY) + message(STATUS "Looking for FFTW -- ${FFTW3_HEADER_TO_FIND} not found") + endif() + endif () + + + # Looking for lib + # --------------- + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_FFTW_LIBDIR "$ENV{FFTW_LIBDIR}") + if(ENV_FFTW_LIBDIR) + list(APPEND _lib_env "${ENV_FFTW_LIBDIR}") + elseif(ENV_FFTW_DIR) + list(APPEND _lib_env "${ENV_FFTW_DIR}") + list(APPEND _lib_env "${ENV_FFTW_DIR}/lib") + if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + list(APPEND _lib_env "${ENV_FFTW_DIR}/lib64") + list(APPEND _lib_env "${ENV_FFTW_DIR}/lib/intel64") + else() + list(APPEND _lib_env "${ENV_FFTW_DIR}/lib32") + list(APPEND _lib_env "${ENV_FFTW_DIR}/lib/ia32") + endif() + else() + if (ENV_MKLROOT) + list(APPEND _lib_env "${ENV_MKLROOT}/lib") + if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + list(APPEND _lib_env "${ENV_MKLROOT}/lib64") + list(APPEND _lib_env "${ENV_MKLROOT}/lib/intel64") + else() + list(APPEND _lib_env "${ENV_MKLROOT}/lib32") + list(APPEND _lib_env "${ENV_MKLROOT}/lib/ia32") + endif() + endif() + if(WIN32) + string(REPLACE ":" ";" _lib_env2 "$ENV{LIB}") + else() + if(APPLE) + string(REPLACE ":" ";" _lib_env2 "$ENV{DYLD_LIBRARY_PATH}") + else() + string(REPLACE ":" ";" _lib_env2 "$ENV{LD_LIBRARY_PATH}") + endif() + list(APPEND _lib_env "${_lib_env2}") + 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}") + + if(FFTW_LOOK_FOR_FFTW_SIMPLE) + set(FFTW_PREC "f") + set(FFTW_PREC_TESTFUNC "s") + elseif(FFTW_LOOK_FOR_FFTW_LONG) + set(FFTW_PREC "l") + set(FFTW_PREC_TESTFUNC "l") + elseif(FFTW_LOOK_FOR_FFTW_QUAD) + set(FFTW_PREC "q") + set(FFTW_PREC_TESTFUNC "q") + else() + set(FFTW_PREC "") + set(FFTW_PREC_TESTFUNC "d") + endif() + + set(FFTW_LIBRARIES "") + set(FFTW_LIBRARY_DIRS "") + + if(NOT FFTW_LOOK_FOR_MKL) + + if (FFTW_LOOK_FOR_THREADS) + set(FFTW_libs_to_find "fftw3${FFTW_PREC}_threads;fftw3${FFTW_PREC};fftw3") + elseif (FFTW_LOOK_FOR_OMP) + set(FFTW_libs_to_find "fftw3${FFTW_PREC}_omp;fftw3${FFTW_PREC};fftw3") + else() + set(FFTW_libs_to_find "fftw3${FFTW_PREC};fftw3") + endif() + if (FFTW_LOOK_FOR_FFTW_QUAD) + if (NOT FFTW_LOOK_FOR_MKL AND NOT FFTW_LOOK_FOR_ESSL) + list(APPEND FFTW_libs_to_find "quadmath") + endif() + endif() + + if (FFTW_LOOK_FOR_ESSL) + set(FFTW_libs_to_find "fftw3_essl") + endif() + + # Try to find the fftw lib in the given paths + # ---------------------------------------------- + + # call cmake macro to find the lib path + if(FFTW_LIBDIR) + foreach(fftw_lib ${FFTW_libs_to_find}) + set(FFTW_${fftw_lib}_LIBRARY "FFTW_${fftw_lib}_LIBRARY-NOTFOUND") + find_library(FFTW_${fftw_lib}_LIBRARY + NAMES ${fftw_lib} + HINTS ${FFTW_LIBDIR}) + endforeach() + else() + if(FFTW_DIR) + foreach(fftw_lib ${FFTW_libs_to_find}) + set(FFTW_${fftw_lib}_LIBRARY "FFTW_${fftw_lib}_LIBRARY-NOTFOUND") + find_library(FFTW_${fftw_lib}_LIBRARY + NAMES ${fftw_lib} + HINTS ${FFTW_DIR} + PATH_SUFFIXES lib lib32 lib64) + endforeach() + else() + foreach(fftw_lib ${FFTW_libs_to_find}) + set(FFTW_${fftw_lib}_LIBRARY "FFTW_${fftw_lib}_LIBRARY-NOTFOUND") + find_library(FFTW_${fftw_lib}_LIBRARY + NAMES ${fftw_lib} + HINTS ${PATH_TO_LOOK_FOR}) + endforeach() + endif() + endif() + + # If found, add path to cmake variable + # ------------------------------------ + foreach(fftw_lib ${FFTW_libs_to_find}) + + if (FFTW_${fftw_lib}_LIBRARY) + get_filename_component(${fftw_lib}_lib_path "${FFTW_${fftw_lib}_LIBRARY}" PATH) + # set cmake variables + list(APPEND FFTW_LIBRARIES "${FFTW_${fftw_lib}_LIBRARY}") + list(APPEND FFTW_LIBRARY_DIRS "${${fftw_lib}_lib_path}") + else () + list(APPEND FFTW_LIBRARIES "${FFTW_${fftw_lib}_LIBRARY}") + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "Looking for FFTW -- lib ${fftw_lib} not found") + endif() + endif () + mark_as_advanced(FFTW_${fftw_lib}_LIBRARY) + + endforeach() + + # check if one lib is NOTFOUND + foreach(lib ${FFTW_LIBRARIES}) + if (NOT lib) + set(FFTW_LIBRARIES "FFTW_LIBRARIES-NOTFOUND") + endif() + endforeach() + + endif(NOT FFTW_LOOK_FOR_MKL) + + if (FFTW_LOOK_FOR_MKL OR FFTW_LOOK_FOR_ESSL) + + # FFTW relies on blas libs + if (FFTW_LOOK_FOR_THREADS) + if (FFTW_LOOK_FOR_MKL) + if (BLAS_PAR_LIBRARIES) + list(APPEND FFTW_LIBRARIES "${BLAS_PAR_LIBRARIES}") + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "Multithreaded FFTW has been found: ${FFTW_LIBRARIES}") + endif() + else() + if (NOT FFTW_FIND_QUIETLY) + if (FFTW_FIND_REQUIRED AND FFTW_FIND_REQUIRED_MKL) + message(FATAL_ERROR "FFTW is required but not found.") + else() + message(STATUS "Multithreaded FFTW not found.") + endif() + endif() + endif(BLAS_PAR_LIBRARIES) + elseif (FFTW_LOOK_FOR_ESSL) + if (FFTW_LIBRARIES AND BLAS_PAR_LIBRARIES) + list(APPEND FFTW_LIBRARIES "${BLAS_PAR_LIBRARIES}") + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "Multithreaded FFTW has been found: ${FFTW_LIBRARIES}") + endif() + else() + if (NOT FFTW_FIND_QUIETLY) + if (FFTW_FIND_REQUIRED AND FFTW_FIND_REQUIRED_MKL) + message(FATAL_ERROR "FFTW is required but not found.") + else() + message(STATUS "Multithreaded FFTW not found.") + endif() + endif() + endif(FFTW_LIBRARIES AND BLAS_PAR_LIBRARIES) + endif() + else(FFTW_LOOK_FOR_THREADS) + if (FFTW_LOOK_FOR_MKL) + if (BLAS_SEQ_LIBRARIES) + list(APPEND FFTW_LIBRARIES "${BLAS_SEQ_LIBRARIES}") + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "FFTW has been found: ${FFTW_LIBRARIES}") + endif() + else() + if (NOT FFTW_FIND_QUIETLY) + if (FFTW_FIND_REQUIRED AND FFTW_FIND_REQUIRED_MKL) + message(FATAL_ERROR "FFTW is required but not found.") + else() + message(STATUS "FFTW not found.") + endif() + endif() + endif(BLAS_SEQ_LIBRARIES) + elseif (FFTW_LOOK_FOR_ESSL) + if (FFTW_LIBRARIES AND BLAS_SEQ_LIBRARIES) + list(APPEND FFTW_LIBRARIES "${BLAS_SEQ_LIBRARIES}") + if (NOT FFTW_FIND_QUIETLY) + message(STATUS "FFTW has been found: ${FFTW_LIBRARIES}") + endif() + else() + if (NOT FFTW_FIND_QUIETLY) + if (FFTW_FIND_REQUIRED AND FFTW_FIND_REQUIRED_MKL) + message(FATAL_ERROR "FFTW is required but not found.") + else() + message(STATUS "FFTW not found.") + endif() + endif() + endif(FFTW_LIBRARIES AND BLAS_SEQ_LIBRARIES) + endif() + endif(FFTW_LOOK_FOR_THREADS) + + if (BLAS_LIBRARY_DIRS) + list(APPEND FFTW_LIBRARY_DIRS "${BLAS_LIBRARY_DIRS}") + else() + if (NOT FFTW_FIND_QUIETLY) + message(WARNING "FFTW_LIBRARY_DIRS may not be complete because BLAS_LIBRARY_DIRS is empty.") + endif() + endif() + + endif(FFTW_LOOK_FOR_MKL OR FFTW_LOOK_FOR_ESSL) + + list(REMOVE_DUPLICATES FFTW_INCLUDE_DIRS) + list(REMOVE_DUPLICATES FFTW_LIBRARY_DIRS) + + # check if one lib is NOTFOUND + foreach(lib ${FFTW_LIBRARIES}) + if (NOT lib) + set(FFTW_LIBRARIES "FFTW_LIBRARIES-NOTFOUND") + endif() + endforeach() + + # check a function to validate the find + if(FFTW_LIBRARIES) + + set(REQUIRED_FLAGS) + set(REQUIRED_LDFLAGS) + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # FFTW + if (FFTW_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${FFTW_INCLUDE_DIRS}") + endif() + if (FFTW_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${FFTW_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${FFTW_LIBRARIES}") + # THREADS + if (FFTW_LOOK_FOR_THREADS) + list(APPEND REQUIRED_LIBS "${CMAKE_THREAD_LIBS_INIT}") + endif() + # OMP + if(FFTW_LOOK_FOR_OMP) + set(REQUIRED_FLAGS "-fopenmp") + #if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + # # either gomp ... + # list(APPEND REQUIRED_LIBS "-lgomp") + # # or iomp5 + # list(APPEND REQUIRED_LIBS "-liomp5") + #elseif (CMAKE_C_COMPILER_ID STREQUAL "Intel") + # list(APPEND REQUIRED_LIBS "-liomp5") + #endif() + endif() + # MKL + if(FFTW_LOOK_FOR_MKL) + list(APPEND REQUIRED_LIBS "${CMAKE_THREAD_LIBS_INIT}") + if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME STREQUAL "Linux") + list(APPEND REQUIRED_LDFLAGS "-Wl,--no-as-needed") + endif() + endif() + # m + find_library(M_LIBRARY NAMES m) + mark_as_advanced(M_LIBRARY) + if(M_LIBRARY) + list(APPEND REQUIRED_LIBS "-lm") + 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(FFTW_WORKS CACHE) + include(CheckFunctionExists) + if (FFTW_LOOK_FOR_ESSL) + check_function_exists(${FFTW_PREC_TESTFUNC}fftw_execute FFTW_WORKS) + else() + check_function_exists(${FFTW_PREC_TESTFUNC}fftw_execute_ FFTW_WORKS) + endif() + mark_as_advanced(FFTW_WORKS) + + if(FFTW_WORKS) + # save link with dependencies + set(FFTW_LIBRARIES_DEP "${REQUIRED_LIBS}") + set(FFTW_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(FFTW_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(FFTW_C_FLAGS "${REQUIRED_FLAGS}") + set(FFTW_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES FFTW_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES FFTW_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES FFTW_LINKER_FLAGS) + else() + if(NOT FFTW_FIND_QUIETLY) + message(STATUS "Looking for FFTW : test of ${FFTW_PREC_TESTFUNC}fftw_execute_ with fftw library fails") + message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}") + message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}") + message(STATUS "CMAKE_REQUIRED_FLAGS: ${CMAKE_REQUIRED_FLAGS}") + message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails") + endif() + else() + set(FFTW_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + endif() + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_LIBRARIES) + endif(FFTW_LIBRARIES) + +endif( (NOT PKG_CONFIG_EXECUTABLE) OR + (PKG_CONFIG_EXECUTABLE AND NOT FFTW_FOUND) OR + FFTW_GIVEN_BY_USER OR + FFTW_LOOK_FOR_MKL OR + FFTW_LOOK_FOR_ESSL + ) + +if (FFTW_LIBRARIES) + list(GET FFTW_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(FFTW_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of FFTW library" FORCE) + else() + set(FFTW_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of FFTW library" FORCE) + endif() +endif() +mark_as_advanced(FFTW_DIR) +mark_as_advanced(FFTW_DIR_FOUND) + +# check that FFTW has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT FFTW_FOUND) OR (FFTW_GIVEN_BY_USER) ) + find_package_handle_standard_args(FFTW DEFAULT_MSG + FFTW_LIBRARIES + FFTW_INCLUDE_DIRS + FFTW_WORKS) +else() + find_package_handle_standard_args(FFTW DEFAULT_MSG + FFTW_LIBRARIES + FFTW_WORKS) +endif() diff --git a/modules/find/FindFXT.cmake b/modules/find/FindFXT.cmake new file mode 100644 index 0000000..3fd9a6e --- /dev/null +++ b/modules/find/FindFXT.cmake @@ -0,0 +1,310 @@ +### +# +# @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 FXT include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(FXT +# [REQUIRED]) # Fail with error if fxt is not found +# +# This module finds headers and fxt library. +# Results are reported in variables: +# FXT_FOUND - True if headers and requested libraries were found +# FXT_INCLUDE_DIRS - fxt include directories +# FXT_LIBRARY_DIRS - Link directories for fxt libraries +# FXT_LIBRARIES - fxt 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 -DFXT_DIR=path/to/fxt): +# FXT_DIR - Where to find the base directory of fxt +# FXT_INCDIR - Where to find the header files +# FXT_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: FXT_DIR, FXT_INCDIR, FXT_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.) + +if (NOT FXT_FOUND) + set(FXT_DIR "" CACHE PATH "Installation directory of FXT library") + if (NOT FXT_FIND_QUIETLY) + message(STATUS "A cache variable, namely FXT_DIR, has been set to specify the install directory of FXT") + endif() +endif() + +set(ENV_FXT_DIR "$ENV{FXT_DIR}") +set(ENV_FXT_INCDIR "$ENV{FXT_INCDIR}") +set(ENV_FXT_LIBDIR "$ENV{FXT_LIBDIR}") +set(FXT_GIVEN_BY_USER "FALSE") +if ( FXT_DIR OR ( FXT_INCDIR AND FXT_LIBDIR) OR ENV_FXT_DIR OR (ENV_FXT_INCDIR AND ENV_FXT_LIBDIR) ) + set(FXT_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 FXT_GIVEN_BY_USER) + + pkg_search_module(FXT fxt) + if (NOT FXT_FIND_QUIETLY) + if (FXT_FOUND AND FXT_LIBRARIES) + message(STATUS "Looking for FXT - found using PkgConfig") + #if(NOT FXT_INCLUDE_DIRS) + # message("${Magenta}FXT_INCLUDE_DIRS is empty using PkgConfig." + # "Perhaps the path to fxt headers is already present in your" + # "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}") + #endif() + else() + message(STATUS "${Magenta}Looking for FXT - not found using PkgConfig." + "\n Perhaps you should add the directory containing fxt.pc to the" + "\n PKG_CONFIG_PATH environment variable.${ColourReset}") + endif() + endif() + +endif(PKG_CONFIG_EXECUTABLE AND NOT FXT_GIVEN_BY_USER) + +if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT FXT_FOUND) OR (FXT_GIVEN_BY_USER) ) + + if (NOT FXT_FIND_QUIETLY) + message(STATUS "Looking for FXT - PkgConfig not used") + endif() + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + unset(_inc_env) + set(ENV_FXT_DIR "$ENV{FXT_DIR}") + set(ENV_FXT_INCDIR "$ENV{FXT_INCDIR}") + if(ENV_FXT_INCDIR) + list(APPEND _inc_env "${ENV_FXT_INCDIR}") + elseif(ENV_FXT_DIR) + list(APPEND _inc_env "${ENV_FXT_DIR}") + list(APPEND _inc_env "${ENV_FXT_DIR}/include") + list(APPEND _inc_env "${ENV_FXT_DIR}/include/fxt") + 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 fxt header in the given paths + # ------------------------------------------------- + # call cmake macro to find the header path + if(FXT_INCDIR) + set(FXT_fxt.h_DIRS "FXT_fxt.h_DIRS-NOTFOUND") + find_path(FXT_fxt.h_DIRS + NAMES fxt.h + HINTS ${FXT_INCDIR}) + else() + if(FXT_DIR) + set(FXT_fxt.h_DIRS "FXT_fxt.h_DIRS-NOTFOUND") + find_path(FXT_fxt.h_DIRS + NAMES fxt.h + HINTS ${FXT_DIR} + PATH_SUFFIXES "include" "include/fxt") + else() + set(FXT_fxt.h_DIRS "FXT_fxt.h_DIRS-NOTFOUND") + find_path(FXT_fxt.h_DIRS + NAMES fxt.h + HINTS ${_inc_env} + PATH_SUFFIXES "fxt") + endif() + endif() + mark_as_advanced(FXT_fxt.h_DIRS) + + # Add path to cmake variable + # ------------------------------------ + if (FXT_fxt.h_DIRS) + set(FXT_INCLUDE_DIRS "${FXT_fxt.h_DIRS}") + else () + set(FXT_INCLUDE_DIRS "FXT_INCLUDE_DIRS-NOTFOUND") + if(NOT FXT_FIND_QUIETLY) + message(STATUS "Looking for fxt -- fxt.h not found") + endif() + endif () + + if (FXT_INCLUDE_DIRS) + list(REMOVE_DUPLICATES FXT_INCLUDE_DIRS) + endif () + + + # Looking for lib + # --------------- + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_FXT_LIBDIR "$ENV{FXT_LIBDIR}") + if(ENV_FXT_LIBDIR) + list(APPEND _lib_env "${ENV_FXT_LIBDIR}") + elseif(ENV_FXT_DIR) + list(APPEND _lib_env "${ENV_FXT_DIR}") + list(APPEND _lib_env "${ENV_FXT_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 fxt lib in the given paths + # ---------------------------------------------- + + # call cmake macro to find the lib path + if(FXT_LIBDIR) + set(FXT_fxt_LIBRARY "FXT_fxt_LIBRARY-NOTFOUND") + find_library(FXT_fxt_LIBRARY + NAMES fxt + HINTS ${FXT_LIBDIR}) + else() + if(FXT_DIR) + set(FXT_fxt_LIBRARY "FXT_fxt_LIBRARY-NOTFOUND") + find_library(FXT_fxt_LIBRARY + NAMES fxt + HINTS ${FXT_DIR} + PATH_SUFFIXES lib lib32 lib64) + else() + set(FXT_fxt_LIBRARY "FXT_fxt_LIBRARY-NOTFOUND") + find_library(FXT_fxt_LIBRARY + NAMES fxt + HINTS ${_lib_env}) + endif() + endif() + mark_as_advanced(FXT_fxt_LIBRARY) + + # If found, add path to cmake variable + # ------------------------------------ + if (FXT_fxt_LIBRARY) + get_filename_component(fxt_lib_path ${FXT_fxt_LIBRARY} PATH) + # set cmake variables (respects naming convention) + set(FXT_LIBRARIES "${FXT_fxt_LIBRARY}") + set(FXT_LIBRARY_DIRS "${fxt_lib_path}") + else () + set(FXT_LIBRARIES "FXT_LIBRARIES-NOTFOUND") + set(FXT_LIBRARY_DIRS "FXT_LIBRARY_DIRS-NOTFOUND") + if(NOT FXT_FIND_QUIETLY) + message(STATUS "Looking for fxt -- lib fxt not found") + endif() + endif () + + if (FXT_LIBRARY_DIRS) + list(REMOVE_DUPLICATES FXT_LIBRARY_DIRS) + endif () + + # check a function to validate the find + if(FXT_LIBRARIES) + + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # FXT + if (FXT_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${FXT_INCLUDE_DIRS}") + endif() + if (FXT_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${FXT_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${FXT_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(FXT_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(fut_keychange FXT_WORKS) + mark_as_advanced(FXT_WORKS) + + if(NOT FXT_WORKS) + if(NOT FXT_FIND_QUIETLY) + message(STATUS "Looking for fxt : test of fut_keychange with fxt 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(FXT_LIBRARIES) + +endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT FXT_FOUND) OR (FXT_GIVEN_BY_USER) ) + +if (FXT_LIBRARIES) + if (FXT_LIBRARY_DIRS) + list(GET FXT_LIBRARY_DIRS 0 first_lib_path) + else() + list(GET FXT_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(FXT_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of FXT library" FORCE) + else() + set(FXT_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of FXT library" FORCE) + endif() +endif() +mark_as_advanced(FXT_DIR) +mark_as_advanced(FXT_DIR_FOUND) + +# check that FXT has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +if (PKG_CONFIG_EXECUTABLE AND FXT_FOUND) + find_package_handle_standard_args(FXT DEFAULT_MSG + FXT_LIBRARIES) +else() + find_package_handle_standard_args(FXT DEFAULT_MSG + FXT_LIBRARIES + FXT_WORKS) +endif() diff --git a/modules/find/FindHWLOC.cmake b/modules/find/FindHWLOC.cmake new file mode 100644 index 0000000..a831b5c --- /dev/null +++ b/modules/find/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/modules/find/FindHYPRE.cmake b/modules/find/FindHYPRE.cmake new file mode 100644 index 0000000..944b5ec --- /dev/null +++ b/modules/find/FindHYPRE.cmake @@ -0,0 +1,273 @@ +### +# +# @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 HYPRE include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(HYPRE +# [REQUIRED]) # Fail with error if hypre is not found +# +# This module finds headers and hypre library. +# Results are reported in variables: +# HYPRE_FOUND - True if headers and requested libraries were found +# HYPRE_INCLUDE_DIRS - hypre include directories +# HYPRE_LIBRARY_DIRS - Link directories for hypre libraries +# HYPRE_LIBRARIES - hypre 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 -DHYPRE_DIR=path/to/hypre): +# HYPRE_DIR - Where to find the base directory of hypre +# HYPRE_INCDIR - Where to find the header files +# HYPRE_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: HYPRE_DIR, HYPRE_INCDIR, HYPRE_LIBDIR + +#============================================================================= +# Copyright 2016 Inria +# Copyright 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 HYPRE_FOUND) + set(HYPRE_DIR "" CACHE PATH "Installation directory of HYPRE library") + if (NOT HYPRE_FIND_QUIETLY) + message(STATUS "A cache variable, namely HYPRE_DIR, has been set to specify the install directory of HYPRE") + endif() +endif() + +set(ENV_HYPRE_DIR "$ENV{HYPRE_DIR}") +set(ENV_HYPRE_INCDIR "$ENV{HYPRE_INCDIR}") +set(ENV_HYPRE_LIBDIR "$ENV{HYPRE_LIBDIR}") +set(HYPRE_GIVEN_BY_USER "FALSE") +if ( HYPRE_DIR OR ( HYPRE_INCDIR AND HYPRE_LIBDIR) OR ENV_HYPRE_DIR OR (ENV_HYPRE_INCDIR AND ENV_HYPRE_LIBDIR) ) + set(HYPRE_GIVEN_BY_USER "TRUE") +endif() + +# Looking for include +# ------------------- + +# Add system include paths to search include +# ------------------------------------------ +unset(_inc_env) +if(ENV_HYPRE_INCDIR) + list(APPEND _inc_env "${ENV_HYPRE_INCDIR}") +elseif(ENV_HYPRE_DIR) + list(APPEND _inc_env "${ENV_HYPRE_DIR}") + list(APPEND _inc_env "${ENV_HYPRE_DIR}/include") + list(APPEND _inc_env "${ENV_HYPRE_DIR}/include/hypre") +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 hypre header in the given paths +# ------------------------------------------------- +# call cmake macro to find the header path +if(HYPRE_INCDIR) + set(HYPRE_HYPRE.h_DIRS "HYPRE_HYPRE.h_DIRS-NOTFOUND") + find_path(HYPRE_HYPRE.h_DIRS + NAMES HYPRE.h + HINTS ${HYPRE_INCDIR}) +else() + if(HYPRE_DIR) + set(HYPRE_HYPRE.h_DIRS "HYPRE_HYPRE.h_DIRS-NOTFOUND") + find_path(HYPRE_HYPRE.h_DIRS + NAMES HYPRE.h + HINTS ${HYPRE_DIR} + PATH_SUFFIXES "include" "include/hypre") + else() + set(HYPRE_HYPRE.h_DIRS "HYPRE_HYPRE.h_DIRS-NOTFOUND") + find_path(HYPRE_HYPRE.h_DIRS + NAMES HYPRE.h + HINTS ${PATH_TO_LOOK_FOR} + PATH_SUFFIXES "hypre") + endif() +endif() +mark_as_advanced(HYPRE_HYPRE.h_DIRS) + +# Add path to cmake variable +# ------------------------------------ +if (HYPRE_HYPRE.h_DIRS) + set(HYPRE_INCLUDE_DIRS "${HYPRE_HYPRE.h_DIRS}") +else () + set(HYPRE_INCLUDE_DIRS "HYPRE_INCLUDE_DIRS-NOTFOUND") + if(NOT HYPRE_FIND_QUIETLY) + message(STATUS "Looking for hypre -- HYPRE.h not found") + endif() +endif () + +if (HYPRE_INCLUDE_DIRS) + list(REMOVE_DUPLICATES HYPRE_INCLUDE_DIRS) +endif () + + +# Looking for lib +# --------------- + +# Add system library paths to search lib +# -------------------------------------- +unset(_lib_env) +if(ENV_HYPRE_LIBDIR) + list(APPEND _lib_env "${ENV_HYPRE_LIBDIR}") +elseif(ENV_HYPRE_DIR) + list(APPEND _lib_env "${ENV_HYPRE_DIR}") + list(APPEND _lib_env "${ENV_HYPRE_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 hypre lib in the given paths +# ---------------------------------------------- + +# call cmake macro to find the lib path +if(HYPRE_LIBDIR) + set(HYPRE_HYPRE_LIBRARY "HYPRE_HYPRE_LIBRARY-NOTFOUND") + find_library(HYPRE_HYPRE_LIBRARY + NAMES HYPRE + HINTS ${HYPRE_LIBDIR}) +else() + if(HYPRE_DIR) + set(HYPRE_HYPRE_LIBRARY "HYPRE_HYPRE_LIBRARY-NOTFOUND") + find_library(HYPRE_HYPRE_LIBRARY + NAMES HYPRE + HINTS ${HYPRE_DIR} + PATH_SUFFIXES lib lib32 lib64) + else() + set(HYPRE_HYPRE_LIBRARY "HYPRE_HYPRE_LIBRARY-NOTFOUND") + find_library(HYPRE_HYPRE_LIBRARY + NAMES HYPRE + HINTS ${PATH_TO_LOOK_FOR}) + endif() +endif() +mark_as_advanced(HYPRE_HYPRE_LIBRARY) + +# If found, add path to cmake variable +# ------------------------------------ +if (HYPRE_HYPRE_LIBRARY) + get_filename_component(hypre_lib_path ${HYPRE_HYPRE_LIBRARY} PATH) + # set cmake variables (respects naming convention) + set(HYPRE_LIBRARIES "${HYPRE_HYPRE_LIBRARY}") + set(HYPRE_LIBRARY_DIRS "${hypre_lib_path}") +else () + set(HYPRE_LIBRARIES "HYPRE_LIBRARIES-NOTFOUND") + set(HYPRE_LIBRARY_DIRS "HYPRE_LIBRARY_DIRS-NOTFOUND") + if(NOT HYPRE_FIND_QUIETLY) + message(STATUS "Looking for hypre -- lib HYPRE not found") + endif() +endif () + +if (HYPRE_LIBRARY_DIRS) + list(REMOVE_DUPLICATES HYPRE_LIBRARY_DIRS) +endif () + +# check a function to validate the find +if(HYPRE_LIBRARIES) + + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # HYPRE + if (HYPRE_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${HYPRE_INCLUDE_DIRS}") + endif() + if (HYPRE_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${HYPRE_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${HYPRE_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(HYPRE_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(HYPRE_StructGridCreate HYPRE_WORKS) + mark_as_advanced(HYPRE_WORKS) + + if(NOT HYPRE_WORKS) + if(NOT HYPRE_FIND_QUIETLY) + message(STATUS "Looking for HYPRE : test of HYPRE_StructGridCreate with HYPRE 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(HYPRE_LIBRARIES) + +if (HYPRE_LIBRARIES) + if (HYPRE_LIBRARY_DIRS) + list(GET HYPRE_LIBRARY_DIRS 0 first_lib_path) + else() + list(GET HYPRE_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(HYPRE_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of HYPRE library" FORCE) + else() + set(HYPRE_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of HYPRE library" FORCE) + endif() +endif() +mark_as_advanced(HYPRE_DIR) +mark_as_advanced(HYPRE_DIR_FOUND) + +# check that HYPRE has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(HYPRE DEFAULT_MSG + HYPRE_LIBRARIES + HYPRE_WORKS) diff --git a/modules/find/FindLAPACK.cmake b/modules/find/FindLAPACK.cmake new file mode 100644 index 0000000..2db025d --- /dev/null +++ b/modules/find/FindLAPACK.cmake @@ -0,0 +1,730 @@ +### +# +# @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 LAPACK library +# This module finds an installed fortran library that implements the LAPACK +# linear-algebra interface (see http://www.netlib.org/lapack/). +# +# The approach follows that taken for the autoconf macro file, acx_lapack.m4 +# (distributed at http://ac-archive.sourceforge.net/ac-archive/acx_lapack.html). +# +# This module sets the following variables: +# LAPACK_FOUND - set to true if a library implementing the LAPACK interface +# is found +# LAPACK_LINKER_FLAGS - uncached list of required linker flags (excluding -l +# and -L). +# LAPACK_LIBRARIES - uncached list of libraries (using full path name) to +# link against to use LAPACK +# LAPACK95_LIBRARIES - uncached list of libraries (using full path name) to +# link against to use LAPACK95 +# LAPACK95_FOUND - set to true if a library implementing the LAPACK 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 +# LAPACK_VENDOR_FOUND stores the LAPACK 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 -DLAPACK_DIR=path/to/lapack): +# LAPACK_DIR - Where to find the base directory of lapack +# LAPACK_INCDIR - Where to find the header files +# LAPACK_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: LAPACK_DIR, LAPACK_INCDIR, LAPACK_LIBDIR +# For MKL case and if no paths are given as hints, we will try to use the MKLROOT +# environment variable +# Note that if BLAS_DIR is set, it will also look for lapack in it +### List of vendors (BLA_VENDOR) valid in this module +## Intel(mkl), ACML, Apple, NAS, Generic + +#============================================================================= +# 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 the 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() + +if (NOT LAPACK_FOUND) + set(LAPACK_DIR "" CACHE PATH "Installation directory of LAPACK library") + if (NOT LAPACK_FIND_QUIETLY) + message(STATUS "A cache variable, namely LAPACK_DIR, has been set to specify the install directory of LAPACK") + endif() +endif (NOT LAPACK_FOUND) + +option(LAPACK_VERBOSE "Print some additional information during LAPACK +libraries detection" OFF) +mark_as_advanced(LAPACK_VERBOSE) +if (BLAS_VERBOSE) + set(LAPACK_VERBOSE ON) +endif () +set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + +get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES) +if (NOT _LANGUAGES_ MATCHES Fortran) + include(CheckFunctionExists) +else (NOT _LANGUAGES_ MATCHES Fortran) + include(CheckFortranFunctionExists) +endif (NOT _LANGUAGES_ MATCHES Fortran) + +set(LAPACK_FOUND FALSE) +set(LAPACK95_FOUND FALSE) + +# TODO: move this stuff to separate module + +macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas _threads) + # 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}") + set(ENV_LAPACK_DIR "$ENV{LAPACK_DIR}") + set(ENV_LAPACK_LIBDIR "$ENV{LAPACK_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() + endif() + if (LAPACK_LIBDIR) + list(APPEND _libdir "${LAPACK_LIBDIR}") + elseif (LAPACK_DIR) + list(APPEND _libdir "${LAPACK_DIR}") + list(APPEND _libdir "${LAPACK_DIR}/lib") + if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + list(APPEND _libdir "${LAPACK_DIR}/lib64") + list(APPEND _libdir "${LAPACK_DIR}/lib/intel64") + else() + list(APPEND _libdir "${LAPACK_DIR}/lib32") + list(APPEND _libdir "${LAPACK_DIR}/lib/ia32") + endif() + elseif(ENV_LAPACK_LIBDIR) + list(APPEND _libdir "${ENV_LAPACK_LIBDIR}") + elseif(ENV_LAPACK_DIR) + list(APPEND _libdir "${ENV_LAPACK_DIR}") + list(APPEND _libdir "${ENV_LAPACK_DIR}/lib") + if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + list(APPEND _libdir "${ENV_LAPACK_DIR}/lib64") + list(APPEND _libdir "${ENV_LAPACK_DIR}/lib/intel64") + else() + list(APPEND _libdir "${ENV_LAPACK_DIR}/lib32") + list(APPEND _libdir "${ENV_LAPACK_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 (LAPACK_VERBOSE) + message("${Cyan}Try to find LAPACK libraries: ${_list}") + endif () + + foreach(_library ${_list}) + set(_combined_name ${_combined_name}_${_library}) + + if(_libraries_work) + if (BLA_STATIC) + if (WIN32) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) + endif ( WIN32 ) + if (APPLE) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else (APPLE) + set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + endif (APPLE) + else (BLA_STATIC) + 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 (BLA_STATIC) + 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 LAPACK_FIND_QUIETLY AND LAPACK_VERBOSE) + Print_Find_Library_Blas_Status(lapack ${_library} ${_libdir}) + endif () + set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY}) + set(_libraries_work ${${_prefix}_${_library}_LIBRARY}) + endif(_libraries_work) + endforeach(_library ${_list}) + + 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() + if(UNIX AND BLA_STATIC) + set(CMAKE_REQUIRED_LIBRARIES ${_flags} "-Wl,--start-group" ${${LIBRARIES}} ${_blas} "-Wl,--end-group" ${_threads}) + else(UNIX AND BLA_STATIC) + set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_threads}) + endif(UNIX AND BLA_STATIC) + if (LAPACK_VERBOSE) + message("${Cyan}LAPACK libs found. Try to compile symbol ${_name} with" + "following libraries: ${CMAKE_REQUIRED_LIBRARIES}") + endif () + if(NOT LAPACK_FOUND) + unset(${_prefix}${_combined_name}_WORKS CACHE) + endif() + if (NOT _LANGUAGES_ MATCHES Fortran) + check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS) + else (NOT _LANGUAGES_ MATCHES Fortran) + check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS) + endif (NOT _LANGUAGES_ MATCHES Fortran) + set(CMAKE_REQUIRED_LIBRARIES) + mark_as_advanced(${_prefix}${_combined_name}_WORKS) + set(_libraries_work ${${_prefix}${_combined_name}_WORKS}) + endif(_libraries_work) + + if(_libraries_work) + set(${LIBRARIES} ${${LIBRARIES}} ${_blas} ${_threads}) + else(_libraries_work) + set(${LIBRARIES} FALSE) + endif(_libraries_work) + +endmacro(Check_Lapack_Libraries) + + +set(LAPACK_LINKER_FLAGS) +set(LAPACK_LIBRARIES) +set(LAPACK95_LIBRARIES) + +if (NOT BLAS_FOUND) + if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) + find_package(BLASEXT) + else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) + find_package(BLASEXT REQUIRED) + endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) +endif () + +if(BLAS_FOUND) + set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS}) + if ($ENV{BLA_VENDOR} MATCHES ".+") + set(BLA_VENDOR $ENV{BLA_VENDOR}) + else ($ENV{BLA_VENDOR} MATCHES ".+") + if(NOT BLA_VENDOR) + set(BLA_VENDOR "All") + endif(NOT BLA_VENDOR) + endif ($ENV{BLA_VENDOR} MATCHES ".+") + + if (UNIX AND NOT WIN32) + # m + find_library(M_LIBRARY NAMES m) + mark_as_advanced(M_LIBRARY) + if(M_LIBRARY) + set(LM "-lm") + else() + set(LM "") + endif() + endif() + + # check if blas lib contains lapack symbols + if (BLAS_LIBRARIES) + if (BLAS_LIBRARIES_DEP) + set(LIBRARIES ${BLAS_LIBRARIES_DEP}) + else() + set(LIBRARIES ${BLAS_LIBRARIES}) + endif() + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + "CHEEV" + "" + "" + "${LIBRARIES}" + "" + ) + if (LAPACK_LIBRARIES) + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK_LIBRARIES) + message(STATUS "Looking for LAPACK in BLAS: found") + else() + message(STATUS "Looking for LAPACK in BLAS: not found") + endif() + endif() + if (LAPACK_LIBRARIES AND NOT LAPACK_VENDOR_FOUND) + set (LAPACK_VENDOR_FOUND "${BLAS_VENDOR_FOUND}") + endif() + endif() + endif(BLAS_LIBRARIES) + + #intel lapack + if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") + + if(NOT LAPACK_LIBRARIES) + if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) + + if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) + find_PACKAGE(Threads) + else() + find_package(Threads REQUIRED) + endif() + + set(LAPACK_SEARCH_LIBS "") + + set(additional_flags "") + if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(additional_flags "-Wl,--no-as-needed") + endif() + + if (BLA_F95) + set(LAPACK_mkl_SEARCH_SYMBOL "CHEEV") + set(_LIBRARIES LAPACK95_LIBRARIES) + set(_BLAS_LIBRARIES ${BLAS95_LIBRARIES}) + + # old + list(APPEND LAPACK_SEARCH_LIBS + "mkl_lapack95") + # new >= 10.3 + list(APPEND LAPACK_SEARCH_LIBS + "mkl_intel_c") + list(APPEND LAPACK_SEARCH_LIBS + "mkl_intel_lp64") + else(BLA_F95) + set(LAPACK_mkl_SEARCH_SYMBOL "cheev") + set(_LIBRARIES LAPACK_LIBRARIES) + set(_BLAS_LIBRARIES ${BLAS_LIBRARIES}) + + # old + list(APPEND LAPACK_SEARCH_LIBS + "mkl_lapack") + # new >= 10.3 + list(APPEND LAPACK_SEARCH_LIBS + "mkl_gf_lp64") + endif(BLA_F95) + + # First try empty lapack libs + if (NOT ${_LIBRARIES}) + check_lapack_libraries( + ${_LIBRARIES} + LAPACK + ${LAPACK_mkl_SEARCH_SYMBOL} + "${additional_flags}" + "" + "${_BLAS_LIBRARIES}" + "${CMAKE_THREAD_LIBS_INIT};${LM}" + ) + if(_LIBRARIES) + set(LAPACK_LINKER_FLAGS "${additional_flags}") + endif() + endif () + # Then try the search libs + foreach (IT ${LAPACK_SEARCH_LIBS}) + if (NOT ${_LIBRARIES}) + check_lapack_libraries( + ${_LIBRARIES} + LAPACK + ${LAPACK_mkl_SEARCH_SYMBOL} + "${additional_flags}" + "${IT}" + "${_BLAS_LIBRARIES}" + "${CMAKE_THREAD_LIBS_INIT};${LM}" + ) + if(_LIBRARIES) + set(LAPACK_LINKER_FLAGS "${additional_flags}") + endif() + endif () + endforeach () + if(NOT LAPACK_FIND_QUIETLY) + if(${_LIBRARIES}) + message(STATUS "Looking for MKL LAPACK: found") + else() + message(STATUS "Looking for MKL LAPACK: not found") + endif() + endif(NOT LAPACK_FIND_QUIETLY) + if (${_LIBRARIES} AND NOT LAPACK_VENDOR_FOUND) + set (LAPACK_VENDOR_FOUND "Intel MKL") + endif() + + endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) + endif(NOT LAPACK_LIBRARIES) + endif(BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") + + #goto lapack + if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All") + if(NOT LAPACK_LIBRARIES) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "goto2" + "${BLAS_LIBRARIES}" + "" + ) + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK_LIBRARIES) + message(STATUS "Looking for Goto LAPACK: found") + else() + message(STATUS "Looking for Goto LAPACK: not found") + endif() + endif() + if (LAPACK_LIBRARIES AND NOT LAPACK_VENDOR_FOUND) + set (LAPACK_VENDOR_FOUND "Goto") + endif() + endif(NOT LAPACK_LIBRARIES) + endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All") + + #open lapack + if (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All") + if(NOT LAPACK_LIBRARIES) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "openblas" + "${BLAS_LIBRARIES}" + "" + ) + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK_LIBRARIES) + message(STATUS "Looking for Open LAPACK: found") + else() + message(STATUS "Looking for Open LAPACK: not found") + endif() + endif() + if (LAPACK_LIBRARIES AND NOT LAPACK_VENDOR_FOUND) + set (LAPACK_VENDOR_FOUND "Openblas") + endif() + endif(NOT LAPACK_LIBRARIES) + endif (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All") + + # LAPACK in IBM ESSL library (requires generic lapack lib, too) + if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All") + if(NOT LAPACK_LIBRARIES) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheevd + "" + "essl;lapack" + "${BLAS_LIBRARIES}" + "" + ) + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK_LIBRARIES) + message(STATUS "Looking for IBM ESSL LAPACK: found") + else() + message(STATUS "Looking for IBM ESSL LAPACK: not found") + endif() + endif() + if (LAPACK_LIBRARIES AND NOT LAPACK_VENDOR_FOUND) + set (LAPACK_VENDOR_FOUND "IBM ESSL") + endif() + endif() + endif () + + # LAPACK in IBM ESSL_MT library (requires generic lapack lib, too) + if (BLA_VENDOR STREQUAL "IBMESSLMT" OR BLA_VENDOR STREQUAL "All") + if(NOT LAPACK_LIBRARIES) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheevd + "" + "esslsmp;lapack" + "${BLAS_PAR_LIBRARIES}" + "" + ) + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK_LIBRARIES) + message(STATUS "Looking for IBM ESSL MT LAPACK: found") + else() + message(STATUS "Looking for IBM ESSL MT LAPACK: not found") + endif() + endif() + if (LAPACK_LIBRARIES AND NOT LAPACK_VENDOR_FOUND) + set (LAPACK_VENDOR_FOUND "IBM ESSL MT") + endif() + endif() + endif () + + #acml lapack + if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All") + if (BLAS_LIBRARIES MATCHES ".+acml.+") + set (LAPACK_LIBRARIES ${BLAS_LIBRARIES}) + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK_LIBRARIES) + message(STATUS "Looking for ACML LAPACK: found") + else() + message(STATUS "Looking for ACML LAPACK: not found") + endif() + endif() + if (LAPACK_LIBRARIES AND NOT LAPACK_VENDOR_FOUND) + set (LAPACK_VENDOR_FOUND "ACML") + endif() + endif () + endif () + + # Apple LAPACK library? + if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All") + if(NOT LAPACK_LIBRARIES) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "Accelerate" + "${BLAS_LIBRARIES}" + "" + ) + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK_LIBRARIES) + message(STATUS "Looking for Apple Accelerate LAPACK: found") + else() + message(STATUS "Looking for Apple Accelerate LAPACK: not found") + endif() + endif() + if (LAPACK_LIBRARIES AND NOT LAPACK_VENDOR_FOUND) + set (LAPACK_VENDOR_FOUND "Apple Accelerate") + endif() + endif(NOT LAPACK_LIBRARIES) + endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All") + + if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All") + if ( NOT LAPACK_LIBRARIES ) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "vecLib" + "${BLAS_LIBRARIES}" + "" + ) + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK_LIBRARIES) + message(STATUS "Looking for NAS LAPACK: found") + else() + message(STATUS "Looking for NAS LAPACK: not found") + endif() + endif() + if (LAPACK_LIBRARIES AND NOT LAPACK_VENDOR_FOUND) + set (LAPACK_VENDOR_FOUND "NAS") + endif() + endif ( NOT LAPACK_LIBRARIES ) + endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All") + + # Generic LAPACK library? + if (BLA_VENDOR STREQUAL "Generic" OR + BLA_VENDOR STREQUAL "ATLAS" OR + BLA_VENDOR STREQUAL "All") + if ( NOT LAPACK_LIBRARIES ) + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "lapack" + "${BLAS_LIBRARIES};${LM}" + "" + ) + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK_LIBRARIES) + message(STATUS "Looking for Generic LAPACK: found") + else() + message(STATUS "Looking for Generic LAPACK: not found") + endif() + endif() + if (LAPACK_LIBRARIES AND NOT LAPACK_VENDOR_FOUND) + set (LAPACK_VENDOR_FOUND "Netlib or other Generic liblapack") + endif() + endif ( NOT LAPACK_LIBRARIES ) + endif () +else(BLAS_FOUND) + message(STATUS "LAPACK requires BLAS") +endif(BLAS_FOUND) + +if(BLA_F95) + if(LAPACK95_LIBRARIES) + set(LAPACK95_FOUND TRUE) + else(LAPACK95_LIBRARIES) + set(LAPACK95_FOUND FALSE) + endif(LAPACK95_LIBRARIES) + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK95_FOUND) + message(STATUS "A library with LAPACK95 API found.") + message(STATUS "LAPACK_LIBRARIES ${LAPACK_LIBRARIES}") + else(LAPACK95_FOUND) + message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but LAPACK 95 libraries could not be found or check of symbols failed." + "\nPlease indicate where to find LAPACK libraries. You have three options:\n" + "- Option 1: Provide the installation directory of LAPACK library with cmake option: -DLAPACK_DIR=your/path/to/lapack\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 -DLAPACK_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(LAPACK_FIND_REQUIRED) + message(FATAL_ERROR + "A required library with LAPACK95 API not found. Please specify library location." + ) + else(LAPACK_FIND_REQUIRED) + message(STATUS + "A library with LAPACK95 API not found. Please specify library location." + ) + endif(LAPACK_FIND_REQUIRED) + endif(LAPACK95_FOUND) + endif(NOT LAPACK_FIND_QUIETLY) + set(LAPACK_FOUND "${LAPACK95_FOUND}") + set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}") +else(BLA_F95) + if(LAPACK_LIBRARIES) + set(LAPACK_FOUND TRUE) + else(LAPACK_LIBRARIES) + set(LAPACK_FOUND FALSE) + endif(LAPACK_LIBRARIES) + + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK_FOUND) + message(STATUS "A library with LAPACK API found.") + message(STATUS "LAPACK_LIBRARIES ${LAPACK_LIBRARIES}") + else(LAPACK_FOUND) + message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but LAPACK libraries could not be found or check of symbols failed." + "\nPlease indicate where to find LAPACK libraries. You have three options:\n" + "- Option 1: Provide the installation directory of LAPACK library with cmake option: -DLAPACK_DIR=your/path/to/lapack\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 -DLAPACK_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(LAPACK_FIND_REQUIRED) + message(FATAL_ERROR + "A required library with LAPACK API not found. Please specify library location." + ) + else(LAPACK_FIND_REQUIRED) + message(STATUS + "A library with LAPACK API not found. Please specify library location." + ) + endif(LAPACK_FIND_REQUIRED) + endif(LAPACK_FOUND) + endif(NOT LAPACK_FIND_QUIETLY) +endif(BLA_F95) + +set(CMAKE_FIND_LIBRARY_SUFFIXES ${_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) + +if (LAPACK_FOUND) + list(GET LAPACK_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(LAPACK_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of LAPACK library" FORCE) + else() + set(LAPACK_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of LAPACK library" FORCE) + endif() +endif() +mark_as_advanced(LAPACK_DIR) +mark_as_advanced(LAPACK_DIR_FOUND) diff --git a/modules/find/FindLAPACKE.cmake b/modules/find/FindLAPACKE.cmake new file mode 100644 index 0000000..145f85e --- /dev/null +++ b/modules/find/FindLAPACKE.cmake @@ -0,0 +1,378 @@ +### +# +# @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 LAPACKE include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(LAPACKE +# [REQUIRED] # Fail with error if lapacke is not found +# [COMPONENTS <comp1> <comp2> ...] # dependencies +# ) +# +# LAPACKE depends on the following libraries: +# - LAPACK +# +# This module finds headers and lapacke library. +# Results are reported in variables: +# LAPACKE_FOUND - True if headers and requested libraries were found +# LAPACKE_LINKER_FLAGS - list of required linker flags (excluding -l and -L) +# LAPACKE_INCLUDE_DIRS - lapacke include directories +# LAPACKE_LIBRARY_DIRS - Link directories for lapacke libraries +# LAPACKE_LIBRARIES - lapacke component libraries to be linked +# LAPACKE_INCLUDE_DIRS_DEP - lapacke + dependencies include directories +# LAPACKE_LIBRARY_DIRS_DEP - lapacke + dependencies link directories +# LAPACKE_LIBRARIES_DEP - lapacke libraries + dependencies +# +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DLAPACKE_DIR=path/to/lapacke): +# LAPACKE_DIR - Where to find the base directory of lapacke +# LAPACKE_INCDIR - Where to find the header files +# LAPACKE_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: LAPACKE_DIR, LAPACKE_INCDIR, LAPACKE_LIBDIR +# +# LAPACKE could be directly embedded in LAPACK library (ex: Intel MKL) so that +# we test a lapacke function with the lapack libraries found and set LAPACKE +# variables to LAPACK ones if test is successful. To skip this feature and +# look for a stand alone lapacke, please add the following in your +# CMakeLists.txt before to call find_package(LAPACKE): +# set(LAPACKE_STANDALONE TRUE) + +#============================================================================= +# 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 LAPACKE_FOUND) + set(LAPACKE_DIR "" CACHE PATH "Installation directory of LAPACKE library") + if (NOT LAPACKE_FIND_QUIETLY) + message(STATUS "A cache variable, namely LAPACKE_DIR, has been set to specify the install directory of LAPACKE") + endif() +endif() + +# LAPACKE depends on LAPACK anyway, try to find it +if (NOT LAPACK_FOUND) + if(LAPACKE_FIND_REQUIRED) + find_package(LAPACKEXT REQUIRED) + else() + find_package(LAPACKEXT) + endif() +endif() + +# LAPACKE depends on LAPACK +if (LAPACK_FOUND) + + if (NOT LAPACKE_STANDALONE) + # check if a lapacke function exists in the LAPACK lib + include(CheckFunctionExists) + set(CMAKE_REQUIRED_LIBRARIES "${LAPACK_LINKER_FLAGS};${LAPACK_LIBRARIES}") + unset(LAPACKE_WORKS CACHE) + check_function_exists(LAPACKE_dgeqrf LAPACKE_WORKS) + mark_as_advanced(LAPACKE_WORKS) + set(CMAKE_REQUIRED_LIBRARIES) + + if(LAPACKE_WORKS) + if(NOT LAPACKE_FIND_QUIETLY) + message(STATUS "Looking for lapacke: test with lapack succeeds") + endif() + # test succeeds: LAPACKE is in LAPACK + set(LAPACKE_LIBRARIES "${LAPACK_LIBRARIES}") + if (LAPACK_LIBRARY_DIRS) + set(LAPACKE_LIBRARY_DIRS "${LAPACK_LIBRARY_DIRS}") + endif() + if(LAPACK_INCLUDE_DIRS) + set(LAPACKE_INCLUDE_DIRS "${LAPACK_INCLUDE_DIRS}") + endif() + if (LAPACK_LINKER_FLAGS) + set(LAPACKE_LINKER_FLAGS "${LAPACK_LINKER_FLAGS}") + endif() + endif() + endif (NOT LAPACKE_STANDALONE) + + if (LAPACKE_STANDALONE OR NOT LAPACKE_WORKS) + + if(NOT LAPACKE_WORKS AND NOT LAPACKE_FIND_QUIETLY) + message(STATUS "Looking for lapacke : test with lapack fails") + endif() + # test fails: try to find LAPACKE lib exterior to LAPACK + + # Try to find LAPACKE lib + ####################### + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + unset(_inc_env) + set(ENV_LAPACKE_DIR "$ENV{LAPACKE_DIR}") + set(ENV_LAPACKE_INCDIR "$ENV{LAPACKE_INCDIR}") + if(ENV_LAPACKE_INCDIR) + list(APPEND _inc_env "${ENV_LAPACKE_INCDIR}") + elseif(ENV_LAPACKE_DIR) + list(APPEND _inc_env "${ENV_LAPACKE_DIR}") + list(APPEND _inc_env "${ENV_LAPACKE_DIR}/include") + list(APPEND _inc_env "${ENV_LAPACKE_DIR}/include/lapacke") + 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 lapacke header in the given paths + # ------------------------------------------------- + # call cmake macro to find the header path + if(LAPACKE_INCDIR) + set(LAPACKE_lapacke.h_DIRS "LAPACKE_lapacke.h_DIRS-NOTFOUND") + find_path(LAPACKE_lapacke.h_DIRS + NAMES lapacke.h + HINTS ${LAPACKE_INCDIR}) + else() + if(LAPACKE_DIR) + set(LAPACKE_lapacke.h_DIRS "LAPACKE_lapacke.h_DIRS-NOTFOUND") + find_path(LAPACKE_lapacke.h_DIRS + NAMES lapacke.h + HINTS ${LAPACKE_DIR} + PATH_SUFFIXES "include" "include/lapacke") + else() + set(LAPACKE_lapacke.h_DIRS "LAPACKE_lapacke.h_DIRS-NOTFOUND") + find_path(LAPACKE_lapacke.h_DIRS + NAMES lapacke.h + HINTS ${_inc_env}) + endif() + endif() + mark_as_advanced(LAPACKE_lapacke.h_DIRS) + + # If found, add path to cmake variable + # ------------------------------------ + if (LAPACKE_lapacke.h_DIRS) + set(LAPACKE_INCLUDE_DIRS "${LAPACKE_lapacke.h_DIRS}") + else () + set(LAPACKE_INCLUDE_DIRS "LAPACKE_INCLUDE_DIRS-NOTFOUND") + if(NOT LAPACKE_FIND_QUIETLY) + message(STATUS "Looking for lapacke -- lapacke.h not found") + endif() + endif() + + + # Looking for lib + # --------------- + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_LAPACKE_LIBDIR "$ENV{LAPACKE_LIBDIR}") + if(ENV_LAPACKE_LIBDIR) + list(APPEND _lib_env "${ENV_LAPACKE_LIBDIR}") + elseif(ENV_LAPACKE_DIR) + list(APPEND _lib_env "${ENV_LAPACKE_DIR}") + list(APPEND _lib_env "${ENV_LAPACKE_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 lapacke lib in the given paths + # ---------------------------------------------- + + # call cmake macro to find the lib path + if(LAPACKE_LIBDIR) + set(LAPACKE_lapacke_LIBRARY "LAPACKE_lapacke_LIBRARY-NOTFOUND") + find_library(LAPACKE_lapacke_LIBRARY + NAMES lapacke + HINTS ${LAPACKE_LIBDIR}) + else() + if(LAPACKE_DIR) + set(LAPACKE_lapacke_LIBRARY "LAPACKE_lapacke_LIBRARY-NOTFOUND") + find_library(LAPACKE_lapacke_LIBRARY + NAMES lapacke + HINTS ${LAPACKE_DIR} + PATH_SUFFIXES lib lib32 lib64) + else() + set(LAPACKE_lapacke_LIBRARY "LAPACKE_lapacke_LIBRARY-NOTFOUND") + find_library(LAPACKE_lapacke_LIBRARY + NAMES lapacke + HINTS ${_lib_env}) + endif() + endif() + mark_as_advanced(LAPACKE_lapacke_LIBRARY) + + # If found, add path to cmake variable + # ------------------------------------ + if (LAPACKE_lapacke_LIBRARY) + get_filename_component(lapacke_lib_path "${LAPACKE_lapacke_LIBRARY}" PATH) + # set cmake variables + set(LAPACKE_LIBRARIES "${LAPACKE_lapacke_LIBRARY}") + set(LAPACKE_LIBRARY_DIRS "${lapacke_lib_path}") + else () + set(LAPACKE_LIBRARIES "LAPACKE_LIBRARIES-NOTFOUND") + set(LAPACKE_LIBRARY_DIRS "LAPACKE_LIBRARY_DIRS-NOTFOUND") + if (NOT LAPACKE_FIND_QUIETLY) + message(STATUS "Looking for lapacke -- lib lapacke not found") + endif() + endif () + + # check a function to validate the find + if(LAPACKE_LIBRARIES) + + set(REQUIRED_LDFLAGS) + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # LAPACKE + if (LAPACKE_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${LAPACKE_INCLUDE_DIRS}") + endif() + if (LAPACKE_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${LAPACKE_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${LAPACKE_LIBRARIES}") + # LAPACK + if (LAPACK_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${LAPACK_INCLUDE_DIRS}") + endif() + if (LAPACK_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${LAPACK_LIBRARY_DIRS}") + endif() + list(APPEND REQUIRED_LIBS "${LAPACK_LIBRARIES}") + if (LAPACK_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${LAPACK_LINKER_FLAGS}") + 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() + # m + find_library(M_LIBRARY NAMES m HINTS ${_lib_env}) + mark_as_advanced(M_LIBRARY) + if(M_LIBRARY) + list(APPEND REQUIRED_LIBS "-lm") + 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}") + string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + + # test link + unset(LAPACKE_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(LAPACKE_dgeqrf LAPACKE_WORKS) + mark_as_advanced(LAPACKE_WORKS) + + if(LAPACKE_WORKS) + # save link with dependencies + set(LAPACKE_LIBRARIES_DEP "${REQUIRED_LIBS}") + set(LAPACKE_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(LAPACKE_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(LAPACKE_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES LAPACKE_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES LAPACKE_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES LAPACKE_LINKER_FLAGS) + else() + if(NOT LAPACKE_FIND_QUIETLY) + message(STATUS "Looking for lapacke: test of LAPACKE_dgeqrf with lapacke and lapack libraries 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(LAPACKE_LIBRARIES) + + endif (LAPACKE_STANDALONE OR NOT LAPACKE_WORKS) + +else(LAPACK_FOUND) + + if (NOT LAPACKE_FIND_QUIETLY) + message(STATUS "LAPACKE requires LAPACK but LAPACK has not been found." + "Please look for LAPACK first.") + endif() + +endif(LAPACK_FOUND) + +if (LAPACKE_LIBRARIES) + list(GET LAPACKE_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(LAPACKE_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of LAPACKE library" FORCE) + else() + set(LAPACKE_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of LAPACKE library" FORCE) + endif() +endif() +mark_as_advanced(LAPACKE_DIR) +mark_as_advanced(LAPACKE_DIR_FOUND) + +# check that LAPACKE has been found +# --------------------------------- +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LAPACKE DEFAULT_MSG + LAPACKE_LIBRARIES + LAPACKE_WORKS) diff --git a/modules/find/FindLAPACKEXT.cmake b/modules/find/FindLAPACKEXT.cmake new file mode 100644 index 0000000..bf62c3d --- /dev/null +++ b/modules/find/FindLAPACKEXT.cmake @@ -0,0 +1,350 @@ +### +# +# @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 LAPACK EXTENDED for MORSE projects: find include dirs and libraries +# +# This module allows to find LAPACK libraries by calling the official FindLAPACK module +# and handles the creation of different library lists whether the user wishes to link +# with a sequential LAPACK or a multihreaded (LAPACK_SEQ_LIBRARIES and LAPACK_PAR_LIBRARIES). +# LAPACK is detected with a FindLAPACK call and if the BLAS vendor is in the following list, +# Intel mkl, ACML then the module tries find the corresponding multithreaded libraries +# +# The following variables have been added to manage links with sequential or multithreaded +# versions: +# LAPACK_INCLUDE_DIRS - LAPACK include directories +# LAPACK_LIBRARY_DIRS - Link directories for LAPACK libraries +# LAPACK_SEQ_LIBRARIES - LAPACK component libraries to be linked (sequential) +# LAPACK_PAR_LIBRARIES - LAPACK 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 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_lapack) + if(LAPACKEXT_FIND_REQUIRED) + if(LAPACKEXT_FIND_QUIETLY) + find_package(LAPACK REQUIRED QUIET) + else() + find_package(LAPACK REQUIRED) + endif() + else() + if(LAPACKEXT_FIND_QUIETLY) + find_package(LAPACK QUIET) + else() + find_package(LAPACK) + endif() + endif() +endmacro() + +# LAPACKEXT depends on BLASEXT +# call our extended module for BLAS +#---------------------------------- +if (NOT BLAS_FOUND) + if(LAPACKEXT_FIND_REQUIRED) + if(LAPACKEXT_FIND_QUIETLY) + find_package(BLAS REQUIRED QUIET) + else() + find_package(BLAS REQUIRED) + endif() + else() + if(LAPACKEXT_FIND_QUIETLY) + find_package(BLAS QUIET) + else() + find_package(BLAS) + endif() + endif() +endif () + +if(NOT LAPACKEXT_FIND_QUIETLY) + message(STATUS "In FindLAPACKEXT") +endif() + +if(BLA_VENDOR MATCHES "Intel*") + + ### + # look for include path if the LAPACK 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) + + if (BLAS_DIR) + set(LAPACK_DIR ${BLAS_DIR}) + endif () + if (BLAS_INCDIR) + set(LAPACK_INCDIR ${BLAS_INCDIR}) + endif () + # find mkl.h inside known include paths + set(LAPACK_mkl_lapack.h_INCLUDE_DIRS "LAPACK_mkl_lapack.h_INCLUDE_DIRS-NOTFOUND") + if(LAPACK_INCDIR) + find_path(LAPACK_mkl_lapack.h_INCLUDE_DIRS + NAMES mkl_lapack.h + HINTS ${LAPACK_INCDIR}) + else() + if(LAPACK_DIR) + find_path(LAPACK_mkl_lapack.h_INCLUDE_DIRS + NAMES mkl_lapack.h + HINTS ${LAPACK_DIR} + PATH_SUFFIXES include) + else() + find_path(LAPACK_mkl_lapack.h_INCLUDE_DIRS + NAMES mkl_lapack.h + HINTS ${_inc_env}) + endif() + endif() + mark_as_advanced(LAPACK_mkl_lapack.h_INCLUDE_DIRS) + ## Print status if not found + ## ------------------------- + #if (NOT LAPACK_mkl_lapack.h_INCLUDE_DIRS) + # Print_Find_Header_Status(lapack mkl_lapack.h) + #endif () + set(LAPACK_INCLUDE_DIRS "") + if(LAPACK_mkl_lapack.h_INCLUDE_DIRS) + list(APPEND LAPACK_INCLUDE_DIRS "${LAPACK_mkl_lapack.h_INCLUDE_DIRS}" ) + endif() + + ### + # look for libs + ### + + if (BLA_VENDOR MATCHES "Intel10_64lp*") + ## look for the sequential version + set(BLA_VENDOR "Intel10_64lp_seq") + endif() + find_package_lapack() + + if (LAPACK_FOUND) + if(BLAS_SEQ_LIBRARIES) + set(LAPACK_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES}") + else() + set(LAPACK_SEQ_LIBRARIES "${LAPACK_SEQ_LIBRARIES-NOTFOUND}") + endif() + # if BLAS Intel 10 64 bit -> save sequential and multithreaded versions + if(BLA_VENDOR MATCHES "Intel10_64lp*") + if(BLAS_PAR_LIBRARIES) + set(LAPACK_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES}") + else() + set(LAPACK_PAR_LIBRARIES "${LAPACK_PAR_LIBRARIES-NOTFOUND}") + endif() + endif() + endif() + +elseif(BLA_VENDOR MATCHES "IBMESSL*") + + ## look for the sequential version + set(BLA_VENDOR "IBMESSL") + find_package_lapack() + + if (LAPACK_FOUND) + if(LAPACK_LIBRARIES) + set(LAPACK_SEQ_LIBRARIES "${LAPACK_LIBRARIES}") + else() + set(LAPACK_SEQ_LIBRARIES "${LAPACK_SEQ_LIBRARIES-NOTFOUND}") + endif() + endif() + + ## look for the multithreaded version + set(BLA_VENDOR "IBMESSLMT") + find_package_lapack() + + if (LAPACK_FOUND) + if(LAPACK_LIBRARIES) + set(LAPACK_PAR_LIBRARIES "${LAPACK_LIBRARIES}") + else() + set(LAPACK_PAR_LIBRARIES "${LAPACK_PAR_LIBRARIES-NOTFOUND}") + endif() + endif() + +elseif(BLA_VENDOR MATCHES "ACML*") + + ### + # look for libs + ### + find_package_lapack() + + if (LAPACK_FOUND) + if(BLAS_SEQ_LIBRARIES) + set(LAPACK_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES}") + else() + set(LAPACK_SEQ_LIBRARIES "${LAPACK_SEQ_LIBRARIES-NOTFOUND}") + endif() + if(BLAS_PAR_LIBRARIES) + set(LAPACK_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES}") + else() + set(LAPACK_PAR_LIBRARIES "${LAPACK_PAR_LIBRARIES-NOTFOUND}") + endif() + endif() + +else() + + ## look for a sequential version + # call to the cmake official FindLAPACK module + # This module sets the following variables: + # LAPACK_FOUND - set to true if a library implementing the LAPACK interface + # is found + # LAPACK_LINKER_FLAGS - uncached list of required linker flags (excluding -l + # and -L). + # LAPACK_LIBRARIES - uncached list of libraries (using full path name) to + # link against to use LAPACK + # LAPACK95_LIBRARIES - uncached list of libraries (using full path name) + # to link against to use LAPACK95 interface + # LAPACK95_FOUND - set to true if a library implementing the LAPACK 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 + # BLA_F95 if set on tries to find the f95 interfaces for LAPACK/LAPACK + # Remark: it looks only into paths contained in the system environment variables + find_package_lapack() + + if(LAPACK_FOUND) + set(LAPACK_SEQ_LIBRARIES "${LAPACK_LIBRARIES}") + else() + set(LAPACK_SEQ_LIBRARIES "${LAPACK_SEQ_LIBRARIES-NOTFOUND}") + endif() + set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}") + +endif() + +if (LAPACK_SEQ_LIBRARIES) + set(LAPACK_LIBRARIES "${LAPACK_SEQ_LIBRARIES}") +endif() + +# extract libs paths +# remark: because it is not given by find_package(LAPACK) +set(LAPACK_LIBRARY_DIRS "") +string(REPLACE " " ";" LAPACK_LIBRARIES "${LAPACK_LIBRARIES}") +foreach(lapack_lib ${LAPACK_LIBRARIES}) + if (EXISTS "${lapack_lib}") + get_filename_component(a_lapack_lib_dir "${lapack_lib}" PATH) + list(APPEND LAPACK_LIBRARY_DIRS "${a_lapack_lib_dir}" ) + else() + string(REPLACE "-L" "" lapack_lib "${lapack_lib}") + if (EXISTS "${lapack_lib}") + list(APPEND LAPACK_LIBRARY_DIRS "${lapack_lib}" ) + else() + get_filename_component(a_lapack_lib_dir "${lapack_lib}" PATH) + if (EXISTS "${a_lapack_lib_dir}") + list(APPEND LAPACK_LIBRARY_DIRS "${a_lapack_lib_dir}" ) + endif() + endif() + endif() +endforeach() +if (LAPACK_LIBRARY_DIRS) + list(REMOVE_DUPLICATES LAPACK_LIBRARY_DIRS) +endif () + +# check that LAPACK has been found +# --------------------------------- +include(FindPackageHandleStandardArgs) +if(BLA_VENDOR MATCHES "Intel*") + if(BLA_VENDOR MATCHES "Intel10_64lp*") + if(NOT LAPACKEXT_FIND_QUIETLY) + message(STATUS "LAPACK found is Intel MKL:" + "\n we manage two lists of libs, one sequential and one parallel" + "\n (see LAPACK_SEQ_LIBRARIES and LAPACK_PAR_LIBRARIES)") + message(STATUS "LAPACK sequential libraries stored in LAPACK_SEQ_LIBRARIES") + endif() + find_package_handle_standard_args(LAPACK DEFAULT_MSG + LAPACK_SEQ_LIBRARIES + LAPACK_LIBRARY_DIRS + LAPACK_INCLUDE_DIRS) + if(LAPACK_PAR_LIBRARIES) + if(NOT LAPACKEXT_FIND_QUIETLY) + message(STATUS "LAPACK parallel libraries stored in LAPACK_PAR_LIBRARIES") + endif() + find_package_handle_standard_args(LAPACK DEFAULT_MSG + LAPACK_PAR_LIBRARIES) + endif() + + else() + if(NOT LAPACKEXT_FIND_QUIETLY) + message(STATUS "LAPACK sequential libraries stored in LAPACK_SEQ_LIBRARIES") + endif() + find_package_handle_standard_args(LAPACK DEFAULT_MSG + LAPACK_SEQ_LIBRARIES + LAPACK_LIBRARY_DIRS + LAPACK_INCLUDE_DIRS) + endif() +elseif(BLA_VENDOR MATCHES "ACML*") + if(NOT LAPACKEXT_FIND_QUIETLY) + message(STATUS "LAPACK found is ACML:" + "\n we manage two lists of libs, one sequential and one parallel" + "\n (see LAPACK_SEQ_LIBRARIES and LAPACK_PAR_LIBRARIES)") + message(STATUS "LAPACK sequential libraries stored in LAPACK_SEQ_LIBRARIES") + endif() + find_package_handle_standard_args(LAPACK DEFAULT_MSG + LAPACK_SEQ_LIBRARIES + LAPACK_LIBRARY_DIRS) + if(LAPACK_PAR_LIBRARIES) + if(NOT LAPACKEXT_FIND_QUIETLY) + message(STATUS "LAPACK parallel libraries stored in LAPACK_PAR_LIBRARIES") + endif() + find_package_handle_standard_args(LAPACK DEFAULT_MSG + LAPACK_PAR_LIBRARIES) + endif() +elseif(BLA_VENDOR MATCHES "IBMESSL*") + if(NOT LAPACKEXT_FIND_QUIETLY) + message(STATUS "LAPACK found is IBMESSL:" + "\n we manage two lists of libs, one sequential and one parallel" + "\n (see LAPACK_SEQ_LIBRARIES and LAPACK_PAR_LIBRARIES)") + message(STATUS "LAPACK sequential libraries stored in LAPACK_SEQ_LIBRARIES") + endif() + find_package_handle_standard_args(LAPACK DEFAULT_MSG + LAPACK_SEQ_LIBRARIES + LAPACK_LIBRARY_DIRS) + if(LAPACK_PAR_LIBRARIES) + if(NOT LAPACKEXT_FIND_QUIETLY) + message(STATUS "LAPACK parallel libraries stored in LAPACK_PAR_LIBRARIES") + endif() + find_package_handle_standard_args(LAPACK DEFAULT_MSG + LAPACK_PAR_LIBRARIES) + endif() +else() + if(NOT LAPACKEXT_FIND_QUIETLY) + message(STATUS "LAPACK sequential libraries stored in LAPACK_SEQ_LIBRARIES") + endif() + find_package_handle_standard_args(LAPACK DEFAULT_MSG + LAPACK_SEQ_LIBRARIES + LAPACK_LIBRARY_DIRS) +endif() diff --git a/modules/find/FindMAGMA.cmake b/modules/find/FindMAGMA.cmake new file mode 100644 index 0000000..d3eda98 --- /dev/null +++ b/modules/find/FindMAGMA.cmake @@ -0,0 +1,438 @@ +### +# +# @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 MAGMA include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(MAGMA +# [REQUIRED] # Fail with error if magma is not found +# [COMPONENTS <comp1> <comp2> ...] # dependencies +# ) +# +# MAGMA depends on the following libraries: +# - CUDA/cuBLAS +# - LAPACK +# - CBLAS +# +# COMPONENTS are optional libraries MAGMA could be linked with, +# Use it to drive detection of a specific compilation chain +# COMPONENTS can be some of the following: +# - no components are available for now: maybe PLASMA in the future? +# +# Results are reported in variables: +# MAGMA_FOUND - True if headers and requested libraries were found +# MAGMA_LINKER_FLAGS - list of required linker flags (excluding -l and -L) +# MAGMA_INCLUDE_DIRS - magma include directories +# MAGMA_LIBRARY_DIRS - Link directories for magma libraries +# MAGMA_LIBRARIES - magma libraries +# MAGMA_INCLUDE_DIRS_DEP - magma + dependencies include directories +# MAGMA_LIBRARY_DIRS_DEP - magma + dependencies link directories +# MAGMA_LIBRARIES_DEP - magma libraries + dependencies +# +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DMAGMA_DIR=path/to/magma): +# MAGMA_DIR - Where to find the base directory of magma +# MAGMA_INCDIR - Where to find the header files +# MAGMA_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: MAGMA_DIR, MAGMA_INCDIR, MAGMA_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 MAGMA_FOUND) + set(MAGMA_DIR "" CACHE PATH "Installation directory of MAGMA library") + if (NOT MAGMA_FIND_QUIETLY) + message(STATUS "A cache variable, namely MAGMA_DIR, has been set to specify the install directory of MAGMA") + endif() +endif(NOT MAGMA_FOUND) + +# MAGMA depends on CUDA anyway, try to find it +if (NOT CUDA_FOUND) + if(MAGMA_FIND_REQUIRED) + find_package(CUDA REQUIRED) + else() + find_package(CUDA) + endif() +endif() +# MAGMA depends on cuBLAS which should come with CUDA, if not found -> error +if (NOT CUDA_CUBLAS_LIBRARIES) + if(MAGMA_FIND_REQUIRED) + message(FATAL_ERROR "Looking for MAGMA - MAGMA depends on cuBLAS which has " + "not been found (should come with cuda install)") + endif() +endif() +# MAGMA depends on LAPACK anyway, try to find it +if (NOT LAPACK_FOUND) + if(MAGMA_FIND_REQUIRED) + find_package(LAPACKEXT REQUIRED) + else() + find_package(LAPACKEXT) + endif() +endif() +# MAGMA depends on CBLAS anyway, try to find it +if (NOT CBLAS_FOUND) + if(MAGMA_FIND_REQUIRED) + find_package(CBLAS REQUIRED) + else() + find_package(CBLAS) + endif() +endif() + +set(ENV_MAGMA_DIR "$ENV{MAGMA_DIR}") +set(ENV_MAGMA_INCDIR "$ENV{MAGMA_INCDIR}") +set(ENV_MAGMA_LIBDIR "$ENV{MAGMA_LIBDIR}") +set(MAGMA_GIVEN_BY_USER "FALSE") +if ( MAGMA_DIR OR ( MAGMA_INCDIR AND MAGMA_LIBDIR) OR ENV_MAGMA_DIR OR (ENV_MAGMA_INCDIR AND ENV_MAGMA_LIBDIR) ) + set(MAGMA_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 MAGMA_GIVEN_BY_USER) + + pkg_search_module(MAGMA magma) + if (NOT MAGMA_FIND_QUIETLY) + if (MAGMA_FOUND AND MAGMA_LIBRARIES) + message(STATUS "Looking for MAGMA - found using PkgConfig") + #if(NOT MAGMA_INCLUDE_DIRS) + # message("${Magenta}MAGMA_INCLUDE_DIRS is empty using PkgConfig." + # "Perhaps the path to magma headers is already present in your" + # "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}") + #endif() + else() + message(STATUS "${Magenta}Looking for MAGMA - not found using PkgConfig. " + "\n Perhaps you should add the directory containing magma.pc " + "\n to the PKG_CONFIG_PATH environment variable.${ColourReset}") + endif() + endif() + + if (MAGMA_FIND_VERSION_EXACT) + if( NOT (MAGMA_FIND_VERSION_MAJOR STREQUAL MAGMA_VERSION_MAJOR) OR + NOT (MAGMA_FIND_VERSION_MINOR STREQUAL MAGMA_VERSION_MINOR) ) + if(NOT MAGMA_FIND_QUIETLY) + message(FATAL_ERROR + "MAGMA version found is ${MAGMA_VERSION_STRING} " + "when required is ${MAGMA_FIND_VERSION}") + endif() + endif() + else() + # if the version found is older than the required then error + if( (MAGMA_FIND_VERSION_MAJOR STRGREATER MAGMA_VERSION_MAJOR) OR + (MAGMA_FIND_VERSION_MINOR STRGREATER MAGMA_VERSION_MINOR) ) + if(NOT MAGMA_FIND_QUIETLY) + message(FATAL_ERROR + "MAGMA version found is ${MAGMA_VERSION_STRING} " + "when required is ${MAGMA_FIND_VERSION} or newer") + endif() + endif() + endif() + + # if pkg-config is used: these variables are empty + # the pkg_search_module call will set the following: + # MAGMA_LDFLAGS: all required linker flags + # MAGMA_CFLAGS: all required cflags + set(MAGMA_INCLUDE_DIRS_DEP "") + set(MAGMA_LIBRARY_DIRS_DEP "") + set(MAGMA_LIBRARIES_DEP "") + # replace it anyway: we should update it with dependencies given by pkg-config + set(MAGMA_INCLUDE_DIRS_DEP "${MAGMA_INCLUDE_DIRS}") + set(MAGMA_LIBRARY_DIRS_DEP "${MAGMA_LIBRARY_DIRS}") + set(MAGMA_LIBRARIES_DEP "${MAGMA_LIBRARIES}") + +endif(PKG_CONFIG_EXECUTABLE AND NOT MAGMA_GIVEN_BY_USER) + +# if MAGMA is not found using pkg-config +if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT MAGMA_FOUND) OR (MAGMA_GIVEN_BY_USER) ) + + if (NOT MAGMA_FIND_QUIETLY) + message(STATUS "Looking for MAGMA - PkgConfig not used") + endif() + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + unset(_inc_env) + set(ENV_MAGMA_DIR "$ENV{MAGMA_DIR}") + set(ENV_MAGMA_INCDIR "$ENV{MAGMA_INCDIR}") + if(ENV_MAGMA_INCDIR) + list(APPEND _inc_env "${ENV_MAGMA_INCDIR}") + elseif(ENV_MAGMA_DIR) + list(APPEND _inc_env "${ENV_MAGMA_DIR}") + list(APPEND _inc_env "${ENV_MAGMA_DIR}/include") + list(APPEND _inc_env "${ENV_MAGMA_DIR}/include/magma") + 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 magma header in the given paths + # ------------------------------------------------- + # call cmake macro to find the header path + if(MAGMA_INCDIR) + set(MAGMA_magma.h_DIRS "MAGMA_magma.h_DIRS-NOTFOUND") + find_path(MAGMA_magma.h_DIRS + NAMES magma.h + HINTS ${MAGMA_INCDIR}) + else() + if(MAGMA_DIR) + set(MAGMA_magma.h_DIRS "MAGMA_magma.h_DIRS-NOTFOUND") + find_path(MAGMA_magma.h_DIRS + NAMES magma.h + HINTS ${MAGMA_DIR} + PATH_SUFFIXES "include" "include/magma") + else() + set(MAGMA_magma.h_DIRS "MAGMA_magma.h_DIRS-NOTFOUND") + find_path(MAGMA_magma.h_DIRS + NAMES magma.h + HINTS ${_inc_env}) + endif() + endif() + mark_as_advanced(MAGMA_magma.h_DIRS) + + # If found, add path to cmake variable + # ------------------------------------ + if (MAGMA_magma.h_DIRS) + set(MAGMA_INCLUDE_DIRS "${MAGMA_magma.h_DIRS}") + else () + set(MAGMA_INCLUDE_DIRS "MAGMA_INCLUDE_DIRS-NOTFOUND") + if(NOT MAGMA_FIND_QUIETLY) + message(STATUS "Looking for magma -- magma.h not found") + endif() + endif() + + + # Looking for lib + # --------------- + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_MAGMA_LIBDIR "$ENV{MAGMA_LIBDIR}") + if(ENV_MAGMA_LIBDIR) + list(APPEND _lib_env "${ENV_MAGMA_LIBDIR}") + elseif(ENV_MAGMA_DIR) + list(APPEND _lib_env "${ENV_MAGMA_DIR}") + list(APPEND _lib_env "${ENV_MAGMA_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 magma lib in the given paths + # ---------------------------------------------- + + # call cmake macro to find the lib path + if(MAGMA_LIBDIR) + set(MAGMA_magma_LIBRARY "MAGMA_magma_LIBRARY-NOTFOUND") + find_library(MAGMA_magma_LIBRARY + NAMES magma + HINTS ${MAGMA_LIBDIR}) + else() + if(MAGMA_DIR) + set(MAGMA_magma_LIBRARY "MAGMA_magma_LIBRARY-NOTFOUND") + find_library(MAGMA_magma_LIBRARY + NAMES magma + HINTS ${MAGMA_DIR} + PATH_SUFFIXES lib lib32 lib64) + else() + set(MAGMA_magma_LIBRARY "MAGMA_magma_LIBRARY-NOTFOUND") + find_library(MAGMA_magma_LIBRARY + NAMES magma + HINTS ${_lib_env}) + endif() + endif() + mark_as_advanced(MAGMA_magma_LIBRARY) + + # If found, add path to cmake variable + # ------------------------------------ + if (MAGMA_magma_LIBRARY) + get_filename_component(magma_lib_path "${MAGMA_magma_LIBRARY}" PATH) + # set cmake variables + set(MAGMA_LIBRARIES "${MAGMA_magma_LIBRARY}") + set(MAGMA_LIBRARY_DIRS "${magma_lib_path}") + else () + set(MAGMA_LIBRARIES "MAGMA_LIBRARIES-NOTFOUND") + set(MAGMA_LIBRARY_DIRS "MAGMA_LIBRARY_DIRS-NOTFOUND") + if(NOT MAGMA_FIND_QUIETLY) + message(STATUS "Looking for magma -- lib magma not found") + endif() + endif () + + # check a function to validate the find + if (MAGMA_LIBRARIES) + + set(REQUIRED_LDFLAGS) + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # MAGMA + if (MAGMA_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${MAGMA_INCLUDE_DIRS}") + endif() + if (MAGMA_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${MAGMA_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${MAGMA_LIBRARIES}") + # CBLAS + if (CBLAS_INCLUDE_DIRS_DEP) + list(APPEND REQUIRED_INCDIRS "${CBLAS_INCLUDE_DIRS_DEP}") + elseif (CBLAS_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${CBLAS_INCLUDE_DIRS}") + endif() + if(CBLAS_LIBRARY_DIRS_DEP) + list(APPEND REQUIRED_LIBDIRS "${CBLAS_LIBRARY_DIRS_DEP}") + elseif(CBLAS_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${CBLAS_LIBRARY_DIRS}") + endif() + if (CBLAS_LIBRARIES_DEP) + list(APPEND REQUIRED_LIBS "${CBLAS_LIBRARIES_DEP}") + elseif(CBLAS_LIBRARIES) + list(APPEND REQUIRED_LIBS "${CBLAS_LIBRARIES}") + endif() + if (BLAS_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}") + endif() + # LAPACK + if (LAPACK_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${LAPACK_INCLUDE_DIRS}") + endif() + if(LAPACK_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${LAPACK_LIBRARY_DIRS}") + endif() + list(APPEND REQUIRED_LIBS "${LAPACK_LIBRARIES}") + if (LAPACK_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${LAPACK_LINKER_FLAGS}") + endif() + # CUDA + if (CUDA_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${CUDA_INCLUDE_DIRS}") + endif() + if(CUDA_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${CUDA_LIBRARY_DIRS}") + endif() + list(APPEND REQUIRED_LIBS "${CUDA_CUBLAS_LIBRARIES};${CUDA_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}") + string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + + # test link + unset(MAGMA_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(magma_dgetrf MAGMA_WORKS) + mark_as_advanced(MAGMA_WORKS) + + if(MAGMA_WORKS) + # save link with dependencies + set(MAGMA_LIBRARIES_DEP "${REQUIRED_LIBS}") + set(MAGMA_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(MAGMA_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(MAGMA_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES MAGMA_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES MAGMA_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES MAGMA_LINKER_FLAGS) + else() + if(NOT MAGMA_FIND_QUIETLY) + message(STATUS "Looking for magma : test of magma_dgetrf with + magma, cblas, cuda and lapack libraries 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(MAGMA_LIBRARIES) + +endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT MAGMA_FOUND) OR (MAGMA_GIVEN_BY_USER) ) + +if (MAGMA_LIBRARIES) + if (MAGMA_LIBRARY_DIRS) + foreach(dir ${MAGMA_LIBRARY_DIRS}) + if ("${dir}" MATCHES "magma") + set(first_lib_path "${dir}") + endif() + endforeach() + else() + list(GET MAGMA_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(MAGMA_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of MAGMA library" FORCE) + else() + set(MAGMA_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of MAGMA library" FORCE) + endif() +endif() +mark_as_advanced(MAGMA_DIR) +mark_as_advanced(MAGMA_DIR_FOUND) + +# check that MAGMA has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +if (PKG_CONFIG_EXECUTABLE AND MAGMA_FOUND) + find_package_handle_standard_args(MAGMA DEFAULT_MSG + MAGMA_LIBRARIES) +else() + find_package_handle_standard_args(MAGMA DEFAULT_MSG + MAGMA_LIBRARIES + MAGMA_WORKS) +endif() diff --git a/modules/find/FindMETIS.cmake b/modules/find/FindMETIS.cmake new file mode 100644 index 0000000..da2f1f1 --- /dev/null +++ b/modules/find/FindMETIS.cmake @@ -0,0 +1,264 @@ +### +# +# @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 + +#============================================================================= +# 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 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() +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() + 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() + + # 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(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) + +# check that METIS has been found +# --------------------------------- +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(METIS DEFAULT_MSG + METIS_LIBRARIES + METIS_WORKS) +# +# TODO: Add possibility to check for specific functions in the library +# diff --git a/modules/find/FindMPIEXT.cmake b/modules/find/FindMPIEXT.cmake new file mode 100644 index 0000000..1409989 --- /dev/null +++ b/modules/find/FindMPIEXT.cmake @@ -0,0 +1,120 @@ +# - Find MPI EXTENDED for MORSE projects: +# +# This module allows to find MPI libraries by calling the official FindMPI module +# and adds an additional variable indicating the level of thread supported: +# MPI_THREAD_SUPPORTED_LEVEL - MPI_THREAD_MULTIPLE, MPI_THREAD_SERIALIZED, MPI_THREAD_FUNNELED, or MPI_THREAD_SINGLE + +#============================================================================= +# 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.) + +# add a cache variable to let the user specify the BLAS vendor +if (NOT MPI_FOUND) + if(MPIEXT_FIND_REQUIRED) + find_package(MPI REQUIRED) + else() + find_package(MPI) + endif() +endif () + +if (MPI_FOUND) + set(CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES}) + set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS}) + # Set flags for building test program + set(CMAKE_REQUIRED_INCLUDES ${MPI_INCLUDE_PATH}) + set(CMAKE_REQUIRED_LIBRARIES ${MPI_LIBRARIES}) + set(CMAKE_REQUIRED_FLAGS ${MPI_COMPILE_FLAGS}) + + include(CheckCSourceRuns) + set(MPI_C_TEST_MULTIPLE_SOURCE " +#include <stdio.h> +#include <mpi.h> + +int main(int argc, char **argv) { + int provided; + + MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); + + if (MPI_THREAD_MULTIPLE > provided) { + fprintf(stderr,\"MPI implementation is not supporting MPI_THREAD_MULTIPLE\"); + MPI_Finalize(); + return 1000+MPI_THREAD_MULTIPLE-provided; + } + MPI_Finalize(); + return 0; +} +") + + set(MPI_C_TEST_SERIALIZED_SOURCE " +#include <stdio.h> +#include <mpi.h> + +int main(int argc, char **argv) { + int provided; + + MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided); + + if (MPI_THREAD_SERIALIZED > provided) { + printf(\"MPI implementation is not supporting MPI_THREAD_SERIALIZED\"); + MPI_Finalize(); + return 1; + } + MPI_Finalize(); + return 0; +} +") + + set(MPI_C_TEST_FUNNELED_SOURCE " +#include <stdio.h> +#include <mpi.h> + +int main(int argc, char **argv) { + int provided; + + MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided); + + if (MPI_THREAD_FUNNELED > provided) { + printf(\"MPI implementation is not supporting MPI_THREAD_FUNNELED\"); + MPI_Finalize(); + return 1; + } + MPI_Finalize(); + return 0; +} +") + + check_c_source_runs("${MPI_C_TEST_MULTIPLE_SOURCE}" MULTIPLE_TEST_RUNS) + if(NOT MULTIPLE_TEST_RUNS) + check_c_source_runs("${MPI_C_TEST_SERIALIZED_SOURCE}" SERIALIZED_TEST_RUNS) + if(NOT SERIALIZED_TEST_RUNS) + check_c_source_runs("${MPI_C_TEST_FUNNELED_SOURCE}" FUNNELED_TEST_RUNS) + if(NOT FUNNELED_TEST_RUNS) + set(MPI_THREAD_SUPPORTED_LEVEL "MPI_THREAD_SINGLE") + else(NOT FUNNELED_TEST_RUNS) + set(MPI_THREAD_SUPPORTED_LEVEL "MPI_THREAD_FUNNELED") + endif(NOT FUNNELED_TEST_RUNS) + else(NOT SERIALIZED_TEST_RUNS) + set(MPI_THREAD_SUPPORTED_LEVEL "MPI_THREAD_SERIALIZED") + endif(NOT SERIALIZED_TEST_RUNS) + else(NOT MULTIPLE_TEST_RUNS) + set(MPI_THREAD_SUPPORTED_LEVEL "MPI_THREAD_MULTIPLE") + endif(NOT MULTIPLE_TEST_RUNS) + # Set flags for building test program + set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE}) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE}) + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE}) +endif(MPI_FOUND) diff --git a/modules/find/FindMUMPS.cmake b/modules/find/FindMUMPS.cmake new file mode 100644 index 0000000..4c956e8 --- /dev/null +++ b/modules/find/FindMUMPS.cmake @@ -0,0 +1,753 @@ +### +# +# @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 MUMPS include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(MUMPS +# [REQUIRED] # Fail with error if mumps is not found +# [COMPONENTS <comp1> <comp2> ...] # dependencies +# ) +# +# MUMPS depends on the following libraries: +# - Threads +# - BLAS +# +# COMPONENTS are optional libraries MUMPS 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, BLAS, MPI and ScaLAPACK libraries +# - SEQ: to activate detection of sequential version (exclude MPI version) +# it looks for Threads and BLAS libraries +# - SCOTCH: to activate detection of MUMPS linked with SCOTCH +# - PTSCOTCH: to activate detection of MUMPS linked with PTSCOTCH +# - METIS: to activate detection of MUMPS linked with METIS +# - PARMETIS: to activate detection of MUMPS linked with PARMETIS +# +# This module finds headers and mumps library. +# Results are reported in variables: +# MUMPS_FOUND - True if headers and requested libraries were found +# MUMPS_LINKER_FLAGS - list of required linker flags (excluding -l and -L) +# MUMPS_INCLUDE_DIRS - mumps include directories +# MUMPS_LIBRARY_DIRS - Link directories for mumps libraries +# MUMPS_LIBRARIES - mumps libraries +# MUMPS_INCLUDE_DIRS_DEP - mumps + dependencies include directories +# MUMPS_LIBRARY_DIRS_DEP - mumps + dependencies link directories +# MUMPS_LIBRARIES_DEP - mumps libraries + dependencies +# +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DMUMPS_DIR=path/to/mumps): +# MUMPS_DIR - Where to find the base directory of mumps +# The module can also look for the following environment variables if paths +# are not given as cmake variable: MUMPS_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 MUMPS_FOUND) + set(MUMPS_DIR "" CACHE PATH "Installation directory of MUMPS library") + if (NOT MUMPS_FIND_QUIETLY) + message(STATUS "A cache variable, namely MUMPS_DIR, has been set to specify the install directory of MUMPS") + endif() +endif() + +# Set the version to find +set(MUMPS_LOOK_FOR_MPI ON) +set(MUMPS_LOOK_FOR_SEQ OFF) +set(MUMPS_LOOK_FOR_SCOTCH OFF) +set(MUMPS_LOOK_FOR_PTSCOTCH OFF) +set(MUMPS_LOOK_FOR_METIS OFF) +set(MUMPS_LOOK_FOR_PARMETIS OFF) + +if( MUMPS_FIND_COMPONENTS ) + foreach( component ${MUMPS_FIND_COMPONENTS} ) + if (${component} STREQUAL "SEQ") + # means we look for the sequential version of MUMPS (without MPI) + set(MUMPS_LOOK_FOR_SEQ ON) + set(MUMPS_LOOK_FOR_MPI OFF) + endif() + if (${component} STREQUAL "MPI") + # means we look for the MPI version of MUMPS (default) + set(MUMPS_LOOK_FOR_MPI ON) + set(MUMPS_LOOK_FOR_SEQ OFF) + endif() + if (${component} STREQUAL "SCOTCH") + set(MUMPS_LOOK_FOR_SCOTCH ON) + endif() + if (${component} STREQUAL "PTSCOTCH") + set(MUMPS_LOOK_FOR_PTSCOTCH ON) + endif() + if (${component} STREQUAL "METIS") + set(MUMPS_LOOK_FOR_METIS ON) + endif() + if (${component} STREQUAL "PARMETIS") + set(MUMPS_LOOK_FOR_PARMETIS ON) + endif() + endforeach() +endif() + +if (NOT MUMPS_FIND_QUIETLY) + if (MUMPS_LOOK_FOR_SEQ) + message(STATUS "Looking for MUMPS - sequential version (without MPI)") + else() + message(STATUS "Looking for MUMPS - MPI version -" + " if you want to force detection of a sequential " + "version use find_package(MUMPS [REQUIRED] COMPONENTS SEQ [...])") + endif() +endif() + +if (NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for MUMPS - PkgConfig not used") +endif() + +# Required dependencies +# --------------------- + +if (NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for MUMPS - Try to detect pthread") +endif() +if (NOT Threads_FOUND) + if (MUMPS_FIND_REQUIRED) + find_package(Threads REQUIRED) + else() + find_package(Threads) + endif() +endif() +set(MUMPS_EXTRA_LIBRARIES "") +if( THREADS_FOUND ) + list(APPEND MUMPS_EXTRA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) +endif () + +# MUMPS depends on BLAS +#---------------------- +if (NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for MUMPS - Try to detect BLAS") +endif() +if (NOT BLASEXT_FOUND) + if (MUMPS_FIND_REQUIRED) + find_package(BLASEXT REQUIRED) + else() + find_package(BLASEXT) + endif() +endif() + +# Optional dependencies +# --------------------- + +# MUMPS may depend on MPI +#------------------------ +if (NOT MPI_FOUND AND MUMPS_LOOK_FOR_MPI) + if (NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for MUMPS - 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 (MUMPS_FIND_REQUIRED AND MUMPS_FIND_REQUIRED_MPI) + find_package(MPI REQUIRED) + else() + find_package(MPI) + endif() + if (MPI_FOUND) + mark_as_advanced(MPI_LIBRARY) + mark_as_advanced(MPI_EXTRA_LIBRARY) + endif() +endif (NOT MPI_FOUND AND MUMPS_LOOK_FOR_MPI) + +# MUMPS may depend on ScaLAPACK (if MPI version) +#----------------------------------------------- +if (NOT SCALAPACK_FOUND AND MUMPS_LOOK_FOR_MPI) + if (NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for MUMPS - Try to detect SCALAPACK") + endif() + # SCALAPACK is a required dependency if MPI is used + if (MUMPS_FIND_REQUIRED AND MUMPS_FIND_REQUIRED_MPI) + find_package(SCALAPACK REQUIRED) + else() + find_package(SCALAPACK) + endif() +endif (NOT SCALAPACK_FOUND AND MUMPS_LOOK_FOR_MPI) + +# MUMPS may depends on SCOTCH +#---------------------------- +if (MUMPS_LOOK_FOR_SCOTCH) + if (NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for MUMPS - Try to detect SCOTCH with esmumps") + endif() + if (MUMPS_FIND_REQUIRED AND MUMPS_FIND_REQUIRED_SCOTCH) + find_package(SCOTCH REQUIRED COMPONENTS ESMUMPS) + else() + find_package(SCOTCH COMPONENTS ESMUMPS) + endif() +endif() + +# MUMPS may depends on PTSCOTCH +#------------------------------ +if (MUMPS_LOOK_FOR_PTSCOTCH) + if (NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for MUMPS - Try to detect PTSCOTCH with esmumps") + endif() + if (MUMPS_FIND_REQUIRED AND MUMPS_FIND_REQUIRED_PTSCOTCH) + find_package(PTSCOTCH REQUIRED COMPONENTS ESMUMPS) + else() + find_package(PTSCOTCH COMPONENTS ESMUMPS) + endif() +endif() + +# MUMPS may depends on METIS +#--------------------------- +if (NOT METIS_FOUND AND MUMPS_LOOK_FOR_METIS) + if (NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for MUMPS - Try to detect METIS") + endif() + if (MUMPS_FIND_REQUIRED AND MUMPS_FIND_REQUIRED_METIS) + find_package(METIS REQUIRED) + else() + find_package(METIS) + endif() +endif() + +# MUMPS may depends on PARMETIS +#------------------------------ +if (NOT PARMETIS_FOUND AND MUMPS_LOOK_FOR_PARMETIS) + if (NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for MUMPS - Try to detect PARMETIS") + endif() + if (MUMPS_FIND_REQUIRED AND MUMPS_FIND_REQUIRED_PARMETIS) + find_package(PARMETIS REQUIRED) + else() + find_package(PARMETIS) + endif() +endif() + +# Looking for MUMPS +# ----------------- + +# Add system include paths to search include +# ------------------------------------------ +unset(_inc_env) +set(ENV_MUMPS_DIR "$ENV{MUMPS_DIR}") +set(ENV_MUMPS_INCDIR "$ENV{MUMPS_INCDIR}") +if(ENV_MUMPS_INCDIR) + list(APPEND _inc_env "${ENV_MUMPS_INCDIR}") +elseif(ENV_MUMPS_DIR) + list(APPEND _inc_env "${ENV_MUMPS_DIR}") + list(APPEND _inc_env "${ENV_MUMPS_DIR}/include") + list(APPEND _inc_env "${ENV_MUMPS_DIR}/include/mumps") +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) + +# Add system library paths to search lib +# -------------------------------------- +unset(_lib_env) +set(ENV_MUMPS_LIBDIR "$ENV{MUMPS_LIBDIR}") +if(ENV_MUMPS_LIBDIR) + list(APPEND _lib_env "${ENV_MUMPS_LIBDIR}") +elseif(ENV_MUMPS_DIR) + list(APPEND _lib_env "${ENV_MUMPS_DIR}") + list(APPEND _lib_env "${ENV_MUMPS_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) + +# Looking for include +# ------------------- + +# Try to find the mumps header in the given path +# ---------------------------------------------- + +# create list of headers to find +list(APPEND MUMPS_hdrs_to_find "smumps_c.h;dmumps_c.h;cmumps_c.h;zmumps_c.h") + +# call cmake macro to find the header path +if(MUMPS_INCDIR) + foreach(mumps_hdr ${MUMPS_hdrs_to_find}) + set(MUMPS_${mumps_hdr}_DIRS "MUMPS_${mumps_hdr}_INCLUDE_DIRS-NOTFOUND") + find_path(MUMPS_${mumps_hdr}_DIRS + NAMES ${mumps_hdr} + HINTS ${MUMPS_INCDIR}) + endforeach() +else() + if(MUMPS_DIR) + set(MUMPS_${mumps_hdr}_DIRS "MUMPS_${mumps_hdr}_INCLUDE_DIRS-NOTFOUND") + foreach(mumps_hdr ${MUMPS_hdrs_to_find}) + find_path(MUMPS_${mumps_hdr}_DIRS + NAMES ${mumps_hdr} + HINTS ${MUMPS_DIR} + PATH_SUFFIXES "include") + endforeach() + else() + foreach(mumps_hdr ${MUMPS_hdrs_to_find}) + set(MUMPS_${mumps_hdr}_DIRS "MUMPS_${mumps_hdr}_INCLUDE_DIRS-NOTFOUND") + find_path(MUMPS_${mumps_hdr}_DIRS + NAMES ${mumps_hdr} + HINTS ${_inc_env}) + endforeach() + endif() +endif() + +# If found, add path to cmake variable +# ------------------------------------ +# detect which precisions are available +if (MUMPS_smumps_c.h_DIRS) + mark_as_advanced(MUMPS_smumps_c.h_DIRS) + set(MUMPS_PREC_S ON) + set(MUMPS_INCLUDE_DIRS "${MUMPS_smumps_c.h_DIRS}") +else () + set(MUMPS_PREC_S OFF) + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- smumps_c.h not found") + endif() +endif() +if (MUMPS_dmumps_c.h_DIRS) + mark_as_advanced(MUMPS_dmumps_c.h_DIRS) + set(MUMPS_PREC_D ON) + set(MUMPS_INCLUDE_DIRS "${MUMPS_dmumps_c.h_DIRS}") +else () + set(MUMPS_PREC_D OFF) + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- dmumps_c.h not found") + endif() +endif() +if (MUMPS_cmumps_c.h_DIRS) + mark_as_advanced(MUMPS_cmumps_c.h_DIRS) + set(MUMPS_PREC_C ON) + set(MUMPS_INCLUDE_DIRS "${MUMPS_cmumps_c.h_DIRS}") +else () + set(MUMPS_PREC_C OFF) + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- cmumps_c.h not found") + endif() +endif() +if (MUMPS_zmumps_c.h_DIRS) + mark_as_advanced(MUMPS_zmumps_c.h_DIRS) + set(MUMPS_PREC_Z ON) + set(MUMPS_INCLUDE_DIRS "${MUMPS_zmumps_c.h_DIRS}") +else () + set(MUMPS_PREC_Z OFF) + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- zmumps_c.h not found") + endif() +endif() + + +# Looking for lib +# --------------- + +# create list of libs to find +set(MUMPS_libs_to_find "mumps_common;pord") +if (MUMPS_LOOK_FOR_SEQ) + list(APPEND MUMPS_libs_to_find "mpiseq") +endif() +if(MUMPS_PREC_S) + list(APPEND MUMPS_libs_to_find "smumps") +endif() +if(MUMPS_PREC_D) + list(APPEND MUMPS_libs_to_find "dmumps") +endif() +if(MUMPS_PREC_C) + list(APPEND MUMPS_libs_to_find "cmumps") +endif() +if(MUMPS_PREC_Z) + list(APPEND MUMPS_libs_to_find "zmumps") +endif() + +# call cmake macro to find the lib path +if(MUMPS_LIBDIR) + foreach(mumps_lib ${MUMPS_libs_to_find}) + set(MUMPS_${mumps_lib}_LIBRARY "MUMPS_${mumps_lib}_LIBRARY-NOTFOUND") + find_library(MUMPS_${mumps_lib}_LIBRARY + NAMES ${mumps_lib} + HINTS ${MUMPS_LIBDIR}) + endforeach() +else() + if(MUMPS_DIR) + foreach(mumps_lib ${MUMPS_libs_to_find}) + set(MUMPS_${mumps_lib}_LIBRARY "MUMPS_${mumps_lib}_LIBRARY-NOTFOUND") + find_library(MUMPS_${mumps_lib}_LIBRARY + NAMES ${mumps_lib} + HINTS ${MUMPS_DIR} + PATH_SUFFIXES lib lib32 lib64) + endforeach() + else() + foreach(mumps_lib ${MUMPS_libs_to_find}) + set(MUMPS_${mumps_lib}_LIBRARY "MUMPS_${mumps_lib}_LIBRARY-NOTFOUND") + find_library(MUMPS_${mumps_lib}_LIBRARY + NAMES ${mumps_lib} + HINTS ${_lib_env}) + endforeach() + endif() +endif() + +# If found, add path to cmake variable +# ------------------------------------ +set(MUMPS_LIBRARIES "") +set(MUMPS_LIBRARY_DIRS "") +# detect which precisions are available +if (MUMPS_smumps_LIBRARY) + mark_as_advanced(MUMPS_smumps_LIBRARY) + list(APPEND MUMPS_LIBRARIES "${MUMPS_smumps_LIBRARY}") + get_filename_component(smumps_lib_path ${MUMPS_smumps_LIBRARY} PATH) + list(APPEND MUMPS_LIBRARY_DIRS "${smumps_lib_path}") +else () + set(MUMPS_PREC_S OFF) + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- libsmumps.a not found") + endif() +endif() +if (MUMPS_dmumps_LIBRARY) + mark_as_advanced(MUMPS_dmumps_LIBRARY) + list(APPEND MUMPS_LIBRARIES "${MUMPS_dmumps_LIBRARY}") + get_filename_component(dmumps_lib_path ${MUMPS_dmumps_LIBRARY} PATH) + list(APPEND MUMPS_LIBRARY_DIRS "${dmumps_lib_path}") +else () + set(MUMPS_PREC_D OFF) + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- libdmumps.a not found") + endif() +endif() +if (MUMPS_cmumps_LIBRARY) + mark_as_advanced(MUMPS_cmumps_LIBRARY) + list(APPEND MUMPS_LIBRARIES "${MUMPS_cmumps_LIBRARY}") + get_filename_component(cmumps_lib_path ${MUMPS_cmumps_LIBRARY} PATH) + list(APPEND MUMPS_LIBRARY_DIRS "${cmumps_lib_path}") +else () + set(MUMPS_PREC_C OFF) + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- libcmumps.a not found") + endif() +endif() +if (MUMPS_zmumps_LIBRARY) + mark_as_advanced(MUMPS_zmumps_LIBRARY) + list(APPEND MUMPS_LIBRARIES "${MUMPS_zmumps_LIBRARY}") + get_filename_component(zmumps_lib_path ${MUMPS_zmumps_LIBRARY} PATH) + list(APPEND MUMPS_LIBRARY_DIRS "${zmumps_lib_path}") +else () + set(MUMPS_PREC_Z OFF) + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- libzmumps.a not found") + endif() +endif() + +# check that one precision arithmetic at least has been discovered +if (NOT MUMPS_PREC_S AND NOT MUMPS_PREC_D AND NOT MUMPS_PREC_C AND NOT MUMPS_PREC_S) + if (MUMPS_FIND_REQUIRED) + message(FATAL_ERROR "Looking for mumps -- " + "no lib[sdcz]mumps.a have been found in ${MUMPS_DIR}/lib when required") + else() + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- no lib[sdcz]mumps.a have been found") + endif() + endif() +endif() +# other MUMPS libraries +if (MUMPS_mumps_common_LIBRARY) + mark_as_advanced(MUMPS_mumps_common_LIBRARY) + list(APPEND MUMPS_LIBRARIES "${MUMPS_mumps_common_LIBRARY}") + get_filename_component(mumps_common_lib_path ${MUMPS_mumps_common_LIBRARY} PATH) + list(APPEND MUMPS_LIBRARY_DIRS "${mumps_common_lib_path}") +else () + if (MUMPS_FIND_REQUIRED) + message(FATAL_ERROR "Looking for mumps -- " + "libmumps_common.a not found in ${MUMPS_DIR}/lib when required") + else() + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- libmumps_common.a not found") + endif() + endif() +endif() +if (MUMPS_mpiseq_LIBRARY) + mark_as_advanced(MUMPS_mpiseq_LIBRARY) + if (MUMPS_LOOK_FOR_SEQ) + list(APPEND MUMPS_LIBRARIES "${MUMPS_mpiseq_LIBRARY}") + get_filename_component(mpiseq_lib_path ${MUMPS_mpiseq_LIBRARY} PATH) + list(APPEND MUMPS_LIBRARY_DIRS "${mpiseq_lib_path}") + list(APPEND MUMPS_INCLUDE_DIRS "${mpiseq_lib_path}") + endif() +else () + if (MUMPS_FIND_REQUIRED AND MUMPS_LOOK_FOR_SEQ) + message(FATAL_ERROR "Looking for mumps -- " + "libmpiseq.a not found in ${MUMPS_DIR}/libseq when required") + else() + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- libmpiseq.a not found") + endif() + endif() +endif() +if (MUMPS_pord_LIBRARY) + mark_as_advanced(MUMPS_pord_LIBRARY) + list(APPEND MUMPS_LIBRARIES "${MUMPS_pord_LIBRARY}") + get_filename_component(pord_lib_path ${MUMPS_pord_LIBRARY} PATH) + list(APPEND MUMPS_LIBRARY_DIRS "${pord_lib_path}") +else () + if (MUMPS_FIND_REQUIRED) + message(FATAL_ERROR "Looking for mumps -- " + "libpord.a not found in ${MUMPS_DIR}/lib when required") + else() + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for mumps -- libpord.a not found") + endif() + endif() +endif() +list(REMOVE_DUPLICATES MUMPS_LIBRARY_DIRS) +list(REMOVE_DUPLICATES MUMPS_INCLUDE_DIRS) + +# check a function to validate the find +if(MUMPS_LIBRARIES) + + set(REQUIRED_LDFLAGS) + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # MUMPS + if (MUMPS_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${MUMPS_INCLUDE_DIRS}") + endif() + foreach(libdir ${MUMPS_LIBRARY_DIRS}) + if (libdir) + list(APPEND REQUIRED_LIBDIRS "${libdir}") + endif() + endforeach() + set(REQUIRED_LIBS "${MUMPS_LIBRARIES}") + # SCALAPACK + if (MUMPS_LOOK_FOR_MPI AND SCALAPACK_FOUND) + if (SCALAPACK_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${SCALAPACK_INCLUDE_DIRS}") + endif() + foreach(libdir ${SCALAPACK_LIBRARY_DIRS}) + if (libdir) + list(APPEND REQUIRED_LIBDIRS "${libdir}") + endif() + endforeach() + list(APPEND REQUIRED_LIBS "${SCALAPACK_LIBRARIES}") + if (SCALAPACK_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${SCALAPACK_LINKER_FLAGS}") + endif() + endif() + # MPI + if (MUMPS_LOOK_FOR_MPI AND MPI_FOUND) + if (MPI_C_INCLUDE_PATH) + list(APPEND REQUIRED_INCDIRS "${MPI_C_INCLUDE_PATH}") + endif() + if (MPI_Fortran_LINK_FLAGS) + if (${MPI_Fortran_LINK_FLAGS} MATCHES " -") + string(REGEX REPLACE " -" "-" MPI_Fortran_LINK_FLAGS ${MPI_Fortran_LINK_FLAGS}) + endif() + list(APPEND REQUIRED_LDFLAGS "${MPI_Fortran_LINK_FLAGS}") + endif() + list(APPEND REQUIRED_LIBS "${MPI_Fortran_LIBRARIES}") + 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 (MUMPS_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 (MUMPS_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 (MUMPS_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() + # PARMETIS + if (MUMPS_LOOK_FOR_PARMETIS AND PARMETIS_FOUND) + if (PARMETIS_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${PARMETIS_INCLUDE_DIRS}") + endif() + foreach(libdir ${PARMETIS_LIBRARY_DIRS}) + if (libdir) + list(APPEND REQUIRED_LIBDIRS "${libdir}") + endif() + endforeach() + list(APPEND REQUIRED_LIBS "${PARMETIS_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 ${MUMPS_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}") + string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + + # test link + include(CheckFortranFunctionExists) + unset(MUMPS_PREC_S_WORKS CACHE) + check_fortran_function_exists(smumps MUMPS_PREC_S_WORKS) + mark_as_advanced(MUMPS_PREC_S_WORKS) + unset(MUMPS_PREC_D_WORKS CACHE) + check_fortran_function_exists(dmumps MUMPS_PREC_D_WORKS) + mark_as_advanced(MUMPS_PREC_D_WORKS) + unset(MUMPS_PREC_C_WORKS CACHE) + check_fortran_function_exists(cmumps MUMPS_PREC_C_WORKS) + mark_as_advanced(MUMPS_PREC_C_WORKS) + unset(MUMPS_PREC_Z_WORKS CACHE) + check_fortran_function_exists(zmumps MUMPS_PREC_Z_WORKS) + mark_as_advanced(MUMPS_PREC_Z_WORKS) + + set(MUMPS_WORKS FALSE) + if(MUMPS_PREC_S_WORKS OR MUMPS_PREC_D_WORKS OR MUMPS_PREC_C_WORKS OR MUMPS_PREC_Z_WORKS) + set(MUMPS_WORKS TRUE) + endif() + + if(MUMPS_WORKS) + # save link with dependencies + set(MUMPS_LIBRARIES_DEP "${REQUIRED_LIBS}") + set(MUMPS_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(MUMPS_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(MUMPS_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES MUMPS_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES MUMPS_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES MUMPS_LINKER_FLAGS) + else() + if(NOT MUMPS_FIND_QUIETLY) + message(STATUS "Looking for MUMPS : test of [sdcz]mumps() 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 MUMPS is linked with specific libraries. " + "Have you tried with COMPONENTS (MPI/SEQ, SCOTCH, PTSCOTCH, METIS, PARMETIS)? " + "See the explanation in FindMUMPS.cmake.") + endif() + endif() + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_LIBRARIES) +endif(MUMPS_LIBRARIES) + +if (MUMPS_LIBRARIES) + list(GET MUMPS_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(MUMPS_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of MUMPS library" FORCE) + else() + set(MUMPS_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of MUMPS library" FORCE) + endif() +endif() +mark_as_advanced(MUMPS_DIR) +mark_as_advanced(MUMPS_DIR_FOUND) + +# check that MUMPS has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MUMPS DEFAULT_MSG + MUMPS_LIBRARIES + MUMPS_WORKS) diff --git a/modules/find/FindPAMPA.cmake b/modules/find/FindPAMPA.cmake new file mode 100644 index 0000000..f5f2953 --- /dev/null +++ b/modules/find/FindPAMPA.cmake @@ -0,0 +1,383 @@ +### +# +# @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 PAMPA include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(PAMPA +# [REQUIRED] # Fail with error if pampa is not found +# ) +# +# PAMPA depends on the following libraries: +# - MPI +# - PTSCOTCH +# +# This module finds headers and pampa library. +# Results are reported in variables: +# PAMPA_FOUND - True if headers and requested libraries were found +# PAMPA_INCLUDE_DIRS - pampa include directories +# PAMPA_LIBRARY_DIRS - Link directories for pampa libraries +# PAMPA_LIBRARIES - pampa component libraries to be linked +# PAMPA_INTSIZE - Number of octets occupied by a PAMPA_Num +# +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DPAMPA=path/to/pampa): +# PAMPA_DIR - Where to find the base directory of pampa +# PAMPA_INCDIR - Where to find the header files +# PAMPA_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: PAMPA_DIR, PAMPA_INCDIR, PAMPA_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 PAMPA_FOUND) + set(PAMPA_DIR "" CACHE PATH "Installation directory of PAMPA library") + if (NOT PAMPA_FIND_QUIETLY) + message(STATUS "A cache variable, namely PAMPA_DIR, has been set to specify the install directory of PAMPA") + endif() +endif() + +# PAMPA depends on MPI, try to find it +if (NOT MPI_FOUND) + if (PAMPA_FIND_REQUIRED) + find_package(MPI REQUIRED) + else() + find_package(MPI) + endif() +endif() + +# PAMPA depends on PAMPA, try to find it +if (NOT PTSCOTCH_FOUND) + if (PAMPA_FIND_REQUIRED) + find_package(PTSCOTCH REQUIRED) + else() + find_package(PTSCOTCH) + endif() +endif() + +# Looking for include +# ------------------- + +# Add system include paths to search include +# ------------------------------------------ +unset(_inc_env) +set(ENV_PAMPA_DIR "$ENV{PAMPA_DIR}") +set(ENV_PAMPA_INCDIR "$ENV{PAMPA_INCDIR}") +if(ENV_PAMPA_INCDIR) + list(APPEND _inc_env "${ENV_PAMPA_INCDIR}") +elseif(ENV_PAMPA_DIR) + list(APPEND _inc_env "${ENV_PAMPA_DIR}") + list(APPEND _inc_env "${ENV_PAMPA_DIR}/include") + list(APPEND _inc_env "${ENV_PAMPA_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(PAMPA_hdrs_to_find "pampa.h") + +# call cmake macro to find the header path +if(PAMPA_INCDIR) + foreach(pampa_hdr ${PAMPA_hdrs_to_find}) + set(PAMPA_${pampa_hdr}_DIRS "PAMPA_${pampa_hdr}_DIRS-NOTFOUND") + find_path(PAMPA_${pampa_hdr}_DIRS + NAMES ${pampa_hdr} + HINTS ${PAMPA_INCDIR}) + mark_as_advanced(PAMPA_${pampa_hdr}_DIRS) + endforeach() +else() + if(PAMPA_DIR) + foreach(pampa_hdr ${PAMPA_hdrs_to_find}) + set(PAMPA_${pampa_hdr}_DIRS "PAMPA_${pampa_hdr}_DIRS-NOTFOUND") + find_path(PAMPA_${pampa_hdr}_DIRS + NAMES ${pampa_hdr} + HINTS ${PAMPA_DIR} + PATH_SUFFIXES "include" "include/pampa") + mark_as_advanced(PAMPA_${pampa_hdr}_DIRS) + endforeach() + else() + foreach(pampa_hdr ${PAMPA_hdrs_to_find}) + set(PAMPA_${pampa_hdr}_DIRS "PAMPA_${pampa_hdr}_DIRS-NOTFOUND") + find_path(PAMPA_${pampa_hdr}_DIRS + NAMES ${pampa_hdr} + HINTS ${_inc_env} + PATH_SUFFIXES "pampa") + mark_as_advanced(PAMPA_${pampa_hdr}_DIRS) + endforeach() + endif() +endif() + +# If found, add path to cmake variable +# ------------------------------------ +foreach(pampa_hdr ${PAMPA_hdrs_to_find}) + if (PAMPA_${pampa_hdr}_DIRS) + list(APPEND PAMPA_INCLUDE_DIRS "${PAMPA_${pampa_hdr}_DIRS}") + else () + set(PAMPA_INCLUDE_DIRS "PAMPA_INCLUDE_DIRS-NOTFOUND") + if (NOT PAMPA_FIND_QUIETLY) + message(STATUS "Looking for pampa -- ${pampa_hdr} not found") + endif() + endif() +endforeach() + +# Looking for lib +# --------------- + +# Add system library paths to search lib +# -------------------------------------- +unset(_lib_env) +set(ENV_PAMPA_LIBDIR "$ENV{PAMPA_LIBDIR}") +if(ENV_PAMPA_LIBDIR) + list(APPEND _lib_env "${ENV_PAMPA_LIBDIR}") +elseif(ENV_PAMPA_DIR) + list(APPEND _lib_env "${ENV_PAMPA_DIR}") + list(APPEND _lib_env "${ENV_PAMPA_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(PAMPA_libs_to_find "pampa;pampaerr") + +# call cmake macro to find the lib path +if(PAMPA_LIBDIR) + foreach(pampa_lib ${PAMPA_libs_to_find}) + set(PAMPA_${pampa_lib}_LIBRARY "PAMPA_${pampa_lib}_LIBRARY-NOTFOUND") + find_library(PAMPA_${pampa_lib}_LIBRARY + NAMES ${pampa_lib} + HINTS ${PAMPA_LIBDIR}) + endforeach() +else() + if(PAMPA_DIR) + foreach(pampa_lib ${PAMPA_libs_to_find}) + set(PAMPA_${pampa_lib}_LIBRARY "PAMPA_${pampa_lib}_LIBRARY-NOTFOUND") + find_library(PAMPA_${pampa_lib}_LIBRARY + NAMES ${pampa_lib} + HINTS ${PAMPA_DIR} + PATH_SUFFIXES lib lib32 lib64) + endforeach() + else() + foreach(pampa_lib ${PAMPA_libs_to_find}) + set(PAMPA_${pampa_lib}_LIBRARY "PAMPA_${pampa_lib}_LIBRARY-NOTFOUND") + find_library(PAMPA_${pampa_lib}_LIBRARY + NAMES ${pampa_lib} + HINTS ${_lib_env}) + endforeach() + endif() +endif() + +set(PAMPA_LIBRARIES "") +set(PAMPA_LIBRARY_DIRS "") +# If found, add path to cmake variable +# ------------------------------------ +foreach(pampa_lib ${PAMPA_libs_to_find}) + + if (PAMPA_${pampa_lib}_LIBRARY) + get_filename_component(${pampa_lib}_lib_path "${PAMPA_${pampa_lib}_LIBRARY}" PATH) + # set cmake variables + list(APPEND PAMPA_LIBRARIES "${PAMPA_${pampa_lib}_LIBRARY}") + list(APPEND PAMPA_LIBRARY_DIRS "${${pampa_lib}_lib_path}") + else () + list(APPEND PAMPA_LIBRARIES "${PAMPA_${pampa_lib}_LIBRARY}") + if (NOT PAMPA_FIND_QUIETLY) + message(STATUS "Looking for ptscotch -- lib ${pampa_lib} not found") + endif() + endif () + + mark_as_advanced(PAMPA_${pampa_lib}_LIBRARY) + +endforeach() +list(REMOVE_DUPLICATES PAMPA_LIBRARY_DIRS) + +# check a function to validate the find +if(PAMPA_LIBRARIES) + + set(REQUIRED_LDFLAGS) + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # PAMPA + if (PAMPA_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${PAMPA_INCLUDE_DIRS}") + endif() + if (PAMPA_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${PAMPA_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${PAMPA_LIBRARIES}") + add_definitions(-Drestrict=__restrict) # pampa uses the restrict keyword + list(APPEND REQUIRED_FLAGS "-Drestrict=__restrict") + # 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() + # PTSCOTCH + 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_DEP}") + # 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(PAMPA_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(PAMPA_dmeshInit PAMPA_WORKS) + mark_as_advanced(PAMPA_WORKS) + + if(PAMPA_WORKS) + # save link with dependencies + set(PAMPA_LIBRARIES_DEP "${REQUIRED_LIBS}") + set(PAMPA_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(PAMPA_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(PAMPA_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES PAMPA_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES PAMPA_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES PAMPA_LINKER_FLAGS) + else() + if(NOT PAMPA_FIND_QUIETLY) + message(STATUS "Looking for PAMPA : test of PAMPA_dmeshInit with PAMPA 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(PAMPA_LIBRARIES) + +if (PAMPA_LIBRARIES) + list(GET PAMPA_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(PAMPA_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of PAMPA library" FORCE) + else() + set(PAMPA_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of PAMPA library" FORCE) + endif() +endif() +mark_as_advanced(PAMPA_DIR) +mark_as_advanced(PAMPA_DIR_FOUND) + +# Check the size of PAMPA_Num +# --------------------------------- +set(CMAKE_REQUIRED_INCLUDES ${PAMPA_INCLUDE_DIRS}) + +include(CheckCSourceRuns) +#stdio.h and stdint.h should be included by scotch.h directly +set(PAMPA_C_TEST_PAMPA_Num_4 " +#include <stdio.h> +#include <stdint.h> +#include <pampa.h> +int main(int argc, char **argv) { + if (sizeof(PAMPA_Num) == 4) + return 0; + else + return 1; +} +") + +set(PAMPA_C_TEST_PAMPA_Num_8 " +#include <stdio.h> +#include <stdint.h> +#include <pampa.h> +int main(int argc, char **argv) { + if (sizeof(PAMPA_Num) == 8) + return 0; + else + return 1; +} +") +check_c_source_runs("${PAMPA_C_TEST_PAMPA_Num_4}" PAMPA_Num_4) +if(NOT PAMPA_Num_4) + check_c_source_runs("${PAMPA_C_TEST_PAMPA_Num_8}" PAMPA_Num_8) + if(NOT PAMPA_Num_8) + set(PAMPA_INTSIZE -1) + else() + set(PAMPA_INTSIZE 8) + endif() +else() + set(PAMPA_INTSIZE 4) +endif() +set(CMAKE_REQUIRED_INCLUDES "") + +# check that PAMPA has been found +# --------------------------------- +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PAMPA DEFAULT_MSG + PAMPA_LIBRARIES + PAMPA_WORKS) diff --git a/modules/find/FindPAPI.cmake b/modules/find/FindPAPI.cmake new file mode 100644 index 0000000..918edb4 --- /dev/null +++ b/modules/find/FindPAPI.cmake @@ -0,0 +1,310 @@ +### +# +# @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 PAPI include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(PAPI +# [REQUIRED]) # Fail with error if papi is not found +# +# This module finds headers and papi library. +# Results are reported in variables: +# PAPI_FOUND - True if headers and requested libraries were found +# PAPI_INCLUDE_DIRS - papi include directories +# PAPI_LIBRARY_DIRS - Link directories for papi libraries +# PAPI_LIBRARIES - papi 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 -DPAPI_DIR=path/to/papi): +# PAPI_DIR - Where to find the base directory of papi +# PAPI_INCDIR - Where to find the header files +# PAPI_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: PAPI_DIR, PAPI_INCDIR, PAPI_LIBDIR + +#============================================================================= +# Copyright 2012-2016 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 PAPI_FOUND) + set(PAPI_DIR "" CACHE PATH "Installation directory of PAPI library") + if (NOT PAPI_FIND_QUIETLY) + message(STATUS "A cache variable, namely PAPI_DIR, has been set to specify the install directory of PAPI") + endif() +endif() + +set(ENV_PAPI_DIR "$ENV{PAPI_DIR}") +set(ENV_PAPI_INCDIR "$ENV{PAPI_INCDIR}") +set(ENV_PAPI_LIBDIR "$ENV{PAPI_LIBDIR}") +set(PAPI_GIVEN_BY_USER "FALSE") +if ( PAPI_DIR OR ( PAPI_INCDIR AND PAPI_LIBDIR) OR ENV_PAPI_DIR OR (ENV_PAPI_INCDIR AND ENV_PAPI_LIBDIR) ) + set(PAPI_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 PAPI_GIVEN_BY_USER) + + pkg_search_module(PAPI papi) + if (NOT PAPI_FIND_QUIETLY) + if (PAPI_FOUND AND PAPI_LIBRARIES) + message(STATUS "Looking for PAPI - found using PkgConfig") + #if(NOT PAPI_INCLUDE_DIRS) + # message("${Magenta}PAPI_INCLUDE_DIRS is empty using PkgConfig." + # "Perhaps the path to papi headers is already present in your" + # "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}") + #endif() + else() + message(STATUS "${Magenta}Looking for PAPI - not found using PkgConfig." + "\n Perhaps you should add the directory containing papi.pc to the" + "\n PKG_CONFIG_PATH environment variable.${ColourReset}") + endif() + endif() + +endif(PKG_CONFIG_EXECUTABLE AND NOT PAPI_GIVEN_BY_USER) + +if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT PAPI_FOUND) OR (PAPI_GIVEN_BY_USER) ) + + if (NOT PAPI_FIND_QUIETLY) + message(STATUS "Looking for PAPI - PkgConfig not used") + endif() + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + unset(_inc_env) + set(ENV_PAPI_DIR "$ENV{PAPI_DIR}") + set(ENV_PAPI_INCDIR "$ENV{PAPI_INCDIR}") + if(ENV_PAPI_INCDIR) + list(APPEND _inc_env "${ENV_PAPI_INCDIR}") + elseif(ENV_PAPI_DIR) + list(APPEND _inc_env "${ENV_PAPI_DIR}") + list(APPEND _inc_env "${ENV_PAPI_DIR}/include") + list(APPEND _inc_env "${ENV_PAPI_DIR}/include/papi") + 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 papi header in the given paths + # ------------------------------------------------- + # call cmake macro to find the header path + if(PAPI_INCDIR) + set(PAPI_papi.h_DIRS "PAPI_papi.h_DIRS-NOTFOUND") + find_path(PAPI_papi.h_DIRS + NAMES papi.h + HINTS ${PAPI_INCDIR}) + else() + if(PAPI_DIR) + set(PAPI_papi.h_DIRS "PAPI_papi.h_DIRS-NOTFOUND") + find_path(PAPI_papi.h_DIRS + NAMES papi.h + HINTS ${PAPI_DIR} + PATH_SUFFIXES "include" "include/papi") + else() + set(PAPI_papi.h_DIRS "PAPI_papi.h_DIRS-NOTFOUND") + find_path(PAPI_papi.h_DIRS + NAMES papi.h + HINTS ${_inc_env} + PATH_SUFFIXES "papi") + endif() + endif() + mark_as_advanced(PAPI_papi.h_DIRS) + + # Add path to cmake variable + # ------------------------------------ + if (PAPI_papi.h_DIRS) + set(PAPI_INCLUDE_DIRS "${PAPI_papi.h_DIRS}") + else () + set(PAPI_INCLUDE_DIRS "PAPI_INCLUDE_DIRS-NOTFOUND") + if(NOT PAPI_FIND_QUIETLY) + message(STATUS "Looking for papi -- papi.h not found") + endif() + endif () + + if (PAPI_INCLUDE_DIRS) + list(REMOVE_DUPLICATES PAPI_INCLUDE_DIRS) + endif () + + + # Looking for lib + # --------------- + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_PAPI_LIBDIR "$ENV{PAPI_LIBDIR}") + if(ENV_PAPI_LIBDIR) + list(APPEND _lib_env "${ENV_PAPI_LIBDIR}") + elseif(ENV_PAPI_DIR) + list(APPEND _lib_env "${ENV_PAPI_DIR}") + list(APPEND _lib_env "${ENV_PAPI_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 papi lib in the given paths + # ---------------------------------------------- + + # call cmake macro to find the lib path + if(PAPI_LIBDIR) + set(PAPI_papi_LIBRARY "PAPI_papi_LIBRARY-NOTFOUND") + find_library(PAPI_papi_LIBRARY + NAMES papi + HINTS ${PAPI_LIBDIR}) + else() + if(PAPI_DIR) + set(PAPI_papi_LIBRARY "PAPI_papi_LIBRARY-NOTFOUND") + find_library(PAPI_papi_LIBRARY + NAMES papi + HINTS ${PAPI_DIR} + PATH_SUFFIXES lib lib32 lib64) + else() + set(PAPI_papi_LIBRARY "PAPI_papi_LIBRARY-NOTFOUND") + find_library(PAPI_papi_LIBRARY + NAMES papi + HINTS ${_lib_env}) + endif() + endif() + mark_as_advanced(PAPI_papi_LIBRARY) + + # If found, add path to cmake variable + # ------------------------------------ + if (PAPI_papi_LIBRARY) + get_filename_component(papi_lib_path ${PAPI_papi_LIBRARY} PATH) + # set cmake variables (respects naming convention) + set(PAPI_LIBRARIES "${PAPI_papi_LIBRARY}") + set(PAPI_LIBRARY_DIRS "${papi_lib_path}") + else () + set(PAPI_LIBRARIES "PAPI_LIBRARIES-NOTFOUND") + set(PAPI_LIBRARY_DIRS "PAPI_LIBRARY_DIRS-NOTFOUND") + if(NOT PAPI_FIND_QUIETLY) + message(STATUS "Looking for papi -- lib papi not found") + endif() + endif () + + if (PAPI_LIBRARY_DIRS) + list(REMOVE_DUPLICATES PAPI_LIBRARY_DIRS) + endif () + + # check a function to validate the find + if(PAPI_LIBRARIES) + + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # PAPI + if (PAPI_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${PAPI_INCLUDE_DIRS}") + endif() + if (PAPI_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${PAPI_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${PAPI_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(PAPI_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(PAPI_start PAPI_WORKS) + mark_as_advanced(PAPI_WORKS) + + if(NOT PAPI_WORKS) + if(NOT PAPI_FIND_QUIETLY) + message(STATUS "Looking for papi : test of PAPI_start with papi 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(PAPI_LIBRARIES) + +endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT PAPI_FOUND) OR (PAPI_GIVEN_BY_USER) ) + +if (PAPI_LIBRARIES) + if (PAPI_LIBRARY_DIRS) + list(GET PAPI_LIBRARY_DIRS 0 first_lib_path) + else() + list(GET PAPI_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(PAPI_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of PAPI library" FORCE) + else() + set(PAPI_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of PAPI library" FORCE) + endif() +endif() +mark_as_advanced(PAPI_DIR) +mark_as_advanced(PAPI_DIR_FOUND) + +# check that PAPI has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +if (PKG_CONFIG_EXECUTABLE AND PAPI_FOUND) + find_package_handle_standard_args(PAPI DEFAULT_MSG + PAPI_LIBRARIES) +else() + find_package_handle_standard_args(PAPI DEFAULT_MSG + PAPI_LIBRARIES + PAPI_WORKS) +endif() diff --git a/modules/find/FindPARMETIS.cmake b/modules/find/FindPARMETIS.cmake new file mode 100644 index 0000000..fd2bd3f --- /dev/null +++ b/modules/find/FindPARMETIS.cmake @@ -0,0 +1,264 @@ +### +# +# @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 PARMETIS include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(PARMETIS +# [REQUIRED] # Fail with error if parmetis is not found +# ) +# +# This module finds headers and parmetis library. +# Results are reported in variables: +# PARMETIS_FOUND - True if headers and requested libraries were found +# PARMETIS_INCLUDE_DIRS - parmetis include directories +# PARMETIS_LIBRARY_DIRS - Link directories for parmetis libraries +# PARMETIS_LIBRARIES - parmetis 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 -DPARMETIS_DIR=path/to/parmetis): +# PARMETIS_DIR - Where to find the base directory of parmetis +# PARMETIS_INCDIR - Where to find the header files +# PARMETIS_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: PARMETIS_DIR, PARMETIS_INCDIR, PARMETIS_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.) + +if (NOT PARMETIS_FOUND) + set(PARMETIS_DIR "" CACHE PATH "Installation directory of PARMETIS library") + if (NOT PARMETIS_FIND_QUIETLY) + message(STATUS "A cache variable, namely PARMETIS_DIR, has been set to specify the install directory of PARMETIS") + endif() +endif() + + +# Looking for include +# ------------------- + +# Add system include paths to search include +# ------------------------------------------ +unset(_inc_env) +set(ENV_PARMETIS_DIR "$ENV{PARMETIS_DIR}") +set(ENV_PARMETIS_INCDIR "$ENV{PARMETIS_INCDIR}") +if(ENV_PARMETIS_INCDIR) + list(APPEND _inc_env "${ENV_PARMETIS_INCDIR}") +elseif(ENV_PARMETIS_DIR) + list(APPEND _inc_env "${ENV_PARMETIS_DIR}") + list(APPEND _inc_env "${ENV_PARMETIS_DIR}/include") + list(APPEND _inc_env "${ENV_PARMETIS_DIR}/include/parmetis") +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 parmetis header in the given paths +# ------------------------------------------------- +# call cmake macro to find the header path +if(PARMETIS_INCDIR) + set(PARMETIS_parmetis.h_DIRS "PARMETIS_parmetis.h_DIRS-NOTFOUND") + find_path(PARMETIS_parmetis.h_DIRS + NAMES parmetis.h + HINTS ${PARMETIS_INCDIR}) +else() + if(PARMETIS_DIR) + set(PARMETIS_parmetis.h_DIRS "PARMETIS_parmetis.h_DIRS-NOTFOUND") + find_path(PARMETIS_parmetis.h_DIRS + NAMES parmetis.h + HINTS ${PARMETIS_DIR} + PATH_SUFFIXES "include" "include/parmetis") + else() + set(PARMETIS_parmetis.h_DIRS "PARMETIS_parmetis.h_DIRS-NOTFOUND") + find_path(PARMETIS_parmetis.h_DIRS + NAMES parmetis.h + HINTS ${_inc_env}) + endif() +endif() +mark_as_advanced(PARMETIS_parmetis.h_DIRS) + + +# If found, add path to cmake variable +# ------------------------------------ +if (PARMETIS_parmetis.h_DIRS AND NOT PARMETIS_FIND_QUIETLY) + set(PARMETIS_INCLUDE_DIRS "${PARMETIS_parmetis.h_DIRS}") +else () + set(PARMETIS_INCLUDE_DIRS "PARMETIS_INCLUDE_DIRS-NOTFOUND") + if(NOT PARMETIS_FIND_QUIETLY) + message(STATUS "Looking for parmetis -- parmetis.h not found") + endif() +endif() + + +# Looking for lib +# --------------- + +# Add system library paths to search lib +# -------------------------------------- +unset(_lib_env) +set(ENV_PARMETIS_LIBDIR "$ENV{PARMETIS_LIBDIR}") +if(ENV_PARMETIS_LIBDIR) + list(APPEND _lib_env "${ENV_PARMETIS_LIBDIR}") +elseif(ENV_PARMETIS_DIR) + list(APPEND _lib_env "${ENV_PARMETIS_DIR}") + list(APPEND _lib_env "${ENV_PARMETIS_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 parmetis lib in the given paths +# ---------------------------------------------- +# call cmake macro to find the lib path +if(PARMETIS_LIBDIR) + set(PARMETIS_parmetis_LIBRARY "PARMETIS_parmetis_LIBRARY-NOTFOUND") + find_library(PARMETIS_parmetis_LIBRARY + NAMES parmetis + HINTS ${PARMETIS_LIBDIR}) +else() + if(PARMETIS_DIR) + set(PARMETIS_parmetis_LIBRARY "PARMETIS_parmetis_LIBRARY-NOTFOUND") + find_library(PARMETIS_parmetis_LIBRARY + NAMES parmetis + HINTS ${PARMETIS_DIR} + PATH_SUFFIXES lib lib32 lib64) + else() + set(PARMETIS_parmetis_LIBRARY "PARMETIS_parmetis_LIBRARY-NOTFOUND") + find_library(PARMETIS_parmetis_LIBRARY + NAMES parmetis + HINTS ${_lib_env}) + endif() +endif() +mark_as_advanced(PARMETIS_parmetis_LIBRARY) + +# If found, add path to cmake variable +# ------------------------------------ +if (PARMETIS_parmetis_LIBRARY) + get_filename_component(parmetis_lib_path "${PARMETIS_parmetis_LIBRARY}" PATH) + # set cmake variables + set(PARMETIS_LIBRARIES "${PARMETIS_parmetis_LIBRARY}") + set(PARMETIS_LIBRARY_DIRS "${parmetis_lib_path}") +else () + set(PARMETIS_LIBRARIES "PARMETIS_LIBRARIES-NOTFOUND") + set(PARMETIS_LIBRARY_DIRS "PARMETIS_LIBRARY_DIRS-NOTFOUND") + if (NOT PARMETIS_FIND_QUIETLY) + message(STATUS "Looking for parmetis -- lib parmetis not found") + endif() +endif () + +# check a function to validate the find +if(PARMETIS_LIBRARIES) + + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # PARMETIS + if (PARMETIS_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${PARMETIS_INCLUDE_DIRS}") + endif() + if (PARMETIS_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${PARMETIS_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${PARMETIS_LIBRARIES}") + # m + find_library(M_LIBRARY NAMES m) + mark_as_advanced(M_LIBRARY) + if(M_LIBRARY) + list(APPEND REQUIRED_LIBS "-lm") + 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(PARMETIS_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(ParMETIS_V3_NodeND PARMETIS_WORKS) + mark_as_advanced(PARMETIS_WORKS) + + if(NOT PARMETIS_WORKS) + if(NOT PARMETIS_FIND_QUIETLY) + message(STATUS "Looking for PARMETIS : test of ParMETIS_V3_NodeND with PARMETIS 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(PARMETIS_LIBRARIES) + +if (PARMETIS_LIBRARIES) + list(GET PARMETIS_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(PARMETIS_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of PARMETIS library" FORCE) + else() + set(PARMETIS_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of PARMETIS library" FORCE) + endif() +endif() +mark_as_advanced(PARMETIS_DIR) +mark_as_advanced(PARMETIS_DIR_FOUND) + +# check that PARMETIS has been found +# ---------------------------------- +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PARMETIS DEFAULT_MSG + PARMETIS_LIBRARIES + PARMETIS_WORKS) +# +# TODO: Add possibility to check for specific functions in the library +# diff --git a/modules/find/FindPARSEC.cmake b/modules/find/FindPARSEC.cmake new file mode 100644 index 0000000..d1daf48 --- /dev/null +++ b/modules/find/FindPARSEC.cmake @@ -0,0 +1,660 @@ +### +# +# @copyright (c) 2009-2015 The University of Tennessee and The University +# of Tennessee Research Foundation. +# All rights reserved. +# @copyright (c) 2012-2015 Inria. All rights reserved. +# @copyright (c) 2012-2015 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved. +# +### +# +# - Find PARSEC include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(PARSEC +# [version] [EXACT] # Minimum or EXACT version e.g. 1.1 +# [REQUIRED] # Fail with error if parsec is not found +# [COMPONENTS <comp1> <comp2> ...] # dependencies +# ) +# +# PARSEC depends on the following libraries: +# - Threads, m, rt +# +# COMPONENTS are optional libraries PARSEC could be linked with, +# Use it to drive detection of a specific compilation chain +# COMPONENTS can be some of the following: +# - HWLOC: to activate the detection of PARSEC linked with HWLOC +# - CUDA: to activate the detection of PARSEC linked with CUDA +# - MPI: to activate the detection of PARSEC linked with MPI +# - AYUDAME: ?? +# +# Results are reported in variables: +# PARSEC_FOUND - True if headers and requested libraries were found +# PARSEC_C_FLAGS - list of required compilation flags (excluding -I) +# PARSEC_LINKER_FLAGS - list of required linker flags (excluding -l and -L) +# PARSEC_INCLUDE_DIRS - parsec include directories +# PARSEC_LIBRARY_DIRS - Link directories for parsec libraries +# PARSEC_LIBRARIES - parsec libraries +# PARSEC_INCLUDE_DIRS_DEP - parsec + dependencies include directories +# PARSEC_LIBRARY_DIRS_DEP - parsec + dependencies link directories +# PARSEC_LIBRARIES_DEP - parsec libraries + dependencies +# PARSEC_daguepp_BIN_DIR - path to parsec driver daguepp +# PARSEC_DAGUEPP - parsec jdf compiler +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DPARSEC=path/to/parsec): +# PARSEC_DIR - Where to find the base directory of parsec +# PARSEC_INCDIR - Where to find the header files +# PARSEC_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: PARSEC_DIR, PARSEC_INCDIR, PARSEC_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(CheckSymbolExists) + +if (NOT PARSEC_FOUND) + set(PARSEC_DIR "" CACHE PATH "Installation directory of PARSEC library") + if (NOT PARSEC_FIND_QUIETLY) + message(STATUS "A cache variable, namely PARSEC_DIR, has been set to specify the install directory of PARSEC") + endif() +endif() + +# PARSEC may depend on other packages (HWLOC, MPI, CUDA, ...) +# try to find them if specified as COMPONENTS during the call +set(PARSEC_LOOK_FOR_HWLOC FALSE) +set(PARSEC_LOOK_FOR_CUDA FALSE) +set(PARSEC_LOOK_FOR_MPI FALSE) + +if( PARSEC_FIND_COMPONENTS ) + foreach( component ${PARSEC_FIND_COMPONENTS} ) + if(${component} STREQUAL "HWLOC") + set(PARSEC_LOOK_FOR_HWLOC TRUE) + elseif(${component} STREQUAL "CUDA") + set(PARSEC_LOOK_FOR_CUDA TRUE) + elseif(${component} STREQUAL "MPI") + set(PARSEC_LOOK_FOR_MPI TRUE) + endif() + endforeach() +endif() + +# Required dependencies +# --------------------- + +if (NOT PARSEC_FIND_QUIETLY) + message(STATUS "Looking for PARSEC - Try to detect pthread") +endif() +if (PARSEC_FIND_REQUIRED) + find_package(Threads REQUIRED) +else() + find_package(Threads) +endif() +set(PARSEC_EXTRA_LIBRARIES "") +if( THREADS_FOUND ) + list(APPEND PARSEC_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 PARSEC_FIND_QUIETLY) + message(STATUS "Looking for PARSEC - Try to detect libm") +endif() +set(PARSEC_M_LIBRARIES "") +if(UNIX OR WIN32) + find_library( + PARSEC_M_m_LIBRARY + NAMES m + ) + mark_as_advanced(PARSEC_M_m_LIBRARY) + if (PARSEC_M_m_LIBRARY) + list(APPEND PARSEC_M_LIBRARIES "${PARSEC_M_m_LIBRARY}") + list(APPEND PARSEC_EXTRA_LIBRARIES "${PARSEC_M_m_LIBRARY}") + else() + if (PARSEC_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 PARSEC_FIND_QUIETLY) + message(STATUS "Looking for PARSEC - Try to detect librt") +endif() +set(PARSEC_RT_LIBRARIES "") +if(UNIX AND NOT APPLE) + find_library( + PARSEC_RT_rt_LIBRARY + NAMES rt + ) + mark_as_advanced(PARSEC_RT_rt_LIBRARY) + if (PARSEC_RT_rt_LIBRARY) + list(APPEND PARSEC_RT_LIBRARIES "${PARSEC_RT_rt_LIBRARY}") + list(APPEND PARSEC_EXTRA_LIBRARIES "${PARSEC_RT_rt_LIBRARY}") + else() + if (PARSEC_FIND_REQUIRED) + message(FATAL_ERROR "Could NOT find librt on your system") + endif() + endif() +endif() + +# Try to find libdl +if (NOT PARSEC_FIND_QUIETLY) + message(STATUS "Looking for PARSEC - Try to detect libdl") +endif() +set(PARSEC_DL_LIBRARIES "") +find_library( + PARSEC_DL_LIBRARY + NAMES dl + ) +mark_as_advanced(PARSEC_DL_LIBRARY) +if (PARSEC_DL_LIBRARY) + list(APPEND PARSEC_DL_LIBRARIES "${PARSEC_DL_LIBRARY}") + list(APPEND PARSEC_EXTRA_LIBRARIES "${PARSEC_DL_LIBRARY}") +endif() + +# PARSEC may depend on HWLOC, try to find it +if (NOT HWLOC_FOUND AND PARSEC_LOOK_FOR_HWLOC) + if (PARSEC_FIND_REQUIRED) + find_package(HWLOC REQUIRED) + else() + find_package(HWLOC) + endif() +endif() + +# PARSEC may depend on CUDA, try to find it +if (NOT CUDA_FOUND AND PARSEC_LOOK_FOR_CUDA) + if (PARSEC_FIND_REQUIRED AND PARSEC_FIND_REQUIRED_CUDA) + find_package(CUDA REQUIRED) + else() + find_package(CUDA) + endif() + if (CUDA_FOUND) + mark_as_advanced(CUDA_BUILD_CUBIN) + mark_as_advanced(CUDA_BUILD_EMULATION) + mark_as_advanced(CUDA_SDK_ROOT_DIR) + mark_as_advanced(CUDA_TOOLKIT_ROOT_DIR) + mark_as_advanced(CUDA_VERBOSE_BUILD) + endif() +endif() + +# PARSEC may depend on MPI, try to find it +if (NOT MPI_FOUND AND PARSEC_LOOK_FOR_MPI) + if (PARSEC_FIND_REQUIRED AND PARSEC_FIND_REQUIRED_MPI) + find_package(MPI REQUIRED) + else() + find_package(MPI) + endif() + if (MPI_FOUND) + mark_as_advanced(MPI_LIBRARY) + mark_as_advanced(MPI_EXTRA_LIBRARY) + endif() +endif() + +set(ENV_PARSEC_DIR "$ENV{PARSEC_DIR}") +set(ENV_PARSEC_INCDIR "$ENV{PARSEC_INCDIR}") +set(ENV_PARSEC_LIBDIR "$ENV{PARSEC_LIBDIR}") +set(PARSEC_GIVEN_BY_USER "FALSE") +if ( PARSEC_DIR OR ( PARSEC_INCDIR AND PARSEC_LIBDIR) OR ENV_PARSEC_DIR OR (ENV_PARSEC_INCDIR AND ENV_PARSEC_LIBDIR) ) + set(PARSEC_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 PARSEC_GIVEN_BY_USER) + + pkg_search_module(PARSEC parsec) + if (NOT PARSEC_FIND_QUIETLY) + if (PARSEC_FOUND AND PARSEC_LIBRARIES) + message(STATUS "Looking for PARSEC - found using PkgConfig") + #if(NOT PARSEC_SHM_INCLUDE_DIRS) + # message("${Magenta}PARSEC_SHM_INCLUDE_DIRS is empty using PkgConfig." + # "Perhaps the path to parsec headers is already present in your" + # "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}") + #endif() + else() + message(STATUS "${Magenta}Looking for PARSEC - not found using PkgConfig." + "\n Perhaps you should add the directory containing libparsec.pc" + "\n to the PKG_CONFIG_PATH environment variable.${ColourReset}") + endif() + endif() + + set(PARSEC_INCLUDE_DIRS_DEP "${PARSEC_INCLUDE_DIRS}") + set(PARSEC_LIBRARY_DIRS_DEP "${PARSEC_LIBRARY_DIRS}") + set(PARSEC_LIBRARIES_DEP "${PARSEC_LIBRARIES}") + + # create list of binaries to find + set(PARSEC_bins_to_find "daguepp") + + # call cmake macro to find the bin path + if(PARSEC_PREFIX) + foreach(parsec_bin ${PARSEC_bins_to_find}) + set(PARSEC_${parsec_bin}_BIN_DIR "PARSEC_${parsec_bin}_BIN_DIR-NOTFOUND") + find_path(PARSEC_${parsec_bin}_BIN_DIR + NAMES ${parsec_bin} + HINTS ${PARSEC_PREFIX} + PATH_SUFFIXES "bin") + endforeach() + else() + if (PARSEC_FIND_REQUIRED) + message(FATAL_ERROR "PARSEC_PREFIX not defined by pkg_search_module") + endif() + endif() + +endif(PKG_CONFIG_EXECUTABLE AND NOT PARSEC_GIVEN_BY_USER) + +if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT PARSEC_FOUND) OR (PARSEC_GIVEN_BY_USER) ) + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + unset(_inc_env) + set(ENV_PARSEC_DIR "$ENV{PARSEC_DIR}") + set(ENV_PARSEC_INCDIR "$ENV{PARSEC_INCDIR}") + if(ENV_PARSEC_INCDIR) + list(APPEND _inc_env "${ENV_PARSEC_INCDIR}") + elseif(ENV_PARSEC_DIR) + list(APPEND _inc_env "${ENV_PARSEC_DIR}") + list(APPEND _inc_env "${ENV_PARSEC_DIR}/include") + list(APPEND _inc_env "${ENV_PARSEC_DIR}/include/dague") + 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 parsec headers in the given paths + # ------------------------------------------------- + + # create list of headers to find + set(PARSEC_hdrs_to_find "dague_config.h" "dague.h") + + # call cmake macro to find the header path + if(PARSEC_INCDIR) + foreach(parsec_hdr ${PARSEC_hdrs_to_find}) + set(PARSEC_${parsec_hdr}_INCLUDE_DIRS "PARSEC_${parsec_hdr}_INCLUDE_DIRS-NOTFOUND") + find_path(PARSEC_${parsec_hdr}_INCLUDE_DIRS + NAMES ${parsec_hdr} + HINTS ${PARSEC_INCDIR}) + endforeach() + else() + if(PARSEC_DIR) + set(PARSEC_${parsec_hdr}_INCLUDE_DIRS "PARSEC_${parsec_hdr}_INCLUDE_DIRS-NOTFOUND") + foreach(parsec_hdr ${PARSEC_hdrs_to_find}) + find_path(PARSEC_${parsec_hdr}_INCLUDE_DIRS + NAMES ${parsec_hdr} + HINTS ${PARSEC_DIR} + PATH_SUFFIXES "include") + endforeach() + else() + foreach(parsec_hdr ${PARSEC_hdrs_to_find}) + set(PARSEC_${parsec_hdr}_INCLUDE_DIRS "PARSEC_${parsec_hdr}_INCLUDE_DIRS-NOTFOUND") + find_path(PARSEC_${parsec_hdr}_INCLUDE_DIRS + NAMES ${parsec_hdr} + HINTS ${_inc_env}) + endforeach() + endif() + endif() + + # If found, add path to cmake variable + # ------------------------------------ + set(PARSEC_INCLUDE_DIRS "") + foreach(parsec_hdr ${PARSEC_hdrs_to_find}) + + if (PARSEC_${parsec_hdr}_INCLUDE_DIRS) + # set cmake variables using the pkg-config naming convention + list(APPEND PARSEC_INCLUDE_DIRS "${PARSEC_${parsec_hdr}_INCLUDE_DIRS}" ) + else () + if(NOT PARSEC_FIND_QUIETLY) + message(STATUS "Looking for parsec -- ${parsec_hdr} not found") + endif() + endif () + mark_as_advanced(PARSEC_${parsec_hdr}_INCLUDE_DIRS) + + endforeach(parsec_hdr ${PARSEC_hdrs_to_find}) + + if (PARSEC_INCLUDE_DIRS) + list(REMOVE_DUPLICATES PARSEC_INCLUDE_DIRS) + endif () + + # Looking for lib + # --------------- + + set(PARSEC_LIBRARIES "") + set(PARSEC_LIBRARY_DIRS "") + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_PARSEC_LIBDIR "$ENV{PARSEC_LIBDIR}") + if(ENV_PARSEC_LIBDIR) + list(APPEND _lib_env "${ENV_PARSEC_LIBDIR}") + elseif(ENV_PARSEC_DIR) + list(APPEND _lib_env "${ENV_PARSEC_DIR}") + list(APPEND _lib_env "${ENV_PARSEC_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 parsec libs in the given paths + # ---------------------------------------------- + + # create list of libs to find + set(PARSEC_libs_to_find "dague" "dague-base" "dague_distribution" "dague_distribution_matrix") + + # call cmake macro to find the lib path + if(PARSEC_LIBDIR) + foreach(parsec_lib ${PARSEC_libs_to_find}) + set(PARSEC_${parsec_lib}_LIBRARY "PARSEC_${parsec_lib}_LIBRARY-NOTFOUND") + find_library(PARSEC_${parsec_lib}_LIBRARY + NAMES ${parsec_lib} + HINTS ${PARSEC_LIBDIR}) + endforeach() + else() + if(PARSEC_DIR) + foreach(parsec_lib ${PARSEC_libs_to_find}) + set(PARSEC_${parsec_lib}_LIBRARY "PARSEC_${parsec_lib}_LIBRARY-NOTFOUND") + find_library(PARSEC_${parsec_lib}_LIBRARY + NAMES ${parsec_lib} + HINTS ${PARSEC_DIR} + PATH_SUFFIXES lib lib32 lib64) + endforeach() + else() + foreach(parsec_lib ${PARSEC_libs_to_find}) + set(PARSEC_${parsec_lib}_LIBRARY "PARSEC_${parsec_lib}_LIBRARY-NOTFOUND") + find_library(PARSEC_${parsec_lib}_LIBRARY + NAMES ${parsec_lib} + HINTS ${_lib_env}) + endforeach() + endif() + endif() + + # If found, add path to cmake variable + # ------------------------------------ + foreach(parsec_lib ${PARSEC_libs_to_find}) + + if (PARSEC_${parsec_lib}_LIBRARY) + + get_filename_component(${parsec_lib}_lib_path ${PARSEC_${parsec_lib}_LIBRARY} PATH) + # set cmake variables (respects naming convention) + list(APPEND PARSEC_LIBRARIES "${PARSEC_${parsec_lib}_LIBRARY}") + list(APPEND PARSEC_LIBRARY_DIRS "${${parsec_lib}_lib_path}") + + else (PARSEC_${parsec_lib}_LIBRARY) + + if(NOT PARSEC_FIND_QUIETLY) + message(STATUS "Looking for parsec -- lib ${parsec_lib} not found") + endif() + + endif (PARSEC_${parsec_lib}_LIBRARY) + + mark_as_advanced(PARSEC_${parsec_lib}_LIBRARY) + + endforeach(parsec_lib ${PARSEC_libs_to_find}) + + list(REMOVE_DUPLICATES PARSEC_LIBRARIES) + if (PARSEC_LIBRARY_DIRS) + list(REMOVE_DUPLICATES PARSEC_LIBRARY_DIRS) + endif () + + # Looking for parsec compilers + # ---------------------------- + + # Add system bin paths to search drivers + # -------------------------------------- + unset(_bin_env) + if(ENV_PARSEC_DIR) + list(APPEND _bin_env "${ENV_PARSEC_DIR}") + list(APPEND _bin_env "${ENV_PARSEC_DIR}/bin") + else() + string(REPLACE ":" ";" _bin_env "$ENV{PATH}") + endif() + list(REMOVE_DUPLICATES _bin_env) + + # create list of binaries to find + set(PARSEC_bins_to_find "daguepp") + + # call cmake macro to find the bin path + if(PARSEC_DIR) + foreach(parsec_bin ${PARSEC_bins_to_find}) + set(PARSEC_${parsec_bin}_BIN_DIR "PARSEC_${parsec_bin}_BIN_DIR-NOTFOUND") + find_path(PARSEC_${parsec_bin}_BIN_DIR + NAMES ${parsec_bin} + HINTS ${PARSEC_DIR} + PATH_SUFFIXES "bin") + endforeach() + else() + foreach(parsec_bin ${PARSEC_bins_to_find}) + set(PARSEC_${parsec_bin}_BIN_DIR "PARSEC_${parsec_bin}_BIN_DIR-NOTFOUND") + find_path(PARSEC_${parsec_bin}_BIN_DIR + NAMES ${parsec_bin} + HINTS ${_bin_env}) + endforeach() + endif() + if (PARSEC_daguepp_BIN_DIR) + if (NOT PARSEC_FIND_QUIETLY) + message(STATUS "Look for PARSEC - compiler daguepp found in ${PARSEC_daguepp_BIN_DIR}") + endif() + else() + if (PARSEC_FIND_REQUIRED) + message(FATAL_ERROR "Look for PARSEC - compiler daguepp not found while required") + endif() + endif() + + # check a function to validate the find + if(PARSEC_LIBRARIES) + + set(REQUIRED_FLAGS) + set(REQUIRED_LDFLAGS) + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # PARSEC + if (PARSEC_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${PARSEC_INCLUDE_DIRS}") + endif() + set(CMAKE_REQUIRED_FLAGS) + foreach(libdir ${PARSEC_LIBRARY_DIRS}) + if (libdir) + list(APPEND REQUIRED_LIBDIRS "${libdir}") + endif() + endforeach() + set(REQUIRED_LIBS "${PARSEC_LIBRARIES}") + # HWLOC + if (HWLOC_FOUND AND PARSEC_LOOK_FOR_HWLOC) + if (HWLOC_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${HWLOC_INCLUDE_DIRS}") + endif() + if (HWLOC_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${HWLOC_LIBRARY_DIRS}") + endif() + 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() + # MPI + if (MPI_FOUND AND PARSEC_LOOK_FOR_MPI) + 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() + # CUDA + if (CUDA_FOUND AND PARSEC_LOOK_FOR_CUDA) + if (CUDA_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${CUDA_INCLUDE_DIRS}") + endif() + if (CUDA_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${CUDA_LIBRARY_DIRS}") + endif() + list(APPEND REQUIRED_LIBS "${CUDA_CUBLAS_LIBRARIES};${CUDA_CUDART_LIBRARY};${CUDA_CUDA_LIBRARY}") + 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, dl + list(APPEND REQUIRED_LIBS ${PARSEC_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(PARSEC_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(dague_init PARSEC_WORKS) + mark_as_advanced(PARSEC_WORKS) + + if(PARSEC_WORKS) + # save link with dependencies + if (REQUIRED_FLAGS) + set(PARSEC_LIBRARIES_DEP "${REQUIRED_FLAGS};${REQUIRED_LIBS}") + else() + set(PARSEC_LIBRARIES_DEP "${REQUIRED_LIBS}") + endif() + set(PARSEC_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(PARSEC_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(PARSEC_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES PARSEC_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES PARSEC_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES PARSEC_LINKER_FLAGS) + else() + if(NOT PARSEC_FIND_QUIETLY) + message(STATUS "Looking for parsec : test of dague_init 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 PARSEC is linked with specific libraries. " + "Have you tried with COMPONENTS (HWLOC, CUDA, MPI)? " + "See the explanation in FindPARSEC.cmake.") + endif() + endif() + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_LIBRARIES) + endif(PARSEC_LIBRARIES) + +endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT PARSEC_FOUND) OR (PARSEC_GIVEN_BY_USER) ) + +if (PARSEC_LIBRARIES) + if (PARSEC_LIBRARY_DIRS) + foreach(dir ${PARSEC_LIBRARY_DIRS}) + if ("${dir}" MATCHES "parsec") + set(first_lib_path "${dir}") + endif() + endforeach() + else() + list(GET PARSEC_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(PARSEC_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of PARSEC library" FORCE) + else() + set(PARSEC_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of PARSEC library" FORCE) + endif() +endif() +mark_as_advanced(PARSEC_DIR) +mark_as_advanced(PARSEC_DIR_FOUND) + +# check that PARSEC has been found +# -------------------------------- +include(FindPackageHandleStandardArgs) +if (PKG_CONFIG_EXECUTABLE AND PARSEC_FOUND) + find_package_handle_standard_args(PARSEC DEFAULT_MSG + PARSEC_LIBRARIES + PARSEC_daguepp_BIN_DIR) +else() + find_package_handle_standard_args(PARSEC DEFAULT_MSG + PARSEC_LIBRARIES + PARSEC_daguepp_BIN_DIR + PARSEC_WORKS) +endif() + +if ( PARSEC_daguepp_BIN_DIR ) + find_program(PARSEC_DAGUEPP + NAMES daguepp + HINTS ${PARSEC_daguepp_BIN_DIR}) +else() + set(PARSEC_DAGUEPP "PARSEC_DAGUEPP-NOTFOUND") +endif() diff --git a/modules/find/FindPASTIX.cmake b/modules/find/FindPASTIX.cmake new file mode 100644 index 0000000..bb278e9 --- /dev/null +++ b/modules/find/FindPASTIX.cmake @@ -0,0 +1,704 @@ +### +# +# @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 + +#============================================================================= +# 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) +else() + find_package(Threads) +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) +else() + find_package(HWLOC) +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) +else() + find_package(BLASEXT) +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) + else() + find_package(MPI) + 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) + else() + find_package(SCOTCH) + 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) + else() + find_package(PTSCOTCH) + 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) + else() + find_package(METIS) + 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_LIBRARIES + PASTIX_WORKS) diff --git a/modules/find/FindPETSc.cmake b/modules/find/FindPETSc.cmake new file mode 100644 index 0000000..1d7fb85 --- /dev/null +++ b/modules/find/FindPETSc.cmake @@ -0,0 +1,318 @@ +# - Try to find PETSc +# Once done this will define +# +# PETSC_FOUND - system has PETSc +# PETSC_INCLUDES - the PETSc include directories +# PETSC_LIBRARIES - Link these to use PETSc +# PETSC_COMPILER - Compiler used by PETSc, helpful to find a compatible MPI +# PETSC_DEFINITIONS - Compiler switches for using PETSc +# PETSC_MPIEXEC - Executable for running MPI programs +# PETSC_VERSION - Version string (MAJOR.MINOR.SUBMINOR) +# +# Usage: +# find_package(PETSc COMPONENTS CXX) - required if build --with-clanguage=C++ --with-c-support=0 +# find_package(PETSc COMPONENTS C) - standard behavior of checking build using a C compiler +# find_package(PETSc) - same as above +# +# Setting these changes the behavior of the search +# PETSC_DIR - directory in which PETSc resides +# PETSC_ARCH - build architecture +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +function (petsc_get_version) + if (EXISTS "${PETSC_DIR}/include/petscversion.h") + file (STRINGS "${PETSC_DIR}/include/petscversion.h" vstrings REGEX "#define PETSC_VERSION_(RELEASE|MAJOR|MINOR|SUBMINOR|PATCH) ") + foreach (line ${vstrings}) + string (REGEX REPLACE " +" ";" fields ${line}) # break line into three fields (the first is always "#define") + list (GET fields 1 var) + list (GET fields 2 val) + set (${var} ${val} PARENT_SCOPE) + set (${var} ${val}) # Also in local scope so we have access below + endforeach () + if (PETSC_VERSION_RELEASE) + set (PETSC_VERSION "${PETSC_VERSION_MAJOR}.${PETSC_VERSION_MINOR}.${PETSC_VERSION_SUBMINOR}p${PETSC_VERSION_PATCH}" PARENT_SCOPE) + else () + # make dev version compare higher than any patch level of a released version + set (PETSC_VERSION "${PETSC_VERSION_MAJOR}.${PETSC_VERSION_MINOR}.${PETSC_VERSION_SUBMINOR}.99" PARENT_SCOPE) + endif () + else () + message (SEND_ERROR "PETSC_DIR can not be used, ${PETSC_DIR}/include/petscversion.h does not exist") + endif () +endfunction () + +find_path (PETSC_DIR include/petsc.h + HINTS ENV PETSC_DIR + PATHS + ${AEROSOL_TOP_DIR}/../../petsc-3.3-p4 ${AEROSOL_TOP_DIR}/../../petsc-3.2-p7 ${AEROSOL_TOP_DIR}/../../petsc-3.2-p6 ${AEROSOL_TOP_DIR}/../../petsc-3.2-p5 + ${AEROSOL_TOP_DIR}/../../petsc + /usr/lib/petscdir/3.1 /usr/lib/petscdir/3.0.0 /usr/lib/petscdir/2.3.3 /usr/lib/petscdir/2.3.2 # Debian + $ENV{HOME}/petsc + DOC "PETSc Directory") + + +find_program (MAKE_EXECUTABLE NAMES make gmake) + +if (PETSC_DIR AND NOT PETSC_ARCH) + set (_petsc_arches + $ENV{PETSC_ARCH} # If set, use environment variable first + arch-linux2-cxx-opt arch-linux2-c-opt + arch-linux2-cxx-debug arch-linux2-c-debug + linux-x86_64-python + linux-gnu-c-debug linux-gnu-c-opt # Debian defaults + x86_64-unknown-linux-gnu i386-unknown-linux-gnu) + set (petscconf "NOTFOUND" CACHE FILEPATH "Cleared" FORCE) + foreach (arch ${_petsc_arches}) + if (NOT PETSC_ARCH) + find_path (petscconf petscconf.h + HINTS ${PETSC_DIR} + PATH_SUFFIXES ${arch}/include bmake/${arch} + NO_DEFAULT_PATH) + if (petscconf) + set (PETSC_ARCH "${arch}" CACHE STRING "PETSc build architecture") + endif (petscconf) + endif (NOT PETSC_ARCH) + endforeach (arch) + set (petscconf "NOTFOUND" CACHE INTERNAL "Scratch variable" FORCE) +endif (PETSC_DIR AND NOT PETSC_ARCH) + +set(PETSC_VALID_COMPONENTS + C + CXX) + +if(NOT PETSc_FIND_COMPONENTS) + #on cherche si on a compile PETSc avec l'option --with-clanguage=cxx + #on regarde dans PETSC_ARCH si on trouve cxx + #on pourrait aussi chercher --with-clanguage=cxx dans configure.log + if (PETSC_ARCH) + string(REGEX MATCH "-cxx-" PETSc_FIND_COMPONENTS ${PETSC_ARCH}) + if(PETSc_FIND_COMPONENTS) + set(PETSC_LANGUAGE_BINDINGS "CXX") + else(PETSc_FIND_COMPONENTS) + set(PETSC_LANGUAGE_BINDINGS "C") + endif(PETSc_FIND_COMPONENTS) + endif(PETSC_ARCH) +else() + # Right now, this is designed for compatability with the --with-clanguage option, so + # only allow one item in the components list. + list(LENGTH ${PETSc_FIND_COMPONENTS} components_length) + if(${components_length} GREATER 1) + message(FATAL_ERROR "Only one component for PETSc is allowed to be specified") + endif() + list(FIND PETSC_VALID_COMPONENTS ${PETSc_FIND_COMPONENTS} component_location) + if(${component_location} EQUAL -1) + message(FATAL_ERROR "\"${PETSc_FIND_COMPONENTS}\" is not a valid PETSc component.") + else() + list(APPEND PETSC_LANGUAGE_BINDINGS ${PETSc_FIND_COMPONENTS}) + endif() +endif() + +if (PETSC_DIR AND PETSC_ARCH) + SET( PETSC_FOUND TRUE) +else(PETSC_DIR AND PETSC_ARCH) + SET( PETSC_FOUND FALSE) +endif(PETSC_DIR AND PETSC_ARCH) + +set (petsc_slaves LIBRARIES_SYS LIBRARIES_VEC LIBRARIES_MAT LIBRARIES_DM LIBRARIES_KSP LIBRARIES_SNES LIBRARIES_TS + INCLUDE_DIR INCLUDE_CONF) +include (FindPackageMultipass) +find_package_multipass (PETSc petsc_config_current + STATES DIR ARCH + DEPENDENTS INCLUDES LIBRARIES COMPILER MPIEXEC ${petsc_slaves}) + +# Determine whether the PETSc layout is old-style (through 2.3.3) or +# new-style (>= 3.0.0) +if (EXISTS "${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h") # > 2.3.3 + set (petsc_conf_rules "${PETSC_DIR}/conf/rules") + set (petsc_conf_variables "${PETSC_DIR}/conf/variables") +elseif (EXISTS "${PETSC_DIR}/bmake/${PETSC_ARCH}/petscconf.h") # <= 2.3.3 + set (petsc_conf_rules "${PETSC_DIR}/bmake/common/rules") + set (petsc_conf_variables "${PETSC_DIR}/bmake/common/variables") +elseif (PETSC_DIR) + message (SEND_ERROR "The pair PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} do not specify a valid PETSc installation") +endif () + +if (petsc_conf_rules AND petsc_conf_variables AND NOT petsc_config_current) + petsc_get_version() + + # Put variables into environment since they are needed to get + # configuration (petscvariables) in the PETSc makefile + set (ENV{PETSC_DIR} "${PETSC_DIR}") + set (ENV{PETSC_ARCH} "${PETSC_ARCH}") + + # A temporary makefile to probe the PETSc configuration + set (petsc_config_makefile "${PROJECT_BINARY_DIR}/Makefile.petsc") + file (WRITE "${petsc_config_makefile}" + "## This file was autogenerated by FindPETSc.cmake +# PETSC_DIR = ${PETSC_DIR} +# PETSC_ARCH = ${PETSC_ARCH} +include ${petsc_conf_rules} +include ${petsc_conf_variables} +show : + @echo -n \${\${VARIABLE}} +") + + macro (PETSC_GET_VARIABLE name var) + set (${var} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) + execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} show VARIABLE=${name} + OUTPUT_VARIABLE ${var} + RESULT_VARIABLE petsc_return) + endmacro (PETSC_GET_VARIABLE) + petsc_get_variable (PETSC_LIB_DIR petsc_lib_dir) + petsc_get_variable (PETSC_EXTERNAL_LIB_BASIC petsc_libs_external) + petsc_get_variable (PETSC_CCPPFLAGS petsc_cpp_line) + petsc_get_variable (PETSC_INCLUDE petsc_include) + petsc_get_variable (PCC petsc_cc) + petsc_get_variable (MPIEXEC petsc_mpiexec) + # We are done with the temporary Makefile, calling PETSC_GET_VARIABLE after this point is invalid! + file (REMOVE ${petsc_config_makefile}) + + include (ResolveCompilerPaths) + # Extract include paths and libraries from compile command line + resolve_includes (petsc_includes_all "${petsc_cpp_line}") + + macro (PETSC_FIND_LIBRARY suffix name) + set (PETSC_LIBRARY_${suffix} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) # Clear any stale value, if we got here, we need to find it again + find_library (PETSC_LIBRARY_${suffix} NAMES ${name} HINTS ${petsc_lib_dir} NO_DEFAULT_PATH) + set (PETSC_LIBRARIES_${suffix} "${PETSC_LIBRARY_${suffix}}") + mark_as_advanced (PETSC_LIBRARY_${suffix}) + endmacro (PETSC_FIND_LIBRARY suffix name) + + # Look for petscvec first, if it doesn't exist, we must be using single-library + petsc_find_library (VEC petscvec) + if (PETSC_LIBRARY_VEC) + petsc_find_library (SYS "petscsys;petsc") # libpetscsys is called libpetsc prior to 3.1 (when single-library was introduced) + petsc_find_library (MAT petscmat) + petsc_find_library (DM petscdm) + petsc_find_library (KSP petscksp) + petsc_find_library (SNES petscsnes) + petsc_find_library (TS petscts) + macro (PETSC_JOIN libs deps) + list (APPEND PETSC_LIBRARIES_${libs} ${PETSC_LIBRARIES_${deps}}) + endmacro (PETSC_JOIN libs deps) + petsc_join (VEC SYS) + petsc_join (MAT VEC) + petsc_join (DM MAT) + petsc_join (KSP DM) + petsc_join (SNES KSP) + petsc_join (TS SNES) + petsc_join (ALL TS) + else () + set (PETSC_LIBRARY_VEC "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) # There is no libpetscvec + petsc_find_library (SINGLE petsc) + foreach (pkg SYS VEC MAT DM KSP SNES TS ALL) + set (PETSC_LIBRARIES_${pkg} "${PETSC_LIBRARY_SINGLE}") + endforeach () + endif () + if (PETSC_LIBRARY_TS) + message (STATUS "Recognized PETSc install with separate libraries for each package") + else () + message (STATUS "Recognized PETSc install with single library for all packages") + endif () + + include(Check${PETSC_LANGUAGE_BINDINGS}SourceRuns) + macro (PETSC_TEST_RUNS includes libraries runs) + if(${PETSC_LANGUAGE_BINDINGS} STREQUAL "C") + set(_PETSC_ERR_FUNC "CHKERRQ(ierr)") + elseif(${PETSC_LANGUAGE_BINDINGS} STREQUAL "CXX") + set(_PETSC_ERR_FUNC "CHKERRXX(ierr)") + endif() + if (PETSC_VERSION VERSION_GREATER 3.1) + set (_PETSC_TSDestroy "TSDestroy(&ts)") + else () + set (_PETSC_TSDestroy "TSDestroy(ts)") + endif () + + set(_PETSC_TEST_SOURCE " +static const char help[] = \"PETSc test program.\"; +#include <petscts.h> +int main(int argc,char *argv[]) { +PetscErrorCode ierr; +TS ts; + +ierr = PetscInitialize(&argc,&argv,0,help);${_PETSC_ERR_FUNC}; +ierr = TSCreate(PETSC_COMM_WORLD,&ts);${_PETSC_ERR_FUNC}; +ierr = TSSetFromOptions(ts);${_PETSC_ERR_FUNC}; +ierr = ${_PETSC_TSDestroy};${_PETSC_ERR_FUNC}; +ierr = PetscFinalize();${_PETSC_ERR_FUNC}; +return 0; +} +") + multipass_source_runs ("${includes}" "${libraries}" "${_PETSC_TEST_SOURCE}" ${runs} "${PETSC_LANGUAGE_BINDINGS}") + if (${${runs}}) + set (PETSC_EXECUTABLE_RUNS "YES" CACHE BOOL + "Can the system successfully run a PETSc executable? This variable can be manually set to \"YES\" to force CMake to accept a given PETSc configuration, but this will almost always result in a broken build. If you change PETSC_DIR, PETSC_ARCH, or PETSC_CURRENT you would have to reset this variable." FORCE) + endif (${${runs}}) + endmacro (PETSC_TEST_RUNS) + + find_path (PETSC_INCLUDE_DIR petscts.h HINTS "${PETSC_DIR}" PATH_SUFFIXES include NO_DEFAULT_PATH) + find_path (PETSC_INCLUDE_CONF petscconf.h HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/include" "bmake/${PETSC_ARCH}" NO_DEFAULT_PATH) + mark_as_advanced (PETSC_INCLUDE_DIR PETSC_INCLUDE_CONF) + set (petsc_includes_minimal ${PETSC_INCLUDE_CONF} ${PETSC_INCLUDE_DIR}) + + petsc_test_runs ("${petsc_includes_minimal}" "${PETSC_LIBRARIES_TS}" petsc_works_minimal) + if (petsc_works_minimal) + message (STATUS "Minimal PETSc includes and libraries work. This probably means we are building with shared libs.") + set (petsc_includes_needed "${petsc_includes_minimal}") + else (petsc_works_minimal) # Minimal includes fail, see if just adding full includes fixes it + petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_allincludes) + if (petsc_works_allincludes) # It does, we just need all the includes ( + message (STATUS "PETSc requires extra include paths, but links correctly with only interface libraries. This is an unexpected configuration (but it seems to work fine).") + set (petsc_includes_needed ${petsc_includes_all}) + else (petsc_works_allincludes) # We are going to need to link the external libs explicitly + resolve_libraries (petsc_libraries_external "${petsc_libs_external}") + foreach (pkg SYS VEC MAT DM KSP SNES TS ALL) + list (APPEND PETSC_LIBRARIES_${pkg} ${petsc_libraries_external}) + endforeach (pkg) + petsc_test_runs ("${petsc_includes_minimal}" "${PETSC_LIBRARIES_TS}" petsc_works_alllibraries) + if (petsc_works_alllibraries) + message (STATUS "PETSc only need minimal includes, but requires explicit linking to all dependencies. This is expected when PETSc is built with static libraries.") + set (petsc_includes_needed ${petsc_includes_minimal}) + else (petsc_works_alllibraries) + # It looks like we really need everything, should have listened to Matt + set (petsc_includes_needed ${petsc_includes_all}) + petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_all) + if (petsc_works_all) # We fail anyways + message (STATUS "PETSc requires extra include paths and explicit linking to all dependencies. This probably means you have static libraries and something unexpected in PETSc headers.") + else (petsc_works_all) # We fail anyways + message (STATUS "PETSc could not be used, maybe the install is broken.") + endif (petsc_works_all) + endif (petsc_works_alllibraries) + endif (petsc_works_allincludes) + endif (petsc_works_minimal) + + # We do an out-of-source build so __FILE__ will be an absolute path, hence __INSDIR__ is superfluous + if (${PETSC_VERSION} VERSION_LESS 3.1) + set (PETSC_DEFINITIONS "-D__SDIR__=\"\"" CACHE STRING "PETSc definitions" FORCE) + else () + set (PETSC_DEFINITIONS "-D__INSDIR__=" CACHE STRING "PETSc definitions" FORCE) + endif () + # Sometimes this can be used to assist FindMPI.cmake + set (PETSC_MPIEXEC ${petsc_mpiexec} CACHE FILEPATH "Executable for running PETSc MPI programs" FORCE) + set (PETSC_INCLUDES ${petsc_includes_needed} CACHE STRING "PETSc include path" FORCE) + set (PETSC_LIBRARIES ${PETSC_LIBRARIES_ALL} CACHE STRING "PETSc libraries" FORCE) + set (PETSC_COMPILER ${petsc_cc} CACHE FILEPATH "PETSc compiler" FORCE) + # Note that we have forced values for all these choices. If you + # change these, you are telling the system to trust you that they + # work. It is likely that you will end up with a broken build. + mark_as_advanced (PETSC_INCLUDES PETSC_LIBRARIES PETSC_COMPILER PETSC_DEFINITIONS PETSC_MPIEXEC PETSC_EXECUTABLE_RUNS) +endif () + +######## +# MESSAGE( "PETSC_DIR : ${PETSC_DIR}") +# MESSAGE( "PETSC_ARCH : ${PETSC_ARCH}") +# MESSAGE( "PETSC_FOUND : ${PETSC_FOUND}") +# MESSAGE( "PETSC_INCLUDES : ${PETSC_INCLUDES}") +# MESSAGE( "PETSC_LIBRARIES : ${PETSC_LIBRARIES}") +# MESSAGE( "PETSC_COMPILER : ${PETSC_COMPILER}") +# MESSAGE( "PETSC_DEFINITIONS : ${PETSC_DEFINITIONS}") +# MESSAGE( "PETSC_MPIEXEC : ${PETSC_MPIEXEC}") +# MESSAGE( "PETSC_VERSION : ${PETSC_VERSION}") +# MESSAGE( "PETSC_EXECUTABLE_RUNS : ${PETSC_EXECUTABLE_RUNS}") + +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args (PETSc + "PETSc could not be found. Be sure to set PETSC_DIR and PETSC_ARCH." + PETSC_INCLUDES PETSC_LIBRARIES PETSC_EXECUTABLE_RUNS) diff --git a/modules/find/FindPTSCOTCH.cmake b/modules/find/FindPTSCOTCH.cmake new file mode 100644 index 0000000..1396d05 --- /dev/null +++ b/modules/find/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/modules/find/FindQUARK.cmake b/modules/find/FindQUARK.cmake new file mode 100644 index 0000000..adc5b65 --- /dev/null +++ b/modules/find/FindQUARK.cmake @@ -0,0 +1,325 @@ +### +# +# @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 QUARK include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(QUARK +# [REQUIRED] # Fail with error if quark is not found +# [COMPONENTS <comp1> <comp2> ...] # dependencies +# ) +# +# QUARK depends on the following libraries: +# - Threads +# +# COMPONENTS are optional libraries QUARK could be linked with, +# Use it to drive detection of a specific compilation chain +# COMPONENTS can be some of the following: +# - HWLOC: to activate detection of QUARK linked with hwloc +# +# This module finds headers and quark library. +# Results are reported in variables: +# QUARK_FOUND - True if headers and requested libraries were found +# QUARK_INCLUDE_DIRS - quark include directories +# QUARK_LIBRARY_DIRS - Link directories for quark libraries +# QUARK_LIBRARIES - quark component libraries to be linked +# QUARK_INCLUDE_DIRS_DEP - quark + dependencies include directories +# QUARK_LIBRARY_DIRS_DEP - quark + dependencies link directories +# QUARK_LIBRARIES_DEP - quark libraries + dependencies +# +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DQUARK=path/to/quark): +# QUARK_DIR - Where to find the base directory of quark +# QUARK_INCDIR - Where to find the header files +# QUARK_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: QUARK_DIR, QUARK_INCDIR, QUARK_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.) + + +if (NOT QUARK_FOUND) + set(QUARK_DIR "" CACHE PATH "Installation directory of QUARK library") + if (NOT QUARK_FIND_QUIETLY) + message(STATUS "A cache variable, namely QUARK_DIR, has been set to specify the install directory of QUARK") + endif() +endif() + +# QUARK may depend on HWLOC +# try to find it specified as COMPONENTS during the call +set(QUARK_LOOK_FOR_HWLOC FALSE) + +if( QUARK_FIND_COMPONENTS ) + foreach( component ${QUARK_FIND_COMPONENTS} ) + if(${component} STREQUAL "HWLOC") + set(QUARK_LOOK_FOR_HWLOC TRUE) + endif() + endforeach() +endif() + +# QUARK may depend on Threads, try to find it +if (NOT Threads_FOUND) + if (QUARK_FIND_REQUIRED) + find_package(Threads REQUIRED) + else() + find_package(Threads) + endif() +endif() + +# QUARK may depend on HWLOC, try to find it +if (NOT HWLOC_FOUND AND QUARK_LOOK_FOR_HWLOC) + if (QUARK_FIND_REQUIRED AND QUARK_FIND_REQUIRED_HWLOC) + find_package(HWLOC REQUIRED) + else() + find_package(HWLOC) + endif() +endif() + +# Looking for include +# ------------------- + +# Add system include paths to search include +# ------------------------------------------ +unset(_inc_env) +set(ENV_QUARK_DIR "$ENV{QUARK_DIR}") +set(ENV_QUARK_INCDIR "$ENV{QUARK_INCDIR}") +if(ENV_QUARK_INCDIR) + list(APPEND _inc_env "${ENV_QUARK_INCDIR}") +elseif(ENV_QUARK_DIR) + list(APPEND _inc_env "${ENV_QUARK_DIR}") + list(APPEND _inc_env "${ENV_QUARK_DIR}/include") + list(APPEND _inc_env "${ENV_QUARK_DIR}/include/quark") + list(APPEND _inc_env "${ENV_QUARK_DIR}/include/plasma") +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 quark header in the given paths +# ------------------------------------------------- +# call cmake macro to find the header path +if(QUARK_INCDIR) + set(QUARK_quark.h_DIRS "QUARK_quark.h_DIRS-NOTFOUND") + find_path(QUARK_quark.h_DIRS + NAMES quark.h + HINTS ${QUARK_INCDIR}) +else() + if(QUARK_DIR) + set(QUARK_quark.h_DIRS "QUARK_quark.h_DIRS-NOTFOUND") + find_path(QUARK_quark.h_DIRS + NAMES quark.h + HINTS ${QUARK_DIR} + PATH_SUFFIXES "include" "include/quark" "include/plasma") + else() + set(QUARK_quark.h_DIRS "QUARK_quark.h_DIRS-NOTFOUND") + find_path(QUARK_quark.h_DIRS + NAMES quark.h + HINTS ${_inc_env}) + endif() +endif() +mark_as_advanced(QUARK_quark.h_DIRS) + +# If found, add path to cmake variable +# ------------------------------------ +if (QUARK_quark.h_DIRS) + set(QUARK_INCLUDE_DIRS "${QUARK_quark.h_DIRS}") +else () + set(QUARK_INCLUDE_DIRS "QUARK_INCLUDE_DIRS-NOTFOUND") + if(NOT QUARK_FIND_QUIETLY) + message(STATUS "Looking for quark -- quark.h not found") + endif() +endif() + + +# Looking for lib +# --------------- + +# Add system library paths to search lib +# -------------------------------------- +unset(_lib_env) +set(ENV_QUARK_LIBDIR "$ENV{QUARK_LIBDIR}") +if(ENV_QUARK_LIBDIR) + list(APPEND _lib_env "${ENV_QUARK_LIBDIR}") +elseif(ENV_QUARK_DIR) + list(APPEND _lib_env "${ENV_QUARK_DIR}") + list(APPEND _lib_env "${ENV_QUARK_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 quark lib in the given paths +# ---------------------------------------------- + +# call cmake macro to find the lib path +if(QUARK_LIBDIR) + set(QUARK_quark_LIBRARY "QUARK_quark_LIBRARY-NOTFOUND") + find_library(QUARK_quark_LIBRARY + NAMES quark + HINTS ${QUARK_LIBDIR}) +else() + if(QUARK_DIR) + set(QUARK_quark_LIBRARY "QUARK_quark_LIBRARY-NOTFOUND") + find_library(QUARK_quark_LIBRARY + NAMES quark + HINTS ${QUARK_DIR} + PATH_SUFFIXES lib lib32 lib64) + else() + set(QUARK_quark_LIBRARY "QUARK_quark_LIBRARY-NOTFOUND") + find_library(QUARK_quark_LIBRARY + NAMES quark + HINTS ${_lib_env}) + endif() +endif() +mark_as_advanced(QUARK_quark_LIBRARY) + +# If found, add path to cmake variable +# ------------------------------------ +if (QUARK_quark_LIBRARY) + get_filename_component(quark_lib_path "${QUARK_quark_LIBRARY}" PATH) + # set cmake variables + set(QUARK_LIBRARIES "${QUARK_quark_LIBRARY}") + set(QUARK_LIBRARY_DIRS "${quark_lib_path}") +else () + set(QUARK_LIBRARIES "QUARK_LIBRARIES-NOTFOUND") + set(QUARK_LIBRARY_DIRS "QUARK_LIBRARY_DIRS-NOTFOUND") + if(NOT QUARK_FIND_QUIETLY) + message(STATUS "Looking for quark -- lib quark not found") + endif() +endif () + +# check a function to validate the find +if(QUARK_LIBRARIES) + + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # QUARK + if (QUARK_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${QUARK_INCLUDE_DIRS}") + endif() + if (QUARK_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${QUARK_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${QUARK_LIBRARIES}") + # HWLOC + if (HWLOC_FOUND AND QUARK_LOOK_FOR_HWLOC) + if (HWLOC_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${HWLOC_INCLUDE_DIRS}") + endif() + if (HWLOC_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${HWLOC_LIBRARY_DIRS}") + endif() + 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() + # THREADS + list(APPEND REQUIRED_LIBS "${CMAKE_THREAD_LIBS_INIT}") + + # 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(QUARK_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(QUARK_New QUARK_WORKS) + mark_as_advanced(QUARK_WORKS) + + if(QUARK_WORKS) + # save link with dependencies + set(QUARK_LIBRARIES_DEP "${REQUIRED_LIBS}") + set(QUARK_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(QUARK_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + list(REMOVE_DUPLICATES QUARK_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES QUARK_INCLUDE_DIRS_DEP) + else() + if(NOT QUARK_FIND_QUIETLY) + message(STATUS "Looking for QUARK : test of QUARK_New with QUARK library fails") + 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 QUARK is linked with specific libraries like. " + "Have you tried with COMPONENTS (HWLOC)? See the explanation in FindQUARK.cmake.") + endif() + endif() + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_LIBRARIES) +endif(QUARK_LIBRARIES) + +if (QUARK_LIBRARIES) + list(GET QUARK_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(QUARK_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of QUARK library" FORCE) + else() + set(QUARK_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of QUARK library" FORCE) + endif() +endif() +mark_as_advanced(QUARK_DIR) +mark_as_advanced(QUARK_DIR_FOUND) + +# check that QUARK has been found +# --------------------------------- +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(QUARK DEFAULT_MSG + QUARK_LIBRARIES + QUARK_WORKS) diff --git a/modules/find/FindSCALAPACK.cmake b/modules/find/FindSCALAPACK.cmake new file mode 100644 index 0000000..5a96239 --- /dev/null +++ b/modules/find/FindSCALAPACK.cmake @@ -0,0 +1,489 @@ +### +# +# @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 SCALAPACK library +# This module finds an installed fortran library that implements the SCALAPACK +# linear-algebra interface. +# +# This module sets the following variables: +# SCALAPACK_FOUND - set to true if a library implementing the SCALAPACK interface +# is found +# SCALAPACK_LINKER_FLAGS - uncached list of required linker flags (excluding -l +# and -L). +# SCALAPACK_LIBRARIES - uncached list of libraries (using full path name) to +# link against to use SCALAPACK +# SCALAPACK95_LIBRARIES - uncached list of libraries (using full path name) to +# link against to use SCALAPACK95 +# SCALAPACK95_FOUND - set to true if a library implementing the SCALAPACK 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 +# BLA_F95 if set on tries to find the f95 interfaces for BLAS/SCALAPACK +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DSCALAPACK_DIR=path/to/scalapack): +# SCALAPACK_DIR - Where to find the base directory of scalapack +# SCALAPACK_INCDIR - Where to find the header files +# SCALAPACK_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: SCALAPACK_DIR, SCALAPACK_INCDIR, SCALAPACK_LIBDIR +# Note that if BLAS_DIR is set, it will also look for scalapack in it +### List of vendors (BLA_VENDOR) valid in this module +## Intel(mkl), ACML, Apple, NAS, Generic + +#============================================================================= +# 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 the 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() + +if (NOT SCALAPACK_FOUND) + set(SCALAPACK_DIR "" CACHE PATH "Installation directory of SCALAPACK library") + if (NOT SCALAPACK_FIND_QUIETLY) + message(STATUS "A cache variable, namely SCALAPACK_DIR, has been set to specify the install directory of SCALAPACK") + endif() +endif (NOT SCALAPACK_FOUND) + +option(SCALAPACK_VERBOSE "Print some additional information during SCALAPACK +libraries detection" OFF) +mark_as_advanced(SCALAPACK_VERBOSE) +if (BLAS_VERBOSE) + set(SCALAPACK_VERBOSE ON) +endif () +set(_scalapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + +get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES) +if (NOT _LANGUAGES_ MATCHES Fortran) + include(CheckFunctionExists) +else (NOT _LANGUAGES_ MATCHES Fortran) + include(CheckFortranFunctionExists) +endif (NOT _LANGUAGES_ MATCHES Fortran) + +set(SCALAPACK_FOUND FALSE) +set(SCALAPACK95_FOUND FALSE) + +# TODO: move this stuff to separate module + +macro(Check_Scalapack_Libraries LIBRARIES _prefix _name _flags _list _blaslapack _mpi _threads) + # 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(_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}") + set(ENV_SCALAPACK_DIR "$ENV{SCALAPACK_DIR}") + set(ENV_SCALAPACK_LIBDIR "$ENV{SCALAPACK_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() + endif() + if (SCALAPACK_LIBDIR) + list(APPEND _libdir "${SCALAPACK_LIBDIR}") + elseif (SCALAPACK_DIR) + list(APPEND _libdir "${SCALAPACK_DIR}") + list(APPEND _libdir "${SCALAPACK_DIR}/lib") + if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + list(APPEND _libdir "${SCALAPACK_DIR}/lib64") + list(APPEND _libdir "${SCALAPACK_DIR}/lib/intel64") + else() + list(APPEND _libdir "${SCALAPACK_DIR}/lib32") + list(APPEND _libdir "${SCALAPACK_DIR}/lib/ia32") + endif() + elseif(ENV_SCALAPACK_LIBDIR) + list(APPEND _libdir "${ENV_SCALAPACK_LIBDIR}") + elseif(ENV_SCALAPACK_DIR) + list(APPEND _libdir "${ENV_SCALAPACK_DIR}") + list(APPEND _libdir "${ENV_SCALAPACK_DIR}/lib") + if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + list(APPEND _libdir "${ENV_SCALAPACK_DIR}/lib64") + list(APPEND _libdir "${ENV_SCALAPACK_DIR}/lib/intel64") + else() + list(APPEND _libdir "${ENV_SCALAPACK_DIR}/lib32") + list(APPEND _libdir "${ENV_SCALAPACK_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 (SCALAPACK_VERBOSE) + message("${Cyan}Try to find SCALAPACK libraries: ${_list}") + endif () + + foreach(_library ${_list}) + set(_combined_name ${_combined_name}_${_library}) + + if(_libraries_work) + if (BLA_STATIC) + if (WIN32) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) + endif ( WIN32 ) + if (APPLE) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else (APPLE) + set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + endif (APPLE) + else (BLA_STATIC) + if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + # for ubuntu's libblas3gf and libscalapack3gf packages + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf) + endif () + endif (BLA_STATIC) + find_library(${_prefix}_${_library}_LIBRARY + NAMES ${_library} + HINTS ${_libdir} + ) + mark_as_advanced(${_prefix}_${_library}_LIBRARY) + # Print status if not found + # ------------------------- + if (NOT ${_prefix}_${_library}_LIBRARY AND NOT SCALAPACK_FIND_QUIETLY AND SCALAPACK_VERBOSE) + Print_Find_Library_Blas_Status(scalapack ${_library} ${_libdir}) + endif () + set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY}) + set(_libraries_work ${${_prefix}_${_library}_LIBRARY}) + endif(_libraries_work) + endforeach(_library ${_list}) + + if(_libraries_work) + # Test this combination of libraries. + if(UNIX AND BLA_STATIC) + set(CMAKE_REQUIRED_LIBRARIES ${_flags} "-Wl,--start-group" ${${LIBRARIES}} ${_blaslapack} "-Wl,--end-group" ${_mpi} ${_threads}) + else(UNIX AND BLA_STATIC) + set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blaslapack} ${_mpi} ${_threads}) + endif(UNIX AND BLA_STATIC) + if (SCALAPACK_VERBOSE) + message("${Cyan}SCALAPACK libs found. Try to compile symbol ${_name} with" + "following libraries: ${CMAKE_REQUIRED_LIBRARIES}") + endif () + if(NOT SCALAPACK_FOUND) + unset(${_prefix}${_combined_name}_WORKS CACHE) + endif() + if (NOT _LANGUAGES_ MATCHES Fortran) + check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS) + else (NOT _LANGUAGES_ MATCHES Fortran) + check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS) + endif (NOT _LANGUAGES_ MATCHES Fortran) + set(CMAKE_REQUIRED_LIBRARIES) + mark_as_advanced(${_prefix}${_combined_name}_WORKS) + set(_libraries_work ${${_prefix}${_combined_name}_WORKS}) + endif(_libraries_work) + + if(_libraries_work) + set(${LIBRARIES} ${${LIBRARIES}} ${_blaslapack} ${_mpi} ${_threads}) + else(_libraries_work) + set(${LIBRARIES} FALSE) + endif(_libraries_work) + +endmacro(Check_Scalapack_Libraries) + + +set(SCALAPACK_LINKER_FLAGS) +set(SCALAPACK_LIBRARIES) +set(SCALAPACK95_LIBRARIES) + +if (NOT BLAS_FOUND) + if(SCALAPACK_FIND_QUIETLY OR NOT SCALAPACK_FIND_REQUIRED) + find_package(BLASEXT) + else() + find_package(BLASEXT REQUIRED) + endif() +endif () + +if (NOT LAPACK_FOUND) + if(SCALAPACK_FIND_QUIETLY OR NOT SCALAPACK_FIND_REQUIRED) + find_package(LAPACKEXT) + else() + find_package(LAPACKEXT REQUIRED) + endif() +endif () + +if (NOT MPI_FOUND) + if(SCALAPACK_FIND_QUIETLY OR NOT SCALAPACK_FIND_REQUIRED) + find_package(MPI) + else() + find_package(MPI REQUIRED) + endif() +endif () + +if(BLAS_FOUND AND LAPACK_FOUND AND MPI_FOUND) + set(SCALAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS}) + list(APPEND SCALAPACK_LINKER_FLAGS ${LAPACK_LINKER_FLAGS}) + if ($ENV{BLA_VENDOR} MATCHES ".+") + set(BLA_VENDOR $ENV{BLA_VENDOR}) + else ($ENV{BLA_VENDOR} MATCHES ".+") + if(NOT BLA_VENDOR) + set(BLA_VENDOR "All") + endif(NOT BLA_VENDOR) + endif ($ENV{BLA_VENDOR} MATCHES ".+") + + # Generic SCALAPACK library + if (BLA_VENDOR STREQUAL "Generic" OR + BLA_VENDOR STREQUAL "All") + if ( NOT SCALAPACK_LIBRARIES ) + check_scalapack_libraries( + SCALAPACK_LIBRARIES + SCALAPACK + pdgemm + "" + "scalapack" # scalapack lib to look for + "${LAPACK_LIBRARIES};${BLAS_LIBRARIES}" # blas and lapack libs + "${MPI_Fortran_LIBRARIES}" # mpi libs + "" # threads libs + ) + endif ( NOT SCALAPACK_LIBRARIES ) + endif () + #intel scalapack + if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") + if (UNIX AND NOT WIN32) + find_library(M_LIBRARY NAMES m) + mark_as_advanced(M_LIBRARY) + if(M_LIBRARY) + set(LM "-lm") + else() + set(LM "") + endif() + endif () + if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) + if(SCALAPACK_FIND_QUIETLY OR NOT SCALAPACK_FIND_REQUIRED) + find_PACKAGE(Threads) + else() + find_package(Threads REQUIRED) + endif() + + set(SCALAPACK_SEARCH_LIBS "") + + if (BLA_F95) + set(SCALAPACK_mkl_SEARCH_SYMBOL "PDGEMM") + set(_LIBRARIES SCALAPACK95_LIBRARIES) + set(_BLAS_LIBRARIES ${BLAS95_LIBRARIES}) + list(APPEND SCALAPACK_SEARCH_LIBS "mkl_scalapack_lp64") + else() + set(SCALAPACK_mkl_SEARCH_SYMBOL "pdgemm") + set(_LIBRARIES SCALAPACK_LIBRARIES) + set(_BLAS_LIBRARIES ${BLAS_LIBRARIES}) + list(APPEND SCALAPACK_SEARCH_LIBS "mkl_scalapack_lp64") + endif() + + # First try empty scalapack libs + if (NOT ${_LIBRARIES}) + check_scalapack_libraries( + ${_LIBRARIES} + BLAS + ${SCALAPACK_mkl_SEARCH_SYMBOL} + "" + "" + "${_BLAS_LIBRARIES}" + "" + "${MPI_Fortran_LIBRARIES}" + ) + endif () + # Then try the search libs + foreach (IT ${SCALAPACK_SEARCH_LIBS}) + if (NOT ${_LIBRARIES}) + check_scalapack_libraries( + ${_LIBRARIES} + BLAS + ${SCALAPACK_mkl_SEARCH_SYMBOL} + "" + "${IT};mkl_blacs_intelmpi_lp64" + "${_BLAS_LIBRARIES}" + "" + "${MPI_Fortran_LIBRARIES}" + ) + endif () + endforeach () + endif () + endif() +else(BLAS_FOUND AND LAPACK_FOUND AND MPI_FOUND) + message(STATUS "SCALAPACK requires BLAS, LAPACK, and MPI") +endif(BLAS_FOUND AND LAPACK_FOUND AND MPI_FOUND) + +if(BLA_F95) + if(SCALAPACK95_LIBRARIES) + set(SCALAPACK95_FOUND TRUE) + else(SCALAPACK95_LIBRARIES) + set(SCALAPACK95_FOUND FALSE) + endif(SCALAPACK95_LIBRARIES) + if(NOT SCALAPACK_FIND_QUIETLY) + if(SCALAPACK95_FOUND) + message(STATUS "A library with SCALAPACK95 API found.") + message(STATUS "SCALAPACK_LIBRARIES ${SCALAPACK_LIBRARIES}") + else(SCALAPACK95_FOUND) + message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but SCALAPACK 95 libraries could not be found or check of symbols failed." + "\nPlease indicate where to find SCALAPACK libraries. You have three options:\n" + "- Option 1: Provide the installation directory of SCALAPACK library with cmake option: -DSCALAPACK_DIR=your/path/to/scalapack\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 -DSCALAPACK_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(SCALAPACK_FIND_REQUIRED) + message(FATAL_ERROR + "A required library with SCALAPACK95 API not found. Please specify library location." + ) + else(SCALAPACK_FIND_REQUIRED) + message(STATUS + "A library with SCALAPACK95 API not found. Please specify library location." + ) + endif(SCALAPACK_FIND_REQUIRED) + endif(SCALAPACK95_FOUND) + endif(NOT SCALAPACK_FIND_QUIETLY) + set(SCALAPACK_FOUND "${SCALAPACK95_FOUND}") + set(SCALAPACK_LIBRARIES "${SCALAPACK95_LIBRARIES}") +else(BLA_F95) + if(SCALAPACK_LIBRARIES) + set(SCALAPACK_FOUND TRUE) + else(SCALAPACK_LIBRARIES) + set(SCALAPACK_FOUND FALSE) + endif(SCALAPACK_LIBRARIES) + + if(NOT SCALAPACK_FIND_QUIETLY) + if(SCALAPACK_FOUND) + message(STATUS "A library with SCALAPACK API found.") + message(STATUS "SCALAPACK_LIBRARIES ${SCALAPACK_LIBRARIES}") + else(SCALAPACK_FOUND) + message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but SCALAPACK libraries could not be found or check of symbols failed." + "\nPlease indicate where to find SCALAPACK libraries. You have three options:\n" + "- Option 1: Provide the installation directory of SCALAPACK library with cmake option: -DSCALAPACK_DIR=your/path/to/scalapack\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 -DSCALAPACK_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(SCALAPACK_FIND_REQUIRED) + message(FATAL_ERROR + "A required library with SCALAPACK API not found. Please specify library location." + ) + else(SCALAPACK_FIND_REQUIRED) + message(STATUS + "A library with SCALAPACK API not found. Please specify library location." + ) + endif(SCALAPACK_FIND_REQUIRED) + endif(SCALAPACK_FOUND) + endif(NOT SCALAPACK_FIND_QUIETLY) +endif(BLA_F95) + +set(CMAKE_FIND_LIBRARY_SUFFIXES ${_scalapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) + +if (SCALAPACK_LIBRARIES) + list(GET SCALAPACK_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(SCALAPACK_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of SCALAPACK library" FORCE) + else() + set(SCALAPACK_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of SCALAPACK library" FORCE) + endif() +endif() +mark_as_advanced(SCALAPACK_DIR) +mark_as_advanced(SCALAPACK_DIR_FOUND) diff --git a/modules/find/FindSCOTCH.cmake b/modules/find/FindSCOTCH.cmake new file mode 100644 index 0000000..89d295a --- /dev/null +++ b/modules/find/FindSCOTCH.cmake @@ -0,0 +1,369 @@ +### +# +# @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 + +#============================================================================= +# 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 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) + + +# 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_LIBRARIES + SCOTCH_WORKS) +# +# TODO: Add possibility to check for specific functions in the library +# diff --git a/modules/find/FindSIMGRID.cmake b/modules/find/FindSIMGRID.cmake new file mode 100644 index 0000000..89e2982 --- /dev/null +++ b/modules/find/FindSIMGRID.cmake @@ -0,0 +1,310 @@ +### +# +# @copyright (c) 2009-2014 The University of Tennessee and The University +# of Tennessee Research Foundation. +# All rights reserved. +# @copyright (c) 2012-2015 Inria. All rights reserved. +# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved. +# +### +# +# - Find SIMGRID include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(SIMGRID +# [REQUIRED]) # Fail with error if simgrid is not found +# +# This module finds headers and simgrid library. +# Results are reported in variables: +# SIMGRID_FOUND - True if headers and requested libraries were found +# SIMGRID_INCLUDE_DIRS - simgrid include directories +# SIMGRID_LIBRARY_DIRS - Link directories for simgrid libraries +# SIMGRID_LIBRARIES - simgrid 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 -DSIMGRID_DIR=path/to/simgrid): +# SIMGRID_DIR - Where to find the base directory of simgrid +# SIMGRID_INCDIR - Where to find the header files +# SIMGRID_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: SIMGRID_DIR, SIMGRID_INCDIR, SIMGRID_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.) + +if (NOT SIMGRID_FOUND) + set(SIMGRID_DIR "" CACHE PATH "Installation directory of SIMGRID library") + if (NOT SIMGRID_FIND_QUIETLY) + message(STATUS "A cache variable, namely SIMGRID_DIR, has been set to specify the install directory of SIMGRID") + endif() +endif() + +set(ENV_SIMGRID_DIR "$ENV{SIMGRID_DIR}") +set(ENV_SIMGRID_INCDIR "$ENV{SIMGRID_INCDIR}") +set(ENV_SIMGRID_LIBDIR "$ENV{SIMGRID_LIBDIR}") +set(SIMGRID_GIVEN_BY_USER "FALSE") +if ( SIMGRID_DIR OR ( SIMGRID_INCDIR AND SIMGRID_LIBDIR) OR ENV_SIMGRID_DIR OR (ENV_SIMGRID_INCDIR AND ENV_SIMGRID_LIBDIR) ) + set(SIMGRID_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 SIMGRID_GIVEN_BY_USER) + + pkg_search_module(SIMGRID simgrid) + if (NOT SIMGRID_FIND_QUIETLY) + if (SIMGRID_FOUND AND SIMGRID_LIBRARIES) + message(STATUS "Looking for SIMGRID - found using PkgConfig") + #if(NOT SIMGRID_INCLUDE_DIRS) + # message("${Magenta}SIMGRID_INCLUDE_DIRS is empty using PkgConfig." + # "Perhaps the path to simgrid headers is already present in your" + # "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}") + #endif() + else() + message(STATUS "${Magenta}Looking for SIMGRID - not found using PkgConfig." + "\n Perhaps you should add the directory containing simgrid.pc to the" + "\n PKG_CONFIG_PATH environment variable.${ColourReset}") + endif() + endif() + +endif(PKG_CONFIG_EXECUTABLE AND NOT SIMGRID_GIVEN_BY_USER) + +if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT SIMGRID_FOUND) OR (SIMGRID_GIVEN_BY_USER) ) + + if (NOT SIMGRID_FIND_QUIETLY) + message(STATUS "Looking for SIMGRID - PkgConfig not used") + endif() + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + unset(_inc_env) + set(ENV_SIMGRID_DIR "$ENV{SIMGRID_DIR}") + set(ENV_SIMGRID_INCDIR "$ENV{SIMGRID_INCDIR}") + if(ENV_SIMGRID_INCDIR) + list(APPEND _inc_env "${ENV_SIMGRID_INCDIR}") + elseif(ENV_SIMGRID_DIR) + list(APPEND _inc_env "${ENV_SIMGRID_DIR}") + list(APPEND _inc_env "${ENV_SIMGRID_DIR}/include") + list(APPEND _inc_env "${ENV_SIMGRID_DIR}/include/simgrid") + 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 simgrid header in the given paths + # ------------------------------------------------- + # call cmake macro to find the header path + if(SIMGRID_INCDIR) + set(SIMGRID_simgrid.h_DIRS "SIMGRID_simgrid.h_DIRS-NOTFOUND") + find_path(SIMGRID_simgrid.h_DIRS + NAMES simgrid.h + HINTS ${SIMGRID_INCDIR}) + else() + if(SIMGRID_DIR) + set(SIMGRID_simgrid.h_DIRS "SIMGRID_simgrid.h_DIRS-NOTFOUND") + find_path(SIMGRID_simgrid.h_DIRS + NAMES simgrid.h + HINTS ${SIMGRID_DIR} + PATH_SUFFIXES "include" "include/simgrid") + else() + set(SIMGRID_simgrid.h_DIRS "SIMGRID_simgrid.h_DIRS-NOTFOUND") + find_path(SIMGRID_simgrid.h_DIRS + NAMES simgrid.h + HINTS ${_inc_env} + PATH_SUFFIXES "simgrid") + endif() + endif() + mark_as_advanced(SIMGRID_simgrid.h_DIRS) + + # Add path to cmake variable + # ------------------------------------ + if (SIMGRID_simgrid.h_DIRS) + set(SIMGRID_INCLUDE_DIRS "${SIMGRID_simgrid.h_DIRS}") + else () + set(SIMGRID_INCLUDE_DIRS "SIMGRID_INCLUDE_DIRS-NOTFOUND") + if(NOT SIMGRID_FIND_QUIETLY) + message(STATUS "Looking for simgrid -- simgrid.h not found") + endif() + endif () + + if (SIMGRID_INCLUDE_DIRS) + list(REMOVE_DUPLICATES SIMGRID_INCLUDE_DIRS) + endif () + + + # Looking for lib + # --------------- + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_SIMGRID_LIBDIR "$ENV{SIMGRID_LIBDIR}") + if(ENV_SIMGRID_LIBDIR) + list(APPEND _lib_env "${ENV_SIMGRID_LIBDIR}") + elseif(ENV_SIMGRID_DIR) + list(APPEND _lib_env "${ENV_SIMGRID_DIR}") + list(APPEND _lib_env "${ENV_SIMGRID_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 simgrid lib in the given paths + # ---------------------------------------------- + + # call cmake macro to find the lib path + if(SIMGRID_LIBDIR) + set(SIMGRID_simgrid_LIBRARY "SIMGRID_simgrid_LIBRARY-NOTFOUND") + find_library(SIMGRID_simgrid_LIBRARY + NAMES simgrid + HINTS ${SIMGRID_LIBDIR}) + else() + if(SIMGRID_DIR) + set(SIMGRID_simgrid_LIBRARY "SIMGRID_simgrid_LIBRARY-NOTFOUND") + find_library(SIMGRID_simgrid_LIBRARY + NAMES simgrid + HINTS ${SIMGRID_DIR} + PATH_SUFFIXES lib lib32 lib64) + else() + set(SIMGRID_simgrid_LIBRARY "SIMGRID_simgrid_LIBRARY-NOTFOUND") + find_library(SIMGRID_simgrid_LIBRARY + NAMES simgrid + HINTS ${_lib_env}) + endif() + endif() + mark_as_advanced(SIMGRID_simgrid_LIBRARY) + + # If found, add path to cmake variable + # ------------------------------------ + if (SIMGRID_simgrid_LIBRARY) + get_filename_component(simgrid_lib_path ${SIMGRID_simgrid_LIBRARY} PATH) + # set cmake variables (respects naming convention) + set(SIMGRID_LIBRARIES "${SIMGRID_simgrid_LIBRARY}") + set(SIMGRID_LIBRARY_DIRS "${simgrid_lib_path}") + else () + set(SIMGRID_LIBRARIES "SIMGRID_LIBRARIES-NOTFOUND") + set(SIMGRID_LIBRARY_DIRS "SIMGRID_LIBRARY_DIRS-NOTFOUND") + if(NOT SIMGRID_FIND_QUIETLY) + message(STATUS "Looking for simgrid -- lib simgrid not found") + endif() + endif () + + if (SIMGRID_LIBRARY_DIRS) + list(REMOVE_DUPLICATES SIMGRID_LIBRARY_DIRS) + endif () + + # check a function to validate the find + if(SIMGRID_LIBRARIES) + + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # SIMGRID + if (SIMGRID_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${SIMGRID_INCLUDE_DIRS}") + endif() + if (SIMGRID_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${SIMGRID_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${SIMGRID_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(SIMGRID_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(MSG_main SIMGRID_WORKS) + mark_as_advanced(SIMGRID_WORKS) + + if(NOT SIMGRID_WORKS) + if(NOT SIMGRID_FIND_QUIETLY) + message(STATUS "Looking for simgrid : test of fut_keychange with simgrid 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(SIMGRID_LIBRARIES) + +endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT SIMGRID_FOUND) OR (SIMGRID_GIVEN_BY_USER) ) + +if (SIMGRID_LIBRARIES) + if (SIMGRID_LIBRARY_DIRS) + list(GET SIMGRID_LIBRARY_DIRS 0 first_lib_path) + else() + list(GET SIMGRID_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(SIMGRID_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of SIMGRID library" FORCE) + else() + set(SIMGRID_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of SIMGRID library" FORCE) + endif() +endif() +mark_as_advanced(SIMGRID_DIR) +mark_as_advanced(SIMGRID_DIR_FOUND) + +# check that SIMGRID has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +if (PKG_CONFIG_EXECUTABLE AND SIMGRID_FOUND) + find_package_handle_standard_args(SIMGRID DEFAULT_MSG + SIMGRID_LIBRARIES) +else() + find_package_handle_standard_args(SIMGRID DEFAULT_MSG + SIMGRID_LIBRARIES + SIMGRID_WORKS) +endif() diff --git a/modules/find/FindSTARPU.cmake b/modules/find/FindSTARPU.cmake new file mode 100644 index 0000000..15973c7 --- /dev/null +++ b/modules/find/FindSTARPU.cmake @@ -0,0 +1,948 @@ +### +# +# @copyright (c) 2009-2014 The University of Tennessee and The University +# of Tennessee Research Foundation. +# All rights reserved. +# @copyright (c) 2012-2015 Inria. All rights reserved. +# @copyright (c) 2012-2016 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved. +# +### +# +# - Find STARPU include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(STARPU +# [version] [EXACT] # Minimum or EXACT version e.g. 1.1 +# [REQUIRED] # Fail with error if starpu is not found +# [COMPONENTS <comp1> <comp2> ...] # dependencies +# ) +# +# COMPONENTS are optional libraries STARPU could be linked with, +# Use it to drive detection of a specific compilation chain +# COMPONENTS can be some of the following: +# - HWLOC: to activate the detection of StarPU linked with HWLOC +# - CUDA: to activate the detection of StarPU linked with CUDA +# - MPI: to activate the detection of StarPU linked with MPI +# - BLAS: to activate the detection of StarPU linked with BLAS +# - MAGMA: to activate the detection of StarPU linked with MAGMA +# - FXT: to activate the detection of StarPU linked with FxT +# - SIMGRID: to activate the detection of StarPU linked with SimGrid +# +# Results are reported in variables: +# STARPU_FOUND - True if headers and requested libraries were found +# STARPU_C_FLAGS - list of required compilation flags (excluding -I) +# STARPU_LINKER_FLAGS - list of required linker flags (excluding -l and -L) +# STARPU_INCLUDE_DIRS - starpu include directories +# STARPU_LIBRARY_DIRS - Link directories for starpu libraries +# STARPU_LIBRARIES - starpu libraries +# STARPU_SHM_LIBRARIES - starpu libraries without libstarpumpi +# STARPU_MPI_LIBRARIES - starpu libraries with libstarpumpi +# STARPU_INCLUDE_DIRS_DEP - starpu + dependencies include directories +# STARPU_LIBRARY_DIRS_DEP - starpu + dependencies link directories +# STARPU_LIBRARIES_DEP - starpu libraries + dependencies +# STARPU_VERSION_STRING - A human-readable string containing the version of the package found +# STARPU_VERSION_MAJOR - The major version of the package found +# STARPU_VERSION_MINOR - The minor version of the package found +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DSTARPU=path/to/starpu): +# STARPU_DIR - Where to find the base directory of starpu +# STARPU_INCDIR - Where to find the header files +# STARPU_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: STARPU_DIR, STARPU_INCDIR, STARPU_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.) + +if (NOT STARPU_FOUND) + set(STARPU_DIR "" CACHE PATH "Installation directory of STARPU library") + if (NOT STARPU_FIND_QUIETLY) + message(STATUS "A cache variable, namely STARPU_DIR, has been set to specify the install directory of STARPU") + endif() +endif() + +# STARPU may depend on other packages (HWLOC, MPI, CUDA, BLAS, MAGMA, FXT, ...) +# try to find them if specified as COMPONENTS during the call +set(STARPU_LOOK_FOR_HWLOC FALSE) +set(STARPU_LOOK_FOR_CUDA FALSE) +set(STARPU_LOOK_FOR_MPI FALSE) +set(STARPU_LOOK_FOR_BLAS FALSE) +set(STARPU_LOOK_FOR_MAGMA FALSE) +set(STARPU_LOOK_FOR_FXT FALSE) +set(STARPU_LOOK_FOR_SIMGRID FALSE) + +if( STARPU_FIND_COMPONENTS ) + foreach( component ${STARPU_FIND_COMPONENTS} ) + if(${component} STREQUAL "HWLOC") + set(STARPU_LOOK_FOR_HWLOC TRUE) + elseif(${component} STREQUAL "CUDA") + set(STARPU_LOOK_FOR_CUDA TRUE) + elseif(${component} STREQUAL "MPI") + set(STARPU_LOOK_FOR_MPI TRUE) + elseif(${component} STREQUAL "BLAS") + set(STARPU_LOOK_FOR_BLAS TRUE) + elseif(${component} STREQUAL "MAGMA") + set(STARPU_LOOK_FOR_MAGMA TRUE) + elseif(${component} STREQUAL "FXT") + set(STARPU_LOOK_FOR_FXT TRUE) + elseif(${component} STREQUAL "SIMGRID") + set(STARPU_LOOK_FOR_SIMGRID TRUE) + endif() + endforeach() +endif() + +# STARPU may depend on pthread, try to find it +find_package(Threads) +if( THREADS_FOUND ) + list(APPEND STARPU_EXTRA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) +endif () +# STARPU may depend on libm, try to find it +find_library(M_m_LIBRARY NAMES m) +mark_as_advanced(M_m_LIBRARY) +if( M_m_LIBRARY ) + list(APPEND STARPU_EXTRA_LIBRARIES ${M_m_LIBRARY}) +endif () +# STARPU may depend on librt, try to find it +find_library(RT_rt_LIBRARY NAMES m) +mark_as_advanced(RT_rt_LIBRARY) +if( RT_rt_LIBRARY ) + list(APPEND STARPU_EXTRA_LIBRARIES ${RT_rt_LIBRARY}) +endif () + +# STARPU may depend on HWLOC, try to find it +if (NOT HWLOC_FOUND AND STARPU_LOOK_FOR_HWLOC) + if (STARPU_FIND_REQUIRED AND STARPU_FIND_REQUIRED_HWLOC) + find_package(HWLOC REQUIRED) + else() + find_package(HWLOC) + endif() +endif() + +# STARPU may depend on CUDA, try to find it +if (NOT CUDA_FOUND AND STARPU_LOOK_FOR_CUDA) + if (STARPU_FIND_REQUIRED AND STARPU_FIND_REQUIRED_CUDA) + find_package(CUDA REQUIRED) + else() + find_package(CUDA) + endif() + if (CUDA_FOUND) + mark_as_advanced(CUDA_BUILD_CUBIN) + mark_as_advanced(CUDA_BUILD_EMULATION) + mark_as_advanced(CUDA_SDK_ROOT_DIR) + mark_as_advanced(CUDA_TOOLKIT_ROOT_DIR) + mark_as_advanced(CUDA_VERBOSE_BUILD) + endif() +endif() + +# STARPU may depend on MPI, try to find it +if (NOT MPI_FOUND AND STARPU_LOOK_FOR_MPI) + if (STARPU_FIND_REQUIRED AND STARPU_FIND_REQUIRED_MPI) + find_package(MPI REQUIRED) + else() + find_package(MPI) + endif() + if (MPI_FOUND) + mark_as_advanced(MPI_LIBRARY) + mark_as_advanced(MPI_EXTRA_LIBRARY) + endif() +endif() + +# STARPU may depend on BLAS, try to find it +if (NOT BLAS_FOUND AND STARPU_LOOK_FOR_BLAS) + if (STARPU_FIND_REQUIRED AND STARPU_FIND_REQUIRED_BLAS) + find_package(BLASEXT REQUIRED) + else() + find_package(BLASEXT) + endif() +endif() + +# STARPU may depend on MAGMA, try to find it +if (NOT MAGMA_FOUND AND STARPU_LOOK_FOR_MAGMA) + if (STARPU_FIND_REQUIRED AND STARPU_FIND_REQUIRED_MAGMA) + find_package(MAGMA REQUIRED) + else() + find_package(MAGMA) + endif() +endif() + +# STARPU may depend on FXT, try to find it +if (NOT FXT_FOUND AND STARPU_LOOK_FOR_FXT) + if (STARPU_FIND_REQUIRED AND STARPU_FIND_REQUIRED_FXT) + find_package(FXT REQUIRED) + else() + find_package(FXT) + endif() +endif() + +# STARPU may depend on SIMGRID, try to find it +if (NOT SIMGRID_FOUND AND STARPU_LOOK_FOR_SIMGRID) + if (STARPU_FIND_REQUIRED AND STARPU_FIND_REQUIRED_SIMGRID) + find_package(SIMGRID REQUIRED) + else() + find_package(SIMGRID) + endif() +endif() + +set(ENV_STARPU_DIR "$ENV{STARPU_DIR}") +set(ENV_STARPU_INCDIR "$ENV{STARPU_INCDIR}") +set(ENV_STARPU_LIBDIR "$ENV{STARPU_LIBDIR}") +set(STARPU_GIVEN_BY_USER "FALSE") +if ( STARPU_DIR OR ( STARPU_INCDIR AND STARPU_LIBDIR) OR ENV_STARPU_DIR OR (ENV_STARPU_INCDIR AND ENV_STARPU_LIBDIR) ) + set(STARPU_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 STARPU_GIVEN_BY_USER) + + pkg_search_module(STARPU_SHM libstarpu) + set(STARPU_INCLUDE_DIRS "${STARPU_SHM_INCLUDE_DIRS}") + set(STARPU_LIBRARY_DIRS "${STARPU_SHM_LIBRARY_DIRS}") + if(STARPU_LOOK_FOR_MPI AND MPI_FOUND) + pkg_search_module(STARPU_MPI libstarpumpi) + endif() + if (NOT STARPU_FIND_QUIETLY) + if (STARPU_SHM_FOUND AND STARPU_SHM_LIBRARIES) + message(STATUS "Looking for STARPU - found using PkgConfig") + #if(NOT STARPU_SHM_INCLUDE_DIRS) + # message("${Magenta}STARPU_SHM_INCLUDE_DIRS is empty using PkgConfig." + # "Perhaps the path to starpu headers is already present in your" + # "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}") + #endif() + set(STARPU_VERSION_STRING "${STARPU_SHM_VERSION}") + string(REPLACE "." ";" STARPU_VERSION_STRING_LIST ${STARPU_VERSION_STRING}) + list(GET STARPU_VERSION_STRING_LIST 0 STARPU_VERSION_MAJOR) + list(GET STARPU_VERSION_STRING_LIST 1 STARPU_VERSION_MINOR) + else() + message(STATUS "${Magenta}Looking for STARPU - not found using PkgConfig." + "\n Perhaps you should add the directory containing libstarpu.pc" + "\n to the PKG_CONFIG_PATH environment variable.${ColourReset}") + endif() + if (STARPU_LOOK_FOR_MPI) + if (STARPU_MPI_FOUND AND STARPU_MPI_LIBRARIES) + message(STATUS "Looking for STARPU MPI - found using PkgConfig") + else() + message(STATUS "${Magenta}Looking for STARPU MPI - not found using PkgConfig." + "Perhaps you should add the directory containing libstarpumpi.pc to" + "the PKG_CONFIG_PATH environment variable.${ColourReset}") + endif() + endif() + endif() + + if (STARPU_FIND_VERSION_EXACT) + if( NOT (STARPU_FIND_VERSION_MAJOR STREQUAL STARPU_VERSION_MAJOR) OR + NOT (STARPU_FIND_VERSION_MINOR STREQUAL STARPU_VERSION_MINOR) ) + if(STARPU_FIND_REQUIRED AND NOT STARPU_FIND_QUIETLY) + message(FATAL_ERROR + "STARPU version found is ${STARPU_VERSION_STRING}" + "when required is ${STARPU_FIND_VERSION}") + endif() + endif() + else() + # if the version found is older than the required then error + if( (STARPU_FIND_VERSION_MAJOR STRGREATER STARPU_VERSION_MAJOR) OR + (STARPU_FIND_VERSION_MINOR STRGREATER STARPU_VERSION_MINOR) ) + if(STARPU_FIND_REQUIRED AND NOT STARPU_FIND_QUIETLY) + message(FATAL_ERROR + "STARPU version found is ${STARPU_VERSION_STRING}" + "when required is ${STARPU_FIND_VERSION} or newer") + endif() + endif() + endif() + + if(STARPU_MPI_LIBRARIES) + if (STARPU_LOOK_FOR_SIMGRID) + # Cmake does not fetch explicit libfxt.a static paths from pkg-config... + find_package(FXT) + string(REGEX MATCH "[^;]*/libfxt.a" FXT_STATIC_LIB "${STARPU_MPI_LDFLAGS_OTHER}") + list(APPEND STARPU_MPI_LIBRARIES "${FXT_STATIC_LIB}") + endif() + set(STARPU_LIBRARIES "${STARPU_MPI_LIBRARIES}") + set(STARPU_LINKER_FLAGS "${STARPU_MPI_LDFLAGS_OTHER}") + elseif(STARPU_SHM_LIBRARIES) + set(STARPU_LIBRARIES "${STARPU_SHM_LIBRARIES}") + set(STARPU_LINKER_FLAGS "${STARPU_SHM_LDFLAGS_OTHER}") + else() + set(STARPU_LIBRARIES "STARPU_LIBRARIES-NOTFOUND") + endif() + set(STARPU_INCLUDE_DIRS_DEP "${STARPU_INCLUDE_DIRS}") + set(STARPU_LIBRARY_DIRS_DEP "${STARPU_LIBRARY_DIRS}") + set(STARPU_LIBRARIES_DEP "${STARPU_LIBRARIES}") + if (STARPU_SHM_FOUND) + set(STARPU_FOUND "TRUE") + else() + set(STARPU_FOUND "FALSE") + endif() + if (STARPU_LOOK_FOR_MPI AND NOT STARPU_MPI_FOUND) + set(STARPU_FOUND "FALSE") + endif() +endif(PKG_CONFIG_EXECUTABLE AND NOT STARPU_GIVEN_BY_USER) + + +if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT STARPU_FOUND) OR (STARPU_GIVEN_BY_USER) ) + + # Looking for include + # ------------------- + + # Add system include paths to search include + # ------------------------------------------ + unset(_inc_env) + set(ENV_STARPU_DIR "$ENV{STARPU_DIR}") + set(ENV_STARPU_INCDIR "$ENV{STARPU_INCDIR}") + if(ENV_STARPU_INCDIR) + list(APPEND _inc_env "${ENV_STARPU_INCDIR}") + elseif(ENV_STARPU_DIR) + list(APPEND _inc_env "${ENV_STARPU_DIR}") + list(APPEND _inc_env "${ENV_STARPU_DIR}/include") + list(APPEND _inc_env "${ENV_STARPU_DIR}/include/starpu/1.0") + list(APPEND _inc_env "${ENV_STARPU_DIR}/include/starpu/1.1") + list(APPEND _inc_env "${ENV_STARPU_DIR}/include/starpu/1.2") + list(APPEND _inc_env "${ENV_STARPU_DIR}/include/starpu/1.3") + 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 version of StarPU in starpu_config.h file + set(STARPU_hdrs_to_find "starpu_config.h") + + # call cmake macro to find the header path + if(STARPU_INCDIR) + foreach(starpu_hdr ${STARPU_hdrs_to_find}) + set(STARPU_${starpu_hdr}_INCLUDE_DIRS "STARPU_${starpu_hdr}_INCLUDE_DIRS-NOTFOUND") + find_path(STARPU_${starpu_hdr}_INCLUDE_DIRS + NAMES ${starpu_hdr} + HINTS ${STARPU_INCDIR}) + endforeach() + else() + if(STARPU_DIR) + foreach(starpu_hdr ${STARPU_hdrs_to_find}) + set(STARPU_${starpu_hdr}_INCLUDE_DIRS "STARPU_${starpu_hdr}_INCLUDE_DIRS-NOTFOUND") + find_path(STARPU_${starpu_hdr}_INCLUDE_DIRS + NAMES ${starpu_hdr} + HINTS ${STARPU_DIR} + PATH_SUFFIXES "include" + "include/starpu/1.0" + "include/starpu/1.1" + "include/starpu/1.2" + "include/starpu/1.3") + endforeach() + else() + foreach(starpu_hdr ${STARPU_hdrs_to_find}) + set(STARPU_${starpu_hdr}_INCLUDE_DIRS "STARPU_${starpu_hdr}_INCLUDE_DIRS-NOTFOUND") + find_path(STARPU_${starpu_hdr}_INCLUDE_DIRS + NAMES ${starpu_hdr} + HINTS ${_inc_env} + PATH_SUFFIXES + "starpu/1.0" + "starpu/1.1" + "starpu/1.2" + "starpu/1.3") + endforeach() + endif() + endif() + mark_as_advanced(STARPU_starpu_config.h_INCLUDE_DIRS) + + ### + # + # GET_VERSION: Get the version of the software by parsing a file + # + ### + MACRO(GET_VERSION _PACKAGE _filepath) + + #message(STATUS "Looking for ${_PACKAGE} version in the file ${_filepath}") + file(READ "${_filepath}" _file) + string(REGEX REPLACE + "(.*)define([ \t]*)${_PACKAGE}_MAJOR_VERSION([ \t]*)([0-9]+)(.*)" + "\\4" ${_PACKAGE}_VERSION_MAJOR "${_file}") + string(REGEX REPLACE + "(.*)define([ \t]*)${_PACKAGE}_MINOR_VERSION([ \t]*)([0-9]+)(.*)" + "\\4" ${_PACKAGE}_VERSION_MINOR "${_file}") + set(${_PACKAGE}_VERSION_STRING + "${${_PACKAGE}_VERSION_MAJOR}.${${_PACKAGE}_VERSION_MINOR}" CACHE PATH "StarPU version found in starpu_config.h") + #message(STATUS "${_PACKAGE}_VERSION_MAJOR = -${${_PACKAGE}_VERSION_MAJOR}-") + #message(STATUS "${_PACKAGE}_VERSION_MINOR = -${${_PACKAGE}_VERSION_MINOR}-") + + ENDMACRO(GET_VERSION) + + # Find the version of StarPU in starpu_config.h file + # remark: the version is defined in this file since the STARPU 1.0 version + if (STARPU_starpu_config.h_INCLUDE_DIRS) + GET_VERSION("STARPU" "${STARPU_starpu_config.h_INCLUDE_DIRS}/starpu_config.h") + if (STARPU_VERSION_MAJOR AND STARPU_VERSION_MINOR) + if (STARPU_FIND_VERSION_EXACT) + if (STARPU_FIND_VERSION_MAJOR AND STARPU_FIND_VERSION_MINOR) + if( NOT (STARPU_FIND_VERSION_MAJOR STREQUAL STARPU_VERSION_MAJOR) OR + NOT (STARPU_FIND_VERSION_MINOR STREQUAL STARPU_VERSION_MINOR) ) + if(STARPU_FIND_REQUIRED AND NOT STARPU_FIND_QUIETLY) + message(FATAL_ERROR + "STARPU version found is ${STARPU_VERSION_STRING} " + "when required is ${STARPU_FIND_VERSION}") + endif() + endif() + endif() + else() + if (STARPU_FIND_VERSION_MAJOR AND STARPU_FIND_VERSION_MINOR) + # if the version found is older than the required then error + if( (STARPU_FIND_VERSION_MAJOR STRGREATER STARPU_VERSION_MAJOR) OR + (STARPU_FIND_VERSION_MINOR STRGREATER STARPU_VERSION_MINOR) ) + if(STARPU_FIND_REQUIRED AND NOT STARPU_FIND_QUIETLY) + message(FATAL_ERROR + "STARPU version found is ${STARPU_VERSION_STRING} " + "when required is ${STARPU_FIND_VERSION} or newer") + endif() + endif() + endif() + endif() + else() + if(STARPU_FIND_REQUIRED AND NOT STARPU_FIND_QUIETLY) + message(FATAL_ERROR + "STARPU version has not been found using starpu_config.h" + "located in ${STARPU_starpu_config.h_INCLUDE_DIRS}") + endif() + endif() + else() + if(STARPU_FIND_REQUIRED AND NOT STARPU_FIND_QUIETLY) + message(FATAL_ERROR + "starpu_config.h has not been found while required to get StarPU version") + endif() + endif() + + + # Try to find the starpu headers in the given paths + # ------------------------------------------------- + + # create list of headers to find + list(APPEND STARPU_hdrs_to_find "starpu.h;starpu_profiling.h") + if(STARPU_LOOK_FOR_MPI AND MPI_FOUND) + list(APPEND STARPU_hdrs_to_find "starpu_mpi.h") + endif() + if(STARPU_LOOK_FOR_CUDA AND CUDA_FOUND) + list(APPEND STARPU_hdrs_to_find "starpu_cuda.h;starpu_scheduler.h") + endif() + + # call cmake macro to find the header path + if(STARPU_INCDIR) + foreach(starpu_hdr ${STARPU_hdrs_to_find}) + set(STARPU_${starpu_hdr}_INCLUDE_DIRS "STARPU_${starpu_hdr}_INCLUDE_DIRS-NOTFOUND") + find_path(STARPU_${starpu_hdr}_INCLUDE_DIRS + NAMES ${starpu_hdr} + HINTS ${STARPU_INCDIR}) + endforeach() + else() + if(STARPU_DIR) + set(STARPU_${starpu_hdr}_INCLUDE_DIRS "STARPU_${starpu_hdr}_INCLUDE_DIRS-NOTFOUND") + foreach(starpu_hdr ${STARPU_hdrs_to_find}) + find_path(STARPU_${starpu_hdr}_INCLUDE_DIRS + NAMES ${starpu_hdr} + HINTS ${STARPU_DIR} + PATH_SUFFIXES "include" + "include/starpu/1.0" + "include/starpu/1.1" + "include/starpu/1.2" + "include/starpu/1.3") + endforeach() + else() + foreach(starpu_hdr ${STARPU_hdrs_to_find}) + set(STARPU_${starpu_hdr}_INCLUDE_DIRS "STARPU_${starpu_hdr}_INCLUDE_DIRS-NOTFOUND") + find_path(STARPU_${starpu_hdr}_INCLUDE_DIRS + NAMES ${starpu_hdr} + HINTS ${_inc_env} + PATH_SUFFIXES + "starpu/1.0" + "starpu/1.1" + "starpu/1.2" + "starpu/1.3") + endforeach() + endif() + endif() + + # If found, add path to cmake variable + # ------------------------------------ + set(STARPU_INCLUDE_DIRS "") + foreach(starpu_hdr ${STARPU_hdrs_to_find}) + + if (STARPU_${starpu_hdr}_INCLUDE_DIRS) + # set cmake variables using the pkg-config naming convention + list(APPEND STARPU_INCLUDE_DIRS "${STARPU_${starpu_hdr}_INCLUDE_DIRS}" ) + else () + if(NOT STARPU_FIND_QUIETLY) + message(STATUS "Looking for starpu -- ${starpu_hdr} not found") + endif() + if(starpu_hdr STREQUAL "starpu_mpi.h") + if(NOT STARPU_FIND_REQUIRED_MPI) + if (NOT STARPU_FIND_QUIETLY) + message(STATUS "Looking for starpu -- ${starpu_hdr} not required") + endif() + else() + list(APPEND STARPU_INCLUDE_DIRS "${STARPU_${starpu_hdr}_INCLUDE_DIRS}" ) + endif() + elseif( (starpu_hdr STREQUAL "starpu_cuda.h") OR (starpu_hdr STREQUAL "starpu_scheduler.h") ) + if(NOT STARPU_FIND_REQUIRED_CUDA) + if (NOT STARPU_FIND_QUIETLY) + message(STATUS "Looking for starpu -- ${starpu_hdr} not required") + endif() + else() + list(APPEND STARPU_INCLUDE_DIRS "${STARPU_${starpu_hdr}_INCLUDE_DIRS}" ) + endif() + endif() + endif () + mark_as_advanced(STARPU_${starpu_hdr}_INCLUDE_DIRS) + + endforeach(starpu_hdr ${STARPU_hdrs_to_find}) + + if (STARPU_INCLUDE_DIRS) + list(REMOVE_DUPLICATES STARPU_INCLUDE_DIRS) + endif () + + if (STARPU_starpu_config.h_INCLUDE_DIRS) + # Looking for lib + # --------------- + + set(STARPU_SHM_LIBRARIES "") + set(STARPU_MPI_LIBRARIES "") + set(STARPU_LIBRARY_DIRS "") + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_STARPU_LIBDIR "$ENV{STARPU_LIBDIR}") + if(ENV_STARPU_LIBDIR) + list(APPEND _lib_env "${ENV_STARPU_LIBDIR}") + elseif(ENV_STARPU_DIR) + list(APPEND _lib_env "${ENV_STARPU_DIR}") + list(APPEND _lib_env "${ENV_STARPU_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 starpu libs in the given paths + # ---------------------------------------------- + + # create list of libs to find + set(STARPU_libs_to_find "starpu-${STARPU_VERSION_STRING}") + set(STARPU_SHM_libs_to_find "starpu-${STARPU_VERSION_STRING}") + if (STARPU_LOOK_FOR_MPI OR MPI_FOUND) + list(INSERT STARPU_libs_to_find 0 "starpumpi-${STARPU_VERSION_STRING}") + set(STARPU_MPI_libs_to_find "${STARPU_libs_to_find}") + endif() + + # call cmake macro to find the lib path + if(STARPU_LIBDIR) + foreach(starpu_lib ${STARPU_libs_to_find}) + set(STARPU_${starpu_lib}_LIBRARY "STARPU_${starpu_lib}_LIBRARY-NOTFOUND") + find_library(STARPU_${starpu_lib}_LIBRARY + NAMES ${starpu_lib} + HINTS ${STARPU_LIBDIR}) + endforeach() + else() + if(STARPU_DIR) + foreach(starpu_lib ${STARPU_libs_to_find}) + set(STARPU_${starpu_lib}_LIBRARY "STARPU_${starpu_lib}_LIBRARY-NOTFOUND") + find_library(STARPU_${starpu_lib}_LIBRARY + NAMES ${starpu_lib} + HINTS ${STARPU_DIR} + PATH_SUFFIXES lib lib32 lib64) + endforeach() + else() + foreach(starpu_lib ${STARPU_libs_to_find}) + set(STARPU_${starpu_lib}_LIBRARY "STARPU_${starpu_lib}_LIBRARY-NOTFOUND") + find_library(STARPU_${starpu_lib}_LIBRARY + NAMES ${starpu_lib} + HINTS ${_lib_env}) + endforeach() + endif() + endif() + + # If found, add path to cmake variable + # ------------------------------------ + foreach(starpu_lib ${STARPU_libs_to_find}) + + if (STARPU_${starpu_lib}_LIBRARY) + + get_filename_component(${starpu_lib}_lib_path ${STARPU_${starpu_lib}_LIBRARY} PATH) + # set cmake variables (respects naming convention) + + foreach(starpu_shm_lib ${STARPU_SHM_libs_to_find}) + if(starpu_shm_lib STREQUAL starpu_lib) + list(APPEND STARPU_SHM_LIBRARIES "${STARPU_${starpu_lib}_LIBRARY}") + endif() + endforeach() + if (STARPU_LOOK_FOR_MPI AND MPI_FOUND) + foreach(starpu_mpi_lib ${STARPU_MPI_libs_to_find}) + if(starpu_mpi_lib STREQUAL starpu_lib) + list(APPEND STARPU_MPI_LIBRARIES "${STARPU_${starpu_lib}_LIBRARY}") + endif() + endforeach() + endif () + list(APPEND STARPU_LIBRARY_DIRS "${${starpu_lib}_lib_path}") + + else (STARPU_${starpu_lib}_LIBRARY) + + if(NOT STARPU_FIND_QUIETLY) + message(STATUS "Looking for starpu -- lib ${starpu_lib} not found") + endif() + if(starpu_lib STREQUAL "starpumpi-${STARPU_VERSION_STRING}" AND + NOT STARPU_FIND_REQUIRED_MPI) + # if MPI optional, not a problem: no NOTFOUND in list of MPI LIBRARIES + if(NOT STARPU_FIND_QUIETLY) + message(STATUS "Looking for starpu -- lib ${starpu_lib} not required") + endif() + else() + # for any other lib, add NOTFOUND in the proper list of LIBRARIES + foreach(starpu_shm_lib ${STARPU_SHM_libs_to_find}) + if(starpu_shm_lib STREQUAL starpu_lib) + set(STARPU_SHM_LIBRARIES "${STARPU_${starpu_lib}_LIBRARY}") + endif() + endforeach() + if (STARPU_LOOK_FOR_MPI AND MPI_FOUND) + foreach(starpu_mpi_lib ${STARPU_MPI_libs_to_find}) + if(starpu_mpi_lib STREQUAL starpu_lib) + list(APPEND STARPU_MPI_LIBRARIES "${STARPU_${starpu_mpi_lib}_LIBRARY}") + endif() + endforeach() + endif () + endif() + + endif (STARPU_${starpu_lib}_LIBRARY) + + mark_as_advanced(STARPU_${starpu_lib}_LIBRARY) + + endforeach(starpu_lib ${STARPU_libs_to_find}) + + list(REMOVE_DUPLICATES STARPU_SHM_LIBRARIES) + list(REMOVE_DUPLICATES STARPU_MPI_LIBRARIES) + if (STARPU_LIBRARY_DIRS) + list(REMOVE_DUPLICATES STARPU_LIBRARY_DIRS) + endif () + + if (STARPU_SHM_LIBRARIES AND STARPU_LIBRARY_DIRS AND STARPU_INCLUDE_DIRS) + set(STARPU_SHM_FOUND TRUE) + if(STARPU_MPI_LIBRARIES) + set(STARPU_MPI_FOUND TRUE) + endif() + endif() + + else(STARPU_starpu_config.h_INCLUDE_DIRS) + if(NOT STARPU_FIND_QUIETLY) + message(STATUS "The version of StarPU is not known so that we do not search libraries") + endif() + endif(STARPU_starpu_config.h_INCLUDE_DIRS) + + foreach(lib ${STARPU_SHM_LIBRARIES}) + if (NOT lib) + set(STARPU_SHM_LIBRARIES "STARPU_SHM_LIBRARIES-NOTFOUND") + endif() + endforeach() + foreach(lib ${STARPU_MPI_LIBRARIES}) + if (NOT lib) + set(STARPU_MPI_LIBRARIES "STARPU_MPI_LIBRARIES-NOTFOUND") + endif() + endforeach() + if(STARPU_LOOK_FOR_MPI) + set(STARPU_LIBRARIES "${STARPU_MPI_LIBRARIES}") + else() + set(STARPU_LIBRARIES "${STARPU_SHM_LIBRARIES}") + endif() + + # check a function to validate the find + if(STARPU_LIBRARIES) + + set(REQUIRED_FLAGS) + set(REQUIRED_LDFLAGS) + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # STARPU + if (STARPU_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${STARPU_INCLUDE_DIRS}") + endif() + set(CMAKE_REQUIRED_FLAGS) + foreach(libdir ${STARPU_LIBRARY_DIRS}) + if (libdir) + list(APPEND REQUIRED_LIBDIRS "${libdir}") + endif() + endforeach() + set(REQUIRED_LIBS "${STARPU_LIBRARIES}") + # HWLOC + if (HWLOC_FOUND AND STARPU_LOOK_FOR_HWLOC) + if (HWLOC_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${HWLOC_INCLUDE_DIRS}") + endif() + if (HWLOC_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${HWLOC_LIBRARY_DIRS}") + endif() + 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() + # MPI + if (MPI_FOUND AND STARPU_LOOK_FOR_MPI) + 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() + # MAGMA + if (MAGMA_FOUND AND STARPU_LOOK_FOR_MAGMA) + if (MAGMA_INCLUDE_DIRS_DEP) + list(APPEND REQUIRED_INCDIRS "${MAGMA_INCLUDE_DIRS_DEP}") + elseif(MAGMA_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${MAGMA_INCLUDE_DIRS}") + endif() + if (MAGMA_LIBRARY_DIRS_DEP) + list(APPEND REQUIRED_LIBDIRS "${MAGMA_LIBRARY_DIRS_DEP}") + elseif(MAGMA_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${MAGMA_LIBRARY_DIRS}") + endif() + if (MAGMA_LIBRARIES_DEP) + list(APPEND REQUIRED_LIBS "${MAGMA_LIBRARIES_DEP}") + elseif(MAGMA_LIBRARIES) + foreach(lib ${MAGMA_LIBRARIES}) + if (EXISTS ${lib} OR ${lib} MATCHES "^-") + list(APPEND REQUIRED_LIBS "${lib}") + else() + list(APPEND REQUIRED_LIBS "-l${lib}") + endif() + endforeach() + endif() + if (MAGMA_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${MAGMA_LINKER_FLAGS}") + endif() + endif() + # CUDA + if (CUDA_FOUND AND STARPU_LOOK_FOR_CUDA) + if (CUDA_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${CUDA_INCLUDE_DIRS}") + endif() + if (CUDA_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${CUDA_LIBRARY_DIRS}") + endif() + list(APPEND REQUIRED_LIBS "${CUDA_CUBLAS_LIBRARIES};${CUDA_LIBRARIES}") + endif() + # FXT + if (FXT_FOUND AND STARPU_LOOK_FOR_FXT) + if (FXT_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${FXT_INCLUDE_DIRS}") + endif() + if (FXT_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${FXT_LIBRARY_DIRS}") + endif() + foreach(lib ${FXT_LIBRARIES}) + if (EXISTS ${lib} OR ${lib} MATCHES "^-") + list(APPEND REQUIRED_LIBS "${lib}") + else() + list(APPEND REQUIRED_LIBS "-l${lib}") + endif() + endforeach() + endif() + # SIMGRID + if (SIMGRID_FOUND AND STARPU_LOOK_FOR_SIMGRID) + if (SIMGRID_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${SIMGRID_INCLUDE_DIRS}") + endif() + if (SIMGRID_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${SIMGRID_LIBRARY_DIRS}") + endif() + foreach(lib ${SIMGRID_LIBRARIES}) + if (EXISTS ${lib} OR ${lib} MATCHES "^-") + list(APPEND REQUIRED_LIBS "${lib}") + else() + list(APPEND REQUIRED_LIBS "-l${lib}") + endif() + endforeach() + list(APPEND REQUIRED_FLAGS "-include starpu_simgrid_wrap.h") + endif() + # BLAS + if (BLAS_FOUND AND STARPU_LOOK_FOR_BLAS) + if (BLAS_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${BLAS_INCLUDE_DIRS}") + endif() + if (BLAS_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${BLAS_LIBRARY_DIRS}") + endif() + list(APPEND REQUIRED_LIBS "${BLAS_LIBRARIES}") + if (BLAS_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}") + endif() + 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 AND CMAKE_C_COMPILER_ID STREQUAL "GNU") + 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 ${STARPU_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(STARPU_WORKS CACHE) + include(CheckFunctionExists) + check_function_exists(starpu_init STARPU_WORKS) + mark_as_advanced(STARPU_WORKS) + + if(STARPU_WORKS) + # save link with dependencies + if (REQUIRED_FLAGS) + set(STARPU_LIBRARIES_DEP "${REQUIRED_FLAGS};${REQUIRED_LIBS}") + else() + set(STARPU_LIBRARIES_DEP "${REQUIRED_LIBS}") + endif() + set(STARPU_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(STARPU_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(STARPU_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES STARPU_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES STARPU_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES STARPU_LINKER_FLAGS) + else() + if(NOT STARPU_FIND_QUIETLY) + message(STATUS "Looking for starpu : test of starpu_init 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 STARPU is linked with specific libraries. " + "Have you tried with COMPONENTS (HWLOC, CUDA, MPI, BLAS, MAGMA, FXT, SIMGRID)? " + "See the explanation in FindSTARPU.cmake.") + endif() + endif() + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_LIBRARIES) + endif(STARPU_LIBRARIES) + +endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT STARPU_FOUND) OR (STARPU_GIVEN_BY_USER) ) + +if (STARPU_LIBRARIES) + if (STARPU_LIBRARY_DIRS) + foreach(dir ${STARPU_LIBRARY_DIRS}) + if ("${dir}" MATCHES "starpu") + set(first_lib_path "${dir}") + endif() + endforeach() + else() + list(GET STARPU_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(STARPU_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of STARPU library" FORCE) + else() + set(STARPU_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of STARPU library" FORCE) + endif() +endif() +mark_as_advanced(STARPU_DIR) +mark_as_advanced(STARPU_DIR_FOUND) + +# check that STARPU has been found +# -------------------------------- +include(FindPackageHandleStandardArgs) +if(NOT STARPU_FIND_QUIETLY) + if(STARPU_SHM_FOUND) + message(STATUS "StarPU library has been found.") + if(STARPU_MPI_LIBRARIES) + message(STATUS "The mpi version of StarPU has been found so that we manage" + "two lists of libs, one sequential and one parallel (see" + "STARPU_SHM_LIBRARIES and STARPU_MPI_LIBRARIES).") + endif() + message(STATUS "StarPU shared memory libraries stored in STARPU_SHM_LIBRARIES") + endif() +endif() +if (PKG_CONFIG_EXECUTABLE AND STARPU_SHM_FOUND AND NOT STARPU_GIVEN_BY_USER) + find_package_handle_standard_args(STARPU DEFAULT_MSG + STARPU_SHM_LIBRARIES) +else() + find_package_handle_standard_args(STARPU DEFAULT_MSG + STARPU_SHM_LIBRARIES + STARPU_WORKS) +endif() +if(STARPU_LOOK_FOR_MPI) + if(STARPU_MPI_LIBRARIES AND NOT STARPU_FIND_QUIETLY) + message(STATUS "StarPU mpi libraries stored in STARPU_MPI_LIBRARIES") + endif() + if (PKG_CONFIG_EXECUTABLE AND STARPU_MPI_FOUND AND NOT STARPU_GIVEN_BY_USER) + find_package_handle_standard_args(STARPU DEFAULT_MSG + STARPU_MPI_LIBRARIES) + else() + find_package_handle_standard_args(STARPU DEFAULT_MSG + STARPU_MPI_LIBRARIES + STARPU_WORKS) + endif() +endif() diff --git a/modules/find/FindSUITESPARSE.cmake b/modules/find/FindSUITESPARSE.cmake new file mode 100644 index 0000000..6a017bf --- /dev/null +++ b/modules/find/FindSUITESPARSE.cmake @@ -0,0 +1,433 @@ +### +# +# @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 SUITESPARSE include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(SUITESPARSE +# [REQUIRED] # Fail with error if suitesparse is not found +# ) +# +# SUITESPARSE depends on the following libraries: +# - BLAS +# - LAPACK +# - METIS +## +# This module finds headers and suitesparse library. +# Results are reported in variables: +# SUITESPARSE_FOUND - True if headers and requested libraries were found +# SUITESPARSE_LINKER_FLAGS - list of required linker flags (excluding -l and -L) +# SUITESPARSE_INCLUDE_DIRS - suitesparse include directories +# SUITESPARSE_LIBRARY_DIRS - Link directories for suitesparse libraries +# SUITESPARSE_LIBRARIES - suitesparse libraries +# SUITESPARSE_INCLUDE_DIRS_DEP - suitesparse + dependencies include directories +# SUITESPARSE_LIBRARY_DIRS_DEP - suitesparse + dependencies link directories +# SUITESPARSE_LIBRARIES_DEP - suitesparse libraries + dependencies +# +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DSUITESPARSE_DIR=path/to/suitesparse): +# SUITESPARSE_DIR - Where to find the base directory of suitesparse +# The module can also look for the following environment variables if paths +# are not given as cmake variable: SUITESPARSE_DIR + +#============================================================================= +# Copyright 2012-2016 Inria +# Copyright 2012-2013 Emmanuel Agullo +# Copyright 2012-2013 Mathieu Faverge +# Copyright 2012 Cedric Castagnede +# Copyright 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 SUITESPARSE_FOUND) + set(SUITESPARSE_DIR "" CACHE PATH "Installation directory of SUITESPARSE library") + if (NOT SUITESPARSE_FIND_QUIETLY) + message(STATUS "A cache variable, namely SUITESPARSE_DIR, has been set to specify the install directory of SUITESPARSE") + endif() +endif() + +if (NOT SUITESPARSE_FIND_QUIETLY) + message(STATUS "Looking for SUITESPARSE") +endif() + +if (NOT SUITESPARSE_FIND_QUIETLY) + message(STATUS "Looking for SUITESPARSE - PkgConfig not used") +endif() + +# Required dependencies +# --------------------- + +if (NOT SUITESPARSE_FIND_QUIETLY) + message(STATUS "Looking for SUITESPARSE - Try to detect metis") +endif() +if (NOT METIS_FOUND) + if (SUITESPARSE_FIND_REQUIRED) + find_package(METIS REQUIRED) + else() + find_package(METIS) + endif() +endif() + +# SUITESPARSE depends on BLAS +#---------------------------- +if (NOT SUITESPARSE_FIND_QUIETLY) + message(STATUS "Looking for SUITESPARSE - Try to detect BLAS") +endif() +if (NOT BLASEXT_FOUND) + if (SUITESPARSE_FIND_REQUIRED) + find_package(BLASEXT REQUIRED) + else() + find_package(BLASEXT) + endif() +endif() + +# SUITESPARSE depends on LAPACK +#------------------------------ +if (NOT SUITESPARSE_FIND_QUIETLY) + message(STATUS "Looking for SUITESPARSE - Try to detect LAPACK") +endif() +if (NOT LAPACKEXT_FOUND) + if (SUITESPARSE_FIND_REQUIRED) + find_package(LAPACKEXT REQUIRED) + else() + find_package(LAPACKEXT) + endif() +endif() + +# Looking for SUITESPARSE +# ----------------- + +# Add system include paths to search include +# ------------------------------------------ +unset(_inc_env) +set(ENV_SUITESPARSE_DIR "$ENV{SUITESPARSE_DIR}") +set(ENV_SUITESPARSE_INCDIR "$ENV{SUITESPARSE_INCDIR}") +if(ENV_SUITESPARSE_INCDIR) + list(APPEND _inc_env "${ENV_SUITESPARSE_INCDIR}") +elseif(ENV_SUITESPARSE_DIR) + list(APPEND _inc_env "${ENV_SUITESPARSE_DIR}") + list(APPEND _inc_env "${ENV_SUITESPARSE_DIR}/include") + list(APPEND _inc_env "${ENV_SUITESPARSE_DIR}/include/suitesparse") +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) + +# Add system library paths to search lib +# -------------------------------------- +unset(_lib_env) +set(ENV_SUITESPARSE_LIBDIR "$ENV{SUITESPARSE_LIBDIR}") +if(ENV_SUITESPARSE_LIBDIR) + list(APPEND _lib_env "${ENV_SUITESPARSE_LIBDIR}") +elseif(ENV_SUITESPARSE_DIR) + list(APPEND _lib_env "${ENV_SUITESPARSE_DIR}") + list(APPEND _lib_env "${ENV_SUITESPARSE_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) + +# Looking for include +# ------------------- + +# Try to find the suitesparse header in the given path +# ---------------------------------------------- + +# create list of headers to find +list(APPEND SUITESPARSE_hdrs_to_find + "amd.h" + "btf.h" + "ccolamd.h" + "colamd.h" + "cs.h" + "klu.h" + "ldl.h" + "RBio.h" + "spqr.hpp" + "SuiteSparse_config.h" + "umfpack.h") + +# call cmake macro to find the header path +if(SUITESPARSE_INCDIR) + foreach(suitesparse_hdr ${SUITESPARSE_hdrs_to_find}) + set(SUITESPARSE_${suitesparse_hdr}_DIRS "SUITESPARSE_${suitesparse_hdr}_INCLUDE_DIRS-NOTFOUND") + find_path(SUITESPARSE_${suitesparse_hdr}_DIRS + NAMES ${suitesparse_hdr} + HINTS ${SUITESPARSE_INCDIR}) + mark_as_advanced(SUITESPARSE_${suitesparse_hdr}_DIRS) + endforeach() +else() + if(SUITESPARSE_DIR) + set(SUITESPARSE_${suitesparse_hdr}_DIRS "SUITESPARSE_${suitesparse_hdr}_INCLUDE_DIRS-NOTFOUND") + foreach(suitesparse_hdr ${SUITESPARSE_hdrs_to_find}) + find_path(SUITESPARSE_${suitesparse_hdr}_DIRS + NAMES ${suitesparse_hdr} + HINTS ${SUITESPARSE_DIR} + PATH_SUFFIXES "include") + mark_as_advanced(SUITESPARSE_${suitesparse_hdr}_DIRS) + endforeach() + else() + foreach(suitesparse_hdr ${SUITESPARSE_hdrs_to_find}) + set(SUITESPARSE_${suitesparse_hdr}_DIRS "SUITESPARSE_${suitesparse_hdr}_INCLUDE_DIRS-NOTFOUND") + find_path(SUITESPARSE_${suitesparse_hdr}_DIRS + NAMES ${suitesparse_hdr} + HINTS ${_inc_env}) + mark_as_advanced(SUITESPARSE_${suitesparse_hdr}_DIRS) + endforeach() + endif() +endif() + +# If found, add path to cmake variable +# ------------------------------------ +# detect which precisions are available +foreach(suitesparse_hdr ${SUITESPARSE_hdrs_to_find}) + if (SUITESPARSE_${suitesparse_hdr}_DIRS) + list(APPEND SUITESPARSE_INCLUDE_DIRS "${SUITESPARSE_${suitesparse_hdr}_DIRS}") + else () + # SuiteSparse_config.h is the minimum to find, consider others as optional? + if (NOT SUITESPARSE_${SuiteSparse_config.h}_DIRS ) + set(SUITESPARSE_INCLUDE_DIRS "SUITESPARSE_INCLUDE_DIRS-NOTFOUND") + endif() + if (NOT SUITESPARSE_FIND_QUIETLY) + message(STATUS "Looking for suitesparse -- ${suitesparse_hdr} not found") + endif() + endif() +endforeach() + + +# Looking for lib +# --------------- + +# create list of libs to find +set(SUITESPARSE_libs_to_find + "cholmod" + "cxsparse" + "klu" + "ldl" + "spqr" + "umfpack" + "amd" + "btf" + "camd" + "ccolamd" + "colamd" + "rbio" + "suitesparseconfig" + ) + +# call cmake macro to find the lib path +if(SUITESPARSE_LIBDIR) + foreach(suitesparse_lib ${SUITESPARSE_libs_to_find}) + set(SUITESPARSE_${suitesparse_lib}_LIBRARY "SUITESPARSE_${suitesparse_lib}_LIBRARY-NOTFOUND") + find_library(SUITESPARSE_${suitesparse_lib}_LIBRARY + NAMES ${suitesparse_lib} + HINTS ${SUITESPARSE_LIBDIR}) + mark_as_advanced(SUITESPARSE_${suitesparse_lib}_LIBRARY) + endforeach() +else() + if(SUITESPARSE_DIR) + foreach(suitesparse_lib ${SUITESPARSE_libs_to_find}) + set(SUITESPARSE_${suitesparse_lib}_LIBRARY "SUITESPARSE_${suitesparse_lib}_LIBRARY-NOTFOUND") + find_library(SUITESPARSE_${suitesparse_lib}_LIBRARY + NAMES ${suitesparse_lib} + HINTS ${SUITESPARSE_DIR} + PATH_SUFFIXES lib lib32 lib64) + mark_as_advanced(SUITESPARSE_${suitesparse_lib}_LIBRARY) + endforeach() + else() + foreach(suitesparse_lib ${SUITESPARSE_libs_to_find}) + set(SUITESPARSE_${suitesparse_lib}_LIBRARY "SUITESPARSE_${suitesparse_lib}_LIBRARY-NOTFOUND") + find_library(SUITESPARSE_${suitesparse_lib}_LIBRARY + NAMES ${suitesparse_lib} + HINTS ${_lib_env}) + mark_as_advanced(SUITESPARSE_${suitesparse_lib}_LIBRARY) + endforeach() + endif() +endif() + +# If found, add path to cmake variable +# ------------------------------------ +set(SUITESPARSE_LIBRARIES "") +set(SUITESPARSE_LIBRARY_DIRS "") +foreach(suitesparse_lib ${SUITESPARSE_libs_to_find}) + if (SUITESPARSE_${suitesparse_lib}_LIBRARY) + list(APPEND SUITESPARSE_LIBRARIES "${SUITESPARSE_${suitesparse_lib}_LIBRARY}") + get_filename_component(${suitesparse_lib}_lib_path ${SUITESPARSE_${suitesparse_lib}_LIBRARY} PATH) + list(APPEND SUITESPARSE_LIBRARY_DIRS "${${suitesparse_lib}_lib_path}") + else () + # libsuitesparseconfig is the minimum to find, consider others as optional? + if (NOT SUITESPARSE_suitesparseconfig_LIBRARY) + list(APPEND SUITESPARSE_LIBRARIES "${SUITESPARSE_LIBRARIES-NOTFOUND}") + endif() + if(NOT SUITESPARSE_FIND_QUIETLY) + message(STATUS "Looking for suitesparse -- lib${suitesparse_lib}.a/so not found") + endif() + endif() +endforeach() +list(REMOVE_DUPLICATES SUITESPARSE_LIBRARY_DIRS) +list(REMOVE_DUPLICATES SUITESPARSE_INCLUDE_DIRS) + +# check a function to validate the find +if(SUITESPARSE_LIBRARIES) + + set(REQUIRED_LDFLAGS) + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # SUITESPARSE + if (SUITESPARSE_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${SUITESPARSE_INCLUDE_DIRS}") + endif() + foreach(libdir ${SUITESPARSE_LIBRARY_DIRS}) + if (libdir) + list(APPEND REQUIRED_LIBDIRS "${libdir}") + endif() + endforeach() + set(REQUIRED_LIBS "${SUITESPARSE_LIBRARIES}") + # METIS + if (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() + # LAPACK + if (LAPACK_FOUND) + if (LAPACK_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${LAPACK_INCLUDE_DIRS}") + endif() + foreach(libdir ${LAPACK_LIBRARY_DIRS}) + if (libdir) + list(APPEND REQUIRED_LIBDIRS "${libdir}") + endif() + endforeach() + list(APPEND REQUIRED_LIBS "${LAPACK_LIBRARIES}") + if (LAPACK_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${LAPACK_LINKER_FLAGS}") + endif() + 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() + # others + 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 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}") + string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + + # test link + include(CheckFortranFunctionExists) + unset(SUITESPARSE_WORKS CACHE) + check_function_exists(SuiteSparse_start SUITESPARSE_WORKS) + mark_as_advanced(SUITESPARSE_WORKS) + + if(SUITESPARSE_WORKS) + # save link with dependencies + set(SUITESPARSE_LIBRARIES_DEP "${REQUIRED_LIBS}") + set(SUITESPARSE_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(SUITESPARSE_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(SUITESPARSE_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES SUITESPARSE_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES SUITESPARSE_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES SUITESPARSE_LINKER_FLAGS) + else() + if(NOT SUITESPARSE_FIND_QUIETLY) + message(STATUS "Looking for SUITESPARSE : test of symbol SuiteSparse_start 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 SUITESPARSE is linked with specific libraries. ") + endif() + endif() + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_LIBRARIES) +endif(SUITESPARSE_LIBRARIES) + +if (SUITESPARSE_LIBRARIES) + list(GET SUITESPARSE_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(SUITESPARSE_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of SUITESPARSE library" FORCE) + else() + set(SUITESPARSE_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of SUITESPARSE library" FORCE) + endif() +endif() +mark_as_advanced(SUITESPARSE_DIR) +mark_as_advanced(SUITESPARSE_DIR_FOUND) + +# check that SUITESPARSE has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SUITESPARSE DEFAULT_MSG + SUITESPARSE_LIBRARIES + SUITESPARSE_WORKS) diff --git a/modules/find/FindTMG.cmake b/modules/find/FindTMG.cmake new file mode 100644 index 0000000..745cb45 --- /dev/null +++ b/modules/find/FindTMG.cmake @@ -0,0 +1,306 @@ +### +# +# @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 TMG include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(TMG +# [REQUIRED] # Fail with error if tmg is not found +# ) +# +# This module finds headers and tmg library. +# Results are reported in variables: +# TMG_FOUND - True if headers and requested libraries were found +# TMG_LINKER_FLAGS - list of required linker flags (excluding -l and -L) +# TMG_INCLUDE_DIRS - tmg include directories +# TMG_LIBRARY_DIRS - Link directories for tmg libraries +# TMG_LIBRARIES - tmg component libraries to be linked +# TMG_INCLUDE_DIRS_DEP - tmg + dependencies include directories +# TMG_LIBRARY_DIRS_DEP - tmg + dependencies link directories +# TMG_LIBRARIES_DEP - tmg libraries + dependencies +# +# The user can give specific paths where to find the libraries adding cmake +# options at configure (ex: cmake path/to/project -DTMG=path/to/tmg): +# TMG_DIR - Where to find the base directory of tmg +# TMG_INCDIR - Where to find the header files +# TMG_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: TMG_DIR, TMG_INCDIR, TMG_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 TMG_FOUND) + set(TMG_DIR "" CACHE PATH "Installation directory of TMG library") + if (NOT TMG_FIND_QUIETLY) + message(STATUS "A cache variable, namely TMG_DIR, has been set to specify the install directory of TMG") + endif() +endif() + + +# used to test a TMG function after +get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES) +if (NOT _LANGUAGES_ MATCHES Fortran) + include(CheckFunctionExists) +else (NOT _LANGUAGES_ MATCHES Fortran) + include(CheckFortranFunctionExists) +endif (NOT _LANGUAGES_ MATCHES Fortran) + +# TMG depends on LAPACK anyway, try to find it +if (NOT LAPACK_FOUND) + if(TMG_FIND_REQUIRED) + find_package(LAPACKEXT REQUIRED) + else() + find_package(LAPACKEXT) + endif() +endif() + +# TMG depends on LAPACK +if (LAPACK_FOUND) + + # check if a tmg function exists in the LAPACK lib + set(CMAKE_REQUIRED_LIBRARIES "${LAPACK_LINKER_FLAGS};${LAPACK_LIBRARIES}") + include(CheckFunctionExists) + include(CheckFortranFunctionExists) + unset(TMG_WORKS CACHE) + if (NOT _LANGUAGES_ MATCHES Fortran) + check_function_exists(dlarnv TMG_WORKS) + else (NOT _LANGUAGES_ MATCHES Fortran) + check_fortran_function_exists(dlarnv TMG_WORKS) + endif (NOT _LANGUAGES_ MATCHES Fortran) + if (TMG_WORKS) + unset(TMG_WORKS CACHE) + if (NOT _LANGUAGES_ MATCHES Fortran) + check_function_exists(dlagsy TMG_WORKS) + else (NOT _LANGUAGES_ MATCHES Fortran) + check_fortran_function_exists(dlagsy TMG_WORKS) + endif (NOT _LANGUAGES_ MATCHES Fortran) + mark_as_advanced(TMG_WORKS) + endif() + set(CMAKE_REQUIRED_LIBRARIES) + + if(TMG_WORKS) + if(NOT TMG_FIND_QUIETLY) + message(STATUS "Looking for tmg: test with lapack succeeds") + endif() + # test succeeds: TMG is in LAPACK + set(TMG_LIBRARIES "${LAPACK_LIBRARIES}") + if (LAPACK_LIBRARY_DIRS) + set(TMG_LIBRARY_DIRS "${LAPACK_LIBRARY_DIRS}") + endif() + if(LAPACK_INCLUDE_DIRS) + set(TMG_INCLUDE_DIRS "${LAPACK_INCLUDE_DIRS}") + endif() + if (LAPACK_LINKER_FLAGS) + set(TMG_LINKER_FLAGS "${LAPACK_LINKER_FLAGS}") + endif() + else() + + if(NOT TMG_FIND_QUIETLY) + message(STATUS "Looking for tmg : test with lapack fails") + message(STATUS "Looking for tmg : try to find it elsewhere") + endif() + # test fails: try to find TMG lib exterior to LAPACK + + # Looking for lib tmg + # ------------------- + + # Add system library paths to search lib + # -------------------------------------- + unset(_lib_env) + set(ENV_TMG_DIR "$ENV{TMG_DIR}") + set(ENV_TMG_LIBDIR "$ENV{TMG_LIBDIR}") + if(ENV_TMG_LIBDIR) + list(APPEND _lib_env "${ENV_TMG_LIBDIR}") + elseif(ENV_TMG_DIR) + list(APPEND _lib_env "${ENV_TMG_DIR}") + list(APPEND _lib_env "${ENV_TMG_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 tmg lib in the given paths + # ---------------------------------------------- + + # call cmake macro to find the lib path + if(TMG_LIBDIR) + set(TMG_tmg_LIBRARY "TMG_tmg_LIBRARY-NOTFOUND") + find_library(TMG_tmg_LIBRARY + NAMES tmglib tmg + HINTS ${TMG_LIBDIR} ) + else() + if(TMG_DIR) + set(TMG_tmg_LIBRARY "TMG_tmg_LIBRARY-NOTFOUND") + find_library(TMG_tmg_LIBRARY + NAMES tmglib tmg + HINTS ${TMG_DIR} + PATH_SUFFIXES lib lib32 lib64 ) + else() + set(TMG_tmg_LIBRARY "TMG_tmg_LIBRARY-NOTFOUND") + find_library(TMG_tmg_LIBRARY + NAMES tmglib tmg + HINTS ${_lib_env} ) + endif() + endif() + mark_as_advanced(TMG_tmg_LIBRARY) + + # If found, add path to cmake variable + # ------------------------------------ + if (TMG_tmg_LIBRARY) + get_filename_component(tmg_lib_path ${TMG_tmg_LIBRARY} PATH) + # set cmake variables (respects naming convention) + set(TMG_LIBRARIES "${TMG_tmg_LIBRARY}") + set(TMG_LIBRARY_DIRS "${tmg_lib_path}") + else () + set(TMG_LIBRARIES "TMG_LIBRARIES-NOTFOUND") + set(TMG_LIBRARY_DIRS "TMG_LIBRARY_DIRS-NOTFOUND") + if(NOT TMG_FIND_QUIETLY) + message(STATUS "Looking for tmg -- lib tmg not found") + endif() + endif () + + if (TMG_LIBRARY_DIRS) + list(REMOVE_DUPLICATES TMG_LIBRARY_DIRS) + endif () + + # check a function to validate the find + if(TMG_LIBRARIES) + + set(REQUIRED_LDFLAGS) + set(REQUIRED_INCDIRS) + set(REQUIRED_LIBDIRS) + set(REQUIRED_LIBS) + + # TMG + if (TMG_INCLUDE_DIRS) + set(REQUIRED_INCDIRS "${TMG_INCLUDE_DIRS}") + endif() + if (TMG_LIBRARY_DIRS) + set(REQUIRED_LIBDIRS "${TMG_LIBRARY_DIRS}") + endif() + set(REQUIRED_LIBS "${TMG_LIBRARIES}") + # LAPACK + if (LAPACK_INCLUDE_DIRS) + list(APPEND REQUIRED_INCDIRS "${LAPACK_INCLUDE_DIRS}") + endif() + if (LAPACK_LIBRARY_DIRS) + list(APPEND REQUIRED_LIBDIRS "${LAPACK_LIBRARY_DIRS}") + endif() + list(APPEND REQUIRED_LIBS "${LAPACK_LIBRARIES}") + if (LAPACK_LINKER_FLAGS) + list(APPEND REQUIRED_LDFLAGS "${LAPACK_LINKER_FLAGS}") + 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}") + string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + + # test link + unset(TMG_WORKS CACHE) + include(CheckFunctionExists) + include(CheckFortranFunctionExists) + if (NOT _LANGUAGES_ MATCHES Fortran) + check_function_exists(dlarnv TMG_WORKS) + else (NOT _LANGUAGES_ MATCHES Fortran) + check_fortran_function_exists(dlarnv TMG_WORKS) + endif (NOT _LANGUAGES_ MATCHES Fortran) + if (TMG_WORKS) + unset(TMG_WORKS CACHE) + if (NOT _LANGUAGES_ MATCHES Fortran) + check_function_exists(dlagsy TMG_WORKS) + else (NOT _LANGUAGES_ MATCHES Fortran) + check_fortran_function_exists(dlagsy TMG_WORKS) + endif (NOT _LANGUAGES_ MATCHES Fortran) + mark_as_advanced(TMG_WORKS) + endif() + + if(TMG_WORKS) + # save link with dependencies + set(TMG_LIBRARIES_DEP "${REQUIRED_LIBS}") + set(TMG_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") + set(TMG_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") + set(TMG_LINKER_FLAGS "${REQUIRED_LDFLAGS}") + list(REMOVE_DUPLICATES TMG_LIBRARY_DIRS_DEP) + list(REMOVE_DUPLICATES TMG_INCLUDE_DIRS_DEP) + list(REMOVE_DUPLICATES TMG_LINKER_FLAGS) + else() + if(NOT TMG_FIND_QUIETLY) + message(STATUS "Looking for tmg: test of dlarnv and dlagsy with tmg and lapack libraries 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(TMG_LIBRARIES) + + endif() + +else() + + if(NOT TMG_FIND_QUIETLY) + message(STATUS "TMG requires LAPACK but LAPACK has not been found." + "Please look for LAPACK first.") + endif() + +endif() + +if (TMG_LIBRARIES) + list(GET TMG_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(TMG_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of TMG library" FORCE) + else() + set(TMG_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of TMG library" FORCE) + endif() +endif() +mark_as_advanced(TMG_DIR) +mark_as_advanced(TMG_DIR_FOUND) + +# check that TMG has been found +# ------------------------------- +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(TMG DEFAULT_MSG + TMG_LIBRARIES + TMG_WORKS) diff --git a/modules/find/MORSE-Copyright.txt b/modules/find/MORSE-Copyright.txt new file mode 100644 index 0000000..1e5650e --- /dev/null +++ b/modules/find/MORSE-Copyright.txt @@ -0,0 +1,41 @@ +### +# +# @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. +# +### +# +# This software is a computer program whose purpose is to process +# Matrices Over Runtime Systems @ Exascale (MORSE). More information +# can be found on the following website: http://www.inria.fr/en/teams/morse. +# +# This software is governed by the CeCILL-C license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-C +# license as circulated by CEA, CNRS and INRIA at the following URL +# "http://www.cecill.info". +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# In this respect, the user's attention is drawn to the risks associated +# with loading, using, modifying and/or developing or reproducing the +# software by the user in light of its specific status of free software, +# that may mean that it is complicated to manipulate, and that also +# therefore means that it is reserved for developers and experienced +# professionals having in-depth computer knowledge. Users are therefore +# encouraged to load and test the software's suitability as regards their +# requirements in conditions enabling the security of their systems and/or +# data to be ensured and, more generally, to use and operate it in the +# same conditions as regards security. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-C license and that you accept its terms. +# +### diff --git a/modules/find/RulesJDF.cmake b/modules/find/RulesJDF.cmake new file mode 100644 index 0000000..2251edd --- /dev/null +++ b/modules/find/RulesJDF.cmake @@ -0,0 +1,54 @@ +# +# Internal module for DAGuE. +# Setup the minimal environment to compile and generate .JDF files. +# + +# +# This macro creates a rule for every jdf basename passed in SOURCES. +# The OUTPUTLIST contains the list of files generated by the maxro. +# +macro(jdf_rules jdf_rules_OUTPUTLIST jdf_rules_SOURCES) + + foreach(jdf_rules_SOURCE ${jdf_rules_SOURCES}) + # Remove .jdf if present + string(REGEX REPLACE ".jdf" "" jdf_rules_SRC ${jdf_rules_SOURCE}) + string(REGEX REPLACE "^(.*/)*(.+)\\.*.*" "\\2" jdf_rules_BSRC ${jdf_rules_SRC}) + set(jdf_rules_OSRC "${jdf_rules_BSRC}") + GET_PROPERTY(ADDITIONAL_DAGUEPP_CFLAGS SOURCE ${jdf_rules_SOURCE} PROPERTY ADDITIONAL_DAGUEPP_CFLAGS) + + get_source_file_property(jdf_rules_IsInBinaryDir ${jdf_rules_SOURCE} IS_IN_BINARY_DIR ) + + # If the file is generated in a different binary dir, + # we force the dependency on the generated file + # otherwise we let cmake choose the correct file, it is so good for that. + if( jdf_rules_IsInBinaryDir ) + + add_custom_command( + OUTPUT ${jdf_rules_OSRC}.h ${jdf_rules_OSRC}.c + COMMAND ${PARSEC_DAGUEPP} ${DAGUEPP_CFLAGS} ${ADDITIONAL_DAGUEPP_CFLAGS} -E -i ${jdf_rules_SRC}.jdf -o ${jdf_rules_OSRC} -f ${jdf_rules_BSRC} + MAIN_DEPENDENCY ${CMAKE_CURRENT_BINARY_DIR}/${jdf_rules_SRC}.jdf + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${jdf_rules_SRC}.jdf ${PARSEC_DAGUEPP}) + + else( jdf_rules_IsInBinaryDir ) + + add_custom_command( + OUTPUT ${jdf_rules_OSRC}.h ${jdf_rules_OSRC}.c + COMMAND ${PARSEC_DAGUEPP} ${DAGUEPP_CFLAGS} ${ADDITIONAL_DAGUEPP_CFLAGS} -E -i ${jdf_rules_SRC}.jdf -o ${jdf_rules_OSRC} -f ${jdf_rules_BSRC} + MAIN_DEPENDENCY ${jdf_rules_SRC}.jdf + DEPENDS ${jdf_rules_SRC}.jdf ${PARSEC_DAGUEPP}) + + endif( jdf_rules_IsInBinaryDir ) + + set_source_files_properties(${jdf_rules_OSRC}.c PROPERTIES COMPILE_FLAGS "-I${PARSEC_DIR_FOUND}/include/daguepp") + list(APPEND ${jdf_rules_OUTPUTLIST} "${CMAKE_CURRENT_BINARY_DIR}/${jdf_rules_OSRC}.h;${CMAKE_CURRENT_BINARY_DIR}/${jdf_rules_OSRC}.c") + get_source_file_property(jdf_rules_CompileFlags ${jdf_rules_SOURCE} COMPILE_FLAGS ) + if( jdf_rules_CompileFlags ) + set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${jdf_rules_OSRC}.c PROPERTIES COMPILE_FLAGS ${jdf_rules_CompileFlags} ) + endif() + + endforeach() + # + # Mark all generated files as such. + # + set_source_files_properties(${jdf_rules_OUTPUTLIST} PROPERTIES GENERATED 1) +endmacro(jdf_rules) diff --git a/modules/find/css b/modules/find/css new file mode 120000 index 0000000..a7287ed --- /dev/null +++ b/modules/find/css @@ -0,0 +1 @@ +../../../../../doc/css \ No newline at end of file diff --git a/modules/find/morse_cmakefind_doc.html b/modules/find/morse_cmakefind_doc.html new file mode 100644 index 0000000..075e085 --- /dev/null +++ b/modules/find/morse_cmakefind_doc.html @@ -0,0 +1,284 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> +<head> +<title>MORSE CMake "Find modules" documentation</title> +<!-- 2016-09-15 jeu. 08:01 --> +<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> +<meta name="generator" content="Org-mode" /> +<meta name="author" content="HiePACS" /> +<link rel="stylesheet" title="Standard" href="css/worg.css" type="text/css" /> +<link rel="stylesheet" type="text/css" href="css/VisuGen.css" /> +<link rel="stylesheet" type="text/css" href="css/VisuRubriqueEncadre.css" /> +<script type="text/javascript"> +/* +@licstart The following is the entire license notice for the +JavaScript code in this tag. + +Copyright (C) 2012-2013 Free Software Foundation, Inc. + +The JavaScript code in this tag is free software: you can +redistribute it and/or modify it under the terms of the GNU +General Public License (GNU GPL) as published by the Free Software +Foundation, either version 3 of the License, or (at your option) +any later version. The code is distributed WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. + +As additional permission under GNU GPL version 3 section 7, you +may distribute non-source (e.g., minimized or compacted) forms of +that code without the copy of the GNU GPL normally required by +section 4, provided you include this license notice and a URL +through which recipients can access the Corresponding Source. + + +@licend The above is the entire license notice +for the JavaScript code in this tag. +*/ +<!--/*--><![CDATA[/*><!--*/ + function CodeHighlightOn(elem, id) + { + var target = document.getElementById(id); + if(null != target) { + elem.cacheClassElem = elem.className; + elem.cacheClassTarget = target.className; + target.className = "code-highlighted"; + elem.className = "code-highlighted"; + } + } + function CodeHighlightOff(elem, id) + { + var target = document.getElementById(id); + if(elem.cacheClassElem) + elem.className = elem.cacheClassElem; + if(elem.cacheClassTarget) + target.className = elem.cacheClassTarget; + } +/*]]>*///--> +</script> +</head> +<body> +<div id="content"> +<h1 class="title">MORSE CMake "Find modules" documentation</h1> +<div id="table-of-contents"> +<h2>Table of Contents</h2> +<div id="text-table-of-contents"> +<ul> +<li><a href="#sec-1">1. CMake find modules: what is it, why is it useful?</a></li> +<li><a href="#sec-2">2. How CMake is aware of these specific modules?</a></li> +<li><a href="#sec-3">3. Internal mechanism: what a "find" mainly do, what are the paths scanned?</a> +<ul> +<li><a href="#sec-3-1">3.1. How to act on the searching process?</a></li> +<li><a href="#sec-3-2">3.2. A version of the library is found but I want another one, how to change?</a></li> +</ul> +</li> +<li><a href="#sec-4">4. How to get more information about a specific module usage?</a></li> +</ul> +</div> +</div> +<p> +This document aims at documenting MORSE find_package CMake modules +which allow to detect library dependencies on UNIX systems (mainly +Linux and MAC OS X). These additional modules have been written +because either, they are not distributed by the CMake community, or, +they already exist but some are outdated or miss the requirements we +need. +</p> + +<div id="outline-container-sec-1" class="outline-2"> +<h2 id="sec-1"><span class="section-number-2">1</span> CMake find modules: what is it, why is it useful?</h2> +<div class="outline-text-2" id="text-1"> +<p> +The CMake modules being here can be used to "find" some installed +libraries on the system through the invocation of the <code>find_package</code> +CMake command ("MODULE" mode signature, cf. CMake documentation of +<code>find_package</code> command) +</p> +<pre class="example"> +find_package(BLAS) # look for BLAS libraries and compiler/linker flags +add_executable(foo ${FOO_SOURCES}) # define an executable from sources +target_link_libraries(foo ${BLAS_LIBRARIES}) # add BLAS libraries for the link +</pre> + +<p> +It allows to find efficiently the libraries we depend on. +The modules are generally written by the library developers or very +active users so that they know very well how the library is built how +it is installed, etc. +</p> +</div> +</div> + +<div id="outline-container-sec-2" class="outline-2"> +<h2 id="sec-2"><span class="section-number-2">2</span> How CMake is aware of these specific modules?</h2> +<div class="outline-text-2" id="text-2"> +<p> +<code>find_package(LIBNAME)</code> rely on a CMake module file called +<i>FindLIBNAME.cmake</i> which should lies in a directory set in the CMake +variable <code>CMAKE_MODULE_PATH</code>. For example, <code>FindLIBNAME.cmake</code> is in the +relative path <code>./cmake_modules/FindLIBNAME.cmake</code> +</p> +<pre class="example"> +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules") +find_package(LIBNAME) +</pre> + +<p> +To use MORSE modules you can add the path to the modules in your CMake +project like this +</p> +<pre class="example"> +list(APPEND CMAKE_MODULE_PATH "${MORSE_DISTRIB_DIR}/cmake_modules/morse/find" ) +</pre> +</div> +</div> + +<div id="outline-container-sec-3" class="outline-2"> +<h2 id="sec-3"><span class="section-number-2">3</span> Internal mechanism: what a "find" mainly do, what are the paths scanned?</h2> +<div class="outline-text-2" id="text-3"> +<p> +The general process consists in looking into some system paths known +from CMake to find headers and libraries and define in output some +CMake variables the user need to link with his dependency. Additionaly +to the system paths, some environment variable can also be scanned +like <code>LD_LIBRARY_PATH</code> and <code>CPATH</code>. A custom CMake cache variable +<code>LIBNAME_DIR</code> is also introduced in our modules in order to let users +indicate directly during the "configure" step a specific installation +directory for the library (e.g. where are located the include/, lib/, +etc, sub-directories). The priority order is the following: +</p> +<ol class="org-ol"> +<li>The CMake variable <code>LIBNAME_DIR</code> is set or both <code>LIBNAME_INCDIR</code> and +<code>LIBNAME_LIBDIR</code> are set +</li> +<li>The environment variable <code>LIBNAME_DIR</code> is set or both <code>LIBNAME_INCDIR</code> and +<code>LIBNAME_LIBDIR</code> +</li> +<li>A pkg-config .pc file (hwloc.pc) of the library is available in the +environment (cf. PKG_CONFIG_PATH environment variable) and is used +</li> +<li>Look into the following paths +<ol class="org-ol"> +<li>for headers: +<ul class="org-ul"> +<li>scan the paths present in the following environment variables +<code>INCLUDE</code>, <code>C_INCLUDE_PATH</code>, <code>CPATH</code>, <code>INCLUDE_PATH</code> +</li> +<li>scan the system paths for headers: look into path present in +the CMake variables +<code>CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES</code> and +<code>CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES</code> +</li> +</ul> +</li> +<li>for libraries: +<ul class="org-ul"> +<li>scan the paths present in the following environment variables +<code>LIB</code> (Windows), <code>DYLD_LIBRARY_PATH</code> (Mac OS X), <code>LD_LIBRARY_PATH</code> (Linux) +</li> +<li>scan the system paths for headers: look into path present in +the CMake variables +<code>CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES</code>, +<code>CMAKE_C_IMPLICIT_LINK_DIRECTORIES</code> +</li> +</ul> +</li> +</ol> +</li> +</ol> + +<p> +When it is possible, compiler flags are also given to users. This last +point suggest that the information can be found in the library +installation, e.g. through a pkg-config file. +</p> + +<p> +In some cases, the library can be searched for a specific +configuration, e.g "I want to find an installation of this library +coming with all these components enabled" such as: MUMPS linear solver +must be able to use SCOTCH graph partitioner. See the "COMPONENTS" +option of the <code>find_package</code> command and look for the header of the +module file to get more information about possible components. +</p> + +<p> +Once some header files and libraries have been found the module tries +to call a basic function of the library to test the link step. During +this process, the CMake <code>check_function_exists</code> is used. If the test +fails a message is given with the compiler and linker flags used +during the test. The precise error can also be found in the +<code>CMakeFiles/CMakeError.log</code> file of the build directory. +</p> +</div> + +<div id="outline-container-sec-3-1" class="outline-3"> +<h3 id="sec-3-1"><span class="section-number-3">3.1</span> How to act on the searching process?</h3> +<div class="outline-text-3" id="text-3-1"> +<p> +If the user does not change the environment (do not modify environment +variables like <code>LD_LIBRARY_PATH</code>), and gives no hint at all about the +location of the libraries, the module will match the situation 4.2 and +will look into system paths. +</p> + +<p> +To give an "exotic" locations, i.e. not in system paths, the user can +use scripts or a <code>module</code> like system to set the paths in environment +variables (<code>LD_LIBRARY_PATH</code>, <code>INCLUDE</code>, …), cf. situation 4.1 and 2. +</p> + +<p> +For some libraries it is possible to rely on <code>pkg-config</code> if the .pc +file path is in the <code>PKG_CONFIG_PATH</code> environment variable, +cf. situation 3. +</p> + +<p> +Finally, to directly give "by hand" the path, the user can set a CMake +variable <code>LIBNAME_DIR</code>, or the pair <code>LIBNAME_INCDIR</code> and <code>LIBNAME_LIBDIR</code>, +cf. situation 1. +</p> +</div> +</div> + +<div id="outline-container-sec-3-2" class="outline-3"> +<h3 id="sec-3-2"><span class="section-number-3">3.2</span> A version of the library is found but I want another one, how to change?</h3> +<div class="outline-text-3" id="text-3-2"> +<p> +If a first configuration has found a library somewhere but you are not +satisfied with this one and want to give some hints to look for it: +</p> +<ul class="org-ul"> +<li>update your environment or give the location "by hand" (<code>LIBNAME_DIR</code>) +</li> +<li>delete the CMake cache file to make it "forget" the libraries +already found: <code>rm CMakeCache.txt</code> +</li> +<li>configure again: <code>cmake path/to/your/CMakeLists.txt ...</code> +</li> +</ul> +</div> +</div> +</div> + +<div id="outline-container-sec-4" class="outline-2"> +<h2 id="sec-4"><span class="section-number-2">4</span> How to get more information about a specific module usage?</h2> +<div class="outline-text-2" id="text-4"> +<p> +Specific information about a precise Find module are given directly at +the head of the module file. The usage, the optional parameters that +can be used and the output variables are explained here. +</p> +</div> +</div> +</div> +<div id="postamble" class="status"> +<p class="author">Author: HiePACS</p> +<p class="date">Created: 2016-09-15 jeu. 08:01</p> +<p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 24.5.1 (<a href="http://orgmode.org">Org</a> mode 8.2.10)</p> +<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p> +</div> +</body> +</html> diff --git a/modules/find/morse_cmakefind_doc.org b/modules/find/morse_cmakefind_doc.org new file mode 100644 index 0000000..75fb9e0 --- /dev/null +++ b/modules/find/morse_cmakefind_doc.org @@ -0,0 +1,135 @@ +#+TITLE: MORSE CMake "Find modules" documentation +#+AUTHOR: HiePACS +#+LANGUAGE: en +#+OPTIONS: H:3 num:t toc:t \n:nil @:t ::t |:t _:nil ^:nil -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil pri:nil tags:not-in-toc html-style:nil +#+EXPORT_SELECT_TAGS: export +#+EXPORT_EXCLUDE_TAGS: noexport +#+TAGS: noexport(n) +#+STARTUP: nolatexpreview + +#+BEAMER_THEME: Rochester + +#+HTML_HEAD: <link rel="stylesheet" title="Standard" href="css/worg.css" type="text/css" /> +#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="css/VisuGen.css" /> +#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="css/VisuRubriqueEncadre.css" /> + +This document aims at documenting MORSE find_package CMake modules +which allow to detect library dependencies on UNIX systems (mainly +Linux and MAC OS X). These additional modules have been written +because either, they are not distributed by the CMake community, or, +they already exist but some are outdated or miss the requirements we +need. + +* CMake find modules: what is it, why is it useful? +The CMake modules being here can be used to "find" some installed +libraries on the system through the invocation of the ~find_package~ +CMake command ("MODULE" mode signature, cf. CMake documentation of +~find_package~ command) +#+BEGIN_EXAMPLE +find_package(BLAS) # look for BLAS libraries and compiler/linker flags +add_executable(foo ${FOO_SOURCES}) # define an executable from sources +target_link_libraries(foo ${BLAS_LIBRARIES}) # add BLAS libraries for the link +#+END_EXAMPLE + +It allows to find efficiently the libraries we depend on. +The modules are generally written by the library developers or very +active users so that they know very well how the library is built how +it is installed, etc. + +* How CMake is aware of these specific modules? +~find_package(LIBNAME)~ rely on a CMake module file called +/FindLIBNAME.cmake/ which should lies in a directory set in the CMake +variable ~CMAKE_MODULE_PATH~. For example, ~FindLIBNAME.cmake~ is in the +relative path ~./cmake_modules/FindLIBNAME.cmake~ +#+BEGIN_EXAMPLE +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules") +find_package(LIBNAME) +#+END_EXAMPLE + +To use MORSE modules you can add the path to the modules in your CMake +project like this +#+BEGIN_EXAMPLE +list(APPEND CMAKE_MODULE_PATH "${MORSE_DISTRIB_DIR}/cmake_modules/morse/find" ) +#+END_EXAMPLE + +* Internal mechanism: what a "find" mainly do, what are the paths scanned? +The general process consists in looking into some system paths known +from CMake to find headers and libraries and define in output some +CMake variables the user need to link with his dependency. Additionaly +to the system paths, some environment variable can also be scanned +like ~LD_LIBRARY_PATH~ and ~CPATH~. A custom CMake cache variable +~LIBNAME_DIR~ is also introduced in our modules in order to let users +indicate directly during the "configure" step a specific installation +directory for the library (e.g. where are located the include/, lib/, +etc, sub-directories). The priority order is the following: +1) The CMake variable ~LIBNAME_DIR~ is set or both ~LIBNAME_INCDIR~ and + ~LIBNAME_LIBDIR~ are set +2) The environment variable ~LIBNAME_DIR~ is set or both ~LIBNAME_INCDIR~ and + ~LIBNAME_LIBDIR~ +3) A pkg-config .pc file (hwloc.pc) of the library is available in the + environment (cf. PKG_CONFIG_PATH environment variable) and is used +4) Look into the following paths + a) for headers: + - scan the paths present in the following environment variables + ~INCLUDE~, ~C_INCLUDE_PATH~, ~CPATH~, ~INCLUDE_PATH~ + - scan the system paths for headers: look into path present in + the CMake variables + ~CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES~ and + ~CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES~ + b) for libraries: + - scan the paths present in the following environment variables + ~LIB~ (Windows), ~DYLD_LIBRARY_PATH~ (Mac OS X), ~LD_LIBRARY_PATH~ (Linux) + - scan the system paths for headers: look into path present in + the CMake variables + ~CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES~, + ~CMAKE_C_IMPLICIT_LINK_DIRECTORIES~ + +When it is possible, compiler flags are also given to users. This last +point suggest that the information can be found in the library +installation, e.g. through a pkg-config file. + +In some cases, the library can be searched for a specific +configuration, e.g "I want to find an installation of this library +coming with all these components enabled" such as: MUMPS linear solver +must be able to use SCOTCH graph partitioner. See the "COMPONENTS" +option of the ~find_package~ command and look for the header of the +module file to get more information about possible components. + +Once some header files and libraries have been found the module tries +to call a basic function of the library to test the link step. During +this process, the CMake ~check_function_exists~ is used. If the test +fails a message is given with the compiler and linker flags used +during the test. The precise error can also be found in the +~CMakeFiles/CMakeError.log~ file of the build directory. + +** How to act on the searching process? +If the user does not change the environment (do not modify environment +variables like ~LD_LIBRARY_PATH~), and gives no hint at all about the +location of the libraries, the module will match the situation 4.2 and +will look into system paths. + +To give an "exotic" locations, i.e. not in system paths, the user can +use scripts or a ~module~ like system to set the paths in environment +variables (~LD_LIBRARY_PATH~, ~INCLUDE~, ...), cf. situation 4.1 and 2. + +For some libraries it is possible to rely on ~pkg-config~ if the .pc +file path is in the ~PKG_CONFIG_PATH~ environment variable, +cf. situation 3. + +Finally, to directly give "by hand" the path, the user can set a CMake +variable ~LIBNAME_DIR~, or the pair ~LIBNAME_INCDIR~ and ~LIBNAME_LIBDIR~, +cf. situation 1. + +** A version of the library is found but I want another one, how to change? +If a first configuration has found a library somewhere but you are not +satisfied with this one and want to give some hints to look for it: +- update your environment or give the location "by hand" (~LIBNAME_DIR~) +- delete the CMake cache file to make it "forget" the libraries + already found: ~rm CMakeCache.txt~ +- configure again: ~cmake path/to/your/CMakeLists.txt ...~ + +* How to get more information about a specific module usage? +Specific information about a precise Find module are given directly at +the head of the module file. The usage, the optional parameters that +can be used and the output variables are explained here. diff --git a/modules/precision_generator/Conversion.py b/modules/precision_generator/Conversion.py new file mode 100644 index 0000000..00202d7 --- /dev/null +++ b/modules/precision_generator/Conversion.py @@ -0,0 +1,266 @@ +#!/usr/bin/env python +"""@package Tools + +This python script is responsible for precision generation replacements +as well as replacements of any kind in other files. Different types of +replacements can be defined such that no two sets can conflict. Multiple +types of replacements can, however, be specified for the same file. + +@author Wesley Alvaro +@date 2011-4-8 + +""" +__author__="alvaro" +__date__ ="$Sep 2, 2010 10:09:19 AM$" +__version__=11.0408 + +import sys; +import re; +import shlex; +import os; +import shutil; +from os import path; +from optparse import OptionParser,OptionGroup; +from subs import subs; +from datetime import datetime; + +"""Keyword used to signal replacement actions on a file""" +KEYWORD = '@precisions'; +"""Replace the above keyword with this one post-replacements""" +DONE_KEYWORD = '@generated'; +"""Regular expression for the replacement formatting""" +REGEX = '^.*'+KEYWORD+'\s+((\w+,?)+)\s+(\w+)\s+->\s*((\s\w+)+).*$'; +"""Default acceptable extensions for files during directory walking""" +EXTS = ['.c','.cpp','.h','.hpp','.f','.jdf','.f90','.F90','.f77','.F77','.cu','.cuf','.CUF','.jdf']; + +def check_gen(file, work, rex): + """Reads the file and determines if the file needs generation.""" + fd = open(path.realpath(file), 'r'); + lines = fd.readlines(); + fd.close(); + for line in lines: + m = rex.match(line); + if m is None: continue; + work.append((file, m.groups(), ''.join(lines))); + +def grep(string,list): + expr = re.compile(string) + return filter(expr.search,list) + +def hidden(file): + """Exclude hidden files""" + return not file.startswith('.'); + +def valid_extension(file): + """Exclude non-valid extensions""" + global EXTS; + for ext in EXTS: + if file.endswith(ext): + return True; + return False; + +def relpath(p): + """Get the relative path of a file.""" + p = path.realpath(p); + return p.replace(path.realpath('.')+'/',''); + +class Conversion: + """ + This class works on a single file to create generations + """ + """Static. Is the conversion in debug mode? More verbose.""" + debug = False; + """Static. Is the conversion in test mode? No real work.""" + test = False; + """Static. Is the conversion in make mode? Output make commands.""" + make = False; + """Static. What (if any) prefix is specified for the output folder? + If None, use the file's resident folder.""" + prefix = None; + required_precisions = []; + """Static. A running list of files that are input.""" + files_in = []; + """Static. A running list of files that are output.""" + files_out = []; + """Static. A running list of files that are output.""" + dependencies = []; + def __init__(self, file = None, match = None, content = None): + """Constructor that takes a file, match, and content. + @param file The file name of the input. + @param match The regular expression matches + @param content The ASCII content of the file. + """ + if file is None: return; + self.content = content; + #file = path.realpath(file); + rel = relpath(file); + self.file = list(path.split(file)); + self.date = path.getmtime(file); + if sys.platform!="win32" and path.samefile(path.join(self.file[0],self.file[1]),sys.argv[0]): + raise ValueError('Let\'s just forget codegen.py'); + try: + """['normal','all','mixed'] for example. This(ese) are the replacement types to be used.""" + self.types = match[0].split(','); + """'z' for example. This is the current file's `type`.""" + self.precision = match[2].lower(); + """['c','d','s'] for example. This is the current file's destination `types`.""" + self.precisions = match[3].lower().split(); + if len(self.required_precisions): + self.precstmp = []; + for prec in self.required_precisions: + if prec in self.precisions or prec == self.precision: + self.precstmp.append(prec); + self.precisions = self.precstmp; + except: + raise ValueError(path.join(self.file[0],self.file[1])+' : Invalid conversion string'); + self.files_in.append(rel); + + def run(self): + """Does the appropriate work, if in test mode, this is limited to only converting names.""" + if self.convert_names() and not self.test: + """If not in test mode, actually make changes and export to disk.""" + self.convert_data(); + self.export_data(); + + def convert_names(self): + """Investigate file name and make appropriate changes.""" + self.names = []; + self.dates = []; + self.copy = []; + self.converted = []; + load = False; + if self.debug: print '|'.join(self.types), self.precision, relpath(path.join(self.file[0],self.file[1])); + for precision in self.precisions: + """For each destination precision, make the appropriate changes to the file name/data.""" + new_file = self.convert(self.file[1], precision); + if self.debug: print precision,':', + copy = False; + if new_file <> self.file[1] or self.prefix is not None: + if self.prefix is None: + """If no prefix is specified, use the file's current folder.""" + prefix = '' + makeprefix = ''; + else: + """If a prefix is specified, set it up.""" + prefix = self.prefix; + makeprefix = '--prefix '+prefix; + if new_file == self.file[1]: + copy = True; + """Where the destination file will reside.""" + conversion = path.join(prefix, new_file); + file_out = relpath(conversion); + if self.make: + """If in GNU Make mode, write the rule to create the file.""" + file_in = relpath(path.join(self.file[0],self.file[1])); + print file_out+':',file_in; + print "\t$(PYTHON)",path.realpath(sys.argv[0]),makeprefix,'-p',precision,"--file",file_in; + self.names.append(new_file); + self.files_out.append(file_out); + self.dependencies.append( (path.join(self.file[0],self.file[1]), precision, file_out) ); + if self.debug: print relpath(conversion), ':', + try: + """Try to emulate Make like time based dependencies.""" + date = path.getmtime(conversion); + diff = self.date - date; + self.dates.append(diff); + if self.debug: + if diff > 0: print 'Old', + else: print 'Current', + print diff; + if diff > 0: load = True; + except: + if self.debug: print 'Missing'; + self.dates.append(None); + load = True; + elif precision <> self.precision : + """There was no change in the file's name, thus, + no work can be done without overwriting the original.""" + if self.debug: print '<No Change>',':'; + else: print >> sys.stderr, new_file, 'had no change for', precision; + self.names.append(None); + self.dates.append(None); + self.copy.append(copy); + return load; + + def export_data(self): + """After all of the conversions are complete, + this will write the output file contents to the disk.""" + for i in range(len(self.names)): + name = self.names[i]; + data = self.converted[i]; + copy = self.copy[i]; + if copy: + shutil.copy(self.files_in[i], self.files_out[i]); + continue; + if data is None or name is None: continue; + fd = open(self.files_out[i], 'w'); + fd.write(data); + fd.close(); + + + def convert_data(self): + """Convert the data in the files by making the + appropriate replacements for each destination precision.""" + for i in range(len(self.precisions)): + precision = self.precisions[i]; + name = self.names[i]; + date = self.dates[i]; + copy = self.copy[i]; + if name is not None and not copy and (date is None or date > 0): + self.converted.append(self.convert(self.content, precision)); + else: self.converted.append(None); + + def substitute(self, sub_type, data, precision): + """This operates on a single replacement type. + @param sub_type The name of the replacement set. + @param data The content subject for replacments. + @param precision The target precision for replacements. + """ + try: + """Try to select the requested replacements.""" + work = subs[sub_type]; + prec_to = work[0].index(precision); + prec_from = work[0].index(self.precision); + except: + """If requested replacement type does not exist, + return unaltered contents.""" + return data; + for i in range(1,len(work)): + """Requested replacements were found, + execute replacements for each entry.""" + try: + search = work[i][prec_from]; + replace = work[i][prec_to]; + if not search: continue; + replace = replace.replace('\*','*'); + if sub_type != 'tracing' : + replace = replace.replace('\(','('); + replace = replace.replace('\)',')'); + data = re.sub(search, replace, data); + except: + print 'Bad replacement pair ',i,'in',sub_type; + continue; + return data; + + def convert(self, data, precision): + """Select appropriate replacements for the current file. + @param data The content subject for the replacements. + @param precision The target precision for generation. + """ + global KEYWORD, DONE_KEYWORD; + try: + """All files undergo the "all" replacements.""" + data = self.substitute('all', data, precision); + except: pass; + for sub_type in self.types: + """For all the other types of conversion for the current file, + make the correct replacements.""" + if sub_type == 'all': continue; + try: + data = self.substitute(sub_type, data, precision); + except Exception, e: + raise ValueError('I encountered an unrecoverable error while working in subtype:',sub_type+'.'); + """Replace the replacement keywork with one that signifies this is an output file, + to prevent multiple replacement issues if run again.""" + data = re.sub(KEYWORD+' '+','.join(self.types)+'.*', DONE_KEYWORD+' '+precision+' '+datetime.now().ctime(), data); + return data; diff --git a/modules/precision_generator/codegen.py b/modules/precision_generator/codegen.py new file mode 100755 index 0000000..8b03223 --- /dev/null +++ b/modules/precision_generator/codegen.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +"""@package Tools + +This python script is responsible for precision generation replacements +as well as replacements of any kind in other files. Different types of +replacements can be defined such that no two sets can conflict. Multiple +types of replacements can, however, be specified for the same file. + +@author Wesley Alvaro +@date 2011-4-8 + +""" +__author__="alvaro" +__date__ ="$Sep 2, 2010 10:09:19 AM$" +__version__=11.0408 + +import sys; +import re; +import shlex; +import os; +import shutil; +from os import path; +from optparse import OptionParser,OptionGroup; +from datetime import datetime; +from Conversion import KEYWORD,DONE_KEYWORD,REGEX,EXTS,Conversion,check_gen,subs; + +def main(): + """Create option parser, set static variables of the converter and manage printing options/order.""" + global REGEX, EXTS; + """The compiled regular expression for detecting proper files.""" + rex = re.compile(REGEX); + """Files found to be workable.""" + work = []; + + """Create the options parser for detecting options on the command line.""" + parser = OptionParser(usage="Usage: %prog [options]",version='%prog '+str(__version__)); + group = OptionGroup(parser,"Printing Options","These options control the printing output."); + group.add_option("-i", "--in-files", help='Print the filenames of files for precision generation.', action='store_true', dest='in_print', default=False); + group.add_option("-o", "--out-files", help='Print the filenames for the precision generated files.', action='store_true', dest='out_print', default=False); + group.add_option("-m", "--make", help='Spew a GNU Make friendly file to standard out.', action='store_true', dest='make', default=False); + group.add_option("-d", "--debug", help='Print debugging messages.', action='store_true', dest='debug', default=False); + parser.add_option_group(group); + group = OptionGroup(parser,"Operating Mode Options","These options alter the way the program operates on the input/output files."); + group.add_option("-c", "--clean", help='Remove the files that are the product of generation.', action='store_true', dest='out_clean', default=False); + group.add_option("-T", "--test", help='Don\'t actually do any work.', action='store_true', dest='test', default=False); + parser.add_option_group(group); + group = OptionGroup(parser,"Settings","These options specify how the work should be done."); + group.add_option("-P", "--prefix", help='The output directory if different from the input directory.', action='store', dest='prefix', default=None); + group.add_option("-f", "--file", help='Specify a file(s) on which to operate.', action='store', dest='fileslst', type='string', default=""); + group.add_option("-p", "--prec", help='Specify a precision(s) on which to operate.', action='store', dest='precslst', type='string', default=""); + group.add_option("-e", "--filetypes", help='Specify file extensions on which to operate when walking.', action='store', dest='fileexts', type='string', default=""); + parser.add_option_group(group); + + (options, args) = parser.parse_args(); + + """If file extensions are specified, override defaults.""" + if options.fileexts: + EXTS = options.fileexts.split(); + + """Fill the 'work' array with files found to be operable.""" + if options.fileslst: + """If files to examine are specified on the command line""" + for file in options.fileslst.split(): + check_gen(file, work, rex); + else: + """Begin directory walking in the current directory.""" + startDir = '.'; + for root, dirs, files in os.walk(startDir, True, None): + dirs = filter(hidden,dirs); + files = filter(hidden,files); + files = filter(valid_extension,files); + for file in files: + check_gen(path.join(root,file), work, rex); + + """Set static options for conversion.""" + Conversion.debug = options.debug; + Conversion.make = options.make; + Conversion.prefix = options.prefix; + Conversion.required_precisions = options.precslst.split(); + if options.out_print or options.out_clean or options.in_print or options.make or options.test: + Conversion.test = True; + + if options.make: + """If the program should be GNU Make friendly.""" + print '## Automatically generated Makefile'; + print 'PYTHON ?= python'; + + c = Conversion(); """This initializes the variable for static member access.""" + + for tuple in work: + """For each valid conversion file found.""" + try: + """Try creating and executing a converter.""" + c = Conversion(tuple[0], tuple[1], tuple[2]); + c.run(); + except Exception, e: + print >> sys.stderr, str(e); + continue; + + if options.make: + """If the program should be GNU Make friendly.""" + print 'gen = ',' '+' '.join(c.files_out); + print 'cleangen:'; + print '\trm -f $(gen)'; + print 'generate: $(gen)'; + print '.PHONY: cleangen generate'; + if options.in_print: + """Should we print the input files?""" + print ' '.join(c.files_in); + if options.out_print: + """Should we print the output files?""" + print ' '.join(c.files_out); + if options.out_clean: + """Clean generated files""" + for file in c.files_out: + if not path.exists(file): continue; + os.remove(file); + +if __name__ == "__main__": + main(); diff --git a/modules/precision_generator/genDependencies.py b/modules/precision_generator/genDependencies.py new file mode 100755 index 0000000..973e5aa --- /dev/null +++ b/modules/precision_generator/genDependencies.py @@ -0,0 +1,211 @@ +#!/usr/bin/env python +"""@package Tools + +This python script is responsible for precision generation replacements +as well as replacements of any kind in other files. Different types of +replacements can be defined such that no two sets can conflict. Multiple +types of replacements can, however, be specified for the same file. + +@author Wesley Alvaro +@date 2011-4-8 + +""" +__author__="alvaro" +__date__ ="$Sep 2, 2010 10:09:19 AM$" +__version__=11.0408 + +import sys; +import re; +import shlex; +import os; +import shutil; +import imp; +from os import path; +from optparse import OptionParser,OptionGroup; +from datetime import datetime; +from Conversion import KEYWORD,DONE_KEYWORD,REGEX,EXTS,Conversion,check_gen,relpath,subs; + +class GenConversion: + """ + This class works on a single file to create generations + """ + """Static. Source directory where to find the input files""" + srcdir = None; + """Static. What (if any) prefix is specified for the output folder? + If None, use the file's resident folder.""" + prefix = None; + """Static. Precisions asked by the user.""" + required_precisions = []; + """The compiled regular expression for detecting proper files.""" + rex = re.compile(REGEX); + + def run(self, file = None): + match = None; + """Local complete """ + if self.srcdir is None: + lfile = file; + else: + lfile = path.join(self.srcdir, file); + """Reads the file and determines if the file needs generation.""" + for line in open(path.realpath(lfile), 'r'): + m = self.rex.match(line); + if m is None: continue; + else: + match = m.groups(); + break; + + """This file need to go through precision generation script""" + if match is None: + return ""; + else: + try: + """['normal','all','mixed'] for example. This(ese) are the replacement types to be used.""" + self.types = match[0].split(','); + """'z' for example. This is the current file's `type`.""" + self.precision = match[2].lower(); + """['c','d','s'] for example. This is the current file's destination `types`.""" + self.precisions = set(match[3].lower().split()); + """Add the local precision to the list if not present""" + self.precisions.add(self.precision); + """Take only the intersection of the available precision and the requested ones""" + self.precisions.intersection_update(self.required_precisions); + except: + raise ValueError(lfile+' : Invalid conversion string'); + + filename = list(path.split(lfile))[1]; + result = ""; + for precision in self.precisions: + """For each destination precision, make the appropriate changes to the file name/data.""" + new_file = self.convert(filename, precision); + if new_file <> filename or self.prefix is not None: + if self.prefix is None: + """If no prefix is specified, use the file's current folder.""" + prefix = '' + else: + """If a prefix is specified, set it up.""" + prefix = self.prefix; + """Where the destination file will reside.""" + conversion = path.join(prefix, new_file); + file_out = relpath(conversion); + result = result+file+","+precision+","+file_out+";"; + return result; + + def substitute(self, sub_type, data, precision): + """This operates on a single replacement type. + @param sub_type The name of the replacement set. + @param data The content subject for replacments. + @param precision The target precision for replacements. + """ + try: + """Try to select the requested replacements.""" + work = subs[sub_type]; + prec_to = work[0].index(precision); + prec_from = work[0].index(self.precision); + except: + """If requested replacement type does not exist, + return unaltered contents.""" + return data; + for i in range(1,len(work)): + """Requested replacements were found, + execute replacements for each entry.""" + try: + search = work[i][prec_from]; + replace = work[i][prec_to]; + if not search: continue; + replace = replace.replace('\*','*'); + if sub_type != 'tracing' : + replace = replace.replace('\(','('); + replace = replace.replace('\)',')'); + data = re.sub(search, replace, data); + except: + print 'Bad replacement pair ',i,'in',sub_type; + continue; + return data; + + def convert(self, data, precision): + """Select appropriate replacements for the current file. + @param data The content subject for the replacements. + @param precision The target precision for generation. + """ + global KEYWORD, DONE_KEYWORD; + try: + """All files undergo the "all" replacements.""" + data = self.substitute('all', data, precision); + except: pass; + for sub_type in self.types: + """For all the other types of conversion for the current file, + make the correct replacements.""" + if sub_type == 'all': continue; + try: + data = self.substitute(sub_type, data, precision); + except Exception, e: + raise ValueError('I encountered an unrecoverable error while working in subtype:',sub_type+'.'); + return data; + + +def main(): + """Create option parser, set static variables of the converter and manage printing options/order.""" + global REGEX, EXTS; + """The compiled regular expression for detecting proper files.""" + rex = re.compile(REGEX); + """Files found to be workable.""" + work = []; + + """Create the options parser for detecting options on the command line.""" + parser = OptionParser(usage="Usage: %prog [options]",version='%prog '+str(__version__)); + group = OptionGroup(parser,"Printing Options","These options control the printing output."); + group.add_option("-i", "--in-files", help='Print the filenames of files for precision generation.', action='store_true', dest='in_print', default=False); + group.add_option("-o", "--out-files", help='Print the filenames for the precision generated files.', action='store_true', dest='out_print', default=False); + group.add_option("-d", "--debug", help='Print debugging messages.', action='store_true', dest='debug', default=False); + parser.add_option_group(group); + group = OptionGroup(parser,"Settings","These options specify how the work should be done."); + group.add_option("-s", "--srcdir", help='The input source directory.', action='store', dest='srcdir', default=None); + group.add_option("-P", "--prefix", help='The output directory if different from the input directory.', action='store', dest='prefix', default=None); + group.add_option("-f", "--file", help='Specify a file(s) on which to operate.', action='store', dest='fileslst', type='string', default=""); + group.add_option("-p", "--prec", help='Specify a precision(s) on which to operate.', action='store', dest='precslst', type='string', default=""); + group.add_option("-e", "--filetypes", help='Specify file extensions on which to operate when walking.', action='store', dest='fileexts', type='string', default=""); + group.add_option("-D", "--dictionnary", help='Specify the dictionnary to use in names conversion.', action='store', dest='dictionnary', type='string', default=""); + parser.add_option_group(group); + + (options, args) = parser.parse_args(); + + """If file extensions are specified, override defaults.""" + if options.fileexts: + EXTS = options.fileexts.split(); + + """Fill the 'work' array with files found to be operable.""" + # if options.fileslst: + # """If files to examine are specified on the command line""" + # for file in options.fileslst.split(): + # check_gen(file, work, rex); + # else: + # """Begin directory walking in the current directory.""" + # startDir = '.'; + # for root, dirs, files in os.walk(startDir, True, None): + # dirs = filter(hidden,dirs); + # files = filter(hidden,files); + # files = filter(valid_extension,files); + # for file in files: + # check_gen(path.join(root,file), work, rex); + + """Set static options for conversion.""" + GenConversion.srcdir = options.srcdir; + GenConversion.prefix = options.prefix; + GenConversion.required_precisions = options.precslst.split(); + + c = GenConversion(); """This initializes the variable for static member access.""" + + result = "" + for file in options.fileslst.split(): + """For each valid conversion file found.""" + try: + """Try creating and executing a converter.""" + result += c.run(file); + except Exception, e: + print >> sys.stderr, str(e); + continue; + + print result; + +if __name__ == "__main__": + main(); diff --git a/modules/precision_generator/subs.py b/modules/precision_generator/subs.py new file mode 100644 index 0000000..76ce89b --- /dev/null +++ b/modules/precision_generator/subs.py @@ -0,0 +1,1003 @@ +#!/usr/bin/env python +# Substitutions are applied in the order listed. This is important in cases +# where multiple substitutions could match, or when one substitution matches +# the result of a previous substitution. For example, these rules are correct +# in this order: +# +# ('real', 'double precision', 'real', 'double precision' ), # before double +# ('float', 'double', 'float', 'double' ), +# +# but if switched would translate 'double precision' -> 'float precision', +# which is wrong. +# +# Reorganized 5/2012 Mark Gates + +# Dictionary is keyed on substitution type (mixed, normal, etc.) +subs = { + # ------------------------------------------------------------ + # replacements applied to ALL files. + 'all' : [ + [None, None] + ], + + # ------------------------------------------------------------ + # replacements applied to mixed precision files. + 'mixed' : [ + # ----- Special line indicating column types + ['ds', 'zc' ], + + # ----- Mixed precisions + ('DS', 'ZC' ), + ('ds', 'zc' ), + + # ----- Preprocessor + ('#define PRECISION_d', '#define PRECISION_z' ), + ('#define PRECISION_s', '#define PRECISION_c' ), + ('#undef PRECISION_d', '#undef PRECISION_z' ), + ('#undef PRECISION_s', '#undef PRECISION_c' ), + + # ----- Fortran Types + ('real\(kind=c_double\)', 'complex\(kind=c_double_complex\)' ), + ('real\(kind=c_float\)', 'real\(kind=c_float_complex\)' ), + + # ----- Data types + ('double', 'double2' ), + ('float', 'float2' ), + ('double', 'cuDoubleComplex' ), + ('float', 'cuFloatComplex' ), + ('DOUBLE PRECISION', 'COMPLEX_16' ), + ('SINGLE PRECISION', 'COMPLEX' ), + ('real', 'complex' ), + ('float', 'MORSE_Complex32_t' ), + ('double', 'MORSE_Complex64_t' ), + ('float', 'MORSE_voidComplex32_t' ), + ('double', 'MORSE_voidComplex64_t' ), + ('MorseRealFloat', 'MorseComplexFloat' ), + ('MorseRealDouble', 'MorseComplexDouble' ), + + # ----- CBLAS + ('', 'CBLAS_SADDR' ), + + # ----- Prefixes + ('blasf77_d', 'blasf77_z' ), + ('blasf77_s', 'blasf77_c' ), + ('cublasIdamax', 'cublasIzamax' ), + ('cublasD', 'cublasZ' ), + ('cublasS', 'cublasC' ), + ('lapackf77_d', 'lapackf77_z' ), + ('lapackf77_s', 'lapackf77_c' ), + ('MAGMA_D', 'MAGMA_Z' ), + ('MAGMA_S', 'MAGMA_C' ), + ('magmablas_d', 'magmablas_z' ), + ('magmablas_s', 'magmablas_c' ), + ('magma_d', 'magma_z' ), + ('magma_s', 'magma_c' ), + ('magma_get_d', 'magma_get_z' ), + ('magma_get_s', 'magma_get_c' ), + + # ----- Prefixes MORSE + ('MORSE_D', 'MORSE_Z' ), + ('MORSE_S', 'MORSE_C' ), + ('morse_get_d', 'morse_get_z' ), + ('morse_get_s', 'morse_get_c' ), + ('TASK_S', 'TASK_C' ), + ('TASK_D', 'TASK_Z' ), + ('RUNTIME_S', 'RUNTIME_C' ), + ('RUNTIME_D', 'RUNTIME_Z' ), + + # ----- Complex numbers + ('(double)', 'cuComplexFloatToDouble' ), + ('(float)', 'cuComplexDoubleToFloat' ), + ('', 'cuCrealf' ), + ('', 'cuCimagf' ), + ('', 'cuCreal' ), + ('', 'cuCimag' ), + ('', 'cuConj' ), + ('abs', 'cuCabs' ), + ('absf', 'cuCabsf' ), + + # ----- PLASMA / MAGMA + ('magma_sdgetrs', 'magma_czgetrs' ), + + # ----- MORSE + ('morse_sdgetrs', 'morse_czgetrs' ), + + # ----- Constants + ('CblasTrans', 'CblasConjTrans' ), + ('MagmaTrans', 'MagmaConjTrans' ), + ('MorseTrans', 'MorseConjTrans' ), + + # ----- BLAS and LAPACK, lowercase, alphabetic order + # copy & paste these to uppercase below and fix case. + # mixed precision + ('dsaxpy', 'zcaxpy' ), + ('dslaswp', 'zclaswp' ), + + # regular + ('daxpy', 'zaxpy' ), + ('dgemm', 'zgemm' ), + ('dgesv', 'zgesv' ), + ('dlacpy', 'zlacpy' ), + ('dlange', 'zlange' ), + ('dlansy', 'zlansy' ), + ('dlarnv', 'zlarnv' ), + ('dpotrf', 'zpotrf' ), + ('dsytrf', 'zsytrf' ), + ('dtrmm', 'ztrmm' ), + ('dtrsm', 'ztrsm' ), + ('dtrsv', 'ztrsv' ), + ('idamax', 'izamax' ), + ('spotrf', 'cpotrf' ), + ('ssytrf', 'csytrf' ), + ('strmm', 'ctrmm' ), + ('strsm', 'ctrsm' ), + ('strsv', 'ctrsv' ), + + # ----- BLAS and LAPACK, where complex base name != real base name + # with precision + ('dlag2s', 'zlag2c' ), + ('dlagsy', 'zlaghe' ), + ('dlansy', 'zlanhe' ), + ('dlat2s', 'zlat2c' ), + ('dormqr', 'zunmqr' ), + ('dsymm', 'zhemm' ), + ('dsymv', 'zhemv' ), + ('dsyrk', 'zherk' ), + ('slag2d', 'clag2z' ), + ('slansy', 'clanhe' ), + ('slat2d', 'clat2z' ), + + # without precision + ('lag2s', 'lag2c' ), + ('lagsy', 'laghe' ), + ('lansy', 'lanhe' ), + ('lat2s', 'lat2c' ), + ('ormqr', 'unmqr' ), + ('symm', 'hemm' ), + ('symv', 'hemv' ), + ('syrk', 'herk' ), + ('lag2d', 'lag2z' ), + ('lansy', 'lanhe' ), + ('lat2d', 'lat2z' ), + + # QUARK codelets protection (to prevent conversion with LAPACK WITH PRECISION) + ('DAG_CORE_L-AG2C', 'DAG_CORE_LAG2C' ), + + # ----- BLAS AND LAPACK, UPPERCASE, ALPHABETIC ORDER + # COPY & PASTE THESE TO UPPERCASE BELOW AND FIX CASE. + # MIXED PRECISION + ('DSAXPY', 'ZCAXPY' ), + ('DSLASWP', 'ZCLASWP' ), + + # REGULAR + ('DAXPY', 'ZAXPY' ), + ('DGEMM', 'ZGEMM' ), + ('DGESV', 'ZGESV' ), + ('DLACPY', 'ZLACPY' ), + ('DLANGE', 'ZLANGE' ), + ('DLANSY', 'ZLANSY' ), + ('DLARNV', 'ZLARNV' ), + ('DPOTRF', 'ZPOTRF' ), + ('DSYTRF', 'ZSYTRF' ), + ('DTRMM', 'ZTRMM' ), + ('DTRSM', 'ZTRSM' ), + ('DTRSV', 'ZTRSV' ), + ('IDAMAX', 'IZAMAX' ), + ('SPOTRF', 'CPOTRF' ), + ('SSYTRF', 'CSYTRF' ), + ('STRMM', 'CTRMM' ), + ('STRSM', 'CTRSM' ), + ('STRSV', 'CTRSV' ), + + # ----- BLAS AND LAPACK, WHERE COMPLEX BASE NAME != REAL BASE NAME + # WITH PRECISION + ('DLAG2S', 'ZLAG2C' ), + ('DLAGSY', 'ZLAGHE' ), + ('DLANSY', 'ZLANHE' ), + ('DLAT2S', 'ZLAT2C' ), + ('DORMQR', 'ZUNMQR' ), + ('DSYMM', 'ZHEMM' ), + ('DSYMV', 'ZHEMV' ), + ('DSYRK', 'ZHERK' ), + ('SLAG2D', 'CLAG2Z' ), + ('SLANSY', 'CLANHE' ), + ('SLAT2D', 'CLAT2Z' ), + + # WITHOUT PRECISION + ('LAG2S', 'LAG2C' ), + ('LAGSY', 'LAGHE' ), + ('LANSY', 'LANHE' ), + ('LAT2S', 'LAT2C' ), + ('ORMQR', 'UNMQR' ), + ('SYMM', 'HEMM' ), + ('SYMV', 'HEMV' ), + ('SYRK', 'HERK' ), + ('LAG2D', 'LAG2Z' ), + ('LANSY', 'LANHE' ), + ('LAT2D', 'LAT2Z' ), + + # QUARK codelets protection (to prevent conversion with LAPACK WITH PRECISION) + ('DAG_CORE_LAG2C', 'DAG_CORE_L-AG2C' ), +], + + # ------------------------------------------------------------ + # replacements applied to most files. + 'normal' : [ + # ----- Special line indicating column types + # old python (2.4) requires this line to be list [] rather than tuple () to use index() function. + ['s', 'd', 'c', 'z' ], + + + # TODO clean; shouldn't be added this way + ('cblas_sscal', ' cblas_dscal', 'cblas_csscal', 'cblas_zdscal'), + ('stsmqr_hetra1', 'dtsmqr_hetra1', 'ctsmqr_hetra1', 'ztsmqr_hetra1'), + ('stsmlq_hetra1', 'dtsmlq_hetra1', 'ctsmlq_hetra1', 'ztsmlq_hetra1'), + ('codelet_ssyrfb', 'codelet_dsyrfb', 'codelet_cherfb', 'codelet_zherfb'), + ('cl_ssyrfb', 'cl_dsyrfb', 'cl_cherfb', 'cl_zherfb'), + ('she2ge', 'dhe2ge', 'che2ge', 'zhe2ge'), + ('sgbcpy', 'dgbcpy', 'cgbcpy', 'zgbcpy'), + + + # ----- Preprocessor + ('#define PRECISION_s', '#define PRECISION_d', '#define PRECISION_c', '#\s*define PRECISION_z' ), + ('#undef PRECISION_s', '#undef PRECISION_d', '#undef PRECISION_c', '#undef PRECISION_z' ), + ('#define REAL', '#define REAL', '#define COMPLEX', '#define COMPLEX' ), + ('#undef COMPLEX', '#undef COMPLEX', '#undef REAL', '#undef REAL' ), + ('#define SINGLE', '#define DOUBLE', '#define SINGLE', '#define DOUBLE' ), + ('#undef DOUBLE', '#undef SINGLE', '#undef DOUBLE', '#undef SINGLE' ), + + # ----- Fortran Types + ('real\(kind=c_float\)', 'real\(kind=c_double\)', 'complex\(kind=c_float_complex\)', 'complex\(kind=c_double_complex\)' ), + ('real(kind=c_float\)', 'real\(kind=c_double\)', 'real\(kind=c_float\)', 'real\(kind=c_double\)' ), + ('real', 'double precision', 'complex', 'complex\(kind=wp\)' ), + + # ----- Data types + ('real', 'double precision', 'real', r'\bdouble precision' ), # before double + ('float', 'double', 'float _Complex', r'\bdouble _Complex' ), + ('float', 'double', 'cuFloatComplex', r'\bcuDoubleComplex' ), + ('float', 'double', 'make_cuFloatComplex', 'make_cuDoubleComplex' ), + ('float', 'double', 'magmaFloatComplex', r'\bmagmaDoubleComplex' ), + ('float', 'double', 'PLASMA_Complex32_t', r'\bPLASMA_Complex64_t' ), + ('float', 'double', 'PLASMA_voidComplex32_t', r'\bPLASMA_voidComplex64_t' ), + ('PlasmaRealFloat', 'PlasmaRealDouble', 'PlasmaComplexFloat', r'\bPlasmaComplexDouble' ), + ('float', 'double', 'MORSE_Complex32_t', r'\bMORSE_Complex64_t' ), + ('float', 'double', 'MORSE_voidComplex32_t', r'\bMORSE_voidComplex64_t' ), + ('MorseRealFloat', 'MorseRealDouble', 'MorseComplexFloat', r'\bMorseComplexDouble' ), + ('real', 'double precision', 'complex', r'\bcomplex\*16' ), + ('REAL', 'DOUBLE_PRECISION', 'COMPLEX', r'\bCOMPLEX_16' ), + ('REAL', 'DOUBLE PRECISION', 'COMPLEX', r'\bDOUBLE COMPLEX' ), + ('REAL', 'DOUBLE PRECISION', 'REAL', r'\bDOUBLE PRECISION' ), + ('sizeof_real', 'sizeof_double', 'sizeof_complex', r'\bsizeof_complex_16' ), # before complex + ('float', 'double', 'pastix_complex32_t', r'\bpastix_complex64_t' ), + ('real', 'real', 'complex', r'\bcomplex' ), + ('float', 'double', 'float2', r'\bdouble2' ), + ('float', 'double', 'float', r'\bdouble' ), + ('ipt_s', 'ipt_d', 'ipt_c', 'ipt_z' ), + + # ----- Text + ('symmetric', 'symmetric', 'Hermitian', 'Hermitian' ), + ('\*\*T', '\*\*T', '\*\*H', '\*\*H' ), + ('%f', '%lf', '%f', '%lf' ), # for scanf + ('%g', '%lg', '%g', '%lg' ), # for scanf + + # ----- CBLAS + ('cblas_sasum', 'cblas_dasum', 'cblas_scasum', 'cblas_dzasum' ), + ('cblas_snrm2', 'cblas_dnrm2', 'cblas_scnrm2', 'cblas_dznrm2' ), + ('', '', 'CBLAS_SADDR', 'CBLAS_SADDR' ), + ('cblas_ssyr', 'cblas_dsyr', 'cblas_cher', 'cblas_zher' ), + + # ----- Core BLAS + ('CORE_sasum', 'CORE_dasum', 'CORE_scasum', 'CORE_dzasum' ), + ('core_sasum', 'core_dasum', 'core_scasum', 'core_dzasum' ), + ('CORE_ssyrfb', 'CORE_dsyrfb', 'CORE_cherfb', 'CORE_zherfb' ), + ('core_ssyrfb', 'core_dsyrfb', 'core_cherfb', 'core_zherfb' ), + ('CORE_stsmlq_sy', 'CORE_dtsmlq_sy', 'CORE_ctsmlq_he', 'CORE_ztsmlq_he' ), + ('core_stsmlq_sy', 'core_dtsmlq_sy', 'core_ctsmlq_he', 'core_ztsmlq_he' ), + ('CORE_stsmqr_sy', 'CORE_dtsmqr_sy', 'CORE_ctsmqr_he', 'CORE_ztsmqr_he' ), + ('core_stsmqr_sy', 'core_dtsmqr_sy', 'core_ctsmqr_he', 'core_ztsmqr_he' ), + + # ----- Prefixes + # Changing prefixes first requires some calls to be fixed without precision, + # e.g., her2k -> syr2k instead of zher2k -> ssyr2k. + # See BLAS and LAPACK without precision, below. + ('blasf77_s', 'blasf77_d', 'blasf77_c', 'blasf77_z' ), + ('blasf77_s', 'blasf77_d', 'blasf77_s', 'blasf77_d' ), + ('BLAS_S', 'BLAS_D', 'BLAS_C', 'BLAS_Z' ), + ('BLAS_s', 'BLAS_d', 'BLAS_c', 'BLAS_z' ), + ('BLAS_s', 'BLAS_d', 'BLAS_s', 'BLAS_d' ), + ('blas_is', 'blas_id', 'blas_ic', 'blas_iz' ), + ('blas_s', 'blas_d', 'blas_c', 'blas_z' ), + ('cl_ps', 'cl_pd', 'cl_pc', 'cl_pz' ), + ('cl_s', 'cl_d', 'cl_c', 'cl_z' ), + ('cl_s', 'cl_d', 'cl_sc', 'cl_dz' ), + ('CODELETS_S', 'CODELETS_D', 'CODELETS_C', 'CODELETS_Z' ), + ('codelet_s', 'codelet_d', 'codelet_c', 'codelet_z' ), + ('compute_s', 'compute_d', 'compute_c', 'compute_z' ), + ('control_s', 'control_d', 'control_c', 'control_z' ), + ('coreblas_s', 'coreblas_d', 'coreblas_c', 'coreblas_z' ), + ('CORE_S', 'CORE_D', 'CORE_C', 'CORE_Z' ), + ('CORE_s', 'CORE_d', 'CORE_c', 'CORE_z' ), + ('core_s', 'core_d', 'core_c', 'core_z' ), + ('CORE_s', 'CORE_d', 'CORE_s', 'CORE_d' ), + ('cpu_gpu_s', 'cpu_gpu_d', 'cpu_gpu_c', 'cpu_gpu_z' ), + ('cublasS', 'cublasD', 'cublasC', 'cublasZ' ), + ('CUDA_S', 'CUDA_D', 'CUDA_C', 'CUDA_Z' ), + ('CUDA_s', 'CUDA_d', 'CUDA_c', 'CUDA_z' ), + ('example_s', 'example_d', 'example_c', 'example_z' ), + ('ipt_s', 'ipt_d', 'ipt_c', 'ipt_z' ), + ('LAPACKE_s', 'LAPACKE_d', 'LAPACKE_c', 'LAPACKE_z' ), + ('lapackf77_s', 'lapackf77_d', 'lapackf77_c', 'lapackf77_z' ), + ('lapackf77_s', 'lapackf77_d', 'lapackf77_s', 'lapackf77_d' ), + ('lapack_s', 'lapack_d', 'lapack_c', 'lapack_z' ), + ('lapack_s', 'lapack_d', 'lapack_s', 'lapack_d' ), + ('MAGMABLAS_S', 'MAGMABLAS_D', 'MAGMABLAS_C', 'MAGMABLAS_Z' ), + ('magmablas_s', 'magmablas_d', 'magmablas_c', 'magmablas_z' ), + ('magmaf_s', 'magmaf_d', 'magmaf_c', 'magmaf_z' ), + ('magma_get_s', 'magma_get_d', 'magma_get_c', 'magma_get_z' ), + ('magma_ps', 'magma_pd', 'magma_pc', 'magma_pz' ), + ('MAGMA_S', 'MAGMA_D', 'MAGMA_C', 'MAGMA_Z' ), + ('MAGMA_s', 'MAGMA_d', 'MAGMA_c', 'MAGMA_z' ), + ('magma_s', 'magma_d', 'magma_c', 'magma_z' ), + ('QUARK_S', 'QUARK_D', 'QUARK_C', 'QUARK_Z' ), + ('QUARK_s', 'QUARK_d', 'QUARK_c', 'QUARK_z' ), + ('quark_s', 'quark_d', 'quark_c', 'quark_z' ), + ('QUARK_s', 'QUARK_d', 'QUARK_s', 'QUARK_d' ), + ('plasma_ps', 'plasma_pd', 'plasma_pc', 'plasma_pz' ), + ('PLASMA_S', 'PLASMA_D', 'PLASMA_C', 'PLASMA_Z' ), + ('PLASMA_sor', 'PLASMA_dor', 'PLASMA_cun', 'PLASMA_zun' ), + ('PLASMA_s', 'PLASMA_d', 'PLASMA_c', 'PLASMA_z' ), + ('plasma_s', 'plasma_d', 'plasma_c', 'plasma_z' ), + ('PROFILE_S', 'PROFILE_D', 'PROFILE_C', 'PROFILE_Z' ), + ('profile_s', 'profile_d', 'profile_c', 'profile_z' ), + ('SCHED_s', 'SCHED_d', 'SCHED_c', 'SCHED_z' ), + ('starpu_s', 'starpu_d', 'starpu_c', 'starpu_z' ), + ('testing_ds', 'testing_ds', 'testing_zc', 'testing_zc' ), + ('TESTING_S', 'TESTING_D', 'TESTING_C', 'TESTING_Z' ), + ('testing_s', 'testing_d', 'testing_c', 'testing_z' ), + ('time_s', 'time_d', 'time_c', 'time_z' ), + ('WRAPPER_S', 'WRAPPER_D', 'WRAPPER_C', 'WRAPPER_Z' ), + ('wrapper_s', 'wrapper_d', 'wrapper_c', 'wrapper_z' ), + ('Workspace_s', 'Workspace_d', 'Workspace_c', 'Workspace_z' ), + ('workspace_s', 'workspace_d', 'workspace_c', 'workspace_z' ), + + ('csc_s', 'csc_d', 'csc_c', 'csc_z' ), + ('sequential_s', 'sequential_d', 'sequential_c', 'sequential_z' ), + ('coeftab_s', 'coeftab_d', 'coeftab_c', 'coeftab_z' ), + + # ----- Prefixes MORSE + ('MORSE_S', 'MORSE_D', 'MORSE_C', 'MORSE_Z' ), + ('MORSE_sor', 'MORSE_dor', 'MORSE_cun', 'MORSE_zun' ), + ('MORSE_s', 'MORSE_d', 'MORSE_c', 'MORSE_z' ), + ('morse_get_s', 'morse_get_d', 'morse_get_c', 'morse_get_z' ), + ('morse_ps', 'morse_pd', 'morse_pc', 'morse_pz' ), + ('morse_s', 'morse_d', 'morse_c', 'morse_z' ), + ('morse_sdesc', 'morse_ddesc', 'morse_sdesc', 'morse_ddesc' ), + ('TASK_sasum', 'TASK_dasum', 'TASK_scasum', 'TASK_dzasum' ), + ('TASK_ssyrfb', 'TASK_dsyrfb', 'TASK_cherfb', 'TASK_zherfb' ), + ('TASK_stsmlq_sy', 'TASK_dtsmlq_sy', 'TASK_ctsmlq_he', 'TASK_ztsmlq_he' ), + ('TASK_stsmqr_sy', 'TASK_dtsmqr_sy', 'TASK_ctsmqr_he', 'TASK_ztsmqr_he' ), + ('TASK_sor', 'TASK_dor', 'TASK_cun', 'TASK_zun' ), + ('TASK_s', 'TASK_d', 'TASK_c', 'TASK_z' ), + ('TASK_slan', 'TASK_dlan', 'TASK_slan', 'TASK_dlan' ), + ('RUNTIME_S', 'RUNTIME_D', 'RUNTIME_C', 'RUNTIME_Z' ), + ('RUNTIME_s', 'RUNTIME_d', 'RUNTIME_c', 'RUNTIME_z' ), + + ('TASK_s', 'TASK_d', 'TASK_s', 'TASK_d' ), + ('dataflush', 'dataflush', 'dataflush', 'sataflush' ), # Correct previous line + + # ----- Complex numbers + # \b regexp here avoids conjugate -> conjfugate, + # assuming we always translate from z, not to z. + ('', '', 'conjf', 'conj\b' ), + ('fabsf', 'fabs', 'cabsf', 'cabs' ), + ('', '', 'cuCrealf', 'cuCreal' ), + ('', '', 'cuCimagf', 'cuCimag' ), + ('', '', 'cuConjf', 'cuConj' ), + ('fabsf', 'fabs', 'cuCabsf', 'cuCabs' ), + ('', '', 'crealf', 'creal' ), + ('sqrtf', 'sqrt', 'csqrtf', 'csqrt' ), + + # ----- CUDA + ('cublasIsamax', 'cublasIdamax', 'cublasIcamax', 'cublasIzamax' ), + ('cublasIsamax', 'cublasIdamax', 'cublasIsamax', 'cublasIdamax' ), + ('cublasSnrm2', 'cublasDnrm2', 'cublasScnrm2', 'cublasDznrm2' ), + + # ----- PLASMA / MAGMA / MORSE + ('bsy2trc', 'bsy2trc', 'bhe2trc', 'bhe2trc' ), + ('magma_ssqrt', 'magma_dsqrt', 'magma_ssqrt', 'magma_dsqrt' ), + ('morse_ssqrt', 'morse_dsqrt', 'morse_ssqrt', 'morse_dsqrt' ), + ('SAUXILIARY', 'DAUXILIARY', 'CAUXILIARY', 'ZAUXILIARY' ), + ('sauxiliary', 'dauxiliary', 'cauxiliary', 'zauxiliary' ), + ('sbcyclic', 'dbcyclic', 'cbcyclic', 'zbcyclic' ), + ('sbulge', 'dbulge', 'cbulge', 'zbulge' ), + ('SCODELETS', 'DCODELETS', 'CCODELETS', 'ZCODELETS' ), + ('sgetmatrix', 'dgetmatrix', 'cgetmatrix', 'zgetmatrix' ), + ('sinplace', 'dinplace', 'cinplace', 'zinplace' ), + ('slocality', 'dlocality', 'clocality', 'zlocality' ), + ('slapack', 'dlapack', 'clapack', 'zlapack' ), + ('SLAPACK', 'DLAPACK', 'CLAPACK', 'ZLAPACK' ), + ('smalloc', 'dmalloc', 'cmalloc', 'zmalloc' ), + ('smalloc', 'dmalloc', 'smalloc', 'dmalloc' ), + ('spanel_to_q', 'dpanel_to_q', 'cpanel_to_q', 'zpanel_to_q' ), + ('spermute', 'dpermute', 'cpermute', 'zpermute' ), + ('sprint', 'dprint', 'cprint', 'zprint' ), + ('sprint', 'dprint', 'sprint', 'dprint' ), + ('sprofiling', 'dprofiling', 'cprofiling', 'zprofiling' ), + ('sq_to_panel', 'dq_to_panel', 'cq_to_panel', 'zq_to_panel' ), + ('sset', 'dset', 'cset', 'zset' ), + ('ssetmatrix', 'dsetmatrix', 'csetmatrix', 'zsetmatrix' ), + ('SSIZE', 'DSIZE', 'CSIZE', 'ZSIZE' ), + ('ssplit', 'dsplit', 'csplit', 'zsplit' ), + ('stile', 'dtile', 'ctile', 'ztile' ), + ('STILE', 'DTILE', 'CTILE', 'ZTILE' ), + ('stranspose', 'dtranspose', 'ctranspose', 'ztranspose' ), + ('szero', 'dzero', 'czero', 'zzero' ), + ('sy2sb', 'sy2sb', 'he2hb', 'he2hb' ), + + # ----- Constants + ('CblasTrans', 'CblasTrans', 'CblasConjTrans', 'CblasConjTrans' ), + ('MagmaTrans', 'MagmaTrans', 'MagmaConjTrans', 'MagmaConjTrans' ), + ('MorseTrans', 'MorseTrans', 'MorseConjTrans', 'MorseConjTrans' ), + ('PlasmaTrans', 'PlasmaTrans', 'PlasmaConjTrans','PlasmaConjTrans' ), + ('symmetric', 'symmetric', 'Hermitian', 'Hermitian' ), + + # ----- BLAS and LAPACK, lowercase, alphabetic order + # copy & paste these to uppercase below and fix case. + # used for filenames lacking magma_z, etc. prefix + ('isamax', 'idamax', 'icamax', 'izamax' ), + ('isamax', 'idamax', 'isamax', 'idamax' ), + ('saxpy', 'daxpy', 'caxpy', 'zaxpy' ), + ('scopy', 'dcopy', 'ccopy', 'zcopy' ), + ('sgeadd', 'dgeadd', 'cgeadd', 'zgeadd' ), + ('sgecfi', 'dgecfi', 'cgecfi', 'zgecfi' ), + ('sgemdm', 'dgemdm', 'cgemdm', 'zgemdm' ), + ('sgemm', 'dgemm', 'cgemm', 'zgemm' ), + ('sgemv', 'dgemv', 'cgemv', 'zgemv' ), + ('sscal', 'dscal', 'cscal', 'zscal' ), + ('sscal', 'dscal', 'csscal', 'zdscal' ), + ('sscal', 'dscal', 'sscal', 'dscal' ), # zdscal -> csscal + ('slascal', 'dlascal', 'clascal', 'zlascal' ), + ('slascal', 'dlascal', 'slascal', 'dlascal' ), + ('sswap', 'dswap', 'cswap', 'zswap' ), + ('ssymm', 'dsymm', 'csymm', 'zsymm' ), + ('ssymv', 'dsymv', 'csymv', 'zsymv' ), + ('ssyr2k', 'dsyr2k', 'csyr2k', 'zsyr2k' ), + ('ssyrk', 'dsyrk', 'csyrk', 'zsyrk' ), + ('stradd', 'dtradd', 'ctradd', 'ztradd' ), + ('strmm', 'dtrmm', 'ctrmm', 'ztrmm' ), + ('strmv', 'dtrmv', 'ctrmv', 'ztrmv' ), + ('strsm', 'dtrsm', 'ctrsm', 'ztrsm' ), + ('strsv', 'dtrsv', 'ctrsv', 'ztrsv' ), + +# ADD FOR NEW VERSION OF CHAMELEON + ('shbcpy', 'dhbcpy', 'chbcpy', 'zhbcpy' ), + ('ssyrbt', 'dsyrbt', 'cherbt', 'zherbt' ), + ('ssygv', 'dsygv', 'chegv', 'zhegv' ), +# END ADD + + # LAPACK + ('sbarrier', 'dbarrier', 'cbarrier', 'zbarrier' ), + ('sbdsqr', 'dbdsqr', 'cbdsqr', 'zbdsqr' ), + ('sbdt01', 'dbdt01', 'cbdt01', 'zbdt01' ), + ('scheck', 'dcheck', 'ccheck', 'zcheck' ), + ('sgebak', 'dgebak', 'cgebak', 'zgebak' ), + ('sgebal', 'dgebal', 'cgebal', 'zgebal' ), + ('sgebd2', 'dgebd2', 'cgebd2', 'zgebd2' ), + ('sgebrd', 'dgebrd', 'cgebrd', 'zgebrd' ), + ('sgeev', 'dgeev', 'cgeev', 'zgeev' ), + ('sgehd2', 'dgehd2', 'cgehd2', 'zgehd2' ), + ('sgehrd', 'dgehrd', 'cgehrd', 'zgehrd' ), + ('sgelq2', 'dgelq2', 'cgelq2', 'zgelq2' ), + ('sgelqf', 'dgelqf', 'cgelqf', 'zgelqf' ), + ('sgelqs', 'dgelqs', 'cgelqs', 'zgelqs' ), + ('sgelqt', 'dgelqt', 'cgelqt', 'zgelqt' ), + ('sgels', 'dgels', 'cgels', 'zgels' ), + ('sgeqlf', 'dgeqlf', 'cgeqlf', 'zgeqlf' ), + ('sgeqp3', 'dgeqp3', 'cgeqp3', 'zgeqp3' ), + ('sgeqr2', 'dgeqr2', 'cgeqr2', 'zgeqr2' ), + ('sgeqrf', 'dgeqrf', 'cgeqrf', 'zgeqrf' ), + ('sgeqrs', 'dgeqrs', 'cgeqrs', 'zgeqrs' ), + ('sgeqrt', 'dgeqrt', 'cgeqrt', 'zgeqrt' ), + ('sgessm', 'dgessm', 'cgessm', 'zgessm' ), + ('sgessq', 'dgessq', 'cgessq', 'zgessq' ), + ('sgesv', 'dgesv', 'cgesv', 'zgesv' ), + ('sgesvd', 'dgesvd', 'cgesvd', 'zgesvd' ), + ('sgesv', 'sgesv', 'cgesv', 'cgesv' ), + ('sget22', 'dget22', 'cget22', 'zget22' ), + ('sgetf2', 'dgetf2', 'cgetf2', 'zgetf2' ), + ('sgetmi', 'dgetmi', 'cgetmi', 'zgetmi' ), + ('sgetmo', 'dgetmo', 'cgetmo', 'zgetmo' ), + ('sgetrf', 'dgetrf', 'cgetrf', 'zgetrf' ), + ('sgetri', 'dgetri', 'cgetri', 'zgetri' ), + ('sgetrl', 'dgetrl', 'cgetrl', 'zgetrl' ), + ('sgetrs', 'dgetrs', 'cgetrs', 'zgetrs' ), + ('shseqr', 'dhseqr', 'chseqr', 'zhseqr' ), + ('shst01', 'dhst01', 'chst01', 'zhst01' ), + ('slabad', 'dlabad', 'slabad', 'dlabad' ), + ('slabrd', 'dlabrd', 'clabrd', 'zlabrd' ), + ('slacgv', 'dlacgv', 'clacgv', 'zlacgv' ), + ('slacpy', 'dlacpy', 'clacpy', 'zlacpy' ), + ('slaed', 'dlaed', 'slaed', 'dlaed' ), + ('slaex', 'dlaex', 'slaex', 'dlaex' ), + ('slagsy', 'dlagsy', 'clagsy', 'zlagsy' ), + ('slahr', 'dlahr', 'clahr', 'zlahr' ), + ('slamc3', 'dlamc3', 'slamc3', 'dlamc3' ), + ('slamch', 'dlamch', 'slamch', 'dlamch' ), + ('slamrg', 'dlamrg', 'slamrg', 'dlamrg' ), + ('slange', 'dlange', 'clange', 'zlange' ), + ('slanst', 'dlanst', 'clanht', 'zlanht' ), + ('slansy', 'dlansy', 'clansy', 'zlansy' ), + ('slantr', 'dlantr', 'clantr', 'zlantr' ), + ('slaqps', 'dlaqps', 'claqps', 'zlaqps' ), + ('slaqp2', 'dlaqp2', 'claqp2', 'zlaqp2' ), + ('slarfb', 'dlarfb', 'clarfb', 'zlarfb' ), + ('slarfg', 'dlarfg', 'clarfg', 'zlarfg' ), + ('slarft', 'dlarft', 'clarft', 'zlarft' ), + ('slarfx', 'dlarfx', 'clarfx', 'zlarfx' ), + ('slarfy', 'dlarfy', 'clarfy', 'zlarfy' ), + ('slarnv', 'dlarnv', 'clarnv', 'zlarnv' ), + ('slarnv', 'dlarnv', 'slarnv', 'dlarnv' ), + ('slartg', 'dlartg', 'clartg', 'zlartg' ), + ('slascl', 'dlascl', 'clascl', 'zlascl' ), + ('slaset', 'dlaset', 'claset', 'zlaset' ), + ('slaswp', 'dlaswp', 'claswp', 'zlaswp' ), + ('slatro', 'dlatro', 'clatro', 'zlatro' ), + ('slatrd', 'dlatrd', 'clatrd', 'zlatrd' ), + ('slauum', 'dlauum', 'clauum', 'zlauum' ), + ('spack', 'dpack', 'cpack', 'zpack' ), + ('splgsy', 'dplgsy', 'cplgsy', 'zplgsy' ), + ('splrnt', 'dplrnt', 'cplrnt', 'zplrnt' ), + ('splssq', 'dplssq', 'cplssq', 'zplssq' ), + ('sposv', 'dposv', 'cposv', 'zposv' ), + ('ssysv', 'dsysv', 'csysv', 'zsysv' ), + ('sposv', 'sposv', 'cposv', 'cposv' ), + ('spotrf', 'dpotrf', 'cpotrf', 'zpotrf' ), + ('ssytrf', 'dsytrf', 'csytrf', 'zsytrf' ), + ('spotri', 'dpotri', 'cpotri', 'zpotri' ), + ('spotrs', 'dpotrs', 'cpotrs', 'zpotrs' ), + ('ssytrs', 'dsytrs', 'csytrs', 'zsytrs' ), + ('sqpt01', 'dqpt01', 'cqpt01', 'zqpt01' ), + ('sqrt02', 'dqrt02', 'cqrt02', 'zqrt02' ), + ('sshift', 'dshift', 'cshift', 'zshift' ), + ('sssssm', 'dssssm', 'cssssm', 'zssssm' ), + ('sstebz', 'dstebz', 'sstebz', 'dstebz' ), + ('sstedc', 'dstedc', 'cstedc', 'zstedc' ), + ('sstedx', 'dstedx', 'cstedx', 'zstedx' ), + ('sstedx', 'dstedx', 'sstedx', 'dstedx' ), + ('sstein', 'dstein', 'cstein', 'zstein' ), + ('sstemr', 'dstemr', 'cstemr', 'zstemr' ), + ('ssteqr', 'dsteqr', 'csteqr', 'zsteqr' ), + ('ssterf', 'dsterf', 'ssterf', 'dsterf' ), + ('ssterm', 'dsterm', 'csterm', 'zsterm' ), + ('sstt21', 'dstt21', 'cstt21', 'zstt21' ), + ('strasm', 'dtrasm', 'ctrasm', 'ztrasm' ), + ('strevc', 'dtrevc', 'ctrevc', 'ztrevc' ), + ('strsmpl', 'dtrsmpl', 'ctrsmpl', 'ztrsmpl' ), + ('strssq', 'dtrssq', 'ctrssq', 'ztrssq' ), + ('strtri', 'dtrtri', 'ctrtri', 'ztrtri' ), + ('stslqt', 'dtslqt', 'ctslqt', 'ztslqt' ), + ('stsmlq_sy', 'dtsmlq_sy', 'ctsmlq_he', 'ztsmlq_he' ), + ('stsmqr_sy', 'dtsmqr_sy', 'ctsmqr_he', 'ztsmqr_he' ), + ('stsmqr', 'dtsmqr', 'ctsmqr', 'ztsmqr' ), + ('stsmlq', 'dtsmlq', 'ctsmlq', 'ztsmlq' ), + ('stsqrt', 'dtsqrt', 'ctsqrt', 'ztsqrt' ), + ('stslqt', 'dtslqt', 'ctslqt', 'ztslqt' ), + ('ststrf', 'dtstrf', 'ctstrf', 'ztstrf' ), + ('sttlqt', 'dttlqt', 'cttlqt', 'zttlqt' ), + ('sttmlq', 'dttmlq', 'cttmlq', 'zttmlq' ), + ('sttmqr', 'dttmqr', 'cttmqr', 'zttmqr' ), + ('sttqrt', 'dttqrt', 'cttqrt', 'zttqrt' ), + ('sungesv', 'sungesv', 'cungesv', 'cungesv' ), + ('sstegr', 'dstegr', 'cstegr', 'zstegr' ), + ('ssyssq', 'dsyssq', 'csyssq', 'zsyssq' ), + + # ----- LAPACK Eigenvalues + ('slatms', 'dlatms', 'slatms', 'dlatms' ), + ('slasrt', 'dlasrt', 'slasrt', 'dlasrt' ), + + # ----- BLAS and LAPACK, where complex base name != real base name + # BLAS, with precision + ('sasum', 'dasum', 'scasum', 'dzasum' ), + ('sasum', 'dasum', 'casum', 'zasum' ), + ('sdot', 'ddot', 'cdotc', 'zdotc' ), + ('sdot_sub', 'ddot_sub', 'cdotc_sub', 'zdotc_sub' ), + ('sdot_sub', 'ddot_sub', 'cdotu_sub', 'zdotu_sub' ), + ('sger', 'dger', 'cgerc', 'zgerc' ), + ('sger', 'dger', 'cgeru', 'zgeru' ), + ('snrm2', 'dnrm2', 'scnrm2', 'dznrm2' ), + ('ssymm', 'dsymm', 'chemm', 'zhemm' ), + ('ssymv', 'dsymv', 'chemv', 'zhemv' ), + ('ssyr2', 'dsyr2', 'cher2', 'zher2' ), + ('ssyr2k', 'dsyr2k', 'cher2k', 'zher2k' ), + ('ssyrk', 'dsyrk', 'cherk', 'zherk' ), + ('ssyr', 'dsyr', 'cher', 'zher' ), + + # LAPACK, with precision + ('slag2d', 'dlag2s', 'clag2z', 'zlag2c' ), + ('slagsy', 'dlagsy', 'claghe', 'zlaghe' ), + ('slasyf', 'dlasyf', 'clahef', 'zlahef' ), + ('slansy', 'dlansy', 'clanhe', 'zlanhe' ), + ('slavsy', 'dlavsy', 'clavhe', 'zlavhe' ), + ('sorg2r', 'dorg2r', 'cung2r', 'zung2r' ), + ('sorgbr', 'dorgbr', 'cungbr', 'zungbr' ), + ('sorghr', 'dorghr', 'cunghr', 'zunghr' ), + ('sorglq', 'dorglq', 'cunglq', 'zunglq' ), + ('sorgql', 'dorgql', 'cungql', 'zungql' ), + ('sorgqr', 'dorgqr', 'cungqr', 'zungqr' ), + ('sorgtr', 'dorgtr', 'cungtr', 'zungtr' ), + ('sorm2r', 'dorm2r', 'cunm2r', 'zunm2r' ), + ('sormbr', 'dormbr', 'cunmbr', 'zunmbr' ), + ('sormlq', 'dormlq', 'cunmlq', 'zunmlq' ), + ('sormql', 'dormql', 'cunmql', 'zunmql' ), + ('sormqr', 'dormqr', 'cunmqr', 'zunmqr' ), + ('sormr2', 'dormr2', 'cunmr2', 'zunmr2' ), + ('sormtr', 'dormtr', 'cunmtr', 'zunmtr' ), + ('sort01', 'dort01', 'cunt01', 'zunt01' ), + ('splgsy', 'dplgsy', 'cplghe', 'zplghe' ), + ('ssbtrd', 'dsbtrd', 'chbtrd', 'zhbtrd' ), + ('ssybbd', 'dsybbd', 'chebbd', 'zhebbd' ), + ('ssyev', 'dsyev', 'cheev', 'zheev' ), + ('ssyevd', 'dsyevd', 'cheevd', 'zheevd' ), + ('ssygs2', 'dsygs2', 'chegs2', 'zhegs2' ), + ('ssygst', 'dsygst', 'chegst', 'zhegst' ), + ('ssygvd', 'dsygvd', 'chegvd', 'zhegvd' ), + ('ssygvr', 'dsygvr', 'chegvr', 'zhegvr' ), + ('ssygvx', 'dsygvx', 'chegvx', 'zhegvx' ), + ('ssyssq', 'dsyssq', 'chessq', 'zhessq' ), + ('ssyt21', 'dsyt21', 'chet21', 'zhet21' ), + ('ssytd2', 'dsytd2', 'chetd2', 'zhetd2' ), + ('ssytrd', 'dsytrd', 'chetrd', 'zhetrd' ), + ('ssytrf', 'dsytrf', 'chetrf', 'zhetrf' ), + + # ----- Auxiliary routines with precision + ('sgemerge', 'dgemerge', 'cgemerge', 'zgemerge' ), + ('sparfb', 'dparfb', 'cparfb', 'zparfb' ), + + # BLAS, without precision + # must be after BLAS with precision + # Ex: cublasZhemm -> cublasShemm -> cublasSsymm + ('dot', 'dot', 'dotc', 'dotc' ), + ('dot_sub', 'dot_sub', 'dotc_sub', 'dotc_sub' ), + ('dot_sub', 'dot_sub', 'dotu_sub', 'dotu_sub' ), + ('ger', 'ger', 'gerc', 'gerc' ), + ('ger', 'ger', 'geru', 'geru' ), + ('nrm2', 'nrm2', 'cnrm2', 'znrm2' ), # dznrm2 -> dnrm2 + ('symm', 'symm', 'hemm', 'hemm' ), + ('symv', 'symv', 'hemv', 'hemv' ), + ('syr2', 'syr2', 'her2', 'her2' ), + ('syr2k', 'syr2k', 'her2k', 'her2k' ), + ('syrk', 'syrk', 'herk', 'herk' ), + + # LAPACK, without precision + ('lag2d', 'lag2s', 'lag2z', 'lag2c' ), + ('lagsy', 'lagsy', 'laghe', 'laghe' ), + ('lasyf', 'lasyf', 'lahef', 'lahef' ), + ('lansy', 'lansy', 'lanhe', 'lanhe' ), + ('lanst', 'lanst', 'lanht', 'lanht' ), + ('lavsy', 'lavsy', 'lavhe', 'lavhe' ), + ('org2r', 'org2r', 'ung2r', 'ung2r' ), + ('orgbr', 'orgbr', 'ungbr', 'ungbr' ), + ('orghr', 'orghr', 'unghr', 'unghr' ), + ('orglq', 'orglq', 'unglq', 'unglq' ), + ('orgql', 'orgql', 'ungql', 'ungql' ), + ('orgqr', 'orgqr', 'ungqr', 'ungqr' ), + ('orgtr', 'orgtr', 'ungtr', 'ungtr' ), + ('orm2r', 'orm2r', 'unm2r', 'unm2r' ), + ('ormbr', 'ormbr', 'unmbr', 'unmbr' ), + ('ormlq', 'ormlq', 'unmlq', 'unmlq' ), + ('ormql', 'ormql', 'unmql', 'unmql' ), + ('ormqr', 'ormqr', 'unmqr', 'unmqr' ), + ('ormr2', 'ormr2', 'unmr2', 'unmr2' ), + ('ormtr', 'ormtr', 'unmtr', 'unmtr' ), + ('ort01', 'ort01', 'unt01', 'unt01' ), + ('plgsy', 'plgsy', 'plghe', 'plghe' ), + ('sbtrd', 'sbtrd', 'hbtrd', 'hbtrd' ), + ('sybbd', 'sybbd', 'hebbd', 'hebbd' ), + ('syev', 'syev', 'heev', 'heev' ), + ('syevd', 'syevd', 'heevd', 'heevd' ), + ('sygs2', 'sygs2', 'hegs2', 'hegs2' ), + ('sygst', 'sygst', 'hegst', 'hegst' ), + ('sygvd', 'sygvd', 'hegvd', 'hegvd' ), + ('sygvr', 'sygvr', 'hegvr', 'hegvr' ), + ('sygvx', 'sygvx', 'hegvx', 'hegvx' ), + ('syssq', 'syssq', 'hessq', 'hessq' ), + ('syt21', 'syt21', 'het21', 'het21' ), + ('sytd2', 'sytd2', 'hetd2', 'hetd2' ), + ('sytrd', 'sytrd', 'hetrd', 'hetrd' ), + ('sytrf', 'sytrf', 'hetrf', 'hetrf' ), + ('syrfb', 'syrfb', 'herfb', 'herfb' ), + + # ----- For norms: compute result in Real or Double + ('slange', 'dlange', 'slange', 'dlange' ), + ('slaset', 'dlaset', 'slaset', 'dlaset' ), + ('splssq', 'dplssq', 'splssq', 'dplssq' ), + ('slacpy', 'dlacpy', 'slacpy', 'dlacpy' ), + ('saxpy', 'daxpy', 'saxpy', 'daxpy' ), + ('MorseRealFloat', 'MorseRealDouble', 'MorseRealFloat', 'MorseRealDouble'), + + # QUARK codelets protection (to prevent conversion with LAPACK WITH PRECISION) + ('DAG_CORE_U-NG2R', 'DAG_CORE_U-NG2R', 'DAG_CORE_UNG2R', 'DAG_CORE_UNG2R' ), + ('DAG_CORE_U-NGBR', 'DAG_CORE_U-NGBR', 'DAG_CORE_UNGBR', 'DAG_CORE_UNGBR' ), + ('DAG_CORE_U-NGHR', 'DAG_CORE_U-NGHR', 'DAG_CORE_UNGHR', 'DAG_CORE_UNGHR' ), + ('DAG_CORE_U-NGLQ', 'DAG_CORE_U-NGLQ', 'DAG_CORE_UNGLQ', 'DAG_CORE_UNGLQ' ), + ('DAG_CORE_U-NGQL', 'DAG_CORE_U-NGQL', 'DAG_CORE_UNGQL', 'DAG_CORE_UNGQL' ), + ('DAG_CORE_U-NGQR', 'DAG_CORE_U-NGQR', 'DAG_CORE_UNGQR', 'DAG_CORE_UNGQR' ), + ('DAG_CORE_U-NGTR', 'DAG_CORE_U-NGTR', 'DAG_CORE_UNGTR', 'DAG_CORE_UNGTR' ), + ('DAG_CORE_U-NM2R', 'DAG_CORE_U-NM2R', 'DAG_CORE_UNM2R', 'DAG_CORE_UNM2R' ), + ('DAG_CORE_U-NMBR', 'DAG_CORE_U-NMBR', 'DAG_CORE_UNMBR', 'DAG_CORE_UNMBR' ), + ('DAG_CORE_U-NMLQ', 'DAG_CORE_U-NMLQ', 'DAG_CORE_UNMLQ', 'DAG_CORE_UNMLQ' ), + ('DAG_CORE_U-NMQL', 'DAG_CORE_U-NMQL', 'DAG_CORE_UNMQL', 'DAG_CORE_UNMQL' ), + ('DAG_CORE_U-NMQR', 'DAG_CORE_U-NMQR', 'DAG_CORE_UNMQR', 'DAG_CORE_UNMQR' ), + + # ----- BLAS AND LAPACK, UPPERCASE, ALPHABETIC ORDER + # COPY & PASTE THESE TO UPPERCASE BELOW AND FIX CASE. + # USED FOR FILENAMES LACKING MAGMA_Z, ETC. PREFIX + ('ISAMAX', 'IDAMAX', 'ICAMAX', 'IZAMAX' ), + ('ISAMAX', 'IDAMAX', 'ISAMAX', 'IDAMAX' ), + ('SAXPY', 'DAXPY', 'CAXPY', 'ZAXPY' ), + ('SCOPY', 'DCOPY', 'CCOPY', 'ZCOPY' ), + ('SGEADD', 'DGEADD', 'CGEADD', 'ZGEADD' ), + ('SGECFI', 'DGECFI', 'CGECFI', 'ZGECFI' ), + ('SGEMDM', 'DGEMDM', 'CGEMDM', 'ZGEMDM' ), + ('SGEMM', 'DGEMM', 'CGEMM', 'ZGEMM' ), + ('SGEMV', 'DGEMV', 'CGEMV', 'ZGEMV' ), + ('SSCAL', 'DSCAL', 'CSCAL', 'ZSCAL' ), + ('SSCAL', 'DSCAL', 'CSSCAL', 'ZDSCAL' ), + ('SSCAL', 'DSCAL', 'SSCAL', 'DSCAL' ), # ZDSCAL -> CSSCAL + ('SSWAP', 'DSWAP', 'CSWAP', 'ZSWAP' ), + ('SSYMM', 'DSYMM', 'CSYMM', 'ZSYMM' ), + ('SSYMV', 'DSYMV', 'CSYMV', 'ZSYMV' ), + ('SSYR2K', 'DSYR2K', 'CSYR2K', 'ZSYR2K' ), + ('SSYRK', 'DSYRK', 'CSYRK', 'ZSYRK' ), + ('STRADD', 'DTRADD', 'CTRADD', 'ZTRADD' ), + ('STRMM', 'DTRMM', 'CTRMM', 'ZTRMM' ), + ('STRMV', 'DTRMV', 'CTRMV', 'ZTRMV' ), + ('STRSM', 'DTRSM', 'CTRSM', 'ZTRSM' ), + ('STRSMPL', 'DTRSMPL', 'CTRSMPL', 'ZTRSMPL' ), + ('STRSV', 'DTRSV', 'CTRSV', 'ZTRSV' ), + + # LAPACK + ('SBDSQR', 'DBDSQR', 'CBDSQR', 'ZBDSQR' ), + ('SBDT01', 'DBDT01', 'CBDT01', 'ZBDT01' ), + ('SCHECK', 'DCHECK', 'CCHECK', 'ZCHECK' ), + ('SGEBAK', 'DGEBAK', 'CGEBAK', 'ZGEBAK' ), + ('SGEBAL', 'DGEBAL', 'CGEBAL', 'ZGEBAL' ), + ('SGEBD2', 'DGEBD2', 'CGEBD2', 'ZGEBD2' ), + ('SGEBRD', 'DGEBRD', 'CGEBRD', 'ZGEBRD' ), + ('SGEEV', 'DGEEV', 'CGEEV', 'ZGEEV' ), + ('SGEHD2', 'DGEHD2', 'CGEHD2', 'ZGEHD2' ), + ('SGEHRD', 'DGEHRD', 'CGEHRD', 'ZGEHRD' ), + ('SGELQ2', 'DGELQ2', 'CGELQ2', 'ZGELQ2' ), + ('SGELQF', 'DGELQF', 'CGELQF', 'ZGELQF' ), + ('SGELQS', 'DGELQS', 'CGELQS', 'ZGELQS' ), + ('SGELS', 'DGELS', 'CGELS', 'ZGELS' ), + ('SGEQLF', 'DGEQLF', 'CGEQLF', 'ZGEQLF' ), + ('SGEQP3', 'DGEQP3', 'CGEQP3', 'ZGEQP3' ), + ('SGEQR2', 'DGEQR2', 'CGEQR2', 'ZGEQR2' ), + ('SGEQRF', 'DGEQRF', 'CGEQRF', 'ZGEQRF' ), + ('SGEQRS', 'DGEQRS', 'CGEQRS', 'ZGEQRS' ), + ('SGESSM', 'DGESSM', 'CGESSM', 'ZGESSM' ), + ('SGESV', 'DGESV', 'CGESV', 'ZGESV' ), + ('SGESV', 'SGESV', 'CGESV', 'CGESV' ), + ('SGET22', 'DGET22', 'CGET22', 'ZGET22' ), + ('SGETF2', 'DGETF2', 'CGETF2', 'ZGETF2' ), + ('SGETRF', 'DGETRF', 'CGETRF', 'ZGETRF' ), + ('SGETRI', 'DGETRI', 'CGETRI', 'ZGETRI' ), + ('SGETRL', 'DGETRL', 'CGETRL', 'ZGETRL' ), + ('SGETRS', 'DGETRS', 'CGETRS', 'ZGETRS' ), + ('SHSEQR', 'DHSEQR', 'CHSEQR', 'ZHSEQR' ), + ('SHST01', 'DHST01', 'CHST01', 'ZHST01' ), + ('SLABAD', 'DLABAD', 'SLABAD', 'DLABAD' ), + ('SLABRD', 'DLABRD', 'CLABRD', 'ZLABRD' ), + ('SLACGV', 'DLACGV', 'CLACGV', 'ZLACGV' ), + ('SLACPY', 'DLACPY', 'CLACPY', 'ZLACPY' ), + ('SLAED', 'DLAED', 'SLAED', 'DLAED' ), + ('SLAEX', 'DLAEX', 'SLAEX', 'DLAEX' ), + ('SLAGSY', 'DLAGSY', 'CLAGSY', 'ZLAGSY' ), + ('SLAHR', 'DLAHR', 'CLAHR', 'ZLAHR' ), + ('SLAMC3', 'DLAMC3', 'SLAMC3', 'DLAMC3' ), + ('SLAMCH', 'DLAMCH', 'SLAMCH', 'DLAMCH' ), + ('SLAMRG', 'DLAMRG', 'SLAMRG', 'DLAMRG' ), + ('SLANGE', 'DLANGE', 'CLANGE', 'ZLANGE' ), + ('SLANST', 'DLANST', 'CLANHT', 'ZLANHT' ), + ('SLANSY', 'DLANSY', 'CLANSY', 'ZLANSY' ), + ('SLANTR', 'DLANTR', 'CLANTR', 'ZLANTR' ), + ('SLAQPS', 'DLAQPS', 'CLAQPS', 'ZLAQPS' ), + ('SLAQP2', 'DLAQP2', 'CLAQP2', 'ZLAQP2' ), + ('SLARFB', 'DLARFB', 'CLARFB', 'ZLARFB' ), + ('SLARFG', 'DLARFG', 'CLARFG', 'ZLARFG' ), + ('SLARFT', 'DLARFT', 'CLARFT', 'ZLARFT' ), + ('SLARFX', 'DLARFX', 'CLARFX', 'ZLARFX' ), + ('SLARFY', 'DLARFY', 'CLARFY', 'ZLARFY' ), + ('SLARNV', 'DLARNV', 'CLARNV', 'ZLARNV' ), + ('SLARNV', 'DLARNV', 'SLARNV', 'DLARNV' ), + ('SLARTG', 'DLARTG', 'CLARTG', 'ZLARTG' ), + ('SLASCL', 'DLASCL', 'CLASCL', 'ZLASCL' ), + ('SLASET', 'DLASET', 'CLASET', 'ZLASET' ), + ('SLASWP', 'DLASWP', 'CLASWP', 'ZLASWP' ), + ('SLATRD', 'DLATRD', 'CLATRD', 'ZLATRD' ), + ('SLAUUM', 'DLAUUM', 'CLAUUM', 'ZLAUUM' ), + ('SPOSV', 'DPOSV', 'CPOSV', 'ZPOSV' ), + ('SSYSV', 'DSYSV', 'CSYSV', 'ZSYSV' ), + ('SPOSV', 'SPOSV', 'CPOSV', 'CPOSV' ), + ('SPOTRF', 'DPOTRF', 'CPOTRF', 'ZPOTRF' ), + ('SSYTRF', 'DSYTRF', 'CSYTRF', 'ZSYTRF' ), + ('SPOTRI', 'DPOTRI', 'CPOTRI', 'ZPOTRI' ), + ('SPOTRS', 'DPOTRS', 'CPOTRS', 'ZPOTRS' ), + ('SSYTRS', 'DSYTRS', 'CSYTRS', 'ZSYTRS' ), + ('SQPT01', 'DQPT01', 'CQPT01', 'ZQPT01' ), + ('SQRT02', 'DQRT02', 'CQRT02', 'ZQRT02' ), + ('SSSSSM', 'DSSSSM', 'CSSSSM', 'ZSSSSM' ), + ('SSTEBZ', 'DSTEBZ', 'SSTEBZ', 'DSTEBZ' ), + ('SSTEDC', 'DSTEDC', 'CSTEDC', 'ZSTEDC' ), + ('SSTEDX', 'DSTEDX', 'CSTEDX', 'ZSTEDX' ), + ('SSTEDX', 'DSTEDX', 'SSTEDX', 'DSTEDX' ), + ('SSTEIN', 'DSTEIN', 'CSTEIN', 'ZSTEIN' ), + ('SSTEMR', 'DSTEMR', 'CSTEMR', 'ZSTEMR' ), + ('SSTEQR', 'DSTEQR', 'CSTEQR', 'ZSTEQR' ), + ('SSTERF', 'DSTERF', 'SSTERF', 'DSTERF' ), + ('SSTERM', 'DSTERM', 'CSTERM', 'ZSTERM' ), + ('SSTT21', 'DSTT21', 'CSTT21', 'ZSTT21' ), + ('STREVC', 'DTREVC', 'CTREVC', 'ZTREVC' ), + ('STRTRI', 'DTRTRI', 'CTRTRI', 'ZTRTRI' ), + ('STSQRT', 'DTSQRT', 'CTSQRT', 'ZTSQRT' ), + ('STSTRF', 'DTSTRF', 'CTSTRF', 'ZTSTRF' ), + ('SUNGESV', 'SUNGESV', 'CUNGESV', 'CUNGESV' ), + ('SSTEGR', 'DSTEGR', 'CSTEGR', 'ZSTEGR' ), + + # ----- BLAS AND LAPACK, WHERE COMPLEX BASE NAME != REAL BASE NAME + # BLAS, WITH PRECISION + ('SDOT', 'DDOT', 'CDOTC', 'ZDOTC' ), + ('SDOT_SUB', 'DDOT_SUB', 'CDOTC_SUB', 'ZDOTC_SUB' ), + ('SDOT_SUB', 'DDOT_SUB', 'CDOTU_SUB', 'ZDOTU_SUB' ), + ('SGER', 'DGER', 'CGERC', 'ZGERC' ), + ('SGER', 'DGER', 'CGERU', 'ZGERU' ), + ('SNRM2', 'DNRM2', 'SCNRM2', 'DZNRM2' ), + ('SSYMM', 'DSYMM', 'CHEMM', 'ZHEMM' ), + ('SSYMV', 'DSYMV', 'CHEMV', 'ZHEMV' ), + ('SSYR2', 'DSYR2', 'CHER2', 'ZHER2' ), + ('SSYR2K', 'DSYR2K', 'CHER2K', 'ZHER2K' ), + ('SSYRK', 'DSYRK', 'CHERK', 'ZHERK' ), + ('SSYR', 'DSYR', 'CHER', 'ZHER' ), + + # LAPACK, WITH PRECISION + ('SLAG2D', 'DLAG2S', 'CLAG2Z', 'ZLAG2C' ), + ('SLAGSY', 'DLAGSY', 'CLAGHE', 'ZLAGHE' ), + ('SLASYF', 'DLASYF', 'CLAHEF', 'ZLAHEF' ), + ('SLANSY', 'DLANSY', 'CLANHE', 'ZLANHE' ), + ('SLAVSY', 'DLAVSY', 'CLAVHE', 'ZLAVHE' ), + ('SORG2R', 'DORG2R', 'CUNG2R', 'ZUNG2R' ), + ('SORGBR', 'DORGBR', 'CUNGBR', 'ZUNGBR' ), + ('SORGHR', 'DORGHR', 'CUNGHR', 'ZUNGHR' ), + ('SORGLQ', 'DORGLQ', 'CUNGLQ', 'ZUNGLQ' ), + ('SORGQL', 'DORGQL', 'CUNGQL', 'ZUNGQL' ), + ('SORGQR', 'DORGQR', 'CUNGQR', 'ZUNGQR' ), + ('SORGTR', 'DORGTR', 'CUNGTR', 'ZUNGTR' ), + ('SORM2R', 'DORM2R', 'CUNM2R', 'ZUNM2R' ), + ('SORMBR', 'DORMBR', 'CUNMBR', 'ZUNMBR' ), + ('SORMLQ', 'DORMLQ', 'CUNMLQ', 'ZUNMLQ' ), + ('SORMQL', 'DORMQL', 'CUNMQL', 'ZUNMQL' ), + ('SORMQR', 'DORMQR', 'CUNMQR', 'ZUNMQR' ), + ('SORMR2', 'DORMR2', 'CUNMR2', 'ZUNMR2' ), + ('SORMTR', 'DORMTR', 'CUNMTR', 'ZUNMTR' ), + ('SORT01', 'DORT01', 'CUNT01', 'ZUNT01' ), + ('SPLGSY', 'DPLGSY', 'CPLGHE', 'ZPLGHE' ), + ('SSBTRD', 'DSBTRD', 'CHBTRD', 'ZHBTRD' ), + ('SSYBBD', 'DSYBBD', 'CHEBBD', 'ZHEBBD' ), + ('SSYEV', 'DSYEV', 'CHEEV', 'ZHEEV' ), + ('SSYEVD', 'DSYEVD', 'CHEEVD', 'ZHEEVD' ), + ('SSYGS2', 'DSYGS2', 'CHEGS2', 'ZHEGS2' ), + ('SSYGST', 'DSYGST', 'CHEGST', 'ZHEGST' ), + ('SSYGVD', 'DSYGVD', 'CHEGVD', 'ZHEGVD' ), + ('SSYGVR', 'DSYGVR', 'CHEGVR', 'ZHEGVR' ), + ('SSYGVX', 'DSYGVX', 'CHEGVX', 'ZHEGVX' ), + ('SSYT21', 'DSYT21', 'CHET21', 'ZHET21' ), + ('SSYTD2', 'DSYTD2', 'CHETD2', 'ZHETD2' ), + ('SSYTRD', 'DSYTRD', 'CHETRD', 'ZHETRD' ), + ('SSYTRF', 'DSYTRF', 'CHETRF', 'ZHETRF' ), + + # BLAS, WITHOUT PRECISION + # MUST BE AFTER BLAS WITH PRECISION + # EX: CUBLASZHEMM -> CUBLASSHEMM -> CUBLASSSYMM + ('DOT', 'DOT', 'DOTC', 'DOTC' ), + ('DOT_SUB', 'DOT_SUB', 'DOTC_SUB', 'DOTC_SUB' ), + ('DOT_SUB', 'DOT_SUB', 'DOTU_SUB', 'DOTU_SUB' ), + ('GER', 'GER', 'GERC', 'GERC' ), + ('GER', 'GER', 'GERU', 'GERU' ), + ('NRM2', 'NRM2', 'CNRM2', 'ZNRM2' ), # DZNRM2 -> DNRM2 + ('SYMM', 'SYMM', 'HEMM', 'HEMM' ), + ('SYMV', 'SYMV', 'HEMV', 'HEMV' ), + ('SYR2', 'SYR2', 'HER2', 'HER2' ), + ('SYR2K', 'SYR2K', 'HER2K', 'HER2K' ), + ('SYRK', 'SYRK', 'HERK', 'HERK' ), + + # LAPACK, WITHOUT PRECISION + ('LAG2D', 'LAG2S', 'LAG2Z', 'LAG2C' ), + ('LAGSY', 'LAGSY', 'LAGHE', 'LAGHE' ), + ('LASYF', 'LASYF', 'LAHEF', 'LAHEF' ), + ('LANSY', 'LANSY', 'LANHE', 'LANHE' ), + ('LAVSY', 'LAVSY', 'LAVHE', 'LAVHE' ), + ('ORG2R', 'ORG2R', 'UNG2R', 'UNG2R' ), + ('ORGBR', 'ORGBR', 'UNGBR', 'UNGBR' ), + ('ORGHR', 'ORGHR', 'UNGHR', 'UNGHR' ), + ('ORGLQ', 'ORGLQ', 'UNGLQ', 'UNGLQ' ), + ('ORGQL', 'ORGQL', 'UNGQL', 'UNGQL' ), + ('ORGQR', 'ORGQR', 'UNGQR', 'UNGQR' ), + ('ORGTR', 'ORGTR', 'UNGTR', 'UNGTR' ), + ('ORM2R', 'ORM2R', 'UNM2R', 'UNM2R' ), + ('ORMBR', 'ORMBR', 'UNMBR', 'UNMBR' ), + ('ORMLQ', 'ORMLQ', 'UNMLQ', 'UNMLQ' ), + ('ORMQL', 'ORMQL', 'UNMQL', 'UNMQL' ), + ('ORMQR', 'ORMQR', 'UNMQR', 'UNMQR' ), + ('ORMR2', 'ORMR2', 'UNMR2', 'UNMR2' ), + ('ORMTR', 'ORMTR', 'UNMTR', 'UNMTR' ), + ('ORT01', 'ORT01', 'UNT01', 'UNT01' ), + ('PLGSY', 'PLGSY', 'PLGHE', 'PLGHE' ), + ('SBTRD', 'SBTRD', 'HBTRD', 'HBTRD' ), + ('SYBBD', 'SYBBD', 'HEBBD', 'HEBBD' ), + ('SYEV', 'SYEV', 'HEEV', 'HEEV' ), + ('SYEVD', 'SYEVD', 'HEEVD', 'HEEVD' ), + ('SYGS2', 'SYGS2', 'HEGS2', 'HEGS2' ), + ('SYGST', 'SYGST', 'HEGST', 'HEGST' ), + ('SYGVD', 'SYGVD', 'HEGVD', 'HEGVD' ), + ('SYGVR', 'SYGVR', 'HEGVR', 'HEGVR' ), + ('SYGVX', 'SYGVX', 'HEGVX', 'HEGVX' ), + ('SYT21', 'SYT21', 'HET21', 'HET21' ), + ('SYTD2', 'SYTD2', 'HETD2', 'HETD2' ), + ('SYTRD', 'SYTRD', 'HETRD', 'HETRD' ), + ('SYTRF', 'SYTRF', 'HETRF', 'HETRF' ), + + # QUARK codelets protection (to prevent conversion with LAPACK WITH PRECISION) + ('DAG_CORE_UNG2R', 'DAG_CORE_UNG2R', 'DAG_CORE_UNG2R', 'DAG_CORE_U-NG2R' ), + ('DAG_CORE_UNGBR', 'DAG_CORE_UNGBR', 'DAG_CORE_UNGBR', 'DAG_CORE_U-NGBR' ), + ('DAG_CORE_UNGHR', 'DAG_CORE_UNGHR', 'DAG_CORE_UNGHR', 'DAG_CORE_U-NGHR' ), + ('DAG_CORE_UNGLQ', 'DAG_CORE_UNGLQ', 'DAG_CORE_UNGLQ', 'DAG_CORE_U-NGLQ' ), + ('DAG_CORE_UNGQL', 'DAG_CORE_UNGQL', 'DAG_CORE_UNGQL', 'DAG_CORE_U-NGQL' ), + ('DAG_CORE_UNGQR', 'DAG_CORE_UNGQR', 'DAG_CORE_UNGQR', 'DAG_CORE_U-NGQR' ), + ('DAG_CORE_UNGTR', 'DAG_CORE_UNGTR', 'DAG_CORE_UNGTR', 'DAG_CORE_U-NGTR' ), + ('DAG_CORE_UNM2R', 'DAG_CORE_UNM2R', 'DAG_CORE_UNM2R', 'DAG_CORE_U-NM2R' ), + ('DAG_CORE_UNMBR', 'DAG_CORE_UNMBR', 'DAG_CORE_UNMBR', 'DAG_CORE_U-NMBR' ), + ('DAG_CORE_UNMLQ', 'DAG_CORE_UNMLQ', 'DAG_CORE_UNMLQ', 'DAG_CORE_U-NMLQ' ), + ('DAG_CORE_UNMQL', 'DAG_CORE_UNMQL', 'DAG_CORE_UNMQL', 'DAG_CORE_U-NMQL' ), + ('DAG_CORE_UNMQR', 'DAG_CORE_UNMQR', 'DAG_CORE_UNMQR', 'DAG_CORE_U-NMQR' ), + + # PaStiX + ('sutils.h', 'dutils.h', 'cutils.h', 'zutils.h' ), + ('SMURGE_', 'DMURGE_', 'CMURGE_', 'ZMURGE_' ), + ('smurge_', 'dmurge_', 'cmurge_', 'zmurge_' ), + ('smurge.h', 'dmurge.h', 'cmurge.h', 'zmurge.h' ), + ('smurge.inc', 'dmurge.inc', 'cmurge.inc', 'zmurge.inc' ), + ('smurge.c', 'dmurge.c', 'cmurge.c', 'zmurge.c' ), + ('ssimple', 'dsimple', 'csimple', 'zsimple' ), + ('sstep-by-step', 'dstep-by-step', 'cstep-by-step', 'zstep-by-step' ), + ('starpu_s', 'starpu_d', 'starpu_c', 'starpu_z' ), + ('STARPU_S', 'STARPU_D', 'STARPU_C', 'STARPU_Z' ), + ('pastix_s', 'pastix_d', 'pastix_c', 'pastix_z' ), + ('s_', 'd_', 'c_', 'z_' ), + ('S_', 'D_', 'C_', 'Z_' ), + ('FLT_EPSILON', 'DBL_EPSILON', 'FLT_EPSILON', 'DBL_EPSILON' ), + ('s_RAFF_FLOAT', 'd_RAFF_FLOAT', 'c_RAFF_FLOAT', 'z_RAFF_FLOAT' ), + ('MPI_FLOAT', 'MPI_DOUBLE', 'MPI_COMPLEX', 'MPI_DOUBLE_COMPLEX'), + ('MPI_FLOAT', 'MPI_DOUBLE', 'MPI_FLOAT', 'MPI_DOUBLE' ), + # ----- unused? + ('s_check', 'd_check', 'c_check', 'z_check' ), + ('s_get_idparm', 'd_get_idparm', 's_get_idparm', 'd_get_idparm', ), + #('stesting', 'dtesting', 'ctesting', 'ztesting' ), + #('SAUXILIARY', 'DAUXILIARY', 'CAUXILIARY', 'ZAUXILIARY' ), + # BUILD + ('sbuild', 'dbuild', 'cbuild', 'zbuild' ), + + ], + + # ------------------------------------------------------------ + # replacements applied for profiling with tau + 'tracing' :[ + # ----- Special line indicating column types + ['plain', 'tau'], + + # ----- Replacements + ('(\w+\*?)\s+(\w+)\s*\(([a-z* ,A-Z_0-9]*)\)\s*{\s+(.*)\s*#pragma tracing_start\s+(.*)\s+#pragma tracing_end\s+(.*)\s+}', + r'\1 \2(\3){\n\4tau("\2");\5tau();\6}'), + ('\.c','.c.tau'), + ], +}; -- GitLab