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
27 # All rights reserved.
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.
41 message(STATUS "Including CMake built-in module CMakePackageConfigHelpers")
42 include(CMakePackageConfigHelpers OPTIONAL)
43 if(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")
53 include(ctkFunctionGeneratePluginUseFile)
55 set(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")
64 if(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.
75 set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
76 set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
78 # Build configuration information.
79 set(CTK_CONFIGURATION_TYPES_CONFIG ${CMAKE_CONFIGURATION_TYPES})
80 set(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
95 set(ctk_plugin_use_file "${CTK_SUPERBUILD_BINARY_DIR}/CTKPluginUseFile.cmake")
96 ctkFunctionGeneratePluginUsefile(${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
105 set(CTK_TARGETS_TO_EXPORT ${CTK_LIBRARIES} ${CTK_PLUGIN_LIBRARIES})
107 # Append CTK PythonQt static libraries
108 if(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
116 export(TARGETS ${CTK_TARGETS_TO_EXPORT} FILE ${CTK_SUPERBUILD_BINARY_DIR}/CTKExports.cmake)
118 install(EXPORT CTKExports DESTINATION ${CTK_INSTALL_CMAKE_DIR})
120 #-----------------------------------------------------------------------------
121 # Configure 'CTKConfig.cmake' for a build tree
123 # CTK external projects variables
124 set(CTK_SUPERBUILD_EP_VARS_CONFIG)
125 foreach(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}
128 set(${varname} \"${${varname}}\")")
130 foreach(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}
134 find_dependency(${package_name})")
137 set(CTK_CONFIG_DIR_CONFIG ${CTK_SUPERBUILD_BINARY_DIR})
138 set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
139 set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
140 set(CTK_CONFIG_H_INCLUDE_DIR_CONFIG ${CTK_CONFIG_H_INCLUDE_DIR})
141 set(CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG ${CTK_SOURCE_DIR}/Libs)
142 set(CTK_LIBRARY_DIR_CONFIG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
144 set(CTK_CONFIG_CODE "####### Expanded from \@CTK_CONFIG_CODE\@ #######\n")
145 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# The CTK DGraph executable used to compute target dependency graphs\n")
146 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_DGRAPH_EXECUTABLE \"${DGraph_EXECUTABLE}\")\n")
147 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Qt configuration\n")
148 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_QT_QMAKE_EXECUTABLE \"${QT_QMAKE_EXECUTABLE}\")\n") # FIXME: Just pass Qt version (and bitness?)
149 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# The CTK Qt designer plugins directory\n")
150 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_QTDESIGNERPLUGINS_DIR \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")\n")
151 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
153 foreach(lib ${CTK_LIBRARIES} CTKTesting)
154 set(${lib}_INCLUDE_DIRS ${${lib}_SOURCE_DIR} ${${lib}_BINARY_DIR})
155 ctkFunctionGetIncludeDirs(${lib}_INCLUDE_DIRS ${lib})
156 list(APPEND _include_dirs ${${lib}_INCLUDE_DIRS})
157 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_INCLUDE_DIRS \"${${lib}_INCLUDE_DIRS}\")\n")
159 list(REMOVE_DUPLICATES _include_dirs)
160 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"${_include_dirs}\")\n")
161 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
162 foreach(lib ${CTK_LIBRARIES})
163 set(${lib}_LIBRARY_DIRS "")
164 ctkFunctionGetLibraryDirs(${lib}_LIBRARY_DIRS ${lib})
165 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_LIBRARY_DIRS \"${${lib}_LIBRARY_DIRS}\")\n")
167 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# External project libraries\n")
168 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_EXTERNAL_LIBRARIES \"${CTK_EXTERNAL_LIBRARIES}\")\n")
169 if(DEFINED DCMTK_HAVE_CONFIG_H_OPTIONAL AND NOT DCMTK_HAVE_CONFIG_H_OPTIONAL AND TARGET CTKDICOMCore)
170 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Definition required to build DCMTK dependent libraries\n")
171 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}if(\"\${CMAKE_VERSION}\" VERSION_GREATER 2.8.10)\n")
172 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE} set_target_properties(CTKDICOMCore PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${DCMTK_DEFINITIONS})\n")
173 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}endif()\n")
175 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
177 set(ctk_config ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfig.cmake)
179 configure_package_config_file(
180 ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
182 INSTALL_DESTINATION ${CTK_SUPERBUILD_BINARY_DIR}
184 CTK_CONFIG_DIR_CONFIG
186 CTK_CMAKE_UTILITIES_DIR_CONFIG
187 CTK_CONFIG_H_INCLUDE_DIR_CONFIG
188 CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG
189 CTK_LIBRARY_DIR_CONFIG
190 NO_CHECK_REQUIRED_COMPONENTS_MACRO
193 #-----------------------------------------------------------------------------
194 # Configure 'CTKConfig.cmake' for an install tree
196 # CTK external projects. We rely on externally set
197 # _DIR variables or a proper CMAKE_PREFIX_PATH such
198 # that find_dependency/find_package can successfully
199 # find the external project.
200 set(CTK_SUPERBUILD_EP_VARS_CONFIG)
201 foreach(varname ${CTK_EP_LABEL_FIND_PACKAGE})
202 string(REPLACE "_DIR" "" package_name "${varname}")
203 set(CTK_SUPERBUILD_EP_VARS_CONFIG
204 "${CTK_SUPERBUILD_EP_VARS_CONFIG}
205 find_dependency(${package_name})")
208 set(CTK_CONFIG_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
209 set(CTK_CMAKE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
210 set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
211 set(CTK_CONFIG_H_INCLUDE_DIR_CONFIG ${CTK_INSTALL_INCLUDE_DIR})
212 set(CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
213 set(CTK_LIBRARY_DIR_CONFIG ${CTK_INSTALL_LIB_DIR})
215 set(CTK_CONFIG_CODE "####### Expanded from \@CTK_CONFIG_CODE\@ #######\n")
216 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
217 foreach(libname ${CTK_LIBRARIES})
218 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${libname}_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
220 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
221 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
222 foreach(lib ${CTK_LIBRARIES})
223 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_LIBRARY_DIRS \"\")\n")
225 if(DEFINED DCMTK_HAVE_CONFIG_H_OPTIONAL AND NOT DCMTK_HAVE_CONFIG_H_OPTIONAL AND TARGET CTKDICOMCore)
226 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Definition required to build DCMTK dependent libraries\n")
227 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}if(\"\${CMAKE_VERSION}\" VERSION_GREATER 2.8.10)\n")
228 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE} set_target_properties(CTKDICOMCore PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${DCMTK_DEFINITIONS})\n")
229 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}endif()\n")
232 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
234 set(ctk_install_config ${CMAKE_BINARY_DIR}/CMakeFiles/CTKConfig.cmake)
236 configure_package_config_file(
237 ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
238 ${ctk_install_config}
239 INSTALL_DESTINATION ${CTK_INSTALL_CMAKE_DIR}
241 CTK_CONFIG_DIR_CONFIG
243 CTK_CMAKE_UTILITIES_DIR_CONFIG
244 CTK_CONFIG_H_INCLUDE_DIR_CONFIG
245 CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG
246 CTK_LIBRARY_DIR_CONFIG
247 NO_CHECK_REQUIRED_COMPONENTS_MACRO
251 FILES ${ctk_install_config}
252 DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
255 #-----------------------------------------------------------------------------
256 # Configure and install 'CTKConfigVersion.cmake'
257 set(ctk_config_version ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfigVersion.cmake)
258 write_basic_package_version_file(
259 ${ctk_config_version}
260 VERSION ${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_PATCH_VERSION}
261 COMPATIBILITY SameMajorVersion
265 FILES ${ctk_config_version}
266 DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development