# * Build details for DOLFINx: Dynamic Object-oriented Library for
# * FINite element computation
#
# This file has been automatically generated.

# FIXME: Check that naming conforms to CMake standards

@PACKAGE_INIT@
include(CMakeFindDependencyMacro)

find_dependency(MPI REQUIRED)
find_dependency(spdlog REQUIRED)
find_dependency(pugixml REQUIRED)

if(POLICY CMP0167)
  cmake_policy(SET CMP0167 NEW)  # Boost CONFIG mode
endif()
if(POLICY CMP0144)
  cmake_policy(SET CMP0144 NEW)  # https://cmake.org/cmake/help/latest/policy/CMP0144.html
endif()

# Check for Boost
if(DEFINED ENV{BOOST_ROOT} OR DEFINED BOOST_ROOT)
  set(Boost_NO_SYSTEM_PATHS on)
endif()
set(Boost_USE_MULTITHREADED $ENV{BOOST_USE_MULTITHREADED})
set(Boost_VERBOSE TRUE)
find_package(Boost 1.70 REQUIRED)

if(@ufcx_FOUND@)
  find_dependency(ufcx)
endif()

# Basix
if(@DOLFINX_BASIX_PYTHON@)
  find_package(
    Python3
    COMPONENTS Interpreter
    QUIET
  )

  if(Python3_Interpreter_FOUND)
    message(STATUS "Checking for Basix hints with ${Python3_EXECUTABLE}")
    execute_process(
      COMMAND
        ${Python3_EXECUTABLE} -c
        "import basix, os, sys; sys.stdout.write(os.path.dirname(basix.__file__))"
      OUTPUT_VARIABLE BASIX_PY_DIR
      RESULT_VARIABLE BASIX_PY_COMMAND_RESULT
      ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
    )
  endif()

  if(BASIX_PY_DIR)
    # TODO: CMake 3.20 has more modern cmake_path.
    file(TO_CMAKE_PATH "${BASIX_PY_DIR}" BASIX_PY_DIR)
    message(STATUS "Adding ${BASIX_PY_DIR} to Basix search hints")
  else()
    message(STATUS "No Basix hint was found.")
  endif()
endif()

find_dependency(Basix REQUIRED CONFIG HINTS ${BASIX_PY_DIR})

# HDF5
if(NOT TARGET hdf5::hdf5)
  set(HDF5_PREFER_PARALLEL TRUE)
  set(HDF5_FIND_DEBUG TRUE)
  find_dependency(HDF5 COMPONENTS C)
  if(HDF5_FOUND AND NOT HDF5_IS_PARALLEL)
    message(FATAL_ERROR "Found serial HDF5 build, MPI HDF5 build required")
  endif()
endif()

if(@PETSC_FOUND@)
  if(NOT TARGET PkgConfig::PETSC)
    find_package(PkgConfig REQUIRED)
    set(ENV{PKG_CONFIG_PATH}
        "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/pkgconfig:$ENV{PETSC_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}"
    )
    pkg_search_module(PETSC REQUIRED IMPORTED_TARGET PETSc petsc)
    include(CheckSymbolExists)
    set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${PETSC_INCLUDE_DIRS})
    check_symbol_exists(PETSC_USE_COMPLEX petscconf.h PETSC_SCALAR_COMPLEX)
  endif()
endif()

if(@SLEPC_FOUND@)
  if(NOT TARGET PkgConfig::SLEPC)
    find_package(PkgConfig REQUIRED)
    set(ENV{PKG_CONFIG_PATH}
        "$ENV{SLEPC_DIR}/$ENV{PETSC_ARCH}/lib/pkgconfig:$ENV{SLEPC_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}"
    )
    set(ENV{PKG_CONFIG_PATH}
        "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/pkgconfig:$ENV{PETSC_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}"
    )
    set(ENV{PKG_CONFIG_PATH}
        "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}:$ENV{PETSC_DIR}:$ENV{PKG_CONFIG_PATH}"
    )
    pkg_search_module(SLEPC REQUIRED IMPORTED_TARGET SLEPc slepc)
  endif()
endif()

if(@ADIOS2_FOUND@)
  find_dependency(ADIOS2 2.8.1 COMPONENTS CXX PATH_SUFFIXES mpi)
endif()

if(NOT TARGET dolfinx)
  include("${CMAKE_CURRENT_LIST_DIR}/DOLFINXTargets.cmake")
endif()

check_required_components(DOLFINX)
