# - CMAKE Config file for the TiledArray package
# The following variables are defined:
#  TILEDARRAY_FOUND                - System has the TiledArray package
#  TILEDARRAY_INCLUDE_DIRS         - The TiledArray include directory
#  TILEDARRAY_LIBRARIES            - The TiledArray libraries and their dependencies
#  TILEDARRAY_VERSION              - The TiledArray (core) version; see semver.org
#  TILEDARRAY_EXT_VERSION          - The TiledArray version, includes prerelease id; see semver.org

# Set package version
set(TILEDARRAY_VERSION "@TILEDARRAY_VERSION@")
set(TILEDARRAY_EXT_VERSION "@TILEDARRAY_EXT_VERSION@")

@PACKAGE_INIT@

# Include library IMPORT targets
if (NOT TARGET BTAS::BTAS)
  get_filename_component(BTAS_DIR "@BTAS_CONFIG@" DIRECTORY)
  find_package(BTAS 1.0.0 QUIET CONFIG REQUIRED HINTS "${BTAS_DIR}")
endif()
if(NOT TARGET MADworld)
  # if madness installed separately, use the madness install discovered when configuring TA
  set(MADNESS_CONFIG_DIR "@MADNESS_CONFIG_DIR@")
  # otherwise assume TA built madness
  if (MADNESS_CONFIG_DIR STREQUAL "")
    set(MADNESS_CONFIG_DIR "${CMAKE_CURRENT_LIST_DIR}/../madness")
  endif()
  include( CMakeFindDependencyMacro )
  find_dependency(MADNESS 0.10.1 CONFIG REQUIRED COMPONENTS world PATHS "${MADNESS_CONFIG_DIR}" NO_DEFAULT_PATH)
endif()
if(NOT TARGET tiledarray)
  include("${CMAKE_CURRENT_LIST_DIR}/tiledarray-targets.cmake")
endif()

# if TA is a CUDA-dependent library it needs CUDA to link properly ... unfortunately CMake is not able to do this correctly
# see https://gitlab.kitware.com/cmake/cmake/issues/18614
# so try workarounds
set(TILEDARRAY_HAS_CUDA "@CUDA_FOUND@")
if(TILEDARRAY_HAS_CUDA)
  cmake_minimum_required(VERSION 3.17)
  if (NOT TARGET CUDA::cublas)
    find_package(CUDAToolkit REQUIRED COMPONENTS cublas nvToolsExt)
  endif(NOT TARGET CUDA::cublas)
  set(CMAKE_CUDA_HOST_COMPILER "@CMAKE_CUDA_HOST_COMPILER@")
  # workaround from https://gitlab.kitware.com/cmake/cmake/issues/18614#note_485631
  set(CUDA_LIBRARIES "@CUDA_LIBRARIES@")
  get_target_property(_ta_interface_libs tiledarray INTERFACE_LINK_LIBRARIES)
  if(_ta_interface_libs)
    list(APPEND _ta_interface_libs ${CUDA_LIBRARIES})
  else()
    set(_ta_interface_libs ${CUDA_LIBRARIES})
  endif()
    string(TOUPPER ${CMAKE_BUILD_TYPE} TA_BUILD_TYPE)
  set_target_properties(tiledarray PROPERTIES
    IMPORTED_LINK_INTERFACE_LANGUAGES_${TA_BUILD_TYPE} CXX
    INTERFACE_LINK_LIBRARIES "${_ta_interface_libs}")
endif()

set(TILEDARRAY_HAS_SCALAPACK "@ENABLE_SCALAPACK@" )
if(TILEDARRAY_HAS_SCALAPACK)
  include( CMakeFindDependencyMacro )
  get_filename_component(blacspp_DIR "@blacspp_CONFIG@" DIRECTORY)
  find_dependency( blacspp CONFIG REQUIRED HINTS "${blacspp_DIR}" )
  get_filename_component(scalapackpp_DIR "@scalapackpp_CONFIG@" DIRECTORY)
  find_dependency( scalapackpp CONFIG REQUIRED HINTS "${scalapackpp_DIR}" )
endif()

# Set the tiledarray compiled library target
set(TILEDARRAY_LIBRARIES tiledarray)

set(TILEDARRAY_SOURCE_DIR "@TILEDARRAY_SOURCE_DIR@")
set(TILEDARRAY_BINARY_DIR "@TILEDARRAY_BINARY_DIR@")

set(TILEDARRAY_BUILD_INCLUDE_DIRS "${TILEDARRAY_SOURCE_DIR}/src" "${TILEDARRAY_BINARY_DIR}/src")
set(TILEDARRAY_INSTALL_INCLUDE_DIRS "@PACKAGE_TILEDARRAY_INSTALL_INCLUDEDIR@"
      "@PACKAGE_TILEDARRAY_INSTALL_INCLUDEDIR@/TiledArray/external")

# define TILEDARRAY_INCLUDE_DIRS according to where we are compiling: TA build tree or outside
# external packages should use TILEDARRAY_BUILD_INCLUDE_DIRS and TILEDARRAY_INSTALL_INCLUDE_DIRS directly
if(CMAKE_CURRENT_LIST_DIR EQUAL TILEDARRAY_BINARY_DIR)
  set(TILEDARRAY_INCLUDE_DIRS "${TILEDARRAY_BUILD_INCLUDE_DIRS}")
else()
  set(TILEDARRAY_INCLUDE_DIRS "${TILEDARRAY_INSTALL_INCLUDE_DIRS}")
endif()

set(TILEDARRAY_CMAKE_TOOLCHAIN_FILE "@CMAKE_TOOLCHAIN_FILE@")

# whether TA assumes ASLR to be disabled
set(TA_ASSUMES_ASLR_DISABLED "@TA_ASSUMES_ASLR_DISABLED@")

set(TILEDARRAY_FOUND TRUE)
