CTKGenerateCTKConfig.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. # CTK external projects variables
  68. string(REPLACE "^" ";" CTK_SUPERBUILD_EP_VARNAMES "${CTK_SUPERBUILD_EP_VARNAMES}")
  69. set(CTK_SUPERBUILD_EP_VARS_CONFIG)
  70. foreach(varname ${CTK_SUPERBUILD_EP_VARNAMES})
  71. set(CTK_SUPERBUILD_EP_VARS_CONFIG
  72. "${CTK_SUPERBUILD_EP_VARS_CONFIG}
  73. set(CTK_${varname} \"${${varname}}\")")
  74. endforeach()
  75. # CMake extension module directory.
  76. set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
  77. 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})
  81. #-----------------------------------------------------------------------------
  82. configure_file(
  83. ${CTK_SOURCE_DIR}/CMake/ctkConfig.h.in
  84. ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h @ONLY
  85. )
  86. install(
  87. FILES ${CTK_CONFIG_H_INCLUDE_DIR}/ctkConfig.h
  88. DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
  89. )
  90. #-----------------------------------------------------------------------------
  91. # Generate a file containing plugin specific variables
  92. set(ctk_plugin_use_file "${CTK_SUPERBUILD_BINARY_DIR}/CTKPluginUseFile.cmake")
  93. ctkFunctionGeneratePluginUsefile(${ctk_plugin_use_file})
  94. install(
  95. FILES ${ctk_plugin_use_file}
  96. DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
  97. )
  98. #-----------------------------------------------------------------------------
  99. # Generate list of target to exports
  100. set(CTK_TARGETS_TO_EXPORT ${CTK_LIBRARIES} ${CTK_PLUGIN_LIBRARIES})
  101. # Append CTK PythonQt static libraries
  102. if(NOT CTK_BUILD_SHARED_LIBS)
  103. foreach(lib ${CTK_WRAPPED_LIBRARIES_PYTHONQT})
  104. list(APPEND CTK_TARGETS_TO_EXPORT ${lib}PythonQt)
  105. endforeach()
  106. endif()
  107. # Export targets so they can be imported by a project using CTK
  108. # as an external library
  109. export(TARGETS ${CTK_TARGETS_TO_EXPORT} FILE ${CTK_SUPERBUILD_BINARY_DIR}/CTKExports.cmake)
  110. install(EXPORT CTKExports DESTINATION ${CTK_INSTALL_CMAKE_DIR})
  111. #-----------------------------------------------------------------------------
  112. # Configure 'CTKConfig.cmake' for a build tree
  113. set(CTK_CONFIG_DIR_CONFIG ${CTK_SUPERBUILD_BINARY_DIR})
  114. set(CTK_CMAKE_DIR_CONFIG ${CTK_CMAKE_DIR})
  115. set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_CMAKE_UTILITIES_DIR})
  116. set(CTK_CONFIG_H_INCLUDE_DIR_CONFIG ${CTK_CONFIG_H_INCLUDE_DIR})
  117. set(CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG ${CTK_SOURCE_DIR}/Libs)
  118. set(CTK_LIBRARY_DIR_CONFIG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
  119. set(CTK_CONFIG_CODE "####### Expanded from \@CTK_CONFIG_CODE\@ #######\n")
  120. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# The CTK DGraph executable used to compute target dependency graphs\n")
  121. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_DGRAPH_EXECUTABLE \"${DGraph_EXECUTABLE}\")\n")
  122. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Qt configuration\n")
  123. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_QT_QMAKE_EXECUTABLE \"${QT_QMAKE_EXECUTABLE}\")\n") # FIXME: Just pass Qt version (and bitness?)
  124. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# The CTK Qt designer plugins directory\n")
  125. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_QTDESIGNERPLUGINS_DIR \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")\n")
  126. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
  127. foreach(lib ${CTK_LIBRARIES} CTKTesting)
  128. set(${lib}_INCLUDE_DIRS ${${lib}_SOURCE_DIR} ${${lib}_BINARY_DIR})
  129. ctkFunctionGetIncludeDirs(${lib}_INCLUDE_DIRS ${lib})
  130. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_INCLUDE_DIRS \"${${lib}_INCLUDE_DIRS}\")\n")
  131. endforeach()
  132. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"${CTK_BASE_INCLUDE_DIRS}\")\n")
  133. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}list(APPEND CTK_INCLUDE_DIRS \"${CTKTesting_INCLUDE_DIRS}\")\n")
  134. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
  135. foreach(lib ${CTK_LIBRARIES})
  136. set(${lib}_LIBRARY_DIRS "")
  137. ctkFunctionGetLibraryDirs(${lib}_LIBRARY_DIRS ${lib})
  138. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_LIBRARY_DIRS \"${${lib}_LIBRARY_DIRS}\")\n")
  139. endforeach()
  140. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# External project libraries\n")
  141. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_EXTERNAL_LIBRARIES \"${CTK_EXTERNAL_LIBRARIES}\")\n")
  142. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# External project library directories\n")
  143. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_EXTERNAL_LIBRARY_DIRS \"${CTK_EXTERNAL_LIBRARY_DIRS}\")\n")
  144. if(DEFINED DCMTK_HAVE_CONFIG_H_OPTIONAL AND NOT DCMTK_HAVE_CONFIG_H_OPTIONAL AND TARGET CTKDICOMCore)
  145. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Definition required to build DCMTK dependent libraries\n")
  146. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}if(\"\${CMAKE_VERSION}\" VERSION_GREATER 2.8.10)\n")
  147. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE} set_target_properties(CTKDICOMCore PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${DCMTK_DEFINITIONS})\n")
  148. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}endif()\n")
  149. endif()
  150. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
  151. set(ctk_config ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfig.cmake)
  152. configure_package_config_file(
  153. ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
  154. ${ctk_config}
  155. INSTALL_DESTINATION ${CTK_SUPERBUILD_BINARY_DIR}
  156. PATH_VARS
  157. CTK_CONFIG_DIR_CONFIG
  158. CTK_CMAKE_DIR_CONFIG
  159. CTK_CMAKE_UTILITIES_DIR_CONFIG
  160. CTK_CONFIG_H_INCLUDE_DIR_CONFIG
  161. CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG
  162. CTK_LIBRARY_DIR_CONFIG
  163. NO_CHECK_REQUIRED_COMPONENTS_MACRO
  164. )
  165. #-----------------------------------------------------------------------------
  166. # Configure 'CTKConfig.cmake' for an install tree
  167. set(CTK_CONFIG_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
  168. set(CTK_CMAKE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
  169. set(CTK_CMAKE_UTILITIES_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
  170. set(CTK_CONFIG_H_INCLUDE_DIR_CONFIG ${CTK_INSTALL_INCLUDE_DIR})
  171. set(CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG ${CTK_INSTALL_CMAKE_DIR})
  172. set(CTK_LIBRARY_DIR_CONFIG ${CTK_INSTALL_LIB_DIR})
  173. set(CTK_CONFIG_CODE "####### Expanded from \@CTK_CONFIG_CODE\@ #######\n")
  174. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library include dirctories\n")
  175. foreach(libname ${CTK_LIBRARIES} CTKTesting)
  176. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${libname}_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
  177. endforeach()
  178. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(CTK_INCLUDE_DIRS \"\${PACKAGE_PREFIX_DIR}/${CTK_INSTALL_INCLUDE_DIR}\")\n")
  179. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# CTK library directories that could be used for linking\n")
  180. foreach(lib ${CTK_LIBRARIES})
  181. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}set(${lib}_LIBRARY_DIRS \"\")\n")
  182. endforeach()
  183. if(DEFINED DCMTK_HAVE_CONFIG_H_OPTIONAL AND NOT DCMTK_HAVE_CONFIG_H_OPTIONAL AND TARGET CTKDICOMCore)
  184. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}# Definition required to build DCMTK dependent libraries\n")
  185. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}if(\"\${CMAKE_VERSION}\" VERSION_GREATER 2.8.10)\n")
  186. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE} set_target_properties(CTKDICOMCore PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${DCMTK_DEFINITIONS})\n")
  187. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}endif()\n")
  188. endif()
  189. set(CTK_CONFIG_CODE "${CTK_CONFIG_CODE}##################################################")
  190. set(ctk_install_config ${CMAKE_BINARY_DIR}/CMakeFiles/CTKConfig.cmake)
  191. configure_package_config_file(
  192. ${CMAKE_SOURCE_DIR}/CMake/CTKConfig.cmake.in
  193. ${ctk_install_config}
  194. INSTALL_DESTINATION ${CTK_INSTALL_CMAKE_DIR}
  195. PATH_VARS
  196. CTK_CONFIG_DIR_CONFIG
  197. CTK_CMAKE_DIR_CONFIG
  198. CTK_CMAKE_UTILITIES_DIR_CONFIG
  199. CTK_CONFIG_H_INCLUDE_DIR_CONFIG
  200. CTK_EXPORT_HEADER_TEMPLATE_DIR_CONFIG
  201. CTK_LIBRARY_DIR_CONFIG
  202. NO_CHECK_REQUIRED_COMPONENTS_MACRO
  203. )
  204. install(
  205. FILES ${ctk_install_config}
  206. DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
  207. )
  208. #-----------------------------------------------------------------------------
  209. # Configure and install 'CTKConfigVersion.cmake'
  210. set(ctk_config_version ${CTK_SUPERBUILD_BINARY_DIR}/CTKConfigVersion.cmake)
  211. write_basic_package_version_file(
  212. ${ctk_config_version}
  213. VERSION ${CTK_MAJOR_VERSION}.${CTK_MINOR_VERSION}.${CTK_PATCH_VERSION}
  214. COMPATIBILITY SameMajorVersion
  215. )
  216. install(
  217. FILES ${ctk_config_version}
  218. DESTINATION ${CTK_INSTALL_CMAKE_DIR} COMPONENT Development
  219. )