##=========================================================================
## 
##   Copyright (c) Kitware, Inc.
##   All rights reserved.
##   See Copyright.txt or http://www.kitware.com/VolViewCopyright.htm for details.
## 
##      This software is distributed WITHOUT ANY WARRANTY; without even
##      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
##      PURPOSE.  See the above copyright notice for more information.
## 
##=========================================================================
# Generate the KWWidgetsProConfig.cmake file in the build tree. Also configure
# one for installation. The file tells external projects how to use
# KWWidgetsPro.

# Help store a literal dollar in a string.  CMake 2.2 allows escaped
# dollars but we have to support CMake 2.0.
SET(DOLLAR "$")

#-----------------------------------------------------------------------------
# Settings shared between the build tree and install tree.

EXPORT_LIBRARY_DEPENDENCIES(
  ${KWWidgetsPro_BINARY_DIR}/KWWidgetsProLibraryDepends.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CMakeExportBuildSettings.cmake)
CMAKE_EXPORT_BUILD_SETTINGS(
  ${KWWidgetsPro_BINARY_DIR}/KWWidgetsProBuildSettings.cmake)

IF(NOT KWWidgetsPro_INSTALL_NO_DEVELOPMENT)
  INSTALL_FILES(${KWWidgetsPro_INSTALL_PACKAGE_DIR} FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/UseKWWidgetsPro.cmake
    ${KWWidgetsPro_BINARY_DIR}/KWWidgetsProLibraryDepends.cmake
    ${KWWidgetsPro_BINARY_DIR}/KWWidgetsProBuildSettings.cmake
    )
ENDIF(NOT KWWidgetsPro_INSTALL_NO_DEVELOPMENT)

#-----------------------------------------------------------------------------
# Settings specific to the build tree.

# The install-only section is empty for the build tree.
SET(KWWidgetsPro_CONFIG_INSTALL_ONLY)

# The "use" file.
SET(KWWidgetsPro_USE_FILE_CONFIG 
  ${CMAKE_CURRENT_SOURCE_DIR}/UseKWWidgetsPro.cmake)

# The build settings file.
SET(KWWidgetsPro_BUILD_SETTINGS_FILE_CONFIG 
  ${KWWidgetsPro_BINARY_DIR}/KWWidgetsProBuildSettings.cmake)

# The library directories.
SET(KWWidgetsPro_LIBRARY_DIRS_CONFIG ${KWWidgetsPro_LIBRARY_DIRS})

# The runtime directories.
SET(KWWidgetsPro_RUNTIME_DIRS_CONFIG ${KWWidgetsPro_RUNTIME_DIRS})

# The include directories.
SET(KWWidgetsPro_INCLUDE_DIRS_CONFIG ${KWWidgetsPro_INCLUDE_PATH})

# The library dependencies file.
SET(KWWidgetsPro_LIBRARY_DEPENDS_FILE 
  ${KWWidgetsPro_BINARY_DIR}/KWWidgetsProLibraryDepends.cmake)

# The CMake macros dir.
SET(KWWidgetsPro_CMAKE_DIR_CONFIG 
  ${KWWidgetsPro_CMAKE_DIR})

# The KWCommonPro options.
SET(KWWidgetsPro_KWCommonPro_DIR_CONFIG ${KWCommonPro_DIR})

# The KWWidgets options.
SET(KWWidgetsPro_KWWidgets_DIR_CONFIG ${KWWidgets_DIR})

# The build configuration information.
SET(KWWidgetsPro_CONFIGURATION_TYPES_CONFIG ${KWWidgetsPro_CONFIGURATION_TYPES})
SET(KWWidgetsPro_BUILD_TYPE_CONFIG ${CMAKE_BUILD_TYPE})

# Configure KWWidgetsProConfig.cmake for the build tree.
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/KWWidgetsProConfig.cmake.in
  ${KWWidgetsPro_BINARY_DIR}/KWWidgetsProConfig.cmake @ONLY IMMEDIATE)

#-----------------------------------------------------------------------------
# Settings specific to the install tree.

# The "use" file.
SET(KWWidgetsPro_USE_FILE_CONFIG 
  ${DOLLAR}{KWWidgetsPro_INSTALL_PREFIX}${KWWidgetsPro_INSTALL_PACKAGE_DIR}/UseKWWidgetsPro.cmake)

# The build settings file.
SET(KWWidgetsPro_BUILD_SETTINGS_FILE_CONFIG 
  ${DOLLAR}{KWWidgetsPro_INSTALL_PREFIX}${KWWidgetsPro_INSTALL_PACKAGE_DIR}/KWWidgetsProBuildSettings.cmake)

# The library directories.
IF(CYGWIN AND KWWidgetsPro_BUILD_SHARED_LIBS)
  # In Cygwin programs directly link to the .dll files.
  SET(KWWidgetsPro_LIBRARY_DIRS_CONFIG 
    ${DOLLAR}{KWWidgetsPro_INSTALL_PREFIX}${KWWidgetsPro_INSTALL_BIN_DIR})
ELSE(CYGWIN AND KWWidgetsPro_BUILD_SHARED_LIBS)
  SET(KWWidgetsPro_LIBRARY_DIRS_CONFIG 
    ${DOLLAR}{KWWidgetsPro_INSTALL_PREFIX}${KWWidgetsPro_INSTALL_LIB_DIR})
ENDIF(CYGWIN AND KWWidgetsPro_BUILD_SHARED_LIBS)

# The runtime directories.
IF(WIN32)
  SET(KWWidgetsPro_RUNTIME_DIRS_CONFIG 
    ${DOLLAR}{KWWidgetsPro_INSTALL_PREFIX}${KWWidgetsPro_INSTALL_BIN_DIR})
ELSE(WIN32)
  SET(KWWidgetsPro_RUNTIME_DIRS_CONFIG 
    ${DOLLAR}{KWWidgetsPro_INSTALL_PREFIX}${KWWidgetsPro_INSTALL_LIB_DIR})
ENDIF(WIN32)

# The include directories.
SET(KWWidgetsPro_INCLUDE_DIRS_CONFIG
  ${DOLLAR}{KWWidgetsPro_INSTALL_PREFIX}${KWWidgetsPro_INSTALL_INCLUDE_DIR})

# The library dependencies file.
SET(KWWidgetsPro_LIBRARY_DEPENDS_FILE 
  ${DOLLAR}{KWWidgetsPro_INSTALL_PREFIX}${KWWidgetsPro_INSTALL_PACKAGE_DIR}/KWWidgetsProLibraryDepends.cmake)

# The CMake macros dir.
SET(KWWidgetsPro_CMAKE_DIR_CONFIG 
  ${DOLLAR}{KWWidgetsPro_INSTALL_PREFIX}${KWWidgetsPro_INSTALL_PACKAGE_DIR}/CMake)

# The KWCommonPro options.
# If KWCommonPro_BINARY_DIR is set, then KWWidgetsPro is part of a larger 
# parent project that also builds KWCommonPro. In that case, 
# KWWidgetsPro_KWCommonPro_INSTALL_PACKAGE_DIR should be set to the value of
# KWCommonPro_INSTALL_PACKAGE_DIR. Otherwise, if not set, then we are using an
# outside KWCommonPro whose location will not change when we install.
IF(KWCommonPro_BINARY_DIR)
  IF(NOT KWWidgetsPro_KWCommonPro_INSTALL_PACKAGE_DIR)
    MESSAGE(
      "KWWidgetsPro_KWCommonPro_INSTALL_PACKAGE_DIR must be set by the parent project to the value of KWCommonPro_INSTALL_PACKAGE_DIR it uses to configure KWCommonPro.")
  ENDIF(NOT KWWidgetsPro_KWCommonPro_INSTALL_PACKAGE_DIR)
  SET(KWWidgetsPro_KWCommonPro_DIR_CONFIG ${KWWidgetsPro_KWCommonPro_INSTALL_PACKAGE_DIR})
ELSE(KWCommonPro_BINARY_DIR)
  SET(KWWidgetsPro_KWCommonPro_DIR_CONFIG ${KWCommonPro_DIR})
ENDIF(KWCommonPro_BINARY_DIR)

# The KWWidgets options.
# If KWWidgets_BINARY_DIR is set, then KWWidgetsPro is part of a larger parent
# project that also builds KWWidgets. In that case, 
# KWWidgetsPro_KWWidgets_INSTALL_PACKAGE_DIR should be set to the value of
# KWWidgets_INSTALL_PACKAGE_DIR. Otherwise, if not set, then we are using an
# outside KWWidgets whose location will not change when we install.
IF(KWWidgets_BINARY_DIR)
  IF(NOT KWWidgetsPro_KWWidgets_INSTALL_PACKAGE_DIR)
    MESSAGE(
      "KWWidgetsPro_KWWidgets_INSTALL_PACKAGE_DIR must be set by the parent project to the value of KWWidgets_INSTALL_PACKAGE_DIR it uses to configure KWWidgets.")
  ENDIF(NOT KWWidgetsPro_KWWidgets_INSTALL_PACKAGE_DIR)
  SET(KWWidgetsPro_KWWidgets_DIR_CONFIG ${KWWidgetsPro_KWWidgets_INSTALL_PACKAGE_DIR})
ELSE(KWWidgets_BINARY_DIR)
  SET(KWWidgetsPro_KWWidgets_DIR_CONFIG ${KWWidgets_DIR})
ENDIF(KWWidgets_BINARY_DIR)


# The build configuration information.
# The install tree only has one configuration.
SET(KWWidgetsPro_CONFIGURATION_TYPES_CONFIG)

# Configure KWWidgetsProConfig.cmake for the install tree.

# Construct the proper number of GET_FILENAME_COMPONENT(... PATH)
# calls to compute the installation prefix from KWWidgetsPro_DIR.
STRING(REGEX REPLACE "/" ";" KWWidgetsPro_INSTALL_PACKAGE_DIR_COUNT
  "${KWWidgetsPro_INSTALL_PACKAGE_DIR}")
SET(KWWidgetsPro_CONFIG_INSTALL_ONLY "
# Compute the installation prefix from KWWidgetsPro_DIR.
SET(KWWidgetsPro_INSTALL_PREFIX \"${DOLLAR}{KWWidgetsPro_DIR}\")
")
FOREACH(p ${KWWidgetsPro_INSTALL_PACKAGE_DIR_COUNT})
  SET(KWWidgetsPro_CONFIG_INSTALL_ONLY
    "${KWWidgetsPro_CONFIG_INSTALL_ONLY}GET_FILENAME_COMPONENT(KWWidgetsPro_INSTALL_PREFIX \"${DOLLAR}{KWWidgetsPro_INSTALL_PREFIX}\" PATH)\n"
    )
ENDFOREACH(p)

IF(CMAKE_CONFIGURATION_TYPES)
  # There are multiple build configurations.  Configure one
  # KWWidgetsProConfig.cmake for each configuration.
  FOREACH(config ${CMAKE_CONFIGURATION_TYPES})
    SET(KWWidgetsPro_BUILD_TYPE_CONFIG ${config})
    CONFIGURE_FILE(
      ${CMAKE_CURRENT_SOURCE_DIR}/KWWidgetsProConfig.cmake.in
      ${CMAKE_CURRENT_BINARY_DIR}/${config}/KWWidgetsProConfig.cmake
      @ONLY IMMEDIATE)
  ENDFOREACH(config)

  # Install the config file corresponding to the build configuration
  # specified when building the install target.  The BUILD_TYPE variable
  # will be set while CMake is processing the install files.
  IF(NOT KWWidgetsPro_INSTALL_NO_DEVELOPMENT)
    INSTALL_FILES(${KWWidgetsPro_INSTALL_PACKAGE_DIR} FILES
      ${CMAKE_CURRENT_BINARY_DIR}/${DOLLAR}{BUILD_TYPE}/KWWidgetsProConfig.cmake)
  ENDIF(NOT KWWidgetsPro_INSTALL_NO_DEVELOPMENT)
ELSE(CMAKE_CONFIGURATION_TYPES)
  # There is only one build configuration. Configure one KWWidgetsProConfig.cmake.
  SET(KWWidgetsPro_BUILD_TYPE_CONFIG ${CMAKE_BUILD_TYPE})
  CONFIGURE_FILE(
    ${CMAKE_CURRENT_SOURCE_DIR}/KWWidgetsProConfig.cmake.in
    ${CMAKE_CURRENT_BINARY_DIR}/KWWidgetsProConfig.cmake @ONLY IMMEDIATE)

  # Setup an install rule for the config file.
  IF(NOT KWWidgetsPro_INSTALL_NO_DEVELOPMENT)
    INSTALL_FILES(${KWWidgetsPro_INSTALL_PACKAGE_DIR} FILES
      ${CMAKE_CURRENT_BINARY_DIR}/KWWidgetsProConfig.cmake)
  ENDIF(NOT KWWidgetsPro_INSTALL_NO_DEVELOPMENT)
ENDIF(CMAKE_CONFIGURATION_TYPES)
