ctkMacroBuildPlugin.cmake 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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.commontk.org/LICENSE
  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. # Depends on:
  22. # CTK/CMake/ctkMacroParseArguments.cmake
  23. # CTK/CMake/ctkMacroGeneratePluginManifest.cmake
  24. #
  25. # This macro takes the usual arguments for building
  26. # a shared library using Qt. Additionally, it generates
  27. # plugin meta-data by creating a MANIFEST.MF text file
  28. # which is embedded in the share library as a Qt resource.
  29. #
  30. # The following variables can be set in a file named
  31. # manifest_headers.cmake, which will then be read by
  32. # this macro:
  33. #
  34. # Plugin-ActivationPolicy
  35. # Plugin-Category
  36. # Plugin-ContactAddress
  37. # Plugin-Copyright
  38. # Plugin-Description
  39. # Plugin-DocURL
  40. # Plugin-Icon
  41. # Plugin-License
  42. # Plugin-Name
  43. # Require-Plugin
  44. # Plugin-Vendor
  45. # Plugin-Version
  46. #
  47. MACRO(ctkMacroBuildPlugin)
  48. CtkMacroParseArguments(MY
  49. "EXPORT_DIRECTIVE;SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES;CACHED_RESOURCEFILES;LIBRARY_TYPE"
  50. "TEST_PLUGIN"
  51. ${ARGN}
  52. )
  53. # Sanity checks
  54. IF(NOT DEFINED MY_EXPORT_DIRECTIVE)
  55. MESSAGE(SEND_ERROR "EXPORT_DIRECTIVE is mandatory")
  56. ENDIF()
  57. IF(NOT DEFINED MY_LIBRARY_TYPE)
  58. SET(MY_LIBRARY_TYPE "SHARED")
  59. ENDIF()
  60. # Define library name
  61. SET(lib_name ${PROJECT_NAME})
  62. # Clear the variables for the manifest headers
  63. SET(Plugin-ActivationPolicy )
  64. SET(Plugin-Category )
  65. SET(Plugin-ContactAddress )
  66. SET(Plugin-Copyright )
  67. SET(Plugin-Description )
  68. SET(Plugin-DocURL )
  69. SET(Plugin-Icon )
  70. SET(Plugin-License )
  71. SET(Plugin-Name )
  72. SET(Require-Plugin )
  73. SET(Plugin-SymbolicName )
  74. SET(Plugin-Vendor )
  75. SET(Plugin-Version )
  76. SET(Custom-Headers )
  77. IF(MY_TEST_PLUGIN)
  78. # Since the test plug-ins are not considered when calculating
  79. # target dependencies via DGraph, we add the dependencies
  80. # manually here
  81. #MESSAGE("${lib_name}_DEPENDENCIES ${MY_TARGET_LIBRARIES}")
  82. LIST(APPEND ${lib_name}_DEPENDENCIES ${MY_TARGET_LIBRARIES})
  83. ENDIF()
  84. # If a file named manifest_headers.cmake exists, read it
  85. SET(manifest_headers_dep )
  86. IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake")
  87. INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake)
  88. SET(manifest_headers_dep "${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake")
  89. ENDIF()
  90. STRING(REPLACE "_" "." Plugin-SymbolicName ${lib_name})
  91. # --------------------------------------------------------------------------
  92. # Include dirs
  93. SET(my_includes
  94. ${CMAKE_CURRENT_SOURCE_DIR}
  95. ${CMAKE_CURRENT_BINARY_DIR}
  96. ${MY_INCLUDE_DIRECTORIES}
  97. )
  98. # Add the include directories from the plugin dependencies
  99. # and external dependencies
  100. ctkFunctionGetIncludeDirs(my_includes ${lib_name})
  101. INCLUDE_DIRECTORIES(
  102. ${my_includes}
  103. )
  104. SET(MY_LIBRARY_EXPORT_DIRECTIVE ${MY_EXPORT_DIRECTIVE})
  105. SET(MY_EXPORT_HEADER_PREFIX "${lib_name}_")
  106. SET(MY_LIBNAME ${lib_name})
  107. CONFIGURE_FILE(
  108. ${CTK_EXPORT_HEADER_TEMPLATE}
  109. ${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
  110. )
  111. SET(dynamicHeaders
  112. "${dynamicHeaders};${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h")
  113. # Make sure variable are cleared
  114. SET(MY_MOC_CPP)
  115. SET(MY_UI_CPP)
  116. SET(MY_QRC_SRCS)
  117. # Wrap
  118. QT4_WRAP_CPP(MY_MOC_CPP ${MY_MOC_SRCS})
  119. QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
  120. IF(DEFINED MY_RESOURCES)
  121. QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
  122. ENDIF()
  123. # Add the generated manifest qrc file
  124. SET(manifest_qrc_src )
  125. ctkFunctionGeneratePluginManifest(manifest_qrc_src
  126. ACTIVATIONPOLICY ${Plugin-ActivationPolicy}
  127. CATEGORY ${Plugin-Category}
  128. CONTACT_ADDRESS ${Plugin-ContactAddress}
  129. COPYRIGHT ${Plugin-Copyright}
  130. DESCRIPTION ${Plugin-Description}
  131. DOC_URL ${Plugin-DocURL}
  132. ICON ${Plugin-Icon}
  133. LICENSE ${Plugin-License}
  134. NAME ${Plugin-Name}
  135. REQUIRE_PLUGIN ${Require-Plugin}
  136. SYMBOLIC_NAME ${Plugin-SymbolicName}
  137. VENDOR ${Plugin-Vendor}
  138. VERSION ${Plugin-Version}
  139. CUSTOM_HEADERS ${Custom-Headers}
  140. )
  141. IF(manifest_headers_dep)
  142. SET_PROPERTY(SOURCE ${manifest_qrc_src} APPEND
  143. PROPERTY OBJECT_DEPENDS ${manifest_headers_dep})
  144. ENDIF()
  145. LIST(APPEND MY_QRC_SRCS ${manifest_qrc_src})
  146. # Add any other additional resource files
  147. IF(MY_CACHED_RESOURCEFILES)
  148. STRING(REPLACE "." "_" _plugin_symbolicname ${Plugin-SymbolicName})
  149. ctkMacroGeneratePluginResourceFile(MY_QRC_SRCS
  150. NAME ${_plugin_symbolicname}_cached.qrc
  151. PREFIX ${Plugin-SymbolicName}
  152. RESOURCES ${MY_CACHED_RESOURCEFILES})
  153. ENDIF()
  154. SOURCE_GROUP("Resources" FILES
  155. ${MY_RESOURCES}
  156. ${MY_UI_FORMS}
  157. )
  158. SOURCE_GROUP("Generated" FILES
  159. ${MY_QRC_SRCS}
  160. ${MY_MOC_CPP}
  161. ${MY_UI_CPP}
  162. )
  163. ADD_LIBRARY(${lib_name} ${MY_LIBRARY_TYPE}
  164. ${MY_SRCS}
  165. ${MY_MOC_CPP}
  166. ${MY_UI_CPP}
  167. ${MY_QRC_SRCS}
  168. )
  169. # Set the output directory for the plugin
  170. SET(output_dir_suffix "plugins")
  171. IF(MY_TEST_PLUGIN)
  172. SET(output_dir_suffix "test_plugins")
  173. ENDIF()
  174. IF(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  175. SET(runtime_output_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${output_dir_suffix}")
  176. ELSE()
  177. SET(runtime_output_dir "${CMAKE_CURRENT_BINARY_DIR}/${output_dir_suffix}")
  178. ENDIF()
  179. IF(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  180. SET(library_output_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${output_dir_suffix}")
  181. ELSE()
  182. SET(library_output_dir "${CMAKE_CURRENT_BINARY_DIR}/${output_dir_suffix}")
  183. ENDIF()
  184. # Apply properties to the library target.
  185. SET_TARGET_PROPERTIES(${lib_name} PROPERTIES
  186. COMPILE_FLAGS "-DQT_PLUGIN"
  187. RUNTIME_OUTPUT_DIRECTORY ${runtime_output_dir}
  188. LIBRARY_OUTPUT_DIRECTORY ${library_output_dir}
  189. PREFIX "lib"
  190. )
  191. # Note: The plugin may be installed in some other location ???
  192. # Install rules
  193. # IF(CTK_BUILD_SHARED_LIBS)
  194. # INSTALL(TARGETS ${lib_name}
  195. # RUNTIME DESTINATION ${CTK_INSTALL_BIN_DIR} COMPONENT Runtime
  196. # LIBRARY DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Runtime
  197. # ARCHIVE DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Development)
  198. # ENDIF()
  199. SET(my_libs
  200. ${MY_TARGET_LIBRARIES}
  201. )
  202. IF(MINGW)
  203. LIST(APPEND my_libs ssp) # add stack smash protection lib
  204. ENDIF()
  205. TARGET_LINK_LIBRARIES(${lib_name} ${my_libs})
  206. # Update CTK_PLUGINS
  207. IF(NOT MY_TEST_PLUGIN)
  208. SET(CTK_PLUGIN_LIBRARIES ${CTK_PLUGIN_LIBRARIES} ${lib_name} CACHE INTERNAL "CTK plugins" FORCE)
  209. ENDIF()
  210. # Install headers
  211. #FILE(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
  212. #INSTALL(FILES
  213. # ${headers}
  214. # ${dynamicHeaders}
  215. # DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
  216. # )
  217. ENDMACRO()