1 ###########################################################################
5 # Copyright (c) Kitware Inc.
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
11 # http://www.apache.org/licenses/LICENSE-2.0.txt
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.
19 ###########################################################################
23 # cmake_parse_arguments ( >= CMake 2.8.3)
27 macro(ctkMacroBuildQtPlugin)
28 cmake_parse_arguments(MY
30 "NAME;EXPORT_DIRECTIVE;FOLDER;PLUGIN_DIR" # one value args
31 "SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES" # multi value args
36 if(NOT DEFINED MY_NAME)
37 message(FATAL_ERROR "NAME is mandatory")
39 if(NOT DEFINED MY_EXPORT_DIRECTIVE)
40 message(FATAL_ERROR "EXPORT_DIRECTIVE is mandatory")
42 if (NOT DEFINED MY_PLUGIN_DIR)
43 message(FATAL_ERROR "PLUGIN_DIR (e.g. designer, iconengines, imageformats...) is mandatory")
45 set(MY_LIBRARY_TYPE "MODULE")
48 set(lib_name ${MY_NAME})
50 # --------------------------------------------------------------------------
54 ${QT_QTDESIGNER_INCLUDE_DIR}
55 ${CMAKE_CURRENT_SOURCE_DIR}
56 ${CMAKE_CURRENT_BINARY_DIR}
57 ${MY_INCLUDE_DIRECTORIES}
60 # Add the include directories from the library dependencies
61 ctkFunctionGetIncludeDirs(my_includes ${MY_TARGET_LIBRARIES})
67 set(MY_LIBRARY_EXPORT_DIRECTIVE ${MY_EXPORT_DIRECTIVE})
68 set(MY_EXPORT_HEADER_PREFIX ${MY_NAME})
69 string(REGEX REPLACE "^CTK" "ctk" MY_EXPORT_HEADER_PREFIX ${MY_EXPORT_HEADER_PREFIX})
70 set(MY_LIBNAME ${lib_name})
72 if(NOT CTK_EXPORT_HEADER_TEMPLATE)
73 message(FATAL_ERROR "CTK_EXPORT_HEADER_TEMPLATE is mandatory")
77 ${CTK_EXPORT_HEADER_TEMPLATE}
78 ${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
81 "${dynamicHeaders};${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h")
83 # Make sure variable are cleared
90 if(CTK_QT_VERSION VERSION_GREATER "4")
92 if(Qt5Core_VERSION VERSION_GREATER "5.2.0")
93 set(target TARGET ${MY_LIBNAME})
95 qt5_wrap_cpp(MY_MOC_CPP ${MY_MOC_SRCS} OPTIONS -DHAVE_QT5 ${target})
97 if(DEFINED MY_RESOURCES)
98 qt5_add_resources(MY_QRC_SRCS ${MY_RESOURCES})
101 QT4_WRAP_CPP(MY_MOC_CPP ${MY_MOC_SRCS})
102 if(DEFINED MY_RESOURCES)
103 QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
107 if(CTK_QT_VERSION VERSION_GREATER "4")
109 qt5_wrap_ui(MY_UI_CPP ${MY_UI_FORMS})
111 message(WARNING "Argument UI_FORMS ignored because Qt5Widgets module was not specified")
114 QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
117 source_group("Resources" FILES
122 source_group("Generated" FILES
128 add_library(${lib_name} ${MY_LIBRARY_TYPE}
135 # Extract library name associated with the plugin and use it as label
136 string(REGEX REPLACE "(.*)Plugin[s]?" "\\1" label ${lib_name})
138 # Apply properties to the library target.
139 set(compile_flags "-DQT_PLUGIN")
140 if(CTK_QT_VERSION VERSION_GREATER "4")
141 set(compile_flags "${compile_flags} -DHAVE_QT5")
143 set_target_properties(${lib_name} PROPERTIES
144 COMPILE_FLAGS "${compile_flags}"
145 LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${MY_PLUGIN_DIR}"
150 ${MY_TARGET_LIBRARIES}
151 ${QT_QTDESIGNER_LIBRARY}
153 target_link_libraries(${lib_name} ${my_libs})
155 if(NOT "${MY_FOLDER}" STREQUAL "")
156 set_target_properties(${lib_name} PROPERTIES FOLDER ${MY_FOLDER})
159 # Install the library
160 # CTK_INSTALL_QTPLUGIN_DIR:STRING can be passed when configuring CTK
161 # By default, it is the same path as CTK_INSTALL_LIB_DIR
162 # Plugins are installed in a subdirectory corresponding to their types (e.g. designer, iconengines, imageformats...)
163 install(TARGETS ${lib_name}
164 RUNTIME DESTINATION ${CTK_INSTALL_QTPLUGIN_DIR}/${MY_PLUGIN_DIR} COMPONENT RuntimePlugins
165 LIBRARY DESTINATION ${CTK_INSTALL_QTPLUGIN_DIR}/${MY_PLUGIN_DIR} COMPONENT RuntimePlugins
166 ARCHIVE DESTINATION ${CTK_INSTALL_QTPLUGIN_DIR}/${MY_PLUGIN_DIR} COMPONENT Development
169 # Install headers - Are headers required ?
170 #file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
173 # DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
177 # Since Qt expects plugins to be directly located under the
178 # subdirectory (e.g. 'designer') but not deeper (e.g. designer/Debug), let's copy them.
180 if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
181 get_target_property(DIR_PATH ${lib_name} LIBRARY_OUTPUT_DIRECTORY)
186 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${lib_name}> ${DIR_PATH}/../${MY_PLUGIN_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${lib_name}${CMAKE_BUILD_TYPE}${CMAKE_SHARED_LIBRARY_SUFFIX}
192 macro(ctkMacroBuildQtDesignerPlugin)
193 if(CTK_QT_VERSION VERSION_GREATER "4")
194 find_package(Qt5 COMPONENTS Designer REQUIRED)
195 add_definitions(${Qt5Designer_DEFINITIONS})
196 include_directories(${Qt5Designer_INCLUDE_DIRS})
198 ctkMacroBuildQtPlugin(
201 if(CTK_QT_VERSION VERSION_GREATER "4")
202 cmake_parse_arguments(MY
204 "NAME;EXPORT_DIRECTIVE;FOLDER;PLUGIN_DIR" # one value args
205 "SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES" # multi value args
208 target_link_libraries(${MY_NAME} Qt5::Designer)
212 macro(ctkMacroBuildQtIconEnginesPlugin)
213 ctkMacroBuildQtPlugin(
214 PLUGIN_DIR iconengines
218 macro(ctkMacroBuildQtStylesPlugin)
219 ctkMacroBuildQtPlugin(