CTKGenerateCTKConfig.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. # Generate the CTKConfig.cmake file in the build tree. Also configure
  37. # one for installation. The file tells external projects how to use CTK.
  38. #
  39. message(STATUS "Including CMake built-in module CMakePackageConfigHelpers")
  40. include(CMakePackageConfigHelpers OPTIONAL)
  41. if(COMMAND configure_package_config_file)
  42. message(STATUS "Including CMake built-in module CMakePackageConfigHelpers - ok")
  43. else()
  44. message(STATUS "Including CMake built-in module CMakePackageConfigHelpers - failed")
  45. message(STATUS "Including CTK module CMakePackageConfigHelpers")
  46. list(APPEND CMAKE_MODULE_PATH ${CTK_CMAKE_DIR}/configure_package_config_file)
  47. include(CMakePackageConfigHelpers)
  48. message(STATUS "Including CTK module CMakePackageConfigHelpers - ok")
  49. endif()
  50. include(ctkFunctionGeneratePluginUseFile)
  51. set(CTKTesting_CMAKE_DIR_CONFIG "${CTKTesting_SOURCE_DIR}/CMake")
  52. # Plug-in output directory
  53. if(WIN32)
  54. set(_plugin_output_type "RUNTIME")
  55. else()
  56. set(_plugin_output_type "LIBRARY")
  57. endif()
  58. if(DEFINED CTK_PLUGIN_${_plugin_output_type}_OUTPUT_DIRECTORY)
  59. if(IS_ABSOLUTE "${CTK_PLUGIN_${_plugin_output_type}_OUTPUT_DIRECTORY}")
  60. set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CTK_PLUGIN_${_plugin_output_type}_OUTPUT_DIRECTORY}")
  61. else()
  62. set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CMAKE_${_plugin_output_type}_OUTPUT_DIRECTORY}/${CTK_PLUGIN_${_plugin_output_type}_OUTPUT_DIRECTORY}")
  63. endif()
  64. else()
  65. set(CTK_PLUGIN_LIBRARIES_DIR_CONFIG "${CMAKE_${_plugin_output_type}_OUTPUT_DIRECTORY}/plugins")
  66. endif()
  67. # CMake extension module directory.
  68. set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
  69. set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
  70. # Build configuration information.
  71. set(CTK_CONFIGURATION_TYPES_CONFIG ${CMAKE_CONFIGURATION_TYPES})
  72. set(CTK_BUILD_TYPE_CONFIG ${CMAKE_BUILD_TYPE})
  73. #-----------------------------------------------------------------------------
  74. configure_file(
  75. ${CTK_SOURCE_DIR}/CMake/ctkConfig.h.in
  76. ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h @ONLY
  77. )
  78. install(
  79. FILES ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h
  80. DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
  81. )
  82. #-----------------------------------------------------------------------------
  83. # Generate a file containing plugin specific variables
  84. set(ctk_plugin_use_file "${CTK_SUPERBUILD_BINARY_DIR}/CTKPluginUseFile.cmake")
  85. ctkFunctionGeneratePluginUsefile(${ctk_plugin_use_file})
  86. install(
  87. FILES ${ctk_plugin_use_file}
  88. DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
  89. )
  90. #-----------------------------------------------------------------------------
  91. # Generate list of target to exports
  92. set(CTK_TARGETS_TO_EXPORT ${CTK_LIBRARIES} ${CTK_PLUGIN_LIBRARIES})
  93. # Append CTK PythonQt static libraries
  94. if(NOT CTK_BUILD_SHARED_LIBS)
  95. foreach(lib ${CTK_WRAPPED_LIBRARIES_PYTHONQT})
  96. list(APPEND CTK_TARGETS_TO_EXPORT ${lib}PythonQt)
  97. endforeach()
  98. endif()
  99. # Export targets so they can be imported by a project using CTK
  100. # as an external library
  101. export(TARGETS ${CTK_TARGETS_TO_EXPORT} FILE ${CTK_SUPERBUILD_BINARY_DIR}/CTKExports.cmake)
  102. install(EXPORT CTKExports DESTINATION ${CTK_INSTALL_CMAKE_DIR})
  103. #-----------------------------------------------------------------------------
  104. # Configure 'CTKConfig.cmake' for a build tree
  105. # CTK external projects variables
  106. set(CTK_SUPERBUILD_EP_VARS_CONFIG)
  107. foreach(varname ${CTK_EP_LABEL_FIND_PACKAGE_VARS} ${CTK_EP_LABEL_FIND_PACKAGE})
  108. set(CTK_SUPERBUILD_EP_VARS_CONFIG
  109. "${CTK_SUPERBUILD_EP_VARS_CONFIG}
  110. set(${varname} \"${${varname}}\")")
  111. endforeach()
  112. foreach(varname ${CTK_EP_LABEL_FIND_PACKAGE})
  113. string(REPLACE "_DIR" "" package_name "${varname}")
  114. set(CTK_SUPERBUILD_EP_VARS_CONFIG
  115. "${CTK_SUPERBUILD_EP_VARS_CONFIG}
  116. find_dependency(${package_name})")
  117. endforeach()
  118. set(CTK_CONFIG_DIR_CONFIG ${CTK_SUPERBUILD_BINARY_DIR})
  119. set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
  120. set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
  121. set(CTK_CONFIG_H_INCLUDE_DIR_CONFIG ${CTK_CONFIG_H_INCLUDE_DIR})
  122. set(CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG ${CTK_SOURCE_DIR}/Libs)
  123. set(CTK_LIBRARY_DIR_CONFIG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
  124. set(CTK_CONFIG_CODE "####### Expanded from \@CTK_CONFIG_CODE\@ #######\n")
  125. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# The CTK DGraph executable used to compute target dependency graphs\n")
  126. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_DGRAPH_EXECUTABLE \"${DGraph_EXECUTABLE}\")\n")
  127. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Qt configuration\n")
  128. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_QT_QMAKE_EXECUTABLE \"${QT_QMAKE_EXECUTABLE}\")\n") # FIXME: Just pass Qt version (and bitness?)
  129. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# The CTK Qt designer plugins directory\n")
  130. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_QTDESIGNERPLUGINS_DIR \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")\n")
  131. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
  132. set(_include_dirs)
  133. foreach(lib ${CTK_LIBRARIES} CTKTesting)
  134. set(${lib}_INCLUDE_DIRS ${${lib}_SOURCE_DIR} ${${lib}_BINARY_DIR})
  135. ctkFunctionGetIncludeDirs(${lib}_INCLUDE_DIRS ${lib})
  136. list(APPEND _include_dirs ${${lib}_INCLUDE_DIRS})
  137. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_INCLUDE_DIRS \"${${lib}_INCLUDE_DIRS}\")\n")
  138. endforeach()
  139. list(REMOVE_DUPLICATES _include_dirs)
  140. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"${_include_dirs}\")\n")
  141. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
  142. foreach(lib ${CTK_LIBRARIES})
  143. set(${lib}_LIBRARY_DIRS "")
  144. ctkFunctionGetLibraryDirs(${lib}_LIBRARY_DIRS ${lib})
  145. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_LIBRARY_DIRS \"${${lib}_LIBRARY_DIRS}\")\n")
  146. endforeach()
  147. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# External project libraries\n")
  148. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_EXTERNAL_LIBRARIES \"${CTK_EXTERNAL_LIBRARIES}\")\n")
  149. if(DEFINED DCMTK_HAVE_CONFIG_H_OPTIONAL AND NOT DCMTK_HAVE_CONFIG_H_OPTIONAL AND TARGET CTKDICOMCore)
  150. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Definition required to build DCMTK dependent libraries\n")
  151. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}if(\"\${CMAKE_VERSION}\" VERSION_GREATER 2.8.10)\n")
  152. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE} set_target_properties(CTKDICOMCore PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${DCMTK_DEFINITIONS})\n")
  153. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}endif()\n")
  154. endif()
  155. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
  156. set(ctk_config ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfig.cmake)
  157. configure_package_config_file(
  158. ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
  159. ${ctk_config}
  160. INSTALL_DESTINATION ${CTK_SUPERBUILD_BINARY_DIR}
  161. PATH_VARS
  162. CTK_CONFIG_DIR_CONFIG
  163. CTK_CMAKE_DIR_CONFIG
  164. CTK_CMAKE_UTILITIES_DIR_CONFIG
  165. CTK_CONFIG_H_INCLUDE_DIR_CONFIG
  166. CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG
  167. CTK_LIBRARY_DIR_CONFIG
  168. NO_CHECK_REQUIRED_COMPONENTS_MACRO
  169. )
  170. #-----------------------------------------------------------------------------
  171. # Configure 'CTKConfig.cmake' for an install tree
  172. # CTK external projects. We rely on externally set
  173. # _DIR variables or a proper CMAKE_PREFIX_PATH such
  174. # that find_dependency/find_package can successfully
  175. # find the external project.
  176. set(CTK_SUPERBUILD_EP_VARS_CONFIG)
  177. foreach(varname ${CTK_EP_LABEL_FIND_PACKAGE})
  178. string(REPLACE "_DIR" "" package_name "${varname}")
  179. set(CTK_SUPERBUILD_EP_VARS_CONFIG
  180. "${CTK_SUPERBUILD_EP_VARS_CONFIG}
  181. find_dependency(${package_name})")
  182. endforeach()
  183. set(CTK_CONFIG_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
  184. set(CTK_CMAKE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
  185. set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
  186. set(CTK_CONFIG_H_INCLUDE_DIR_CONFIG ${CTK_INSTALL_INCLUDE_DIR})
  187. set(CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
  188. set(CTK_LIBRARY_DIR_CONFIG ${CTK_INSTALL_LIB_DIR})
  189. set(CTK_CONFIG_CODE "####### Expanded from \@CTK_CONFIG_CODE\@ #######\n")
  190. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
  191. foreach(libname ${CTK_LIBRARIES})
  192. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${libname}_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
  193. endforeach()
  194. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
  195. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
  196. foreach(lib ${CTK_LIBRARIES})
  197. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_LIBRARY_DIRS \"\")\n")
  198. endforeach()
  199. if(DEFINED DCMTK_HAVE_CONFIG_H_OPTIONAL AND NOT DCMTK_HAVE_CONFIG_H_OPTIONAL AND TARGET CTKDICOMCore)
  200. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Definition required to build DCMTK dependent libraries\n")
  201. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}if(\"\${CMAKE_VERSION}\" VERSION_GREATER 2.8.10)\n")
  202. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE} set_target_properties(CTKDICOMCore PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${DCMTK_DEFINITIONS})\n")
  203. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}endif()\n")
  204. endif()
  205. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
  206. set(ctk_install_config ${CMAKE_BINARY_DIR}/CMakeFiles/CTKConfig.cmake)
  207. configure_package_config_file(
  208. ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
  209. ${ctk_install_config}
  210. INSTALL_DESTINATION ${CTK_INSTALL_CMAKE_DIR}
  211. PATH_VARS
  212. CTK_CONFIG_DIR_CONFIG
  213. CTK_CMAKE_DIR_CONFIG
  214. CTK_CMAKE_UTILITIES_DIR_CONFIG
  215. CTK_CONFIG_H_INCLUDE_DIR_CONFIG
  216. CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG
  217. CTK_LIBRARY_DIR_CONFIG
  218. NO_CHECK_REQUIRED_COMPONENTS_MACRO
  219. )
  220. install(
  221. FILES ${ctk_install_config}
  222. DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
  223. )
  224. #-----------------------------------------------------------------------------
  225. # Configure and install 'CTKConfigVersion.cmake'
  226. set(ctk_config_version ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfigVersion.cmake)
  227. write_basic_package_version_file(
  228. ${ctk_config_version}
  229. VERSION ${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_PATCH_VERSION}
  230. COMPATIBILITY SameMajorVersion
  231. )
  232. install(
  233. FILES ${ctk_config_version}
  234. DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
  235. )