# # @file FindPETSc.cmake # # @brief # # @copyright # Copyright (©) 2021 EPFL (Ecole Polytechnique Fédérale de Lausanne) # SPC (Swiss Plasma Center) # # SPClibs is free software: you can redistribute it and/or modify it under # the terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. # # SPClibs is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . # # @authors # (in alphabetical order) # @author Nicolas Richart # # - Try to find PETSc # PETSC_FOUND - system has PETSc # PETSC_INCLUDE_DIRS - the PETSc include directories # PETSC_LIBRARIES - Link these to use PETSc # PETSC_VERSION - Version string (MAJOR.MINOR.SUBMINOR) if(PETSc_FIND_REQUIRED) find_package(PkgConfig REQUIRED) else() find_package(PkgConfig QUIET) if(NOT PKG_CONFIG_FOUND) return() endif() endif() pkg_search_module(_petsc PETSc) # Some debug code #get_property(_vars DIRECTORY PROPERTY VARIABLES) #foreach(_var ${_vars}) # if ("${_var}" MATCHES "^_petsc") # message("${_var} -> ${${_var}}") # endif() #endforeach() if(_petsc_FOUND AND _petsc_VERSION) set(PETSC_VERSION ${_petsc_VERSION}) endif() if(_petsc_FOUND) set(_petsc_libs) foreach(_lib ${_petsc_LIBRARIES}) string(TOUPPER "${_lib}" _u_lib) find_library(PETSC_LIBRARY_${_u_lib} ${_lib} PATHS ${_petsc_LIBRARY_DIRS}) list(APPEND _petsc_libs ${PETSC_LIBRARY_${_u_lib}}) mark_as_advanced(PETSC_LIBRARY_${_u_lib}) endforeach() if (NOT _petsc_INCLUDE_DIRS) pkg_get_variable(_petsc_INCLUDE_DIRS ${_petsc_MODULE_NAME} includedir) #message(${_petsc_INCLUDE_DIRS}) endif() find_path(PETSC_Fortran_INCLUDE_DIRS "finclude/petsc.h" PATHS ${_petsc_INCLUDE_DIRS}/petsc NO_CMAKE_PATH NO_DEFAULT_PATH ) set(PETSC_LIBRARIES ${_petsc_libs} CACHE FILEPATH "") set(PETSC_INCLUDE_DIRS ${_petsc_INCLUDE_DIRS} CACHE PATH "") add_library(petsc::petsc INTERFACE IMPORTED) set_property(TARGET petsc::petsc PROPERTY INTERFACE_LINK_LIBRARIES ${PETSC_LIBRARIES}) set_property(TARGET petsc::petsc PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PETSC_INCLUDE_DIRS}) add_library(petsc::petscf INTERFACE IMPORTED) target_link_libraries(petsc::petscf INTERFACE petsc::petsc) set_property(TARGET petsc::petscf PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PETSC_Fortran_INCLUDE_DIRS}) endif() include (FindPackageHandleStandardArgs) find_package_handle_standard_args(PETSc REQUIRED_VARS PETSC_LIBRARIES PETSC_INCLUDE_DIRS VERSION_VAR PETSC_VERSION)