##=========================================================================
## 
##   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 KWCommonProConfig.cmake file in the build tree. Also configure
# one for installation. The file tells external projects how to use
# KWCommonPro.

# 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(
  ${KWCommonPro_BINARY_DIR}/KWCommonProLibraryDepends.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CMakeExportBuildSettings.cmake)
CMAKE_EXPORT_BUILD_SETTINGS(
  ${KWCommonPro_BINARY_DIR}/KWCommonProBuildSettings.cmake)

IF(NOT KWCommonPro_INSTALL_NO_DEVELOPMENT)
  INSTALL_FILES(${KWCommonPro_INSTALL_PACKAGE_DIR} FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/UseKWCommonPro.cmake
    ${KWCommonPro_BINARY_DIR}/KWCommonProLibraryDepends.cmake
    ${KWCommonPro_BINARY_DIR}/KWCommonProBuildSettings.cmake
    )
ENDIF(NOT KWCommonPro_INSTALL_NO_DEVELOPMENT)

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

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

# The "use" file.
SET(KWCommonPro_USE_FILE_CONFIG 
  ${CMAKE_CURRENT_SOURCE_DIR}/UseKWCommonPro.cmake)

# The build settings file.
SET(KWCommonPro_BUILD_SETTINGS_FILE_CONFIG 
  ${KWCommonPro_BINARY_DIR}/KWCommonProBuildSettings.cmake)

# The library directories.
SET(KWCommonPro_LIBRARY_DIRS_CONFIG ${KWCommonPro_LIBRARY_DIRS})

# The runtime directories.
SET(KWCommonPro_RUNTIME_DIRS_CONFIG ${KWCommonPro_RUNTIME_DIRS})

# The include directories.
SET(KWCommonPro_INCLUDE_DIRS_CONFIG ${KWCommonPro_INCLUDE_PATH})

# The library dependencies file.
SET(KWCommonPro_LIBRARY_DEPENDS_FILE 
  ${KWCommonPro_BINARY_DIR}/KWCommonProLibraryDepends.cmake)

# The CMake macros dir.
SET(KWCommonPro_CMAKE_DIR_CONFIG 
  ${KWCommonPro_CMAKE_DIR})

# The KWCommon options.
SET(KWCommonPro_KWCommon_DIR_CONFIG ${KWCommon_DIR})

# The CTNLIB options.
SET(KWCommonPro_CTNLIB_DIR_CONFIG ${CTNLIB_DIR})

# The GDCM options.
SET(KWCommonPro_GDCM_DIR_CONFIG ${GDCM_DIR})

# The build configuration information.
SET(KWCommonPro_CONFIGURATION_TYPES_CONFIG ${KWCommonPro_CONFIGURATION_TYPES})
SET(KWCommonPro_BUILD_TYPE_CONFIG ${CMAKE_BUILD_TYPE})

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

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

# The "use" file.
SET(KWCommonPro_USE_FILE_CONFIG 
  ${DOLLAR}{KWCommonPro_INSTALL_PREFIX}${KWCommonPro_INSTALL_PACKAGE_DIR}/UseKWCommonPro.cmake)

# The build settings file.
SET(KWCommonPro_BUILD_SETTINGS_FILE_CONFIG 
  ${DOLLAR}{KWCommonPro_INSTALL_PREFIX}${KWCommonPro_INSTALL_PACKAGE_DIR}/KWCommonProBuildSettings.cmake)

# The library directories.
IF(CYGWIN AND KWCommonPro_BUILD_SHARED_LIBS)
  # In Cygwin programs directly link to the .dll files.
  SET(KWCommonPro_LIBRARY_DIRS_CONFIG 
    ${DOLLAR}{KWCommonPro_INSTALL_PREFIX}${KWCommonPro_INSTALL_BIN_DIR})
ELSE(CYGWIN AND KWCommonPro_BUILD_SHARED_LIBS)
  SET(KWCommonPro_LIBRARY_DIRS_CONFIG 
    ${DOLLAR}{KWCommonPro_INSTALL_PREFIX}${KWCommonPro_INSTALL_LIB_DIR})
ENDIF(CYGWIN AND KWCommonPro_BUILD_SHARED_LIBS)

# The runtime directories.
IF(WIN32)
  SET(KWCommonPro_RUNTIME_DIRS_CONFIG 
    ${DOLLAR}{KWCommonPro_INSTALL_PREFIX}${KWCommonPro_INSTALL_BIN_DIR})
ELSE(WIN32)
  SET(KWCommonPro_RUNTIME_DIRS_CONFIG 
    ${DOLLAR}{KWCommonPro_INSTALL_PREFIX}${KWCommonPro_INSTALL_LIB_DIR})
ENDIF(WIN32)

# The include directories.
SET(KWCommonPro_INCLUDE_DIRS_CONFIG
  ${DOLLAR}{KWCommonPro_INSTALL_PREFIX}${KWCommonPro_INSTALL_INCLUDE_DIR})
IF(KWCommonPro_USE_XML_RW)
  SET(KWCommonPro_INCLUDE_DIRS_CONFIG ${KWCommonPro_INCLUDE_DIRS_CONFIG}
    ${DOLLAR}{KWCommonPro_INSTALL_PREFIX}${KWCommonPro_INSTALL_INCLUDE_DIR}/XML)
ENDIF(KWCommonPro_USE_XML_RW)

# The library dependencies file.
SET(KWCommonPro_LIBRARY_DEPENDS_FILE 
  ${DOLLAR}{KWCommonPro_INSTALL_PREFIX}${KWCommonPro_INSTALL_PACKAGE_DIR}/KWCommonProLibraryDepends.cmake)

# The CMake macros dir.
SET(KWCommonPro_CMAKE_DIR_CONFIG 
  ${DOLLAR}{KWCommonPro_INSTALL_PREFIX}${KWCommonPro_INSTALL_PACKAGE_DIR}/CMake)

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

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

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

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

# Configure KWCommonProConfig.cmake for the install tree.

# Construct the proper number of GET_FILENAME_COMPONENT(... PATH)
# calls to compute the installation prefix from KWCommonPro_DIR.
STRING(REGEX REPLACE "/" ";" KWCommonPro_INSTALL_PACKAGE_DIR_COUNT
  "${KWCommonPro_INSTALL_PACKAGE_DIR}")
SET(KWCommonPro_CONFIG_INSTALL_ONLY "
# Compute the installation prefix from KWCommonPro_DIR.
SET(KWCommonPro_INSTALL_PREFIX \"${DOLLAR}{KWCommonPro_DIR}\")
")
FOREACH(p ${KWCommonPro_INSTALL_PACKAGE_DIR_COUNT})
  SET(KWCommonPro_CONFIG_INSTALL_ONLY
    "${KWCommonPro_CONFIG_INSTALL_ONLY}GET_FILENAME_COMPONENT(KWCommonPro_INSTALL_PREFIX \"${DOLLAR}{KWCommonPro_INSTALL_PREFIX}\" PATH)\n"
    )
ENDFOREACH(p)

IF(CMAKE_CONFIGURATION_TYPES)
  # There are multiple build configurations.  Configure one
  # KWCommonProConfig.cmake for each configuration.
  FOREACH(config ${CMAKE_CONFIGURATION_TYPES})
    SET(KWCommonPro_BUILD_TYPE_CONFIG ${config})
    CONFIGURE_FILE(
      ${CMAKE_CURRENT_SOURCE_DIR}/KWCommonProConfig.cmake.in
      ${CMAKE_CURRENT_BINARY_DIR}/${config}/KWCommonProConfig.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 KWCommonPro_INSTALL_NO_DEVELOPMENT)
    INSTALL_FILES(${KWCommonPro_INSTALL_PACKAGE_DIR} FILES
      ${CMAKE_CURRENT_BINARY_DIR}/${DOLLAR}{BUILD_TYPE}/KWCommonProConfig.cmake)
  ENDIF(NOT KWCommonPro_INSTALL_NO_DEVELOPMENT)
ELSE(CMAKE_CONFIGURATION_TYPES)
  # There is only one build configuration. Configure one KWCommonProConfig.cmake.
  SET(KWCommonPro_BUILD_TYPE_CONFIG ${CMAKE_BUILD_TYPE})
  CONFIGURE_FILE(
    ${CMAKE_CURRENT_SOURCE_DIR}/KWCommonProConfig.cmake.in
    ${CMAKE_CURRENT_BINARY_DIR}/KWCommonProConfig.cmake @ONLY IMMEDIATE)

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