1###########################################################################
5# Copyright (c) Kitware Inc.
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
11# http://www.apache.org/licenses/LICENSE-2.0.txt
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
19###########################################################################
20###########################################################################
22# Program: Visualization Toolkit
23# Module: vtkGenerateVTKConfig.cmake
25# Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
28# See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
30# This software is distributed WITHOUT ANY WARRANTY; without even
31# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
32# PURPOSE. See the above copyright notice for more information.
34###########################################################################
37# Generate the CTKConfig.cmake file in the build tree. Also configure
38# one for installation. The file tells external projects how to use CTK.
41message(STATUS "Including CMake built-in module CMakePackageConfigHelpers")
42include(CMakePackageConfigHelpers OPTIONAL)
43if(COMMAND configure_package_config_file)
44 message(STATUS "Including CMake built-in module CMakePackageConfigHelpers - ok")
46 message(STATUS "Including CMake built-in module CMakePackageConfigHelpers - failed")
47 message(STATUS "Including CTK module CMakePackageConfigHelpers")
48 list(APPEND CMAKE_MODULE_PATH ${CTK_CMAKE_DIR}/configure_package_config_file)
49 include(CMakePackageConfigHelpers)
50 message(STATUS "Including CTK module CMakePackageConfigHelpers - ok")
53include(ctkFunctionGeneratePluginUseFile)
55set(CTKTesting_CMAKE_DIR_CONFIG "${CTKTesting_SOURCE_DIR}/CMake")
58# Plug-in output directory
60 set(_plugin_output_type "RUNTIME")
62 set(_plugin_output_type "LIBRARY")
64if(DEFINED CTK_PLUGIN_${_plugin_output_type}_OUTPUT_DIRECTORY)
65 if(IS_ABSOLUTE "${CTK_PLUGIN_${_plugin_output_type}_OUTPUT_DIRECTORY}")
66 set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CTK_PLUGIN_${_plugin_output_type}_OUTPUT_DIRECTORY}")
68 set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CMAKE_${_plugin_output_type}_OUTPUT_DIRECTORY}/${CTK_PLUGIN_${_plugin_output_type}_OUTPUT_DIRECTORY}")
71 set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CMAKE_${_plugin_output_type}_OUTPUT_DIRECTORY}/plugins")
74# CMake extension module directory.
75set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
76set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
78# Build configuration information.
79set(CTK_CONFIGURATION_TYPES_CONFIG ${CMAKE_CONFIGURATION_TYPES})
80set(CTK_BUILD_TYPE_CONFIG ${CMAKE_BUILD_TYPE})
82#-----------------------------------------------------------------------------
84 ${CTK_SOURCE_DIR}/CMake/ctkConfig.h.in
85 ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h @ONLY
89 FILES ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h
90 DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
93#-----------------------------------------------------------------------------
94# Generate a file containing plugin specific variables
95set(ctk_plugin_use_file "${CTK_SUPERBUILD_BINARY_DIR}/CTKPluginUseFile.cmake")
96ctkFunctionGeneratePluginUsefile(${ctk_plugin_use_file})
99 FILES ${ctk_plugin_use_file}
100 DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
103#-----------------------------------------------------------------------------
104# Generate list of target to exports
105set(CTK_TARGETS_TO_EXPORT ${CTK_LIBRARIES} ${CTK_PLUGIN_LIBRARIES})
107# Append CTK PythonQt static libraries
108if(NOT CTK_BUILD_SHARED_LIBS)
109 foreach(lib ${CTK_WRAPPED_LIBRARIES_PYTHONQT})
110 list(APPEND CTK_TARGETS_TO_EXPORT ${lib}PythonQt)
114# Export targets so they can be imported by a project using CTK
115# as an external library
116export(TARGETS ${CTK_TARGETS_TO_EXPORT} FILE ${CTK_SUPERBUILD_BINARY_DIR}/CTKExports.cmake)
118install(EXPORT CTKExports DESTINATION ${CTK_INSTALL_CMAKE_DIR})
120#-----------------------------------------------------------------------------
121# Configure 'CTKConfig.cmake' for a build tree
123# CTK external projects variables
124set(CTK_SUPERBUILD_EP_VARS_CONFIG)
125foreach(varname ${CTK_EP_LABEL_FIND_PACKAGE_VARS} ${CTK_EP_LABEL_FIND_PACKAGE})
126 set(CTK_SUPERBUILD_EP_VARS_CONFIG
127 "${CTK_SUPERBUILD_EP_VARS_CONFIG}
128set(${varname} \"${${varname}}\")")
130foreach(varname ${CTK_EP_LABEL_FIND_PACKAGE})
131 string(REPLACE "_DIR" "" package_name "${varname}")
132 set(CTK_SUPERBUILD_EP_VARS_CONFIG
133 "${CTK_SUPERBUILD_EP_VARS_CONFIG}
134find_dependency(${package_name})")
137set(CTK_CONFIG_DIR_CONFIG ${CTK_SUPERBUILD_BINARY_DIR})
138set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
139set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
140set(CTK_CONFIG_H_INCLUDE_DIR_CONFIG ${CTK_CONFIG_H_INCLUDE_DIR})
141set(CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG ${CTK_SOURCE_DIR}/Libs)
142set(CTK_LIBRARY_DIR_CONFIG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
144set(CTK_CONFIG_CODE "####### Expanded from \@CTK_CONFIG_CODE\@ #######\n")
145set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# The CTK DGraph executable used to compute target dependency graphs\n")
146set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_DGRAPH_EXECUTABLE \"${DGraph_EXECUTABLE}\")\n")
147set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Qt configuration\n")
148if(CTK_QT_VERSION STREQUAL "4")
149 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_QT_QMAKE_EXECUTABLE \"${QT_QMAKE_EXECUTABLE}\")\n") # FIXME: Just pass Qt version (and bitness?)
150elseif(DEFINED Qt5_DIR)
151 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_Qt5_DIR \"${Qt5_DIR}\")\n")
152elseif(DEFINED CMAKE_PREFIX_PATH)
153 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_CMAKE_PREFIX_PATH \"${CMAKE_PREFIX_PATH}\")\n")
155set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# The CTK Qt designer plugins directory\n")
156set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_QTDESIGNERPLUGINS_DIR \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")\n")
157set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
159foreach(lib ${CTK_LIBRARIES} CTKTesting)
160 set(${lib}_INCLUDE_DIRS ${${lib}_SOURCE_DIR} ${${lib}_BINARY_DIR})
161 ctkFunctionGetIncludeDirs(${lib}_INCLUDE_DIRS ${lib})
162 list(APPEND _include_dirs ${${lib}_INCLUDE_DIRS})
163 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_INCLUDE_DIRS \"${${lib}_INCLUDE_DIRS}\")\n")
165list(REMOVE_DUPLICATES _include_dirs)
166set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"${_include_dirs}\")\n")
167set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
168foreach(lib ${CTK_LIBRARIES})
169 set(${lib}_LIBRARY_DIRS "")
170 ctkFunctionGetLibraryDirs(${lib}_LIBRARY_DIRS ${lib})
171 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_LIBRARY_DIRS \"${${lib}_LIBRARY_DIRS}\")\n")
173set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# External project libraries\n")
174set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_EXTERNAL_LIBRARIES \"${CTK_EXTERNAL_LIBRARIES}\")\n")
175if(DEFINED DCMTK_HAVE_CONFIG_H_OPTIONAL AND NOT DCMTK_HAVE_CONFIG_H_OPTIONAL AND TARGET CTKDICOMCore)
176 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Definition required to build DCMTK dependent libraries\n")
177 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}if(\"\${CMAKE_VERSION}\" VERSION_GREATER 2.8.10)\n")
178 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE} set_target_properties(CTKDICOMCore PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${DCMTK_DEFINITIONS})\n")
179 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}endif()\n")
181set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
183set(ctk_config ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfig.cmake)
185configure_package_config_file(
186 ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
188 INSTALL_DESTINATION ${CTK_SUPERBUILD_BINARY_DIR}
190 CTK_CONFIG_DIR_CONFIG
192 CTK_CMAKE_UTILITIES_DIR_CONFIG
193 CTK_CONFIG_H_INCLUDE_DIR_CONFIG
194 CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG
195 CTK_LIBRARY_DIR_CONFIG
196 NO_CHECK_REQUIRED_COMPONENTS_MACRO
199#-----------------------------------------------------------------------------
200# Configure 'CTKConfig.cmake' for an install tree
202# CTK external projects. We rely on externally set
203# _DIR variables or a proper CMAKE_PREFIX_PATH such
204# that find_dependency/find_package can successfully
205# find the external project.
206set(CTK_SUPERBUILD_EP_VARS_CONFIG)
207foreach(varname ${CTK_EP_LABEL_FIND_PACKAGE})
208 string(REPLACE "_DIR" "" package_name "${varname}")
209 set(CTK_SUPERBUILD_EP_VARS_CONFIG
210 "${CTK_SUPERBUILD_EP_VARS_CONFIG}
211find_dependency(${package_name})")
214set(CTK_CONFIG_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
215set(CTK_CMAKE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
216set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
217set(CTK_CONFIG_H_INCLUDE_DIR_CONFIG ${CTK_INSTALL_INCLUDE_DIR})
218set(CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
219set(CTK_LIBRARY_DIR_CONFIG ${CTK_INSTALL_LIB_DIR})
221set(CTK_CONFIG_CODE "####### Expanded from \@CTK_CONFIG_CODE\@ #######\n")
222set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
223foreach(libname ${CTK_LIBRARIES})
224 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${libname}_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
226set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
227set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
228foreach(lib ${CTK_LIBRARIES})
229 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_LIBRARY_DIRS \"\")\n")
231if(DEFINED DCMTK_HAVE_CONFIG_H_OPTIONAL AND NOT DCMTK_HAVE_CONFIG_H_OPTIONAL AND TARGET CTKDICOMCore)
232 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Definition required to build DCMTK dependent libraries\n")
233 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}if(\"\${CMAKE_VERSION}\" VERSION_GREATER 2.8.10)\n")
234 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE} set_target_properties(CTKDICOMCore PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${DCMTK_DEFINITIONS})\n")
235 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}endif()\n")
238set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
240set(ctk_install_config ${CMAKE_BINARY_DIR}/CMakeFiles/CTKConfig.cmake)
242configure_package_config_file(
243 ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
244 ${ctk_install_config}
245 INSTALL_DESTINATION ${CTK_INSTALL_CMAKE_DIR}
247 CTK_CONFIG_DIR_CONFIG
249 CTK_CMAKE_UTILITIES_DIR_CONFIG
250 CTK_CONFIG_H_INCLUDE_DIR_CONFIG
251 CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG
252 CTK_LIBRARY_DIR_CONFIG
253 NO_CHECK_REQUIRED_COMPONENTS_MACRO
257 FILES ${ctk_install_config}
258 DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
261#-----------------------------------------------------------------------------
262# Configure and install 'CTKConfigVersion.cmake'
263set(ctk_config_version ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfigVersion.cmake)
264write_basic_package_version_file(
265 ${ctk_config_version}
266 VERSION ${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_PATCH_VERSION}
267 COMPATIBILITY SameMajorVersion
271 FILES ${ctk_config_version}
272 DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development