Browse Source

Merge branch '403-relocatable-ctkconfig-usectk'

* 403-relocatable-ctkconfig-usectk:
  Add support for install-able and relocatable package.
  Remove explicit setting of CMake policies.
  Explicitly set default value for CTK_INSTALL_QTPLUGIN_DIR
  Remove commented code and unused vars from CTKConfig / CTKGenerateCTKConfig
  Set plugin install rules for target and include files
  Install CTK's *.cmake files
  By default, do not install application headers
  Ensure "CMAKE_INSTALL_PREFIX" is properly passed to inner project.
  Ensure CTK_INSTALL_QTPLUGIN_DIR is properly set
Jean-Christophe Fillion-Robin 11 years ago
parent
commit
e9c73b2c3c

+ 59 - 145
CMake/CTKConfig.cmake.in

@@ -1,37 +1,3 @@
-###########################################################################
-#
-#  Library:   CTK
-#
-#  Copyright (c) Kitware Inc.
-#
-#  Licensed under the Apache License, Version 2.0 (the "License");
-#  you may not use this file except in compliance with the License.
-#  You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0.txt
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-#
-###########################################################################
-###########################################################################
-#
-#  Program:   Visualization Toolkit
-#  Module:    VTKConfig.cmake.in
-#
-#  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
-#
-#  All rights reserved.
-#  See Copyright.txt or http://www.kitware.com/Copyright.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.
-#
-###########################################################################
 
 #
 # CTKConfig.cmake - CTK CMake configuration file for external projects.
@@ -40,120 +6,76 @@
 # to load CTK's settings for an external project.
 
 
-# Import CTK targets
-IF(NOT CTK_EXPORTS_INCLUDED)
-  INCLUDE("@CTK_SUPERBUILD_BINARY_DIR@/CTKExports.cmake")
-  SET(CTK_EXPORTS_INCLUDED 1)
-ENDIF()
-
-# Include CTK macros
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetGccVersion.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionCheckCompilerFlags.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetCompilerVisibilityFlags.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroParseArguments.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroSetPaths.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroListFilter.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroBuildLibWrapper.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroBuildPlugin.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroBuildQtPlugin.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroTargetLibraries.cmake") # Import multiple macros
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionExtractOptionNameAndValue.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroValidateBuildOptions.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGenerateDGraphInput.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGeneratePluginManifest.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGeneratePluginUseFile.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroGeneratePluginResourceFile.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetIncludeDirs.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetLibraryDirs.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionExtractPluginTargets.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetAllPluginTargets.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetTargetDependencies.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkFunctionGetPluginDependencies.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroSetupPlugins.cmake")
-INCLUDE("@CTK_CMAKE_DIR_CONFIG@/ctkMacroGenerateMocs.cmake")
-
-SET(CTK_EXPORT_HEADER_TEMPLATE "@CTK_EXPORT_HEADER_TEMPLATE@")
-
-# Directory containing the ctkConfig.h file
-SET(CTK_CONFIG_H_INCLUDE_DIR @CTK_CONFIG_H_INCLUDE_DIR@)
+@PACKAGE_INIT@
 
-# The CTK DGraph executable used to compute target dependency graphs
-SET(CTK_DGRAPH_EXECUTABLE "@DGraph_EXECUTABLE@")
-
-# List all libraries
-SET(CTK_LIBRARIES @CTK_LIBRARIES@)
+# CMake extension module directory
+set_and_check(CTK_CMAKE_DIR "@PACKAGE_CTK_CMAKE_DIR_CONFIG@")
+set_and_check(CTK_CMAKE_UTILITIES_DIR "@PACKAGE_CTK_CMAKE_UTILITIES_DIR_CONFIG@")
 
-# List all CTK libraries wrapped with PythonQt
-SET(CTK_WRAPPED_LIBRARIES_PYTHONQT @CTK_WRAPPED_LIBRARIES_PYTHONQT@)
+# The location of the UseCTK.cmake file.
+set_and_check(CTK_USE_FILE "@PACKAGE_CTK_CONFIG_DIR_CONFIG@/UseCTK.cmake")
 
 # Include CTK Plugin specific variables
-INCLUDE("@CTK_PLUGIN_USE_FILE@")
+set_and_check(CTK_PLUGIN_USE_FILE "@PACKAGE_CTK_CONFIG_DIR_CONFIG@/CTKPluginUseFile.cmake")
 
-@CTK_CONFIG_INSTALL_ONLY@
+set_and_check(CTK_TARGETS "@PACKAGE_CTK_CONFIG_DIR_CONFIG@/CTKExports.cmake")
 
-# Library specific include directories
-@CTK_LIBRARY_INCLUDE_DIRS_CONFIG@
+# Directory containing the ctkConfig.h file
+set_and_check(CTK_CONFIG_H_INCLUDE_DIR "@PACKAGE_CTK_CONFIG_H_INCLUDE_DIR_CONFIG@")
 
-# Library specific library directories
-@CTK_LIBRARY_LIBRARY_DIRS_CONFIG@
+# Set the header template which defines custom export/import macros
+# for shared libraries
+set_and_check(CTK_EXPORT_HEADER_TEMPLATE "@PACKAGE_CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG@/ctkExport.h.in")
 
-# The CTK include file directories.
-SET(CTK_INCLUDE_DIRS "@CTK_BUILD_DIR@;@CTK_INCLUDE_DIRS_CONFIG@")
+# Set CTK library directory
+set_and_check(CTK_LIBRARY_DIR "@PACKAGE_CTK_LIBRARY_DIR_CONFIG@")
+set(CTK_LIBRARY_DIRS ${CTK_LIBRARY_DIR})
 
-# The CTK library directories. Note that if
-# CTK_CONFIGURATION_TYPES is set (see below) then these directories
-# will be the parent directories under which there will be a directory
-# of runtime binaries for each configuration type.
-SET(CTK_LIBRARY_DIRS "@CTK_LIBRARY_DIRS_CONFIG@")
+@CTK_CONFIG_CODE@
 
-# The CTK external project libraries.
-SET(CTK_EXTERNAL_LIBRARIES "@CTK_EXTERNAL_LIBRARIES_CONFIG@")
+# Import CTK targets
+if(NOT TARGET CTKCore)
+  include(${CTK_TARGETS})
+endif()
 
-# The CTK external project library directories. Note that if
-# CTK_CONFIGURATION_TYPES is set (see below) then these directories
-# will be the parent directories under which there will be a directory
-# of runtime binaries for each configuration type.
-SET(CTK_EXTERNAL_LIBRARY_DIRS "@CTK_EXTERNAL_LIBRARY_DIRS_CONFIG@")
+# Include CTK macros
+include("${CTK_CMAKE_DIR}/ctkFunctionGetGccVersion.cmake")
+include("${CTK_CMAKE_DIR}/ctkFunctionCheckCompilerFlags.cmake")
+include("${CTK_CMAKE_DIR}/ctkFunctionGetCompilerVisibilityFlags.cmake")
+include("${CTK_CMAKE_DIR}/ctkMacroParseArguments.cmake")
+include("${CTK_CMAKE_DIR}/ctkMacroSetPaths.cmake")
+include("${CTK_CMAKE_DIR}/ctkMacroListFilter.cmake")
+include("${CTK_CMAKE_DIR}/ctkMacroBuildLibWrapper.cmake")
+include("${CTK_CMAKE_DIR}/ctkMacroBuildPlugin.cmake")
+include("${CTK_CMAKE_DIR}/ctkMacroBuildQtPlugin.cmake")
+include("${CTK_CMAKE_DIR}/ctkMacroTargetLibraries.cmake") # Import multiple macros
+include("${CTK_CMAKE_DIR}/ctkFunctionExtractOptionNameAndValue.cmake")
+include("${CTK_CMAKE_DIR}/ctkMacroValidateBuildOptions.cmake")
+include("${CTK_CMAKE_DIR}/ctkFunctionGenerateDGraphInput.cmake")
+include("${CTK_CMAKE_DIR}/ctkFunctionGeneratePluginManifest.cmake")
+include("${CTK_CMAKE_DIR}/ctkFunctionGeneratePluginUseFile.cmake")
+include("${CTK_CMAKE_DIR}/ctkMacroGeneratePluginResourceFile.cmake")
+include("${CTK_CMAKE_DIR}/ctkFunctionGetIncludeDirs.cmake")
+include("${CTK_CMAKE_DIR}/ctkFunctionGetLibraryDirs.cmake")
+include("${CTK_CMAKE_DIR}/ctkFunctionExtractPluginTargets.cmake")
+include("${CTK_CMAKE_DIR}/ctkFunctionGetAllPluginTargets.cmake")
+include("${CTK_CMAKE_DIR}/ctkFunctionGetTargetDependencies.cmake")
+include("${CTK_CMAKE_DIR}/ctkFunctionGetPluginDependencies.cmake")
+include("${CTK_CMAKE_DIR}/ctkMacroSetupPlugins.cmake")
+include("${CTK_CMAKE_DIR}/ctkMacroGenerateMocs.cmake")
 
-# The CTK binary executable directories. Note that if
-# CTK_CONFIGURATION_TYPES is set (see below) then these directories
-# will be the parent directories under which there will be a directory
-# of runtime binaries for each configuration type.
-SET(CTK_EXECUTABLE_DIRS "@CTK_EXECUTABLE_DIRS_CONFIG@")
+# List all libraries
+SET(CTK_LIBRARIES @CTK_LIBRARIES@)
 
-# The CTK runtime library directories. Note that if
-# CTK_CONFIGURATION_TYPES is set (see below) then these directories
-# will be the parent directories under which there will be a directory
-# of runtime libraries for each configuration type.
-SET(CTK_RUNTIME_LIBRARY_DIRS "@CTK_RUNTIME_LIBRARY_DIRS_CONFIG@")
+# List all CTK libraries wrapped with PythonQt
+SET(CTK_WRAPPED_LIBRARIES_PYTHONQT @CTK_WRAPPED_LIBRARIES_PYTHONQT@)
 
-# The CTK Qt designer plugin directory. Note that if
-# CTK_CONFIGURATION_TYPES is set (see below) then these directories
-# will be the parent directories under which there will be a directory
-# of runtime libraries for each configuration type.
-SET(CTK_QTDESIGNERPLUGINS_DIR "@CTK_QTDESIGNERPLUGINS_DIR_CONFIG@")
+# Include CTK Plugin specific variables
+include(${CTK_PLUGIN_USE_FILE})
 
 # CTK external projects variables
 @CTK_SUPERBUILD_EP_VARS_CONFIG@
 
-# Qt configuration
-SET(CTK_QT_RCC_EXECUTABLE "@QT_RCC_EXECUTABLE@")
-SET(CTK_QT_MOC_EXECUTABLE "@QT_MOC_EXECUTABLE@")
-SET(CTK_QT_UIC_EXECUTABLE "@QT_UIC_EXECUTABLE@")
-SET(CTK_QT_QMAKE_EXECUTABLE "@QT_QMAKE_EXECUTABLE@")
-
-# The CTK version number
-SET(CTK_MAJOR_VERSION "@CTK_MAJOR_VERSION@")
-SET(CTK_MINOR_VERSION "@CTK_MINOR_VERSION@")
-SET(CTK_PATCH_VERSION "@CTK_PATCH_VERSION@")
-
-# The location of the UseCTK.cmake file.
-SET(CTK_USE_FILE "@CTK_USE_FILE@")
-
-# CMake extension module directory
-SET(CTK_CMAKE_DIR "@CTK_CMAKE_DIR_CONFIG@")
-SET(CTK_CMAKE_UTILITIES_DIR "@CTK_CMAKE_UTILITIES_DIR_CONFIG@")
-
 # Update CMake module path so that calling "find_package(DCMTK)" works as expected 
 # after calling "find_package(CTK)"
 # Ideally projects like DCMTK or PythonQt should provide both "Config" and "Use" files.
@@ -162,21 +84,13 @@ set(CMAKE_MODULE_PATH
   ${CMAKE_MODULE_PATH}
   )
 
-# TODO The list of available libraries.
-
-# TODO The list of available plugins.
-
-# TODO The list of available applications.
-
-# TODO The Doxygen configuration.
-#SET(CTK_DOXYGEN_HOME "@CTK_DOXYGEN_HOME_CONFIG@")
-
-# TODO Relative install paths in the CTK install tree
-SET(CTK_INSTALL_BIN_DIR "@CTK_INSTALL_BIN_DIR@")
-SET(CTK_INSTALL_INCLUDE_DIR "@CTK_INSTALL_INCLUDE_DIR@")
-SET(CTK_INSTALL_LIB_DIR "@CTK_INSTALL_LIB_DIR@")
-SET(CTK_INSTALL_QTPLUGIN_DIR "@CTK_INSTALL_QTPLUGIN_DIR@")
-#SET(CTK_INSTALL_PACKAGE_DIR "@CTK_INSTALL_PACKAGE_DIR@")
+# Relative install paths
+set(CTK_INSTALL_BIN_DIR "@CTK_INSTALL_BIN_DIR@")
+set(CTK_INSTALL_INCLUDE_DIR "@CTK_INSTALL_INCLUDE_DIR@")
+set(CTK_INSTALL_LIB_DIR "@CTK_INSTALL_LIB_DIR@")
+set(CTK_INSTALL_PLUGIN_INCLUDE_DIR "@CTK_INSTALL_PLUGIN_INCLUDE_DIR@")
+set(CTK_INSTALL_PLUGIN_DIR "@CTK_INSTALL_PLUGIN_DIR@")
+set(CTK_INSTALL_QTPLUGIN_DIR "@CTK_INSTALL_QTPLUGIN_DIR@")
 
 # A CTK install tree always provides one build configuration. A CTK
 # build tree may provide either one or multiple build configurations

+ 0 - 52
CMake/CTKConfigVersion.cmake.in

@@ -1,52 +0,0 @@
-###########################################################################
-#
-#  Library:   CTK
-#
-#  Copyright (c) Kitware Inc.
-#
-#  Licensed under the Apache License, Version 2.0 (the "License");
-#  you may not use this file except in compliance with the License.
-#  You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0.txt
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-#
-###########################################################################
-###########################################################################
-#
-#  Program:   Visualization Toolkit
-#  Module:    VTKConfigVersion.cmake.in
-#
-#  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
-#
-#  All rights reserved.
-#  See Copyright.txt or http://www.kitware.com/Copyright.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.
-#
-###########################################################################
-
-#
-# This file is used by 
-#
-
-# The full CTK version number.
-SET(PACKAGE_VERSION "@_CTK_VERSION_MAJOR@.@_CTK_VERSION_MINOR@.@_CTK_VERSION_PATCH@")
- 
-# This version is compatible only with matching major.minor versions.
-IF("@_CTK_VERSION_MAJOR@.@_CTK_VERSION_MINOR@" VERSION_EQUAL "${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}")
-  # This version is compatible with equal or lesser patch versions.
-  IF(NOT "@_CTK_VERSION_PATCH@" VERSION_LESS "${PACKAGE_FIND_VERSION_PATCH}")
-    SET(PACKAGE_VERSION_COMPATIBLE 1)
-    IF("@_CTK_VERSION_PATCH@" VERSION_EQUAL "${PACKAGE_FIND_VERSION_PATCH}")
-      SET(PACKAGE_VERSION_EXACT 1)
-    ENDIF()
-  ENDIF()
-ENDIF()

+ 153 - 100
CMake/LastConfigureStep/CTKGenerateCTKConfig.cmake

@@ -38,86 +38,23 @@
 # one for installation.  The file tells external projects how to use CTK.
 #
 
-include(ctkFunctionGeneratePluginUseFile)
-
-# Construct version numbers for CTKConfigVersion.cmake.
-set(_CTK_VERSION_MAJOR ${CTK_MAJOR_VERSION})
-set(_CTK_VERSION_MINOR ${CTK_MINOR_VERSION})
-set(_CTK_VERSION_PATCH ${CTK_PATCH_VERSION})
-# We use odd minor numbers for development versions.
-# Use a date for the development patch level.
-# if("${_CTK_VERSION_MINOR}" MATCHES "[13579]$")
-#   include(${CTK_SOURCE_DIR}/Utilities/kwsys/kwsysDateStamp.cmake)
-#   set(_CTK_VERSION_PATCH
-#     "${KWSYS_DATE_STAMP_YEAR}${KWSYS_DATE_STAMP_MONTH}${KWSYS_DATE_STAMP_DAY}"
-#     )
-# endif()
-
-#-----------------------------------------------------------------------------
-# Settings shared between the build tree and install tree.
-
-
-#-----------------------------------------------------------------------------
-# Settings specific to the build tree.
-
-# The install-only section is empty for the build tree.
-set(CTK_CONFIG_INSTALL_ONLY)
-
-# The "use" file.
-set(CTK_USE_FILE ${CTK_SUPERBUILD_BINARY_DIR}/UseCTK.cmake)
-
-# Generate list of target to exports
-set(CTK_TARGETS_TO_EXPORT ${CTK_LIBRARIES} ${CTK_PLUGIN_LIBRARIES})
 
-# Append CTK PythonQt static libraries
-if(NOT CTK_BUILD_SHARED_LIBS)
-  foreach(lib ${CTK_WRAPPED_LIBRARIES_PYTHONQT})
-    list(APPEND CTK_TARGETS_TO_EXPORT ${lib}PythonQt)
-  endforeach()
+message(STATUS "Including CMake built-in module CMakePackageConfigHelpers")
+include(CMakePackageConfigHelpers OPTIONAL)
+if(COMMAND configure_package_config_file)
+  message(STATUS "Including CMake built-in module CMakePackageConfigHelpers - ok")
+else()
+  message(STATUS "Including CMake built-in module CMakePackageConfigHelpers - failed")
+  message(STATUS "Including CTK module CMakePackageConfigHelpers")
+  list(APPEND CMAKE_MODULE_PATH ${CTK_CMAKE_DIR}/configure_package_config_file)
+  include(CMakePackageConfigHelpers)
+  message(STATUS "Including CTK module CMakePackageConfigHelpers - ok")
 endif()
 
-# Export targets so they can be imported by a project using CTK
-# as an external library
-export(TARGETS ${CTK_TARGETS_TO_EXPORT} FILE ${CTK_SUPERBUILD_BINARY_DIR}/CTKExports.cmake)
-
-# Generate a file containing plugin specific variables
-set(CTK_PLUGIN_USE_FILE "${CTK_SUPERBUILD_BINARY_DIR}/CTKPluginUseFile.cmake")
-ctkFunctionGeneratePluginUsefile(${CTK_PLUGIN_USE_FILE})
-
-# Write a set of variables containing library specific include and library directories
-set(CTK_LIBRARY_INCLUDE_DIRS_CONFIG)
-foreach(lib ${CTK_LIBRARIES})
-  set(${lib}_INCLUDE_DIRS ${${lib}_SOURCE_DIR} ${${lib}_BINARY_DIR})
-  ctkFunctionGetIncludeDirs(${lib}_INCLUDE_DIRS ${lib})
-  set(CTK_LIBRARY_INCLUDE_DIRS_CONFIG "${CTK_LIBRARY_INCLUDE_DIRS_CONFIG}
-set(${lib}_INCLUDE_DIRS \"${${lib}_INCLUDE_DIRS}\")")
-
-  ctkFunctionGetLibraryDirs(${lib}_LIBRARY_DIRS ${lib})
-  set(CTK_LIBRARY_LIBRARY_DIRS_CONFIG "${CTK_LIBRARY_LIBRARY_DIRS_CONFIG}
-set(${lib}_LIBRARY_DIRS \"${${lib}_LIBRARY_DIRS}\")")
-endforeach()
-
-# Determine the include directories needed.
-set(CTK_INCLUDE_DIRS_CONFIG
-  ${CTK_BASE_INCLUDE_DIRS}
-)
+include(ctkFunctionGeneratePluginUseFile)
 
 set(CTKTesting_CMAKE_DIR_CONFIG "${CTKTesting_SOURCE_DIR}/CMake")
 
-# Consider "headeronly" libraries
-set(headeronly_libs CTKTesting)
-foreach(lib ${headeronly_libs})
-  set(${lib}_INCLUDE_DIRS ${${lib}_SOURCE_DIR} ${${lib}_BINARY_DIR})
-  ctkFunctionGetIncludeDirs(${lib}_INCLUDE_DIRS ${lib})
-  set(CTK_LIBRARY_INCLUDE_DIRS_CONFIG "${CTK_LIBRARY_INCLUDE_DIRS_CONFIG}
-set(${lib}_INCLUDE_DIRS \"${${lib}_INCLUDE_DIRS}\")")
-  set(CTK_INCLUDE_DIRS_CONFIG ${CTK_INCLUDE_DIRS_CONFIG} ${${lib}_INCLUDE_DIRS})
-endforeach()
-
-
-
-# Library directory.
-set(CTK_LIBRARY_DIRS_CONFIG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
 
 # Plug-in output directory
 if(WIN32)
@@ -135,21 +72,6 @@ else()
   set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CMAKE_${_plugin_output_type}_OUTPUT_DIRECTORY}/plugins")
 endif()
 
-# External project libraries.
-set(CTK_EXTERNAL_LIBRARIES_CONFIG ${CTK_EXTERNAL_LIBRARIES})
-
-# External project library directory.
-set(CTK_EXTERNAL_LIBRARY_DIRS_CONFIG ${CTK_EXTERNAL_LIBRARY_DIRS})
-
-# Runtime library directory.
-set(CTK_RUNTIME_LIBRARY_DIRS_CONFIG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
-
-# Binary executable directory.
-set(CTK_EXECUTABLE_DIRS_CONFIG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
-
-# QtDesigner plugins directory
-set(CTK_QTDESIGNERPLUGINS_DIR_CONFIG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
-
 # CTK external projects variables
 string(REPLACE "^" ";" CTK_SUPERBUILD_EP_VARNAMES "${CTK_SUPERBUILD_EP_VARNAMES}")
 set(CTK_SUPERBUILD_EP_VARS_CONFIG)
@@ -159,8 +81,6 @@ foreach(varname ${CTK_SUPERBUILD_EP_VARNAMES})
 set(CTK_${varname} \"${${varname}}\")")
 endforeach()
 
-# Executable locations.
-
 # CMake extension module directory.
 set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
 set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
@@ -170,16 +90,149 @@ set(CTK_CONFIGURATION_TYPES_CONFIG ${CMAKE_CONFIGURATION_TYPES})
 set(CTK_BUILD_TYPE_CONFIG ${CMAKE_BUILD_TYPE})
 
 #-----------------------------------------------------------------------------
-# Configure CTKConfig.cmake for the build tree.
-configure_file(${CTK_SOURCE_DIR}/CMake/CTKConfig.cmake.in
-               ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfig.cmake @ONLY IMMEDIATE)
-configure_file(${CTK_SOURCE_DIR}/CMake/CTKConfigVersion.cmake.in
-               ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfigVersion.cmake @ONLY IMMEDIATE)
-configure_file(${CTK_SOURCE_DIR}/CMake/ctkConfig.h.in
-               ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h @ONLY IMMEDIATE)
+configure_file(
+  ${CTK_SOURCE_DIR}/CMake/ctkConfig.h.in
+  ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h @ONLY
+  )
+
+install(
+  FILES ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h
+  DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
+  )
+
+#-----------------------------------------------------------------------------
+# Generate a file containing plugin specific variables
+set(ctk_plugin_use_file "${CTK_SUPERBUILD_BINARY_DIR}/CTKPluginUseFile.cmake")
+ctkFunctionGeneratePluginUsefile(${ctk_plugin_use_file})
+
+install(
+  FILES ${ctk_plugin_use_file}
+  DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
+  )
 
 #-----------------------------------------------------------------------------
-# Settings specific to the install tree.
+# Generate list of target to exports
+set(CTK_TARGETS_TO_EXPORT ${CTK_LIBRARIES} ${CTK_PLUGIN_LIBRARIES})
+
+# Append CTK PythonQt static libraries
+if(NOT CTK_BUILD_SHARED_LIBS)
+  foreach(lib ${CTK_WRAPPED_LIBRARIES_PYTHONQT})
+    list(APPEND CTK_TARGETS_TO_EXPORT ${lib}PythonQt)
+  endforeach()
+endif()
+
+# Export targets so they can be imported by a project using CTK
+# as an external library
+export(TARGETS ${CTK_TARGETS_TO_EXPORT} FILE ${CTK_SUPERBUILD_BINARY_DIR}/CTKExports.cmake)
+
+install(EXPORT CTKExports DESTINATION ${CTK_INSTALL_CMAKE_DIR})
+
+#-----------------------------------------------------------------------------
+# Configure 'CTKConfig.cmake' for a build tree
+
+set(CTK_CONFIG_DIR_CONFIG ${CTK_SUPERBUILD_BINARY_DIR})
+set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
+set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
+set(CTK_CONFIG_H_INCLUDE_DIR_CONFIG ${CTK_CONFIG_H_INCLUDE_DIR})
+set(CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG ${CTK_SOURCE_DIR}/Libs)
+set(CTK_LIBRARY_DIR_CONFIG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
+
+set(CTK_CONFIG_CODE "####### Expanded from \@CTK_CONFIG_CODE\@ #######\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# The CTK DGraph executable used to compute target dependency graphs\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_DGRAPH_EXECUTABLE \"${DGraph_EXECUTABLE}\")\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Qt configuration\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_QT_QMAKE_EXECUTABLE \"${QT_QMAKE_EXECUTABLE}\")\n") # FIXME: Just pass Qt version (and bitness?)
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# The CTK Qt designer plugins directory\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_QTDESIGNERPLUGINS_DIR \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
+foreach(lib ${CTK_LIBRARIES} CTKTesting)
+  set(${lib}_INCLUDE_DIRS ${${lib}_SOURCE_DIR} ${${lib}_BINARY_DIR})
+  ctkFunctionGetIncludeDirs(${lib}_INCLUDE_DIRS ${lib})
+  set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_INCLUDE_DIRS \"${${lib}_INCLUDE_DIRS}\")\n")
+endforeach()
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"${CTK_BASE_INCLUDE_DIRS}\")\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}list(APPEND CTK_INCLUDE_DIRS \"${CTKTesting_INCLUDE_DIRS}\")\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
+foreach(lib ${CTK_LIBRARIES})
+  set(${lib}_LIBRARY_DIRS "")
+  ctkFunctionGetLibraryDirs(${lib}_LIBRARY_DIRS ${lib})
+  set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_LIBRARY_DIRS \"${${lib}_LIBRARY_DIRS}\")\n")
+endforeach()
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# External project libraries\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_EXTERNAL_LIBRARIES \"${CTK_EXTERNAL_LIBRARIES}\")\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# External project library directories\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_EXTERNAL_LIBRARY_DIRS \"${CTK_EXTERNAL_LIBRARY_DIRS}\")\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
+
+set(ctk_config ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfig.cmake)
+
+configure_package_config_file(
+  ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
+  ${ctk_config}
+  INSTALL_DESTINATION ${CTK_SUPERBUILD_BINARY_DIR}
+  PATH_VARS
+    CTK_CONFIG_DIR_CONFIG
+    CTK_CMAKE_DIR_CONFIG
+    CTK_CMAKE_UTILITIES_DIR_CONFIG
+    CTK_CONFIG_H_INCLUDE_DIR_CONFIG
+    CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG
+    CTK_LIBRARY_DIR_CONFIG
+  NO_CHECK_REQUIRED_COMPONENTS_MACRO
+  )
+
+#-----------------------------------------------------------------------------
+# Configure 'CTKConfig.cmake' for an install tree
+
+set(CTK_CONFIG_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
+set(CTK_CMAKE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
+set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
+set(CTK_CONFIG_H_INCLUDE_DIR_CONFIG ${CTK_INSTALL_INCLUDE_DIR})
+set(CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
+set(CTK_LIBRARY_DIR_CONFIG ${CTK_INSTALL_LIB_DIR})
+
+set(CTK_CONFIG_CODE "####### Expanded from \@CTK_CONFIG_CODE\@ #######\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
+foreach(libname ${CTK_LIBRARIES} CTKTesting)
+  set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${libname}_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
+endforeach()
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
+foreach(lib ${CTK_LIBRARIES})
+  set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_LIBRARY_DIRS \"\")\n")
+endforeach()
+set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
+
+set(ctk_install_config ${CMAKE_BINARY_DIR}/CMakeFiles/CTKConfig.cmake)
+
+configure_package_config_file(
+  ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
+  ${ctk_install_config}
+  INSTALL_DESTINATION ${CTK_INSTALL_CMAKE_DIR}
+  PATH_VARS
+    CTK_CONFIG_DIR_CONFIG
+    CTK_CMAKE_DIR_CONFIG
+    CTK_CMAKE_UTILITIES_DIR_CONFIG
+    CTK_CONFIG_H_INCLUDE_DIR_CONFIG
+    CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG
+    CTK_LIBRARY_DIR_CONFIG
+  NO_CHECK_REQUIRED_COMPONENTS_MACRO
+  )
+
+install(
+  FILES ${ctk_install_config}
+  DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
+  )
 
 #-----------------------------------------------------------------------------
-# Configure CTKConfig.cmake for the install tree.
+# Configure and install 'CTKConfigVersion.cmake'
+set(ctk_config_version ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfigVersion.cmake)
+write_basic_package_version_file(
+  ${ctk_config_version}
+  VERSION ${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_PATCH_VERSION}
+  COMPATIBILITY SameMajorVersion
+  )
+
+install(
+  FILES ${ctk_config_version}
+  DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
+  )

+ 331 - 0
CMake/configure_package_config_file/CMakePackageConfigHelpers.cmake

@@ -0,0 +1,331 @@
+#.rst:
+# CMakePackageConfigHelpers
+# -------------------------
+#
+# CONFIGURE_PACKAGE_CONFIG_FILE(), WRITE_BASIC_PACKAGE_VERSION_FILE()
+#
+#
+#
+# ::
+#
+#     CONFIGURE_PACKAGE_CONFIG_FILE(<input> <output> INSTALL_DESTINATION <path>
+#                                                    [PATH_VARS <var1> <var2> ... <varN>]
+#                                                    [NO_SET_AND_CHECK_MACRO]
+#                                                    [NO_CHECK_REQUIRED_COMPONENTS_MACRO]
+#                                                    [NO_FIND_DEPENDENCY_MACRO])
+#
+#
+#
+# CONFIGURE_PACKAGE_CONFIG_FILE() should be used instead of the plain
+# configure_file() command when creating the <Name>Config.cmake or
+# <Name>-config.cmake file for installing a project or library.  It
+# helps making the resulting package relocatable by avoiding hardcoded
+# paths in the installed Config.cmake file.
+#
+# In a FooConfig.cmake file there may be code like this to make the
+# install destinations know to the using project:
+#
+# ::
+#
+#    set(FOO_INCLUDE_DIR   "@CMAKE_INSTALL_FULL_INCLUDEDIR@" )
+#    set(FOO_DATA_DIR   "@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@" )
+#    set(FOO_ICONS_DIR   "@CMAKE_INSTALL_PREFIX@/share/icons" )
+#    ...logic to determine installedPrefix from the own location...
+#    set(FOO_CONFIG_DIR  "${installedPrefix}/@CONFIG_INSTALL_DIR@" )
+#
+# All 4 options shown above are not sufficient, since the first 3
+# hardcode the absolute directory locations, and the 4th case works only
+# if the logic to determine the installedPrefix is correct, and if
+# CONFIG_INSTALL_DIR contains a relative path, which in general cannot
+# be guaranteed.  This has the effect that the resulting FooConfig.cmake
+# file would work poorly under Windows and OSX, where users are used to
+# choose the install location of a binary package at install time,
+# independent from how CMAKE_INSTALL_PREFIX was set at build/cmake time.
+#
+# Using CONFIGURE_PACKAGE_CONFIG_FILE() helps.  If used correctly, it
+# makes the resulting FooConfig.cmake file relocatable.  Usage:
+#
+# ::
+#
+#    1. write a FooConfig.cmake.in file as you are used to
+#    2. insert a line containing only the string "@PACKAGE_INIT@"
+#    3. instead of set(FOO_DIR "@SOME_INSTALL_DIR@"), use set(FOO_DIR "@PACKAGE_SOME_INSTALL_DIR@")
+#       (this must be after the @PACKAGE_INIT@ line)
+#    4. instead of using the normal configure_file(), use CONFIGURE_PACKAGE_CONFIG_FILE()
+#
+#
+#
+# The <input> and <output> arguments are the input and output file, the
+# same way as in configure_file().
+#
+# The <path> given to INSTALL_DESTINATION must be the destination where
+# the FooConfig.cmake file will be installed to.  This can either be a
+# relative or absolute path, both work.
+#
+# The variables <var1> to <varN> given as PATH_VARS are the variables
+# which contain install destinations.  For each of them the macro will
+# create a helper variable PACKAGE_<var...>.  These helper variables
+# must be used in the FooConfig.cmake.in file for setting the installed
+# location.  They are calculated by CONFIGURE_PACKAGE_CONFIG_FILE() so
+# that they are always relative to the installed location of the
+# package.  This works both for relative and also for absolute
+# locations.  For absolute locations it works only if the absolute
+# location is a subdirectory of CMAKE_INSTALL_PREFIX.
+#
+# By default configure_package_config_file() also generates two helper
+# macros, set_and_check() and check_required_components() into the
+# FooConfig.cmake file.
+#
+# set_and_check() should be used instead of the normal set() command for
+# setting directories and file locations.  Additionally to setting the
+# variable it also checks that the referenced file or directory actually
+# exists and fails with a FATAL_ERROR otherwise.  This makes sure that
+# the created FooConfig.cmake file does not contain wrong references.
+# When using the NO_SET_AND_CHECK_MACRO, this macro is not generated
+# into the FooConfig.cmake file.
+#
+# check_required_components(<package_name>) should be called at the end
+# of the FooConfig.cmake file if the package supports components.  This
+# macro checks whether all requested, non-optional components have been
+# found, and if this is not the case, sets the Foo_FOUND variable to
+# FALSE, so that the package is considered to be not found.  It does
+# that by testing the Foo_<Component>_FOUND variables for all requested
+# required components.  When using the NO_CHECK_REQUIRED_COMPONENTS
+# option, this macro is not generated into the FooConfig.cmake file.
+#
+# For an example see below the documentation for
+# WRITE_BASIC_PACKAGE_VERSION_FILE().
+#
+#
+#
+# ::
+#
+#   WRITE_BASIC_PACKAGE_VERSION_FILE( filename VERSION major.minor.patch COMPATIBILITY (AnyNewerVersion|SameMajorVersion|ExactVersion) )
+#
+#
+#
+# Writes a file for use as <package>ConfigVersion.cmake file to
+# <filename>.  See the documentation of find_package() for details on
+# this.
+#
+# ::
+#
+#     filename is the output filename, it should be in the build tree.
+#     major.minor.patch is the version number of the project to be installed
+#
+# The COMPATIBILITY mode AnyNewerVersion means that the installed
+# package version will be considered compatible if it is newer or
+# exactly the same as the requested version.  This mode should be used
+# for packages which are fully backward compatible, also across major
+# versions.  If SameMajorVersion is used instead, then the behaviour
+# differs from AnyNewerVersion in that the major version number must be
+# the same as requested, e.g.  version 2.0 will not be considered
+# compatible if 1.0 is requested.  This mode should be used for packages
+# which guarantee backward compatibility within the same major version.
+# If ExactVersion is used, then the package is only considered
+# compatible if the requested version matches exactly its own version
+# number (not considering the tweak version).  For example, version
+# 1.2.3 of a package is only considered compatible to requested version
+# 1.2.3.  This mode is for packages without compatibility guarantees.
+# If your project has more elaborated version matching rules, you will
+# need to write your own custom ConfigVersion.cmake file instead of
+# using this macro.
+#
+# Internally, this macro executes configure_file() to create the
+# resulting version file.  Depending on the COMPATIBLITY, either the
+# file BasicConfigVersion-SameMajorVersion.cmake.in or
+# BasicConfigVersion-AnyNewerVersion.cmake.in is used.  Please note that
+# these two files are internal to CMake and you should not call
+# configure_file() on them yourself, but they can be used as starting
+# point to create more sophisticted custom ConfigVersion.cmake files.
+#
+#
+#
+# Example using both configure_package_config_file() and
+# write_basic_package_version_file(): CMakeLists.txt:
+#
+# ::
+#
+#    set(INCLUDE_INSTALL_DIR include/ ... CACHE )
+#    set(LIB_INSTALL_DIR lib/ ... CACHE )
+#    set(SYSCONFIG_INSTALL_DIR etc/foo/ ... CACHE )
+#    ...
+#    include(CMakePackageConfigHelpers)
+#    configure_package_config_file(FooConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake
+#                                  INSTALL_DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake
+#                                  PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR)
+#    write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake
+#                                     VERSION 1.2.3
+#                                     COMPATIBILITY SameMajorVersion )
+#    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake
+#            DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake )
+#
+#
+#
+# With a FooConfig.cmake.in:
+#
+# ::
+#
+#    set(FOO_VERSION x.y.z)
+#    ...
+#    @PACKAGE_INIT@
+#    ...
+#    set_and_check(FOO_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
+#    set_and_check(FOO_SYSCONFIG_DIR "@PACKAGE_SYSCONFIG_INSTALL_DIR@")
+#
+#
+#
+# ::
+#
+#    check_required_components(Foo)
+
+
+#=============================================================================
+# Copyright 2012 Alexander Neundorf <neundorf@kde.org>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+include(CMakeParseArguments)
+
+include(WriteBasicConfigVersionFile)
+
+macro(WRITE_BASIC_PACKAGE_VERSION_FILE)
+  write_basic_config_version_file(${ARGN})
+endmacro()
+
+
+function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile)
+  set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO NO_FIND_DEPENDENCY_MACRO)
+  set(oneValueArgs INSTALL_DESTINATION )
+  set(multiValueArgs PATH_VARS )
+
+  cmake_parse_arguments(CCF "${options}" "${oneValueArgs}" "${multiValueArgs}"  ${ARGN})
+
+  if(CCF_UNPARSED_ARGUMENTS)
+    message(FATAL_ERROR "Unknown keywords given to CONFIGURE_PACKAGE_CONFIG_FILE(): \"${CCF_UNPARSED_ARGUMENTS}\"")
+  endif()
+
+  if(NOT CCF_INSTALL_DESTINATION)
+    message(FATAL_ERROR "No INSTALL_DESTINATION given to CONFIGURE_PACKAGE_CONFIG_FILE()")
+  endif()
+
+  if(IS_ABSOLUTE "${CCF_INSTALL_DESTINATION}")
+    set(absInstallDir "${CCF_INSTALL_DESTINATION}")
+  else()
+    set(absInstallDir "${CMAKE_INSTALL_PREFIX}/${CCF_INSTALL_DESTINATION}")
+  endif()
+
+  file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${absInstallDir}" "${CMAKE_INSTALL_PREFIX}" )
+
+  foreach(var ${CCF_PATH_VARS})
+    if(NOT DEFINED ${var})
+      message(FATAL_ERROR "Variable ${var} does not exist")
+    else()
+      if(IS_ABSOLUTE "${${var}}")
+        string(REPLACE "${CMAKE_INSTALL_PREFIX}" "\${PACKAGE_PREFIX_DIR}"
+                        PACKAGE_${var} "${${var}}")
+      else()
+        set(PACKAGE_${var} "\${PACKAGE_PREFIX_DIR}/${${var}}")
+      endif()
+    endif()
+  endforeach()
+
+  get_filename_component(inputFileName "${_inputFile}" NAME)
+
+  set(PACKAGE_INIT "
+####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
+####### Any changes to this file will be overwritten by the next CMake run ####
+####### The input file was ${inputFileName}                            ########
+
+get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE_RELATIVE_PATH}\" ABSOLUTE)
+")
+
+  if("${absInstallDir}" MATCHES "^(/usr)?/lib(64)?/.+")
+    # Handle "/usr move" symlinks created by some Linux distros.
+    set(PACKAGE_INIT "${PACKAGE_INIT}
+# Use original install prefix when loaded through a \"/usr move\"
+# cross-prefix symbolic link such as /lib -> /usr/lib.
+get_filename_component(_realCurr \"\${CMAKE_CURRENT_LIST_DIR}\" REALPATH)
+get_filename_component(_realOrig \"${absInstallDir}\" REALPATH)
+if(_realCurr STREQUAL _realOrig)
+  set(PACKAGE_PREFIX_DIR \"${CMAKE_INSTALL_PREFIX}\")
+endif()
+unset(_realOrig)
+unset(_realCurr)
+")
+  endif()
+
+  if(NOT CCF_NO_SET_AND_CHECK_MACRO)
+    set(PACKAGE_INIT "${PACKAGE_INIT}
+macro(set_and_check _var _file)
+  set(\${_var} \"\${_file}\")
+  if(NOT EXISTS \"\${_file}\")
+    message(FATAL_ERROR \"File or directory \${_file} referenced by variable \${_var} does not exist !\")
+  endif()
+endmacro()
+")
+  endif()
+
+
+  if(NOT CCF_NO_CHECK_REQUIRED_COMPONENTS_MACRO)
+    set(PACKAGE_INIT "${PACKAGE_INIT}
+macro(check_required_components _NAME)
+  foreach(comp \${\${_NAME}_FIND_COMPONENTS})
+    if(NOT \${_NAME}_\${comp}_FOUND)
+      if(\${_NAME}_FIND_REQUIRED_\${comp})
+        set(\${_NAME}_FOUND FALSE)
+      endif()
+    endif()
+  endforeach()
+endmacro()
+")
+  endif()
+
+  if(NOT CCF_NO_FIND_DEPENDENCY_MACRO)
+    set(PACKAGE_INIT "${PACKAGE_INIT}
+macro(find_dependency dep)
+  if (NOT \${dep}_FOUND)
+    if (\${ARGV1})
+      set(version \${ARGV1})
+    endif()
+    set(exact_arg)
+    if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION_EXACT)
+      set(exact_arg EXACT)
+    endif()
+    set(quiet_arg)
+    if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
+      set(quiet_arg QUIET)
+    endif()
+    set(required_arg)
+    if(\${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
+      set(required_arg REQUIRED)
+    endif()
+
+    find_package(\${dep} \${version} \${exact_arg} \${quiet_arg} \${required_arg})
+    if (NOT \${dep}_FOUND)
+      set(\${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE \"\${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency \${dep} could not be found.\")
+      set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
+      return()
+    endif()
+    set(required_arg)
+    set(quiet_arg)
+    set(exact_arg)
+  endif()
+endmacro()
+")
+  endif()
+
+  set(PACKAGE_INIT "${PACKAGE_INIT}
+####################################################################################")
+
+  configure_file("${_inputFile}" "${_outputFile}" @ONLY)
+
+endfunction()

+ 9 - 7
CMake/ctkMacroBuildApp.cmake

@@ -27,7 +27,7 @@
 macro(ctkMacroBuildApp)
   ctkMacroParseArguments(MY
     "NAME;SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES"
-    ""
+    "INSTALL"
     ${ARGN}
     )
 
@@ -120,12 +120,14 @@ macro(ctkMacroBuildApp)
   target_link_libraries(${proj_name} ${my_libs})
 
   # Install headers
-  file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
-  install(FILES
-    ${headers}
-    ${dynamicHeaders}
-    DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
-    )
+  if(MY_INSTALL)
+    file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+    install(FILES
+      ${headers}
+      ${dynamicHeaders}
+      DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
+      )
+  endif()
 
 endmacro()
 

+ 1 - 1
CMake/ctkMacroBuildLib.cmake

@@ -151,7 +151,7 @@ macro(ctkMacroBuildLib)
 
   # Install rules
   if(MY_LIBRARY_TYPE STREQUAL "SHARED")
-    install(TARGETS ${lib_name}
+    install(TARGETS ${lib_name} EXPORT CTKExports
       RUNTIME DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
       LIBRARY DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
       ARCHIVE DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Development)

+ 16 - 15
CMake/ctkMacroBuildPlugin.cmake

@@ -311,14 +311,13 @@ macro(ctkMacroBuildPlugin)
     PREFIX "lib"
     )
 
-  # Note: The plugin may be installed in some other location ???
-  # Install rules
-# if(MY_LIBRARY_TYPE STREQUAL "SHARED")
-# install(TARGETS ${lib_name}
-# RUNTIME DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT RuntimePlugins
-# LIBRARY DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT RuntimePlugins
-# ARCHIVE DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Development)
-# endif()
+  if(NOT MY_TEST_PLUGIN)
+    # Install rules
+    install(TARGETS ${lib_name} EXPORT CTKExports
+      RUNTIME DESTINATION ${CTK_INSTALL_PLUGIN_DIR} COMPONENT RuntimePlugins
+      LIBRARY DESTINATION ${CTK_INSTALL_PLUGIN_DIR} COMPONENT RuntimePlugins
+      ARCHIVE DESTINATION ${CTK_INSTALL_PLUGIN_DIR} COMPONENT Development)
+  endif()
 
   set(my_libs
     ${MY_TARGET_LIBRARIES}
@@ -334,13 +333,15 @@ macro(ctkMacroBuildPlugin)
     set(${CMAKE_PROJECT_NAME}_PLUGIN_LIBRARIES ${${CMAKE_PROJECT_NAME}_PLUGIN_LIBRARIES} ${lib_name} CACHE INTERNAL "CTK plugins" FORCE)
   endif()
 
-  # Install headers
-  #file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.tpp")
-  #install(FILES
-  # ${headers}
-  # ${dynamicHeaders}
-  # DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
-  # )
+  if(NOT MY_TEST_PLUGIN)
+    # Install headers
+    file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.tpp")
+    install(FILES
+      ${headers}
+      ${dynamicHeaders}
+      DESTINATION ${CTK_INSTALL_PLUGIN_INCLUDE_DIR}/${Plugin-SymbolicName} COMPONENT Development
+      )
+  endif()
 
 endmacro()
 

+ 0 - 3
CMake/ctkMacroBuildQtPlugin.cmake

@@ -127,9 +127,6 @@ macro(ctkMacroBuildQtPlugin)
   # CTK_INSTALL_QTPLUGIN_DIR:STRING can be passed when configuring CTK
   # By default, it is the same path as CTK_INSTALL_LIB_DIR
   # Plugins are installed in a subdirectory corresponding to their types (e.g. designer, iconengines, imageformats...)
-  if (NOT CTK_INSTALL_QTPLUGIN_DIR)
-    set(CTK_INSTALL_QTPLUGIN_DIR "${CTK_INSTALL_LIB_DIR}")
-  endif()
   install(TARGETS ${lib_name}
     RUNTIME DESTINATION ${CTK_INSTALL_QTPLUGIN_DIR}/${MY_PLUGIN_DIR} COMPONENT RuntimePlugins
     LIBRARY DESTINATION ${CTK_INSTALL_QTPLUGIN_DIR}/${MY_PLUGIN_DIR} COMPONENT RuntimePlugins

+ 58 - 56
CMakeLists.txt

@@ -21,32 +21,6 @@
 cmake_minimum_required(VERSION 2.8.4)
 
 #-----------------------------------------------------------------------------
-# See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details
-#
-
-set(project_policies
-  CMP0001 # NEW: CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.
-  CMP0002 # NEW: Logical target names must be globally unique.
-  CMP0003 # NEW: Libraries linked via full path no longer produce linker search paths.
-  CMP0004 # NEW: Libraries linked may NOT have leading or trailing whitespace.
-  CMP0005 # NEW: Preprocessor definition values are now escaped automatically.
-  CMP0006 # NEW: Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.
-  CMP0007 # NEW: List command no longer ignores empty elements.
-  CMP0008 # NEW: Libraries linked by full-path must have a valid library file name.
-  CMP0009 # NEW: FILE GLOB_RECURSE calls should not follow symlinks by default.
-  CMP0010 # NEW: Bad variable reference syntax is an error.
-  CMP0011 # NEW: Included scripts do automatic cmake_policy PUSH and POP.
-  CMP0012 # NEW: if() recognizes numbers and boolean constants.
-  CMP0013 # NEW: Duplicate binary directories are not allowed.
-  CMP0014 # NEW: Input directories must have CMakeLists.txt
-  )
-foreach(policy ${project_policies})
-  if(POLICY ${policy})
-    cmake_policy(SET ${policy} NEW)
-  endif()
-endforeach()
-
-#-----------------------------------------------------------------------------
 if(APPLE)
   # Note: By setting CMAKE_OSX_* variables before any enable_language() or project() calls,
   #       we ensure that the bitness will be properly detected.
@@ -142,9 +116,21 @@ endif()
 if(NOT CTK_INSTALL_LIB_DIR)
   set(CTK_INSTALL_LIB_DIR "lib/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}")
 endif()
+if(NOT CTK_INSTALL_PLUGIN_DIR)
+  set(CTK_INSTALL_PLUGIN_DIR "lib/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}/plugins")
+endif()
+if(NOT CTK_INSTALL_CMAKE_DIR)
+  set(CTK_INSTALL_CMAKE_DIR "lib/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}/CMake")
+endif()
 if(NOT CTK_INSTALL_INCLUDE_DIR)
   set(CTK_INSTALL_INCLUDE_DIR "include/ctk-${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}")
 endif()
+if(NOT CTK_INSTALL_PLUGIN_INCLUDE_DIR)
+  set(CTK_INSTALL_PLUGIN_INCLUDE_DIR ${CTK_INSTALL_INCLUDE_DIR})
+endif()
+if(NOT CTK_INSTALL_QTPLUGIN_DIR)
+  set(CTK_INSTALL_QTPLUGIN_DIR ${CTK_INSTALL_LIB_DIR})
+endif()
 if(NOT CTK_INSTALL_DOC_DIR)
   set(CTK_INSTALL_DOC_DIR "doc")
 endif()
@@ -176,35 +162,46 @@ set(CTK_CMAKE_UTILITIES_DIR ${CTK_SOURCE_DIR}/Utilities/CMake)
 #-----------------------------------------------------------------------------
 # CMake function(s) and macro(s)
 #
-include(CMake/ctkMacroParseArguments.cmake)
-include(CMake/ctkMacroSetPaths.cmake)
-include(CMake/ctkMacroListFilter.cmake)
-include(CMake/ctkMacroOptionUtils.cmake)
-include(CMake/ctkMacroBuildLib.cmake)
-include(CMake/ctkMacroBuildLibWrapper.cmake)
-include(CMake/ctkMacroBuildPlugin.cmake)
-include(CMake/ctkMacroBuildApp.cmake)
-include(CMake/ctkMacroBuildQtPlugin.cmake)
-include(CMake/ctkMacroCompilePythonScript.cmake)
-include(CMake/ctkMacroGenerateMocs.cmake)
-include(CMake/ctkMacroWrapPythonQt.cmake)
-include(CMake/ctkMacroSetupQt.cmake)
-include(CMake/ctkMacroTargetLibraries.cmake) # Import multiple macros
-include(CMake/ctkFunctionExtractOptionNameAndValue.cmake)
-include(CMake/ctkMacroValidateBuildOptions.cmake)
-include(CMake/ctkMacroAddCtkLibraryOptions.cmake)
-include(CMake/ctkFunctionGenerateDGraphInput.cmake)
-include(CMake/ctkFunctionGenerateProjectXml.cmake)
-include(CMake/ctkFunctionGeneratePluginManifest.cmake)
-include(CMake/ctkMacroGeneratePluginResourceFile.cmake)
-include(CMake/ctkFunctionAddPluginRepo.cmake)
-include(CMake/ctkFunctionCheckCompilerFlags.cmake)
-include(CMake/ctkFunctionCheckoutRepo.cmake)
-include(CMake/ctkFunctionGetIncludeDirs.cmake)
-include(CMake/ctkFunctionGetLibraryDirs.cmake)
-include(CMake/ctkFunctionGetGccVersion.cmake)
-include(CMake/ctkFunctionGetCompilerVisibilityFlags.cmake)
-include(CMake/ctkFunctionCompileSnippets.cmake)
+foreach(file
+  CMake/ctkMacroParseArguments.cmake
+  CMake/ctkMacroSetPaths.cmake
+  CMake/ctkMacroListFilter.cmake
+  CMake/ctkMacroOptionUtils.cmake
+  CMake/ctkMacroBuildLib.cmake
+  CMake/ctkMacroBuildLibWrapper.cmake
+  CMake/ctkMacroBuildPlugin.cmake
+  CMake/ctkMacroBuildApp.cmake
+  CMake/ctkMacroBuildQtPlugin.cmake
+  CMake/ctkMacroCompilePythonScript.cmake
+  CMake/ctkMacroGenerateMocs.cmake
+  CMake/ctkMacroWrapPythonQt.cmake
+  CMake/ctkMacroSetupQt.cmake
+  CMake/ctkMacroTargetLibraries.cmake # Import multiple macros
+  CMake/ctkFunctionExtractOptionNameAndValue.cmake
+  CMake/ctkMacroValidateBuildOptions.cmake
+  CMake/ctkMacroAddCtkLibraryOptions.cmake
+  CMake/ctkFunctionGenerateDGraphInput.cmake
+  CMake/ctkFunctionGenerateProjectXml.cmake
+  CMake/ctkFunctionGeneratePluginManifest.cmake
+  CMake/ctkMacroGeneratePluginResourceFile.cmake
+  CMake/ctkFunctionAddPluginRepo.cmake
+  CMake/ctkFunctionCheckCompilerFlags.cmake
+  CMake/ctkFunctionCheckoutRepo.cmake
+  CMake/ctkFunctionGetIncludeDirs.cmake
+  CMake/ctkFunctionGetLibraryDirs.cmake
+  CMake/ctkFunctionGetGccVersion.cmake
+  CMake/ctkFunctionGetCompilerVisibilityFlags.cmake
+  CMake/ctkFunctionCompileSnippets.cmake
+  )
+  include(${file})
+  install(FILES ${file} DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development)
+endforeach()
+
+foreach(file
+  Libs/ctkExport.h.in
+  )
+  install(FILES ${file} DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development)
+endforeach()
 
 #-----------------------------------------------------------------------------
 # Testing
@@ -944,7 +941,12 @@ endif()
 # Configure files with settings
 #
 configure_file(${CTK_SOURCE_DIR}/CMake/UseCTK.cmake.in
-               ${CTK_SUPERBUILD_BINARY_DIR}/UseCTK.cmake COPYONLY IMMEDIATE)
+               ${CTK_SUPERBUILD_BINARY_DIR}/UseCTK.cmake COPYONLY)
+
+install(
+  FILES ${CTK_SUPERBUILD_BINARY_DIR}/UseCTK.cmake
+  DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
+  )
 
 set(CTK_CONFIG_H_INCLUDE_DIR ${CTK_BINARY_DIR})
 

+ 4 - 2
SuperBuild.cmake

@@ -151,7 +151,7 @@ ExternalProject_Add(${proj}
     -DCMAKE_C_FLAGS_INIT:STRING=${CMAKE_C_FLAGS_INIT}
     -DADDITIONAL_C_FLAGS:STRING=${ADDITIONAL_C_FLAGS}
     -DADDITIONAL_CXX_FLAGS:STRING=${ADDITIONAL_CXX_FLAGS}
-    -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir}
+    -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
     -DCTK_BUILD_SHARED_LIBS:BOOL=${CTK_BUILD_SHARED_LIBS}
     ${CMAKE_OSX_EXTERNAL_PROJECT_ARGS}
     -DDOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:PATH=${DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY}
@@ -161,8 +161,10 @@ ExternalProject_Add(${proj}
     -DCTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${CTK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}
     -DCTK_INSTALL_BIN_DIR:STRING=${CTK_INSTALL_BIN_DIR}
     -DCTK_INSTALL_LIB_DIR:STRING=${CTK_INSTALL_LIB_DIR}
-    -DCTK_INSTALL_QTPLUGIN_DIR:STRING=${CTK_INSTALL_QTPLUGIN_DIR}
+    -DCTK_INSTALL_PLUGIN_DIR:STRING=${CTK_INSTALL_PLUGIN_DIR}
     -DCTK_INSTALL_INCLUDE_DIR:STRING=${CTK_INSTALL_INCLUDE_DIR}
+    -DCTK_INSTALL_PLUGIN_INCLUDE_DIR:STRING=${CTK_INSTALL_PLUGIN_INCLUDE_DIR}
+    -DCTK_INSTALL_QTPLUGIN_DIR:STRING=${CTK_INSTALL_QTPLUGIN_DIR}
     -DCTK_INSTALL_DOC_DIR:STRING=${CTK_INSTALL_DOC_DIR}
     -DCTK_EXTERNAL_LIBRARY_DIRS:STRING=${CTK_EXTERNAL_LIBRARY_DIRS}
     -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}