From cc9041de35eb7b83e486d1e029e9d9a892fc2899 Mon Sep 17 00:00:00 2001 From: Florent Pruvost <florent.pruvost@inria.fr> Date: Tue, 24 Apr 2018 11:47:23 +0200 Subject: [PATCH] factorize remove duplicate and move some finds related files in find/ --- modules/LibrariesAbsolutePath.cmake | 68 --------- modules/MorseInit.cmake | 19 +-- modules/find/FindBLAS.cmake | 56 +------ modules/find/FindCBLAS.cmake | 6 +- modules/find/FindCHAMELEON.cmake | 6 +- modules/find/FindCommon.cmake | 47 ++++++ modules/find/FindEZTRACE.cmake | 4 + modules/find/FindFABULOUS.cmake | 7 +- modules/find/FindFFTW.cmake | 6 +- modules/find/FindFXT.cmake | 4 + modules/find/FindGTG.cmake | 4 + modules/find/FindHQR.cmake | 4 + modules/find/FindHWLOC.cmake | 4 + modules/find/FindHYPRE.cmake | 4 + modules/{ => find}/FindHeadersAndLibs.cmake | 5 - modules/find/FindInit.cmake | 44 ++++++ modules/find/FindLAPACK.cmake | 40 +---- modules/find/FindLAPACKE.cmake | 56 +++---- modules/find/FindMAGMA.cmake | 7 +- modules/find/FindMETIS.cmake | 5 +- modules/find/FindMUMPS.cmake | 6 +- modules/find/FindPAMPA.cmake | 7 +- modules/find/FindPAPI.cmake | 4 + modules/find/FindPARMETIS.cmake | 7 +- modules/find/FindPARSEC.cmake | 7 +- modules/find/FindPASTIX.cmake | 6 +- modules/find/FindPTSCOTCH.cmake | 7 +- .../FindPkgconfigLibrariesAbsolutePath.cmake | 0 modules/find/FindQUARK.cmake | 6 +- modules/find/FindSCALAPACK.cmake | 40 +---- modules/find/FindSCOTCH.cmake | 5 +- modules/find/FindSIMGRID.cmake | 4 + modules/find/FindSTARPU.cmake | 7 +- modules/find/FindSUITESPARSE.cmake | 6 +- modules/find/FindTMG.cmake | 6 +- modules/find/LibrariesAbsolutePath.cmake | 140 ++++++++++++++++++ modules/{ => find}/PrintFindStatus.cmake | 0 modules/find/tests/CMakeLists.txt | 4 +- 38 files changed, 365 insertions(+), 293 deletions(-) delete mode 100644 modules/LibrariesAbsolutePath.cmake create mode 100644 modules/find/FindCommon.cmake rename modules/{ => find}/FindHeadersAndLibs.cmake (93%) create mode 100644 modules/find/FindInit.cmake rename modules/{ => find}/FindPkgconfigLibrariesAbsolutePath.cmake (100%) create mode 100644 modules/find/LibrariesAbsolutePath.cmake rename modules/{ => find}/PrintFindStatus.cmake (100%) diff --git a/modules/LibrariesAbsolutePath.cmake b/modules/LibrariesAbsolutePath.cmake deleted file mode 100644 index eb59c11..0000000 --- a/modules/LibrariesAbsolutePath.cmake +++ /dev/null @@ -1,68 +0,0 @@ -### -# -# @copyright (c) 2018 Inria. All rights reserved. -# -### -# -# @file LibrariesAbsolutePath.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 1.0.0 -# @author Florent Pruvost -# @date 13-04-2018 -# -### - -# Transform relative path into absolute path for libraries -# lib_list (input/output): the name of the CMake variable containing libraries, e.g. BLAS_LIBRARIES -# hints_paths (input): additional paths to add when looking for libraries -macro(LIBRARIES_ABSOLUTE_PATH lib_list hints_paths) - # collect environment paths to dig - if(WIN32) - string(REPLACE ":" ";" _lib_env "$ENV{LIB}") - elseif(APPLE) - string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}") - else() - string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}") - endif() - list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}") - # copy the lib list - set (${lib_list}_COPY "${${lib_list}}") - # reset the lib list to populate - set(${lib_list} "") - foreach(_library ${${lib_list}_COPY}) - if(EXISTS "${_library}") - # if already an absolute path, nothing special to do - list(APPEND ${lib_list} ${_library}) - else() - # replace pattern -lfoo -> foo - string(REGEX REPLACE "^-l" "" _library "${_library}") - # remove extensions if exist - get_filename_component(_ext "${_library}" EXT) - set(_lib_extensions ".so" ".a" ".dyld" ".dll") - list(FIND _lib_extensions "${_ext}" _index) - if (${_index} GREATER -1) - get_filename_component(_library "${_library}" NAME_WE) - endif() - # try to find the lib - find_library(_library_path NAMES ${_library} HINTS ${hints_paths} ${_lib_env}) - if (_library_path) - list(APPEND ${lib_list} ${_library_path}) - else() - message(FATAL_ERROR "Dependency of ${lib_list} '${_library}' NOT FOUND") - endif() - unset(_library_path CACHE) - endif() - endforeach() -endmacro() - -## -## @end file LibrariesAbsolutePath.cmake -## diff --git a/modules/MorseInit.cmake b/modules/MorseInit.cmake index 9d4bf78..fc51170 100644 --- a/modules/MorseInit.cmake +++ b/modules/MorseInit.cmake @@ -27,6 +27,9 @@ # ### +# Path to Morse modules +get_filename_component(MORSE_CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_FILE} DIRECTORY CACHE) + # Global Morse options option(MORSE_ENABLE_WARNING "Enable warning messages" OFF) option(MORSE_ENABLE_COVERAGE "Enable flags for coverage test" OFF) @@ -47,19 +50,6 @@ if (MORSE_ENABLE_COLOR_MESSAGE) include(ColorizeMessage) endif() -# To find headers and libs -include(FindHeadersAndLibs) - -# To transform relative path from pkg-config into absolute -include(FindPkgconfigLibrariesAbsolutePath) - -# To transform relative path into absolute for a list of libraries -include(LibrariesAbsolutePath) - -# 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) @@ -69,6 +59,9 @@ 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) +# To load some macros used in Finds (could be useful for other projects) +include(FindInit) + ## ## @end file MorseInit.cmake ## diff --git a/modules/find/FindBLAS.cmake b/modules/find/FindBLAS.cmake index 2b4b916..f66066d 100644 --- a/modules/find/FindBLAS.cmake +++ b/modules/find/FindBLAS.cmake @@ -98,60 +98,8 @@ # (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_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() +# Common macros to use in finds +include(FindInit) if (NOT BLAS_FOUND) set(BLAS_DIR "" CACHE PATH "Installation directory of BLAS library") diff --git a/modules/find/FindCBLAS.cmake b/modules/find/FindCBLAS.cmake index feec87f..29ac109 100644 --- a/modules/find/FindCBLAS.cmake +++ b/modules/find/FindCBLAS.cmake @@ -91,6 +91,8 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) if (NOT CBLAS_FOUND) set(CBLAS_DIR "" CACHE PATH "Installation directory of CBLAS library") @@ -396,6 +398,7 @@ if (BLAS_FOUND) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -424,9 +427,6 @@ if (BLAS_FOUND) set(CBLAS_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(CBLAS_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(CBLAS_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES CBLAS_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES CBLAS_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES CBLAS_LDFLAGS_OTHER_DEP) else() if(NOT CBLAS_FIND_QUIETLY) message(STATUS "Looking for cblas : test of cblas_dscal with cblas and blas libraries fails") diff --git a/modules/find/FindCHAMELEON.cmake b/modules/find/FindCHAMELEON.cmake index 71b8baf..06be58e 100644 --- a/modules/find/FindCHAMELEON.cmake +++ b/modules/find/FindCHAMELEON.cmake @@ -86,6 +86,8 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) if (NOT CHAMELEON_FOUND) set(CHAMELEON_DIR "" CACHE PATH "Installation directory of CHAMELEON library") @@ -707,6 +709,7 @@ if(CHAMELEON_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -727,9 +730,6 @@ if(CHAMELEON_LIBRARIES) set(CHAMELEON_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(CHAMELEON_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(CHAMELEON_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES CHAMELEON_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES CHAMELEON_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES CHAMELEON_LDFLAGS_OTHER_DEP) else() if(NOT CHAMELEON_FIND_QUIETLY) message(STATUS "Looking for chameleon : test of MORSE_Init fails") diff --git a/modules/find/FindCommon.cmake b/modules/find/FindCommon.cmake new file mode 100644 index 0000000..95d8c1f --- /dev/null +++ b/modules/find/FindCommon.cmake @@ -0,0 +1,47 @@ +### +# +# @copyright (c) 2018 Inria. All rights reserved. +# +### +# +# @file FindCommon.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 1.0.0 +# @author Florent Pruvost +# @date 13-04-2018 +# +### + +# clean these variables before using them in CMAKE_REQUIRED_* variables in +# check_function_exists +macro(finds_remove_duplicates) + if (REQUIRED_DEFINITIONS) + list(REMOVE_DUPLICATES REQUIRED_DEFINITIONS) + endif() + if (REQUIRED_INCDIRS) + list(REMOVE_DUPLICATES REQUIRED_INCDIRS) + endif() + if (REQUIRED_FLAGS) + list(REMOVE_DUPLICATES REQUIRED_FLAGS) + endif() + if (REQUIRED_LDFLAGS) + list(REMOVE_DUPLICATES REQUIRED_LDFLAGS) + endif() + if (REQUIRED_LIBS) + list(REVERSE REQUIRED_LIBS) + list(REMOVE_DUPLICATES REQUIRED_LIBS) + list(REVERSE REQUIRED_LIBS) + endif() +endmacro() + +## +## @end file FindCommon +## diff --git a/modules/find/FindEZTRACE.cmake b/modules/find/FindEZTRACE.cmake index e85b543..f6115fe 100644 --- a/modules/find/FindEZTRACE.cmake +++ b/modules/find/FindEZTRACE.cmake @@ -63,6 +63,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT EZTRACE_FOUND) set(EZTRACE_DIR "" CACHE PATH "Installation directory of EZTRACE library") if (NOT EZTRACE_FIND_QUIETLY) @@ -330,6 +333,7 @@ if(EZTRACE_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) diff --git a/modules/find/FindFABULOUS.cmake b/modules/find/FindFABULOUS.cmake index 265d4f8..a4df2d9 100644 --- a/modules/find/FindFABULOUS.cmake +++ b/modules/find/FindFABULOUS.cmake @@ -64,6 +64,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT FABULOUS_FOUND) set(FABULOUS_DIR "" CACHE PATH "Installation directory of FABULOUS library") if (NOT FABULOUS_FIND_QUIETLY) @@ -374,6 +377,7 @@ if(FABULOUS_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -394,9 +398,6 @@ if(FABULOUS_LIBRARIES) set(FABULOUS_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(FABULOUS_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(FABULOUS_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES FABULOUS_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES FABULOUS_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES FABULOUS_LDFLAGS_OTHER_DEP) else() if(NOT FABULOUS_FIND_QUIETLY) message(STATUS "Looking for fabulous : test of fabulous_topology_init with fabulous library fails") diff --git a/modules/find/FindFFTW.cmake b/modules/find/FindFFTW.cmake index 9f2e6ee..cb4e1d9 100644 --- a/modules/find/FindFFTW.cmake +++ b/modules/find/FindFFTW.cmake @@ -80,6 +80,8 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) if (NOT FFTW_FOUND) set(FFTW_DIR "" CACHE PATH "Installation directory of FFTW library given by user") @@ -767,6 +769,7 @@ if(FFTW_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -792,9 +795,6 @@ if(FFTW_LIBRARIES) set(FFTW_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(FFTW_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(FFTW_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES FFTW_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES FFTW_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES FFTW_LDFLAGS_OTHER_DEP) else() if(NOT FFTW_FIND_QUIETLY) message(STATUS "Looking for FFTW : test of ${FFTW_PREC_TESTFUNC}fftw_execute_ with fftw library fails") diff --git a/modules/find/FindFXT.cmake b/modules/find/FindFXT.cmake index 1e9ebd2..d2eada5 100644 --- a/modules/find/FindFXT.cmake +++ b/modules/find/FindFXT.cmake @@ -59,6 +59,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT FXT_FOUND) set(FXT_DIR "" CACHE PATH "Installation directory of FXT library") if (NOT FXT_FIND_QUIETLY) @@ -289,6 +292,7 @@ if(FXT_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) diff --git a/modules/find/FindGTG.cmake b/modules/find/FindGTG.cmake index 673bf7d..b3b7f0f 100644 --- a/modules/find/FindGTG.cmake +++ b/modules/find/FindGTG.cmake @@ -59,6 +59,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT GTG_FOUND) set(GTG_DIR "" CACHE PATH "Installation directory of GTG library") if (NOT GTG_FIND_QUIETLY) @@ -289,6 +292,7 @@ if(GTG_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) diff --git a/modules/find/FindHQR.cmake b/modules/find/FindHQR.cmake index e69c9a4..3695d26 100644 --- a/modules/find/FindHQR.cmake +++ b/modules/find/FindHQR.cmake @@ -59,6 +59,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT HQR_FOUND) set(HQR_DIR "" CACHE PATH "Installation directory of HQR library") if (NOT HQR_FIND_QUIETLY) @@ -284,6 +287,7 @@ if(HQR_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) diff --git a/modules/find/FindHWLOC.cmake b/modules/find/FindHWLOC.cmake index fa53d6b..a4dc408 100644 --- a/modules/find/FindHWLOC.cmake +++ b/modules/find/FindHWLOC.cmake @@ -59,6 +59,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + include(CheckStructHasMember) include(CheckCSourceCompiles) @@ -295,6 +298,7 @@ if(HWLOC_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) diff --git a/modules/find/FindHYPRE.cmake b/modules/find/FindHYPRE.cmake index 275ef4d..b83794f 100644 --- a/modules/find/FindHYPRE.cmake +++ b/modules/find/FindHYPRE.cmake @@ -45,6 +45,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT HYPRE_FOUND) set(HYPRE_DIR "" CACHE PATH "Installation directory of HYPRE library") if (NOT HYPRE_FIND_QUIETLY) @@ -222,6 +225,7 @@ if(HYPRE_LIBRARIES) set(REQUIRED_LIBS "${HYPRE_LIBRARIES}") # set required libraries for link + finds_remove_duplicates() set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}") set(CMAKE_REQUIRED_LIBRARIES) foreach(lib_dir ${REQUIRED_LIBDIRS}) diff --git a/modules/FindHeadersAndLibs.cmake b/modules/find/FindHeadersAndLibs.cmake similarity index 93% rename from modules/FindHeadersAndLibs.cmake rename to modules/find/FindHeadersAndLibs.cmake index 992b9fb..64144bd 100644 --- a/modules/FindHeadersAndLibs.cmake +++ b/modules/find/FindHeadersAndLibs.cmake @@ -27,14 +27,9 @@ # ### -# 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 diff --git a/modules/find/FindInit.cmake b/modules/find/FindInit.cmake new file mode 100644 index 0000000..8a7acc5 --- /dev/null +++ b/modules/find/FindInit.cmake @@ -0,0 +1,44 @@ +### +# +# @copyright (c) 2018 Inria. All rights reserved. +# +### +# +# @file FindInit.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 1.0.0 +# @author Florent Pruvost +# @date 24-04-2018 +# +### + + +# This include is required to check symbols of libs +include(CheckFunctionExists) + +# This include is required to check defines in headers +include(CheckIncludeFiles) + +# Factorize some piece of code +include(FindCommon) + +# To find headers and libs +include(FindHeadersAndLibs) + +# To transform relative path into absolute for a list of libraries +include(LibrariesAbsolutePath) + +# Some macros to print status when search for headers and libs +include(PrintFindStatus) + +## +## @end file FindInit.cmake +## diff --git a/modules/find/FindLAPACK.cmake b/modules/find/FindLAPACK.cmake index b0bce5d..18852d7 100644 --- a/modules/find/FindLAPACK.cmake +++ b/modules/find/FindLAPACK.cmake @@ -76,44 +76,8 @@ # (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_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() +# Common macros to use in finds +include(FindInit) if (NOT LAPACK_FOUND) set(LAPACK_DIR "" CACHE PATH "Installation directory of LAPACK library") diff --git a/modules/find/FindLAPACKE.cmake b/modules/find/FindLAPACKE.cmake index 1f334b3..2600c29 100644 --- a/modules/find/FindLAPACKE.cmake +++ b/modules/find/FindLAPACKE.cmake @@ -83,6 +83,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT LAPACKE_FOUND) set(LAPACKE_DIR "" CACHE PATH "Installation directory of LAPACKE library") if (NOT LAPACKE_FIND_QUIETLY) @@ -100,7 +103,16 @@ if( LAPACKE_FIND_COMPONENTS ) endforeach() endif() -# LAPACKE depends on LAPACK anyway, try to find it +# LAPACKE may depend on TMG, try to find it +if (LAPACKE_WITH_TMG) + if(LAPACKE_FIND_REQUIRED) + find_package(TMG REQUIRED) + else() + find_package(TMG) + endif() +endif() + +# LAPACKE depends on LAPACK, try to find it if(LAPACKE_FIND_REQUIRED) find_package(LAPACK REQUIRED) else() @@ -355,6 +367,22 @@ if (LAPACK_FOUND) set(REQUIRED_LIBDIRS "${LAPACKE_LIBRARY_DIRS}") endif() set(REQUIRED_LIBS "${LAPACKE_LIBRARIES}") + # TMG + if (LAPACKE_WITH_TMG) + if (TMG_INCLUDE_DIRS_DEP) + list(APPEND REQUIRED_INCDIRS "${TMG_INCLUDE_DIRS_DEP}") + endif() + if (TMG_CFLAGS_OTHER_DEP) + list(APPEND REQUIRED_FLAGS "${TMG_CFLAGS_OTHER_DEP}") + endif() + if (TMG_LDFLAGS_OTHER_DEP) + list(APPEND REQUIRED_LDFLAGS "${TMG_LDFLAGS_OTHER_DEP}") + endif() + if (TMG_LIBRARY_DIRS_DEP) + list(APPEND REQUIRED_LIBDIRS "${TMG_LIBRARY_DIRS_DEP}") + endif() + list(APPEND REQUIRED_LIBS "${TMG_LIBRARIES_DEP}") + endif() # LAPACK if (LAPACK_INCLUDE_DIRS_DEP) list(APPEND REQUIRED_INCDIRS "${LAPACK_INCLUDE_DIRS_DEP}") @@ -369,28 +397,6 @@ if (LAPACK_FOUND) list(APPEND REQUIRED_LIBDIRS "${LAPACK_LIBRARY_DIRS_DEP}") endif() list(APPEND REQUIRED_LIBS "${LAPACK_LIBRARIES_DEP}") - # 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) @@ -411,6 +417,7 @@ if (LAPACK_FOUND) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -435,9 +442,6 @@ if (LAPACK_FOUND) set(LAPACKE_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(LAPACKE_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(LAPACKE_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES LAPACKE_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES LAPACKE_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES LAPACKE_LDFLAGS_OTHER_DEP) else() if(NOT LAPACKE_FIND_QUIETLY) message(STATUS "Looking for lapacke: test of LAPACKE_dgeqrf with lapacke and lapack libraries fails") diff --git a/modules/find/FindMAGMA.cmake b/modules/find/FindMAGMA.cmake index 057d566..95549c5 100644 --- a/modules/find/FindMAGMA.cmake +++ b/modules/find/FindMAGMA.cmake @@ -63,6 +63,8 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) if(NOT MAGMA_FOUND) set(MAGMA_DIR "" CACHE PATH "Installation directory of MAGMA library") @@ -361,7 +363,7 @@ if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT MAGMA_FOUND) O list(APPEND REQUIRED_LIBDIRS "${CUDA_LIBRARY_DIRS}") endif() list(APPEND REQUIRED_LIBS "${CUDA_CUBLAS_LIBRARIES};${CUDA_LIBRARIES}") - + finds_remove_duplicates() # set required libraries for link set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -384,9 +386,6 @@ if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT MAGMA_FOUND) O 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 diff --git a/modules/find/FindMETIS.cmake b/modules/find/FindMETIS.cmake index 9ce9ca6..860de60 100644 --- a/modules/find/FindMETIS.cmake +++ b/modules/find/FindMETIS.cmake @@ -47,6 +47,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT METIS_FOUND) set(METIS_DIR "" CACHE PATH "Installation directory of METIS library") if (NOT METIS_FIND_QUIETLY) @@ -210,7 +213,7 @@ if(METIS_LIBRARIES) if(M_LIBRARY) list(APPEND REQUIRED_LIBS "${M_LIBRARY}") endif() - + finds_remove_duplicates() # set required libraries for link set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}") set(CMAKE_REQUIRED_LIBRARIES) diff --git a/modules/find/FindMUMPS.cmake b/modules/find/FindMUMPS.cmake index b1e9be5..a88c570 100644 --- a/modules/find/FindMUMPS.cmake +++ b/modules/find/FindMUMPS.cmake @@ -69,6 +69,8 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) if (NOT MUMPS_FOUND) set(MUMPS_DIR "" CACHE PATH "Installation directory of MUMPS library") @@ -712,6 +714,7 @@ if(MUMPS_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -746,9 +749,6 @@ if(MUMPS_LIBRARIES) set(MUMPS_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(MUMPS_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(MUMPS_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES MUMPS_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES MUMPS_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES MUMPS_LDFLAGS_OTHER_DEP) else() if(NOT MUMPS_FIND_QUIETLY) message(STATUS "Looking for MUMPS : test of [sdcz]mumps() fails") diff --git a/modules/find/FindPAMPA.cmake b/modules/find/FindPAMPA.cmake index fba85f8..e3f0ae0 100644 --- a/modules/find/FindPAMPA.cmake +++ b/modules/find/FindPAMPA.cmake @@ -58,6 +58,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT PAMPA_FOUND) set(PAMPA_DIR "" CACHE PATH "Installation directory of PAMPA library") if (NOT PAMPA_FIND_QUIETLY) @@ -303,6 +306,7 @@ if(PAMPA_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -323,9 +327,6 @@ if(PAMPA_LIBRARIES) set(PAMPA_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(PAMPA_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(PAMPA_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES PAMPA_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES PAMPA_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES PAMPA_LDFLAGS_OTHER_DEP) else() if(NOT PAMPA_FIND_QUIETLY) message(STATUS "Looking for PAMPA : test of PAMPA_dmeshInit with PAMPA library fails") diff --git a/modules/find/FindPAPI.cmake b/modules/find/FindPAPI.cmake index add232d..4445a1f 100644 --- a/modules/find/FindPAPI.cmake +++ b/modules/find/FindPAPI.cmake @@ -59,6 +59,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT PAPI_FOUND) set(PAPI_DIR "" CACHE PATH "Installation directory of PAPI library") if (NOT PAPI_FIND_QUIETLY) @@ -289,6 +292,7 @@ if(PAPI_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) diff --git a/modules/find/FindPARMETIS.cmake b/modules/find/FindPARMETIS.cmake index 8033659..19202dd 100644 --- a/modules/find/FindPARMETIS.cmake +++ b/modules/find/FindPARMETIS.cmake @@ -57,6 +57,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT PARMETIS_FOUND) set(PARMETIS_DIR "" CACHE PATH "Installation directory of PARMETIS library") if (NOT PARMETIS_FIND_QUIETLY) @@ -275,6 +278,7 @@ if(PARMETIS_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -295,9 +299,6 @@ if(PARMETIS_LIBRARIES) set(PARMETIS_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(PARMETIS_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(PARMETIS_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES PARMETIS_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES PARMETIS_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES PARMETIS_LDFLAGS_OTHER_DEP) else() if(NOT PARMETIS_FIND_QUIETLY) message(STATUS "Looking for PARMETIS : test of ParMETIS_V3_NodeND with PARMETIS library fails") diff --git a/modules/find/FindPARSEC.cmake b/modules/find/FindPARSEC.cmake index c3ff3e9..da015ea 100644 --- a/modules/find/FindPARSEC.cmake +++ b/modules/find/FindPARSEC.cmake @@ -79,6 +79,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + include(CheckSymbolExists) if (NOT PARSEC_FOUND) @@ -602,6 +605,7 @@ if(PARSEC_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -622,9 +626,6 @@ if(PARSEC_LIBRARIES) set(PARSEC_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(PARSEC_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(PARSEC_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES PARSEC_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES PARSEC_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES PARSEC_LDFLAGS_OTHER_DEP) else() if(NOT PARSEC_FIND_QUIETLY) message(STATUS "Looking for parsec : test of parsec_init fails") diff --git a/modules/find/FindPASTIX.cmake b/modules/find/FindPASTIX.cmake index 06d4604..6b40995 100644 --- a/modules/find/FindPASTIX.cmake +++ b/modules/find/FindPASTIX.cmake @@ -94,6 +94,8 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) if (NOT PASTIX_FOUND) set(PASTIX_DIR "" CACHE PATH "Installation directory of PASTIX library") @@ -777,6 +779,7 @@ if(PASTIX_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -797,9 +800,6 @@ if(PASTIX_LIBRARIES) set(PASTIX_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(PASTIX_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(PASTIX_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES PASTIX_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES PASTIX_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES PASTIX_LDFLAGS_OTHER_DEP) else() if(NOT PASTIX_FIND_QUIETLY) message(STATUS "Looking for PASTIX : test of pastix() fails") diff --git a/modules/find/FindPTSCOTCH.cmake b/modules/find/FindPTSCOTCH.cmake index bc10873..b0f983b 100644 --- a/modules/find/FindPTSCOTCH.cmake +++ b/modules/find/FindPTSCOTCH.cmake @@ -62,6 +62,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT PTSCOTCH_FOUND) set(PTSCOTCH_DIR "" CACHE PATH "Installation directory of PTSCOTCH library") if (NOT PTSCOTCH_FIND_QUIETLY) @@ -333,6 +336,7 @@ if(PTSCOTCH_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -353,9 +357,6 @@ if(PTSCOTCH_LIBRARIES) set(PTSCOTCH_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(PTSCOTCH_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(PTSCOTCH_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES PTSCOTCH_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES PTSCOTCH_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES PTSCOTCH_LDFLAGS_OTHER_DEP) else() if(NOT PTSCOTCH_FIND_QUIETLY) message(STATUS "Looking for PTSCOTCH : test of SCOTCH_dgraphInit with PTSCOTCH library fails") diff --git a/modules/FindPkgconfigLibrariesAbsolutePath.cmake b/modules/find/FindPkgconfigLibrariesAbsolutePath.cmake similarity index 100% rename from modules/FindPkgconfigLibrariesAbsolutePath.cmake rename to modules/find/FindPkgconfigLibrariesAbsolutePath.cmake diff --git a/modules/find/FindQUARK.cmake b/modules/find/FindQUARK.cmake index 6431029..78f76cf 100644 --- a/modules/find/FindQUARK.cmake +++ b/modules/find/FindQUARK.cmake @@ -62,6 +62,8 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) if (NOT QUARK_FOUND) set(QUARK_DIR "" CACHE PATH "Installation directory of QUARK library") @@ -286,6 +288,7 @@ if(QUARK_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -306,9 +309,6 @@ if(QUARK_LIBRARIES) set(QUARK_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(QUARK_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(QUARK_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES QUARK_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES QUARK_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES QUARK_LDFLAGS_OTHER_DEP) else() if(NOT QUARK_FIND_QUIETLY) message(STATUS "Looking for QUARK : test of QUARK_New with QUARK library fails") diff --git a/modules/find/FindSCALAPACK.cmake b/modules/find/FindSCALAPACK.cmake index 9d0514d..1d7d19c 100644 --- a/modules/find/FindSCALAPACK.cmake +++ b/modules/find/FindSCALAPACK.cmake @@ -58,44 +58,8 @@ # (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_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() +# Common macros to use in finds +include(FindInit) if (NOT SCALAPACK_FOUND) set(SCALAPACK_DIR "" CACHE PATH "Installation directory of SCALAPACK library") diff --git a/modules/find/FindSCOTCH.cmake b/modules/find/FindSCOTCH.cmake index f86f038..ddf258d 100644 --- a/modules/find/FindSCOTCH.cmake +++ b/modules/find/FindSCOTCH.cmake @@ -51,6 +51,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT SCOTCH_FOUND) set(SCOTCH_DIR "" CACHE PATH "Installation directory of SCOTCH library") if (NOT SCOTCH_FIND_QUIETLY) @@ -270,7 +273,7 @@ if(SCOTCH_LIBRARIES) if(RT_LIBRARY) list(APPEND REQUIRED_LIBS "${RT_LIBRARY}") endif() - + finds_remove_duplicates() # set required libraries for link set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}") set(CMAKE_REQUIRED_LIBRARIES) diff --git a/modules/find/FindSIMGRID.cmake b/modules/find/FindSIMGRID.cmake index 5378964..691c2c5 100644 --- a/modules/find/FindSIMGRID.cmake +++ b/modules/find/FindSIMGRID.cmake @@ -59,6 +59,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT SIMGRID_FOUND) set(SIMGRID_DIR "" CACHE PATH "Installation directory of SIMGRID library") if (NOT SIMGRID_FIND_QUIETLY) @@ -299,6 +302,7 @@ if(SIMGRID_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) diff --git a/modules/find/FindSTARPU.cmake b/modules/find/FindSTARPU.cmake index 90d3837..3829c62 100644 --- a/modules/find/FindSTARPU.cmake +++ b/modules/find/FindSTARPU.cmake @@ -82,6 +82,9 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) + if (NOT STARPU_FOUND) set(STARPU_DIR "" CACHE PATH "Installation directory of STARPU library") if (NOT STARPU_FIND_QUIETLY) @@ -813,6 +816,7 @@ if(STARPU_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -833,9 +837,6 @@ if(STARPU_LIBRARIES) set(STARPU_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(STARPU_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(STARPU_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES STARPU_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES STARPU_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES STARPU_LDFLAGS_OTHER_DEP) else() if(NOT STARPU_FIND_QUIETLY) message(STATUS "Looking for starpu : test of starpu_init fails") diff --git a/modules/find/FindSUITESPARSE.cmake b/modules/find/FindSUITESPARSE.cmake index 8a9eff8..9124598 100644 --- a/modules/find/FindSUITESPARSE.cmake +++ b/modules/find/FindSUITESPARSE.cmake @@ -56,6 +56,8 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) if (NOT SUITESPARSE_FOUND) set(SUITESPARSE_DIR "" CACHE PATH "Installation directory of SUITESPARSE library") @@ -358,6 +360,7 @@ if(SUITESPARSE_LIBRARIES) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -378,9 +381,6 @@ if(SUITESPARSE_LIBRARIES) set(SUITESPARSE_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(SUITESPARSE_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(SUITESPARSE_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES SUITESPARSE_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES SUITESPARSE_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES SUITESPARSE_LDFLAGS_OTHER_DEP) else() if(NOT SUITESPARSE_FIND_QUIETLY) message(STATUS "Looking for SUITESPARSE : test of symbol SuiteSparse_start fails") diff --git a/modules/find/FindTMG.cmake b/modules/find/FindTMG.cmake index 5721dab..09992e8 100644 --- a/modules/find/FindTMG.cmake +++ b/modules/find/FindTMG.cmake @@ -53,6 +53,8 @@ # (To distribute this file outside of Morse, substitute the full # License text for the above reference.) +# Common macros to use in finds +include(FindInit) if (NOT TMG_FOUND) set(TMG_DIR "" CACHE PATH "Installation directory of TMG library") @@ -243,6 +245,7 @@ if (LAPACK_FOUND) list(APPEND REQUIRED_FLAGS "${_flag}") endforeach() endif() + finds_remove_duplicates() set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}") set(CMAKE_REQUIRED_LIBRARIES) @@ -276,9 +279,6 @@ if (LAPACK_FOUND) set(TMG_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(TMG_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}") set(TMG_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}") - list(REMOVE_DUPLICATES TMG_LIBRARY_DIRS_DEP) - list(REMOVE_DUPLICATES TMG_CFLAGS_OTHER_DEP) - list(REMOVE_DUPLICATES TMG_LDFLAGS_OTHER_DEP) else() if(NOT TMG_FIND_QUIETLY) message(STATUS "Looking for tmg: test of dlarnv and dlagsy with tmg and lapack libraries fails") diff --git a/modules/find/LibrariesAbsolutePath.cmake b/modules/find/LibrariesAbsolutePath.cmake new file mode 100644 index 0000000..93f7b35 --- /dev/null +++ b/modules/find/LibrariesAbsolutePath.cmake @@ -0,0 +1,140 @@ +### +# +# @copyright (c) 2018 Inria. All rights reserved. +# +### +# +# @file LibrariesAbsolutePath.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 1.0.0 +# @author Florent Pruvost +# @date 13-04-2018 +# +### + +# Transform relative path into absolute path for libraries +# lib_list (input/output): the name of the CMake variable containing libraries, e.g. BLAS_LIBRARIES +# hints_paths (input): additional paths to add when looking for libraries +macro(LIBRARIES_ABSOLUTE_PATH lib_list hints_paths) + # collect environment paths to dig + if(WIN32) + string(REPLACE ":" ";" _lib_env "$ENV{LIB}") + elseif(APPLE) + string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}") + else() + string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}") + endif() + list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}") + # copy the lib list + set (${lib_list}_COPY "${${lib_list}}") + # reset the lib list to populate + set(${lib_list} "") + foreach(_library ${${lib_list}_COPY}) + if(EXISTS "${_library}") + # if already an absolute path, nothing special to do + list(APPEND ${lib_list} ${_library}) + else() + # replace pattern -lfoo -> foo + string(REGEX REPLACE "^-l" "" _library "${_library}") + # remove extensions if exist + get_filename_component(_ext "${_library}" EXT) + set(_lib_extensions ".so" ".a" ".dyld" ".dll") + list(FIND _lib_extensions "${_ext}" _index) + if (${_index} GREATER -1) + get_filename_component(_library "${_library}" NAME_WE) + endif() + # try to find the lib + find_library(_library_path NAMES ${_library} HINTS ${hints_paths} ${_lib_env}) + if (_library_path) + list(APPEND ${lib_list} ${_library_path}) + else() + message(FATAL_ERROR "Dependency of ${lib_list} '${_library}' NOT FOUND") + endif() + unset(_library_path CACHE) + endif() + endforeach() +endmacro() + +# Transform relative path into absolute path for libraries found with the +# pkg_search_module cmake macro +# _prefix: the name of the CMake variable used when pkg_search_module was called +# e.g. for pkg_search_module(BLAS blas) _prefix would be BLAS +macro(FIND_PKGCONFIG_LIBRARIES_ABSOLUTE_PATH _prefix) + if(WIN32) + string(REPLACE ":" ";" _lib_env "$ENV{LIB}") + elseif(APPLE) + string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}") + else() + string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}") + endif() + list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}") + # non static case + set(${_prefix}_LIBRARIES_COPY "${${_prefix}_LIBRARIES}") + set(${_prefix}_LIBRARIES "") + foreach(_library ${${_prefix}_LIBRARIES_COPY}) + if(EXISTS "${_library}") + list(APPEND ${_prefix}_LIBRARIES ${_library}) + else() + get_filename_component(_ext "${_library}" EXT) + set(_lib_extensions ".so" ".a" ".dyld" ".dll") + list(FIND _lib_extensions "${_ext}" _index) + if (${_index} GREATER -1) + get_filename_component(_library "${_library}" NAME_WE) + endif() + find_library(_library_path NAMES ${_library} + HINTS ${${_prefix}_LIBDIR} ${${_prefix}_LIBRARY_DIRS} ${_lib_env}) + if (_library_path) + list(APPEND ${_prefix}_LIBRARIES ${_library_path}) + else() + message(FATAL_ERROR "Dependency of ${_prefix} '${_library}' NOT FOUND") + endif() + unset(_library_path CACHE) + endif() + endforeach() + set (${_prefix}_LIBRARIES "${${_prefix}_LIBRARIES}" CACHE INTERNAL "" FORCE) + # static case + set(${_prefix}_STATIC_LIBRARIES_COPY "${${_prefix}_STATIC_LIBRARIES}") + set(${_prefix}_STATIC_LIBRARIES "") + foreach(_library ${${_prefix}_STATIC_LIBRARIES_COPY}) + if(EXISTS "${_library}") + list(APPEND ${_prefix}_STATIC_LIBRARIES ${_library}) + else() + get_filename_component(_ext "${_library}" EXT) + set(_lib_extensions ".so" ".a" ".dyld" ".dll") + list(FIND _lib_extensions "${_ext}" _index) + if (${_index} GREATER -1) + get_filename_component(_library "${_library}" NAME_WE) + endif() + # try static first + set (default_find_library_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set (CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX}) + find_library(_library_path NAMES ${_library} + HINTS ${${_prefix}_STATIC_LIBDIR} ${${_prefix}_STATIC_LIBRARY_DIRS} ${_lib_env}) + set (CMAKE_FIND_LIBRARY_SUFFIXES ${default_find_library_suffixes}) + # if not found try dynamic + if (NOT _library_path) + find_library(_library_path NAMES ${_library} + HINTS ${${_prefix}_STATIC_LIBDIR} ${${_prefix}_STATIC_LIBRARY_DIRS} ${_lib_env}) + endif() + if (_library_path) + list(APPEND ${_prefix}_STATIC_LIBRARIES ${_library_path}) + else() + message(FATAL_ERROR "Dependency of ${_prefix} '${_library}' NOT FOUND") + endif() + unset(_library_path CACHE) + endif() + endforeach() + set (${_prefix}_STATIC_LIBRARIES "${${_prefix}_STATIC_LIBRARIES}" CACHE INTERNAL "" FORCE) +endmacro() + +## +## @end file LibrariesAbsolutePath.cmake +## diff --git a/modules/PrintFindStatus.cmake b/modules/find/PrintFindStatus.cmake similarity index 100% rename from modules/PrintFindStatus.cmake rename to modules/find/PrintFindStatus.cmake diff --git a/modules/find/tests/CMakeLists.txt b/modules/find/tests/CMakeLists.txt index c664e71..abccab8 100644 --- a/modules/find/tests/CMakeLists.txt +++ b/modules/find/tests/CMakeLists.txt @@ -2,10 +2,8 @@ cmake_minimum_required(VERSION 2.8) project(TEST_MORSE_CMAKE_MODULES_FIND Fortran C CXX) # location of Morse modules to get some specific macros -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../") include(MorseInit) -# location of find package modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../") # main variable: control the list of libraries to find thanks to find_package # pay attention that package names must be given with capital letters -- GitLab