CTK 0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
CTKGenerateCTKConfig.cmake
Go to the documentation of this file.
1###########################################################################
2#
3# Library: CTK
4#
5# Copyright (c) Kitware Inc.
6#
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
10#
11# http://www.apache.org/licenses/LICENSE-2.0.txt
12#
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.
18#
19###########################################################################
20###########################################################################
21#
22# Program: Visualization Toolkit
23# Module: vtkGenerateVTKConfig.cmake
24#
25# Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
26#
27# All rights reserved.
28# See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
29#
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.
33#
34###########################################################################
35
36#
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.
39#
40
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")
45else()
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")
51endif()
52
53include(ctkFunctionGeneratePluginUseFile)
54
55set(CTKTesting_CMAKE_DIR_CONFIG "${CTKTesting_SOURCE_DIR}/CMake")
56
57
58# Plug-in output directory
59if(WIN32)
60 set(_plugin_output_type "RUNTIME")
61else()
62 set(_plugin_output_type "LIBRARY")
63endif()
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}")
67 else()
68 set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CMAKE_${_plugin_output_type}_OUTPUT_DIRECTORY}/${CTK_PLUGIN_${_plugin_output_type}_OUTPUT_DIRECTORY}")
69 endif()
70else()
71 set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CMAKE_${_plugin_output_type}_OUTPUT_DIRECTORY}/plugins")
72endif()
73
74# CMake extension module directory.
75set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
76set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
77
78# Build configuration information.
79set(CTK_CONFIGURATION_TYPES_CONFIG ${CMAKE_CONFIGURATION_TYPES})
80set(CTK_BUILD_TYPE_CONFIG ${CMAKE_BUILD_TYPE})
81
82#-----------------------------------------------------------------------------
83configure_file(
84 ${CTK_SOURCE_DIR}/CMake/ctkConfig.h.in
85 ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h @ONLY
86 )
87
88install(
89 FILES ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h
90 DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
91 )
92
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})
97
98install(
99 FILES ${ctk_plugin_use_file}
100 DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
101 )
102
103#-----------------------------------------------------------------------------
104# Generate list of target to exports
105set(CTK_TARGETS_TO_EXPORT ${CTK_LIBRARIES} ${CTK_PLUGIN_LIBRARIES})
106
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)
111 endforeach()
112endif()
113
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)
117
118install(EXPORT CTKExports DESTINATION ${CTK_INSTALL_CMAKE_DIR})
119
120#-----------------------------------------------------------------------------
121# Configure 'CTKConfig.cmake' for a build tree
122
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}}\")")
129endforeach()
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})")
135endforeach()
136
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})
143
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")
154endif()
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")
158set(_include_dirs)
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")
164endforeach()
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")
172endforeach()
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")
180endif()
181set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
182
183set(ctk_config ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfig.cmake)
184
185configure_package_config_file(
186 ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
187 ${ctk_config}
188 INSTALL_DESTINATION ${CTK_SUPERBUILD_BINARY_DIR}
189 PATH_VARS
190 CTK_CONFIG_DIR_CONFIG
191 CTK_CMAKE_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
197 )
198
199#-----------------------------------------------------------------------------
200# Configure 'CTKConfig.cmake' for an install tree
201
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})")
212endforeach()
213
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})
220
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")
225endforeach()
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")
230endforeach()
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")
236endif()
237
238set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
239
240set(ctk_install_config ${CMAKE_BINARY_DIR}/CMakeFiles/CTKConfig.cmake)
241
242configure_package_config_file(
243 ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
244 ${ctk_install_config}
245 INSTALL_DESTINATION ${CTK_INSTALL_CMAKE_DIR}
246 PATH_VARS
247 CTK_CONFIG_DIR_CONFIG
248 CTK_CMAKE_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
254 )
255
256install(
257 FILES ${ctk_install_config}
258 DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
259 )
260
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
268 )
269
270install(
271 FILES ${ctk_config_version}
272 DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
273 )