Include PETSc and SLEPc in fenics 2017


385
views
0
9 months ago by
Hello everyone,

I recently installed fenics v.2017.1.0 and I've been trying to make my old code (build in fenics v.2014) run. Unfortunatelly, I have been facing problems since the beginning when I try to run CMake. My input file has the following form:

# This file is automatically generated by running
#
#     cmake/scripts/generate- cmakefiles
#
# Require CMake 3.5
cmake_minimum_required(VERSION 3.5)

set(PROJECT_NAME MAXEIG)
project(${PROJECT_NAME})

# Set CMake behavior
cmake_policy(SET CMP0004 NEW)

# Get DOLFIN configuration data (DOLFINConfig.cmake must be in
# DOLFIN_CMAKE_CONFIG_PATH)
find_package(DOLFIN REQUIRED)
find_package(PETSc)
find_package(SLEPc)

if (EXISTS ${DOLFIN_USE_FILE})
  include(${DOLFIN_USE_FILE})

  # Default build type (can be overridden by user)
  if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
      "Choose the type of build, options are: Debug MinSizeRel Release RelWithDebInfo." FORCE)
  endif()

if (SLEPC_FOUND)
  list(APPEND MAXEIG_CXX_DEFINITIONS "-DHAS_SLEPC")
  list(APPEND MAXEIG_DEP_INCLUDE_DIRECTORIES ${SLEPC_INCLUDE_DIRS})
  list(APPEND MAXEIG_TARGET_LINK_LIBRARIES ${SLEPC_LIBRARIES})
endif()

# PETSc
if (PETSC_FOUND)
  list(APPEND MAXEIG_CXX_DEFINITIONS "-DHAS_PETSC")
  list(APPEND MAXEIG_DEP_SYSTEM_INCLUDE_ DIRECTORIES ${PETSC_INCLUDE_DIRS})
  list(APPEND MAXEIG_TARGET_LINK_LIBRARIES ${PETSC_LIBRARIES})
  if (PETSC_CUSP_FOUND)
    list(APPEND MAXEIG_CXX_DEFINITIONS "-DHAS_PETSC_CUSP")
  endif()
endif()

  # Do not throw error for 'multi-line comments' (these are typical in
  # rst which includes LaTeX)
  include(CheckCXXCompilerFlag)
  CHECK_CXX_COMPILER_FLAG("-Wno- comment" HAVE_NO_MULTLINE)
  if (HAVE_NO_MULTLINE)
    set(CMAKE_CXX_FLAGS "-Wno-comment ${CMAKE_CXX_FLAGS}")
  endif()

else()
  # Compiler definitions
  add_definitions(${DOLFIN_CXX_ DEFINITIONS})
  add_definitions(${MAXEIG_CXX_ DEFINITIONS})

  # Compiler flags
  set(CMAKE_CXX_FLAGS "${DOLFIN_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")

  # Do not throw error for 'multi-line comments' (these are typical in
  # rst which includes LaTeX)
  include(CheckCXXCompilerFlag)
  CHECK_CXX_COMPILER_FLAG("-Wno- comment" HAVE_NO_MULTLINE)
  if (HAVE_NO_MULTLINE)
    set(CMAKE_CXX_FLAGS "-Wno-comment ${CMAKE_CXX_FLAGS}")
  endif()

  # Include directories
include_directories(${MAXEIG_ SOURCE_DIR} ${DOLFIN_INCLUDE_DIRS})
include_directories(SYSTEM ${DOLFIN_3RD_PARTY_INCLUDE_ DIRS})
include_directories(SYSTEM ${MAXEIG_DEP_INCLUDE_ DIRECTORIES})
endif()

set(PROJECT_SOURCES
.........
)

# Executable
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})

# Target libraries
target_link_libraries(${ PROJECT_NAME} ${DOLFIN_LIBRARIES} ${DOLFIN_3RD_PARTY_LIBRARIES} ${MAXEIG_TARGET_LINK_ LIBRARIES})

The problem appears hear in SLEPc and PETSc, where I receive the following error message:

CMake Warning at CMakeLists.txt:17 (find_package): By not providing "FindPETSc.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "PETSc", but CMake did not find one. Could not find a package configuration file provided by "PETSc" with any of the following names:

PETScConfig.cmake
petsc-config.cmake

Add the installation prefix of "PETSc" to CMAKE_PREFIX_PATH or set "PETSc_DIR" to a directory containing one of the above files. If "PETSc" provides a separate development package or SDK, be sure it has been installed.

I erase the lines which refer to petsc and slepc from CMakeList.txt, but then I face problems during the building of my code. Is another way to include these libraries?

Thank you for your time!
Community: FEniCS Project

1 Answer


4
9 months ago by
This is actually a bit of a missing feature in CMake, i.e. an easy way to do transitive dependencies of modern CMake packages. DOLFIN, like the rest of us, tries to do what it can, in this case it does put the FindPETSc.cmake file in its config directory, but CMake doesn't think to look for it there. You can just add DOLFIN_CONFIG to CMAKE_MODULE_PATH like so:

find_package(DOLFIN REQUIRED)
# DOLFIN does conveniently provide us with its
# FindPETSc and FindSLEPC modules alongside
# its CMake configuration file
get_filename_component(DOLFIN_MODULES_DIR "${DOLFIN_CONFIG}" DIRECTORY)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${DOLFIN_MODULES_DIR}")
Please login to add an answer/comment or follow this question.

Similar posts:
Search »