ctkMacroBuildQtDesignerPlugin.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. # Depends on:
  22. # CTK/CMake/ctkMacroParseArguments.cmake
  23. #
  24. #! \ingroup CMakeAPI
  25. macro(ctkMacroBuildQtDesignerPlugin)
  26. CtkMacroParseArguments(MY
  27. "NAME;EXPORT_DIRECTIVE;SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES"
  28. ""
  29. ${ARGN}
  30. )
  31. # Sanity checks
  32. if(NOT DEFINED MY_NAME)
  33. message(FATAL_ERROR "NAME is mandatory")
  34. endif()
  35. if(NOT DEFINED MY_EXPORT_DIRECTIVE)
  36. message(FATAL_ERROR "EXPORT_DIRECTIVE is mandatory")
  37. endif()
  38. set(MY_LIBRARY_TYPE "MODULE")
  39. # Define library name
  40. set(lib_name ${MY_NAME})
  41. # --------------------------------------------------------------------------
  42. # Include dirs
  43. set(my_includes
  44. ${CTK_BASE_INCLUDE_DIRS}
  45. ${QT_QTDESIGNER_INCLUDE_DIR}
  46. ${CMAKE_CURRENT_SOURCE_DIR}
  47. ${CMAKE_CURRENT_BINARY_DIR}
  48. ${MY_INCLUDE_DIRECTORIES}
  49. )
  50. include_directories(
  51. ${my_includes}
  52. )
  53. set(MY_LIBRARY_EXPORT_DIRECTIVE ${MY_EXPORT_DIRECTIVE})
  54. set(MY_EXPORT_HEADER_PREFIX ${MY_NAME})
  55. string(REGEX REPLACE "^CTK" "ctk" MY_EXPORT_HEADER_PREFIX ${MY_EXPORT_HEADER_PREFIX})
  56. set(MY_LIBNAME ${lib_name})
  57. configure_file(
  58. ${CTK_SOURCE_DIR}/Libs/ctkExport.h.in
  59. ${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
  60. )
  61. set(dynamicHeaders
  62. "${dynamicHeaders};${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h")
  63. # Make sure variable are cleared
  64. set(MY_MOC_CPP)
  65. set(MY_UI_CPP)
  66. set(MY_QRC_SRCS)
  67. # Wrap
  68. QT4_WRAP_CPP(MY_MOC_CPP ${MY_MOC_SRCS})
  69. QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
  70. set(MY_QRC_SRCS "")
  71. if(DEFINED MY_RESOURCES)
  72. QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
  73. endif()
  74. source_group("Resources" FILES
  75. ${MY_RESOURCES}
  76. ${MY_UI_FORMS}
  77. )
  78. source_group("Generated" FILES
  79. ${MY_MOC_CPP}
  80. ${MY_QRC_SRCS}
  81. ${MY_UI_CPP}
  82. )
  83. add_library(${lib_name} ${MY_LIBRARY_TYPE}
  84. ${MY_SRCS}
  85. ${MY_MOC_CPP}
  86. ${MY_UI_CPP}
  87. ${MY_QRC_SRCS}
  88. )
  89. # Extract library name associated with the plugin and use it as label
  90. string(REGEX REPLACE "(.*)Plugins" "\\1" label ${lib_name})
  91. # Apply properties to the library target.
  92. set_target_properties(${lib_name} PROPERTIES
  93. COMPILE_FLAGS "-DQT_PLUGIN"
  94. LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/designer"
  95. LABELS ${label}
  96. )
  97. set(my_libs
  98. ${MY_TARGET_LIBRARIES}
  99. ${QT_QTDESIGNER_LIBRARY}
  100. )
  101. target_link_libraries(${lib_name} ${my_libs})
  102. # Install the library
  103. install(TARGETS ${lib_name}
  104. RUNTIME DESTINATION ${CTK_INSTALL_LIB_DIR}/designer COMPONENT RuntimePlugins
  105. LIBRARY DESTINATION ${CTK_INSTALL_LIB_DIR}/designer COMPONENT RuntimePlugins
  106. ARCHIVE DESTINATION ${CTK_INSTALL_LIB_DIR}/designer COMPONENT Development
  107. )
  108. # Install headers - Are headers required ?
  109. #file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
  110. #install(FILES
  111. # ${headers}
  112. # DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
  113. # )
  114. # Since QtDesigner expects plugin to be directly located under the
  115. # directory 'designer', let's copy them.
  116. if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
  117. get_target_property(FILE_PATH ${lib_name} LOCATION)
  118. get_target_property(DIR_PATH ${lib_name} LIBRARY_OUTPUT_DIRECTORY)
  119. add_custom_command(
  120. TARGET ${lib_name}
  121. POST_BUILD
  122. COMMAND ${CMAKE_COMMAND} -E copy ${FILE_PATH} ${DIR_PATH}/../designer/${CMAKE_SHARED_LIBRARY_PREFIX}${lib_name}${CMAKE_BUILD_TYPE}${CMAKE_SHARED_LIBRARY_SUFFIX}
  123. )
  124. endif()
  125. endmacro()