-
Notifications
You must be signed in to change notification settings - Fork 480
/
ctkMacroBuildQtPlugin.cmake
223 lines (192 loc) · 6.58 KB
/
ctkMacroBuildQtPlugin.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
###########################################################################
#
# Library: CTK
#
# Copyright (c) Kitware Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
#
# Depends on:
# cmake_parse_arguments ( >= CMake 2.8.3)
#
#! \ingroup CMakeAPI
macro(ctkMacroBuildQtPlugin)
cmake_parse_arguments(MY
"" # no options
"NAME;EXPORT_DIRECTIVE;FOLDER;PLUGIN_DIR" # one value args
"SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES" # multi value args
${ARGN}
)
# Sanity checks
if(NOT DEFINED MY_NAME)
message(FATAL_ERROR "NAME is mandatory")
endif()
if(NOT DEFINED MY_EXPORT_DIRECTIVE)
message(FATAL_ERROR "EXPORT_DIRECTIVE is mandatory")
endif()
if (NOT DEFINED MY_PLUGIN_DIR)
message(FATAL_ERROR "PLUGIN_DIR (e.g. designer, iconengines, imageformats...) is mandatory")
endif()
set(MY_LIBRARY_TYPE "MODULE")
# Define library name
set(lib_name ${MY_NAME})
# --------------------------------------------------------------------------
# Include dirs
set(my_includes
${QT_QTDESIGNER_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${MY_INCLUDE_DIRECTORIES}
)
if(CTK_SOURCE_DIR)
# Add the include directories from the library dependencies
ctkFunctionGetIncludeDirs(my_includes ${MY_TARGET_LIBRARIES})
endif()
include_directories(
${my_includes}
)
set(MY_LIBRARY_EXPORT_DIRECTIVE ${MY_EXPORT_DIRECTIVE})
set(MY_EXPORT_HEADER_PREFIX ${MY_NAME})
string(REGEX REPLACE "^CTK" "ctk" MY_EXPORT_HEADER_PREFIX ${MY_EXPORT_HEADER_PREFIX})
set(MY_LIBNAME ${lib_name})
if(NOT CTK_EXPORT_HEADER_TEMPLATE)
message(FATAL_ERROR "CTK_EXPORT_HEADER_TEMPLATE is mandatory")
endif()
configure_file(
${CTK_EXPORT_HEADER_TEMPLATE}
${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
)
set(dynamicHeaders
"${dynamicHeaders};${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h")
# Make sure variable are cleared
set(MY_MOC_CPP)
set(MY_UI_CPP)
set(MY_QRC_SRCS)
# Wrap
set(MY_QRC_SRCS "")
if(CTK_QT_VERSION VERSION_GREATER "4")
set(target)
if(Qt5Core_VERSION VERSION_GREATER "5.2.0")
set(target TARGET ${MY_LIBNAME})
endif()
qt5_wrap_cpp(MY_MOC_CPP ${MY_MOC_SRCS} OPTIONS -DHAVE_QT5 ${target})
if(DEFINED MY_RESOURCES)
qt5_add_resources(MY_QRC_SRCS ${MY_RESOURCES})
endif()
else()
QT4_WRAP_CPP(MY_MOC_CPP ${MY_MOC_SRCS})
if(DEFINED MY_RESOURCES)
QT4_ADD_RESOURCES(MY_QRC_SRCS ${MY_RESOURCES})
endif()
endif()
if(CTK_QT_VERSION VERSION_GREATER "4")
if(Qt5Widgets_FOUND)
qt5_wrap_ui(MY_UI_CPP ${MY_UI_FORMS})
elseif(MY_UI_FORMS)
message(WARNING "Argument UI_FORMS ignored because Qt5Widgets module was not specified")
endif()
else()
QT4_WRAP_UI(MY_UI_CPP ${MY_UI_FORMS})
endif()
source_group("Resources" FILES
${MY_RESOURCES}
${MY_UI_FORMS}
)
source_group("Generated" FILES
${MY_MOC_CPP}
${MY_QRC_SRCS}
${MY_UI_CPP}
)
add_library(${lib_name} ${MY_LIBRARY_TYPE}
${MY_SRCS}
${MY_MOC_CPP}
${MY_UI_CPP}
${MY_QRC_SRCS}
)
# Extract library name associated with the plugin and use it as label
string(REGEX REPLACE "(.*)Plugin[s]?" "\\1" label ${lib_name})
# Apply properties to the library target.
set(compile_flags "-DQT_PLUGIN")
if(CTK_QT_VERSION VERSION_GREATER "4")
set(compile_flags "${compile_flags} -DHAVE_QT5")
endif()
set_target_properties(${lib_name} PROPERTIES
COMPILE_FLAGS "${compile_flags}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${MY_PLUGIN_DIR}"
LABELS ${label}
)
set(my_libs
${MY_TARGET_LIBRARIES}
${QT_QTDESIGNER_LIBRARY}
)
target_link_libraries(${lib_name} ${my_libs})
if(NOT "${MY_FOLDER}" STREQUAL "")
set_target_properties(${lib_name} PROPERTIES FOLDER ${MY_FOLDER})
endif()
# Install the library
# CTK_INSTALL_QTPLUGIN_DIR:STRING can be passed when configuring CTK
# By default, it is the same path as CTK_INSTALL_LIB_DIR
# Plugins are installed in a subdirectory corresponding to their types (e.g. designer, iconengines, imageformats...)
install(TARGETS ${lib_name}
RUNTIME DESTINATION ${CTK_INSTALL_QTPLUGIN_DIR}/${MY_PLUGIN_DIR} COMPONENT RuntimePlugins
LIBRARY DESTINATION ${CTK_INSTALL_QTPLUGIN_DIR}/${MY_PLUGIN_DIR} COMPONENT RuntimePlugins
ARCHIVE DESTINATION ${CTK_INSTALL_QTPLUGIN_DIR}/${MY_PLUGIN_DIR} COMPONENT Development
)
# Install headers - Are headers required ?
#file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
#install(FILES
# ${headers}
# DESTINATION ${CTK_INSTALL_INCLUDE_DIR} COMPONENT Development
# )
# Since Qt expects plugins to be directly located under the
# subdirectory (e.g. 'designer') but not deeper (e.g. designer/Debug), let's copy them.
if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
get_target_property(DIR_PATH ${lib_name} LIBRARY_OUTPUT_DIRECTORY)
add_custom_command(
TARGET ${lib_name}
POST_BUILD
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}
)
endif()
endmacro()
macro(ctkMacroBuildQtDesignerPlugin)
if(CTK_QT_VERSION VERSION_GREATER "4")
find_package(Qt5 COMPONENTS Designer REQUIRED)
add_definitions(${Qt5Designer_DEFINITIONS})
include_directories(${Qt5Designer_INCLUDE_DIRS})
endif()
ctkMacroBuildQtPlugin(
PLUGIN_DIR designer
${ARGN})
if(CTK_QT_VERSION VERSION_GREATER "4")
cmake_parse_arguments(MY
"" # no options
"NAME;EXPORT_DIRECTIVE;FOLDER;PLUGIN_DIR" # one value args
"SRCS;MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES" # multi value args
${ARGN}
)
target_link_libraries(${MY_NAME} Qt5::Designer)
endif()
endmacro()
macro(ctkMacroBuildQtIconEnginesPlugin)
ctkMacroBuildQtPlugin(
PLUGIN_DIR iconengines
${ARGN})
endmacro()
macro(ctkMacroBuildQtStylesPlugin)
ctkMacroBuildQtPlugin(
PLUGIN_DIR styles
${ARGN})
endmacro()