diff --git a/CMakeScripts/FindCommon.cmake b/CMakeScripts/FindCommon.cmake new file mode 100644 index 0000000000000000000000000000000000000000..95d8c1f5404c0d7ea2384d84bd12c2e4a3cc3418 --- /dev/null +++ b/CMakeScripts/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/CMakeScripts/FindHeadersAndLibs.cmake b/CMakeScripts/FindHeadersAndLibs.cmake new file mode 100644 index 0000000000000000000000000000000000000000..64144bdbf8a35f966f1ac802e5765e6ad81abf7c --- /dev/null +++ b/CMakeScripts/FindHeadersAndLibs.cmake @@ -0,0 +1,94 @@ +### +# +# @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 +# +### + +# Some macros to print status when search for headers and libs +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_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/CMakeScripts/FindInit.cmake b/CMakeScripts/FindInit.cmake new file mode 100644 index 0000000000000000000000000000000000000000..e59d41a077848029e04065d5f46bba57bcf0277d --- /dev/null +++ b/CMakeScripts/FindInit.cmake @@ -0,0 +1,45 @@ +### +# +# @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) +include(FindPkgconfigLibrariesAbsolutePath) + +# Some macros to print status when search for headers and libs +include(PrintFindStatus) + +## +## @end file FindInit.cmake +## diff --git a/CMakeScripts/FindPTSCOTCH.cmake b/CMakeScripts/FindPTSCOTCH.cmake index bc10873f3c0acd74cbff7319522ee96ada8a3c5e..b0f983b8d87ef1fa20cd3835b479466f68d3dd78 100755 --- a/CMakeScripts/FindPTSCOTCH.cmake +++ b/CMakeScripts/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/CMakeScripts/FindPkgconfigLibrariesAbsolutePath.cmake b/CMakeScripts/FindPkgconfigLibrariesAbsolutePath.cmake new file mode 100644 index 0000000000000000000000000000000000000000..fdedfe3fca5c78916dfde351042e669c628e9273 --- /dev/null +++ b/CMakeScripts/FindPkgconfigLibrariesAbsolutePath.cmake @@ -0,0 +1,97 @@ +### +# +# @copyright (c) 2018 Inria. All rights reserved. +# +### +# +# @file FindPkgconfigLibrariesAbsolutePath.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 06-04-2018 +# +### + +# 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 FindPkgconfigLibrariesAbsolutePath.cmake +## diff --git a/CMakeScripts/FindSCOTCH.cmake b/CMakeScripts/FindSCOTCH.cmake index f86f03855e65240f543ef6c45f8f441f82aba515..ddf258d3d37e3900c294c745cea207f9fec6ca93 100644 --- a/CMakeScripts/FindSCOTCH.cmake +++ b/CMakeScripts/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/CMakeScripts/PrintFindStatus.cmake b/CMakeScripts/PrintFindStatus.cmake new file mode 100644 index 0000000000000000000000000000000000000000..1fdd403b7de11a8b946b178c5aada2da5e6fe33e --- /dev/null +++ b/CMakeScripts/PrintFindStatus.cmake @@ -0,0 +1,207 @@ +### +# +# @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_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_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_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()