ctkMacroBuildPlugin.cmake 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. # If a file named manifest_headers.cmake exists, read it
  77. SET(manifest_headers_dep )
  78. IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake")
  79. INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake)
  80. SET(manifest_headers_dep "${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake")
  81. ENDIF()
  82. STRING(REPLACE "_" "." Plugin-SymbolicName ${lib_name})
  83. # --------------------------------------------------------------------------
  84. # Include dirs
  85. SET(my_includes
  86. ${CMAKE_CURRENT_SOURCE_DIR}
  87. ${CMAKE_CURRENT_BINARY_DIR}
  88. ${MY_INCLUDE_DIRECTORIES}
  89. )
  90. # Add the include directories from the plugin dependencies
  91. # and external dependencies
  92. ctkFunctionGetIncludeDirs(my_includes ${lib_name})
  93. INCLUDE_DIRECTORIES(
  94. ${my_includes}
  95. )
  96. SET(MY_LIBRARY_EXPORT_DIRECTIVE ${MY_EXPORT_DIRECTIVE})
  97. SET(MY_EXPORT_HEADER_PREFIX "${lib_name}_")
  98. SET(MY_LIBNAME ${lib_name})
  99. CONFIGURE_FILE(
  100. ${CTK_EXPORT_HEADER_TEMPLATE}
  101. ${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
  102. )
  103. SET(dynamicHeaders
  104. "${dynamicHeaders};${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h")
  105. # Make sure variable are cleared
  106. SET(MY_MOC_CPP)
  107. SET(MY_UI_CPP)
  108. SET(MY_QRC_SRCS)
  109. # Wrap
  110. QT4_WRAP_CPP(MY_MOC_CPP ${MY_MOC_SRCS})
  111. QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
  112. IF(DEFINED MY_RESOURCES)
  113. QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
  114. ENDIF()
  115. # Add the generated manifest qrc file
  116. SET(manifest_qrc_src )
  117. ctkFunctionGeneratePluginManifest(manifest_qrc_src
  118. ACTIVATIONPOLICY ${Plugin-ActivationPolicy}
  119. CATEGORY ${Plugin-Category}
  120. CONTACT_ADDRESS ${Plugin-ContactAddress}
  121. COPYRIGHT ${Plugin-Copyright}
  122. DESCRIPTION ${Plugin-Description}
  123. DOC_URL ${Plugin-DocURL}
  124. ICON ${Plugin-Icon}
  125. LICENSE ${Plugin-License}
  126. NAME ${Plugin-Name}
  127. REQUIRE_PLUGIN ${Require-Plugin}
  128. SYMBOLIC_NAME ${Plugin-SymbolicName}
  129. VENDOR ${Plugin-Vendor}
  130. VERSION ${Plugin-Version}
  131. )
  132. IF(manifest_headers_dep)
  133. SET_PROPERTY(SOURCE ${manifest_qrc_src} APPEND
  134. PROPERTY OBJECT_DEPENDS ${manifest_headers_dep})
  135. ENDIF()
  136. LIST(APPEND MY_QRC_SRCS ${manifest_qrc_src})
  137. # Add any other additional resource files
  138. IF(MY_CACHED_RESOURCEFILES)
  139. STRING(REPLACE "." "_" _plugin_symbolicname ${Plugin-SymbolicName})
  140. ctkMacroGeneratePluginResourceFile(MY_QRC_SRCS
  141. NAME ${_plugin_symbolicname}_cached.qrc
  142. PREFIX ${Plugin-SymbolicName}
  143. RESOURCES ${MY_CACHED_RESOURCEFILES})
  144. ENDIF()
  145. SOURCE_GROUP("Resources" FILES
  146. ${MY_RESOURCES}
  147. ${MY_UI_FORMS}
  148. )
  149. SOURCE_GROUP("Generated" FILES
  150. ${MY_QRC_SRCS}
  151. ${MY_MOC_CPP}
  152. ${MY_UI_CPP}
  153. )
  154. ADD_LIBRARY(${lib_name} ${MY_LIBRARY_TYPE}
  155. ${MY_SRCS}
  156. ${MY_MOC_CPP}
  157. ${MY_UI_CPP}
  158. ${MY_QRC_SRCS}
  159. )
  160. # Set the output directory for the plugin
  161. SET(output_dir_suffix "plugins")
  162. IF(MY_TEST_PLUGIN)
  163. SET(output_dir_suffix "test_plugins")
  164. ENDIF()
  165. IF(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  166. SET(runtime_output_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${output_dir_suffix}")
  167. ELSE()
  168. SET(runtime_output_dir "${CMAKE_CURRENT_BINARY_DIR}/${output_dir_suffix}")
  169. ENDIF()
  170. IF(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  171. SET(library_output_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${output_dir_suffix}")
  172. ELSE()
  173. SET(library_output_dir "${CMAKE_CURRENT_BINARY_DIR}/${output_dir_suffix}")
  174. ENDIF()
  175. # Apply properties to the library target.
  176. SET_TARGET_PROPERTIES(${lib_name} PROPERTIES
  177. COMPILE_FLAGS "-DQT_PLUGIN"
  178. RUNTIME_OUTPUT_DIRECTORY ${runtime_output_dir}
  179. LIBRARY_OUTPUT_DIRECTORY ${library_output_dir}
  180. PREFIX "lib"
  181. )
  182. # Note: The plugin may be installed in some other location ???
  183. # Install rules
  184. # IF(CTK_BUILD_SHARED_LIBS)
  185. # INSTALL(TARGETS ${lib_name}
  186. # RUNTIME DESTINATION ${CTK_INSTALL_BIN_DIR} COMPONENT Runtime
  187. # LIBRARY DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Runtime
  188. # ARCHIVE DESTINATION ${CTK_INSTALL_LIB_DIR} COMPONENT Development)
  189. # ENDIF()
  190. SET(my_libs
  191. ${MY_TARGET_LIBRARIES}
  192. )
  193. IF(MINGW)
  194. LIST(APPEND my_libs ssp) # add stack smash protection lib
  195. ENDIF()
  196. TARGET_LINK_LIBRARIES(${lib_name} ${my_libs})
  197. # Update CTK_PLUGINS
  198. IF(NOT MY_TEST_PLUGIN)
  199. SET(CTK_PLUGIN_LIBRARIES ${CTK_PLUGIN_LIBRARIES} ${lib_name} CACHE INTERNAL "CTK plugins" FORCE)
  200. ENDIF()
  201. # Install headers
  202. #FILE(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
  203. #INSTALL(FILES
  204. # ${headers}
  205. # ${dynamicHeaders}
  206. # DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
  207. # )
  208. ENDMACRO()