# - @opm-project_DESCRIPTION@ config mode
#
# Defines the following variables:
#  @opm-project_NAME@_FOUND        - true
#  @opm-project_NAME@_VERSION      - version of the @opm-project_NAME@ library found, e.g. 0.2
#  @opm-project_NAME@_DEFINITIONS  - defines to be made on the command line
#  @opm-project_NAME@_INCLUDE_DIRS - header directories with which to compile
#  @opm-project_NAME@_LINKER_FLAGS - flags that must be passed to the linker
#  @opm-project_NAME@_LIBRARIES    - names of the libraries with which to link
#  @opm-project_NAME@_LIBRARY_DIRS - directories in which the libraries are situated
#
# You should put lines like this in your CMakeLists.txt
#  set (@opm-project_NAME@_DIR "${PROJECT_BINARY_DIR}/../@opm-project_NAME@" CACHE LOCATION "Build tree of @opm-project_NAME@")
#  find_package (@opm-project_NAME@)
#  configure_vars (
#    FILE  CXX  "${PROJECT_BINARY_DIR}/config.h"
#    WRITE ${@opm-project_NAME@_CONFIG_VARS}
#    )

# <http://www.vtk.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file>

# Prevent multiple inclusions
if(NOT @opm-project_NAME@_FOUND)
  # propagate these properties from one build system to the other
  set (@opm-project_NAME@_PREFIX "@DUNE_PREFIX@")
  set (@opm-project_NAME@_VERSION "@opm-project_VERSION@")
  set (@opm-project_NAME@_DEFINITIONS "@opm-project_DEFINITIONS@")
  set (@opm-project_NAME@_INCLUDE_DIRS "@opm-project_INCLUDE_DIRS@")
  set (@opm-project_NAME@_LIBRARY_DIRS "@opm-project_LIBRARY_DIRS@" "@CMAKE_LIBRARY_OUTPUT_DIRECTORY@")
  set (@opm-project_NAME@_LINKER_FLAGS "@opm-project_LINKER_FLAGS@")
  set (@opm-project_NAME@_CONFIG_VARS "@opm-project_CONFIG_VARS@")

  # The flag whether embedded Python is supported or not is passed to downstream modules,
  # it is only used to enable/disable regression testing with Python enabled input. The
  # actual code is self contained - and can be used downstream without awareness of this.
  set (@opm-project_NAME@_EMBEDDED_PYTHON @OPM_ENABLE_EMBEDDED_PYTHON@)

  # libraries come from the build tree where this file was generated
  set (@opm-project_NAME@_LIBRARY "@opm-project_LIBRARY@")
  set (@opm-project_NAME@_LIBRARIES ${@opm-project_NAME@_LIBRARY} "@opm-project_LIBRARIES@")

  # The purpose of this string replacement operation is to enable use of the
  # generated opm-project-config.cmake file also in the situation where 'make
  # install' has been invoked with the DESTDIR option:
  #
  # opm-common/build> cmake .. -DCMAKE_INSTALL_PREFIX=/real/prefix
  # opm-common/budil> make install DESTDIR=/tmp/prefix
  #
  # downstream/build> cmake .. -DDEST_PREFIX=/tmp/prefix -DCMAKE_PREFIX_PATH=/tmp/prefix
  # downstream/build> make install
  #
  # That way the downstream dependency can still use find_package( opm-common )
  # even though the opm-common-config.cmake file is not internally consistent
  # with it's own location in the filesystem.

  if(DEST_PREFIX)
    set(DEST_PREFIX "${DEST_PREFIX}${@opm-project_NAME@_PREFIX}")
    string(REPLACE ${@opm-project_NAME@_PREFIX} ${DEST_PREFIX} @opm-project_NAME@_INCLUDE_DIRS "${@opm-project_NAME@_INCLUDE_DIRS}")
    string(REPLACE ${@opm-project_NAME@_PREFIX} ${DEST_PREFIX} @opm-project_NAME@_LIBRARY_DIRS "${@opm-project_NAME@_LIBRARY_DIRS}")
    string(REPLACE ${@opm-project_NAME@_PREFIX} ${DEST_PREFIX} @opm-project_NAME@_LIBRARY      "${@opm-project_NAME@_LIBRARY}")
  endif()


  set (HAVE_@opm-project_NAME_UC@ 1)
  mark_as_advanced (@opm-project_NAME@_LIBRARY)

  # not all projects have targets; conditionally add this part
  if (NOT "@opm-project_TARGET@" STREQUAL "")
    # add the library as a target, so that other things in the project including
    # this file may depend on it and get rebuild if this library changes.
    if(NOT TARGET @opm-project_TARGET@)
      get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
      include("${_dir}/@opm-project_NAME@-targets.cmake")
    endif()
  endif (NOT "@opm-project_TARGET@" STREQUAL "")

  # same as above, but for C99
  string (REPLACE "@C_STD99_FLAGS@" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  string (STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS)
  set (CMAKE_C_FLAG "@C_STD99_FLAGS@ ${CMAKE_C_FLAGS}")

  # build with OpenMP if that was found
  if (NOT "@OpenMP_C_FLAGS@" STREQUAL "")
    string (REPLACE "@OpenMP_C_FLAGS@" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
    string (STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS)
    set (CMAKE_C_FLAG "@OpenMP_C_FLAGS@ ${CMAKE_C_FLAGS}")
  endif (NOT "@OpenMP_C_FLAGS@" STREQUAL "")
  if (NOT "@OpenMP_CXX_FLAGS@" STREQUAL "")
    string (REPLACE "@OpenMP_CXX_FLAGS@" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    string (STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS)
    set (CMAKE_C_FLAG "@OpenMP_CXX_FLAGS@ ${CMAKE_CXX_FLAGS}")
  endif (NOT "@OpenMP_CXX_FLAGS@" STREQUAL "")

  # this is the contents of config.h as far as our probes can tell:


  # The settings in this block do not mix well with the DEST_PREFIX
  # setting.
  if (NOT DEST_PREFIX)
    # This is required to include OpmPackage
    set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" @PREREQ_LOCATION@)

    # extra code from variable OPM_PROJECT_EXTRA_CODE
    @OPM_PROJECT_EXTRA_CODE@
    # end extra code

    include(@opm-project_NAME@-prereqs)
  endif()
endif()
