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 
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")
45 else()
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")
51 endif()
52 
53 include(ctkFunctionGeneratePluginUseFile)
54 
55 set(CTKTesting_CMAKE_DIR_CONFIG "${CTKTesting_SOURCE_DIR}/CMake")
56 
57 
58 # Plug-in output directory
59 if(WIN32)
60  set(_plugin_output_type "RUNTIME")
61 else()
62  set(_plugin_output_type "LIBRARY")
63 endif()
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}")
67  else()
68  set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CMAKE_${_plugin_output_type}_OUTPUT_DIRECTORY}/${CTK_PLUGIN_${_plugin_output_type}_OUTPUT_DIRECTORY}")
69  endif()
70 else()
71  set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CMAKE_${_plugin_output_type}_OUTPUT_DIRECTORY}/plugins")
72 endif()
73 
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})
77 
78 # Build configuration information.
79 set(CTK_CONFIGURATION_TYPES_CONFIG ${CMAKE_CONFIGURATION_TYPES})
80 set(CTK_BUILD_TYPE_CONFIG ${CMAKE_BUILD_TYPE})
81 
82 #-----------------------------------------------------------------------------
83 configure_file(
84  ${CTK_SOURCE_DIR}/CMake/ctkConfig.h.in
85  ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h @ONLY
86  )
87 
88 install(
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
95 set(ctk_plugin_use_file "${CTK_SUPERBUILD_BINARY_DIR}/CTKPluginUseFile.cmake")
96 ctkFunctionGeneratePluginUsefile(${ctk_plugin_use_file})
97 
98 install(
99  FILES ${ctk_plugin_use_file}
100  DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
101  )
102 
103 #-----------------------------------------------------------------------------
104 # Generate list of target to exports
105 set(CTK_TARGETS_TO_EXPORT ${CTK_LIBRARIES} ${CTK_PLUGIN_LIBRARIES})
106 
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)
111  endforeach()
112 endif()
113 
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)
117 
118 install(EXPORT CTKExports DESTINATION ${CTK_INSTALL_CMAKE_DIR})
119 
120 #-----------------------------------------------------------------------------
121 # Configure 'CTKConfig.cmake' for a build tree
122 
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}}\")")
129 endforeach()
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})")
135 endforeach()
136 
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})
143 
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 if(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?)
150 elseif(DEFINED Qt5_DIR)
151  set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_Qt5_DIR \"${Qt5_DIR}\")\n")
152 elseif(DEFINED CMAKE_PREFIX_PATH)
153  set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_CMAKE_PREFIX_PATH \"${CMAKE_PREFIX_PATH}\")\n")
154 endif()
155 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# The CTK Qt designer plugins directory\n")
156 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_QTDESIGNERPLUGINS_DIR \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")\n")
157 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
158 set(_include_dirs)
159 foreach(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")
164 endforeach()
165 list(REMOVE_DUPLICATES _include_dirs)
166 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"${_include_dirs}\")\n")
167 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
168 foreach(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")
172 endforeach()
173 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# External project libraries\n")
174 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_EXTERNAL_LIBRARIES \"${CTK_EXTERNAL_LIBRARIES}\")\n")
175 if(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")
180 endif()
181 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
182 
183 set(ctk_config ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfig.cmake)
184 
185 configure_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.
206 set(CTK_SUPERBUILD_EP_VARS_CONFIG)
207 foreach(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}
211 find_dependency(${package_name})")
212 endforeach()
213 
214 set(CTK_CONFIG_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
215 set(CTK_CMAKE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
216 set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
217 set(CTK_CONFIG_H_INCLUDE_DIR_CONFIG ${CTK_INSTALL_INCLUDE_DIR})
218 set(CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
219 set(CTK_LIBRARY_DIR_CONFIG ${CTK_INSTALL_LIB_DIR})
220 
221 set(CTK_CONFIG_CODE "####### Expanded from \@CTK_CONFIG_CODE\@ #######\n")
222 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
223 foreach(libname ${CTK_LIBRARIES})
224  set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${libname}_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
225 endforeach()
226 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
227 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
228 foreach(lib ${CTK_LIBRARIES})
229  set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_LIBRARY_DIRS \"\")\n")
230 endforeach()
231 if(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")
236 endif()
237 
238 set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
239 
240 set(ctk_install_config ${CMAKE_BINARY_DIR}/CMakeFiles/CTKConfig.cmake)
241 
242 configure_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 
256 install(
257  FILES ${ctk_install_config}
258  DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
259  )
260 
261 #-----------------------------------------------------------------------------
262 # Configure and install 'CTKConfigVersion.cmake'
263 set(ctk_config_version ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfigVersion.cmake)
264 write_basic_package_version_file(
265  ${ctk_config_version}
266  VERSION ${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_PATCH_VERSION}
267  COMPATIBILITY SameMajorVersion
268  )
269 
270 install(
271  FILES ${ctk_config_version}
272  DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
273  )