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
|
# - Try to find an installed version of Qt based on QT_VERSION
# Once done this will define
#
# Qt4or5_FOUND - The specified Qt version was found
# Qt4or5_<Component>_FOUND - For each <Component> specified, if found
# QT_QMAKE_EXECUTABLE - Path to qmake
# QT_IMPORTS_DIR - Path to qtquick1 imports dir
#
# Use qt4or5_use_modules(target [ LINK_PUBLIC | LINK_PRIVATE ] <modules>)
# to make use of Qt4 or Qt5 on a target
#
# Copyright (c) 2013, Fluendo S.L. <support@fluendo.com>
# Copyright (c) 2013, Collabora Ltd. <info@collabora.com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
set(QT_VERSION "4" CACHE STRING "Qt version used for the build")
macro(_qt4or5_component_name_to_qt_component qt_component component)
if (${component} STREQUAL "Widgets" AND ${QT_VERSION} STREQUAL "4")
set(${qt_component} "Gui")
elseif (${component} STREQUAL "Quick1")
set(${qt_component} "Declarative")
elseif (${component} STREQUAL "Quick2" AND ${QT_VERSION} STREQUAL "5")
set(${qt_component} "Quick")
else()
set(${qt_component} ${component})
endif()
endmacro()
macro(_qt4or5_component_name_from_qt_component component qt_component)
if (${qt_component} STREQUAL "Declarative")
set(${component} "Quick1")
elseif (${qt_component} STREQUAL "Quick")
set(${component} "Quick2")
else()
set(${component} ${qt_component})
endif()
endmacro()
macro(_qt4or5_component_names_to_qt_components output_list)
foreach(module ${ARGN})
_qt4or5_component_name_to_qt_component(qt_component ${module})
list(APPEND ${output_list} ${qt_component})
unset(qt_component)
endforeach()
list(REMOVE_DUPLICATES ${output_list})
endmacro()
if (Qt4or5_FIND_QUIETLY)
set(_Qt4or5_FIND_PACKAGE_ARGS QUIET)
endif()
_qt4or5_component_names_to_qt_components(_Qt4or5_FIND_COMPONENTS ${Qt4or5_FIND_COMPONENTS})
_qt4or5_component_names_to_qt_components(_Qt4or5_FIND_COMPONENTS ${Qt4or5_FIND_OPTIONAL_COMPONENTS})
if (${QT_VERSION} STREQUAL "5")
set(Qt4or5_MIN_VERSION "${Qt5_MIN_VERSION}")
if (NOT Qt4or5_FIND_QUIETLY)
message(STATUS "Using Qt5 (min: ${Qt4or5_MIN_VERSION})")
endif()
# Find Qt5 modules
foreach (qt_component ${_Qt4or5_FIND_COMPONENTS})
find_package(Qt5${qt_component} ${Qt5_MIN_VERSION} ${_Qt4or5_FIND_PACKAGE_ARGS})
if (Qt5${qt_component}_FOUND)
_qt4or5_component_name_from_qt_component(component ${qt_component})
set (Qt4or5_${component}_FOUND TRUE)
unset(component)
endif()
endforeach()
set(_Qt4or5_FOUND ${Qt5Core_FOUND})
# Set QT_QMAKE_EXECUTABLE and QT_IMPORTS_DIR
if (Qt5Core_FOUND)
get_target_property(QT_QMAKE_EXECUTABLE ${Qt5Core_QMAKE_EXECUTABLE} IMPORTED_LOCATION)
function(_QT5_QUERY_QMAKE VAR RESULT)
execute_process(COMMAND "${QT_QMAKE_EXECUTABLE}" -query ${VAR}
RESULT_VARIABLE return_code
OUTPUT_VARIABLE output
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)
if(NOT return_code)
file(TO_CMAKE_PATH "${output}" output)
set(${RESULT} ${output} PARENT_SCOPE)
endif()
endfunction()
_qt5_query_qmake(QT_INSTALL_IMPORTS QT_IMPORTS_DIR)
endif()
# Set pkg-config package names
foreach(component Core Gui Widgets Quick1 Quick2 Test OpenGL)
_qt4or5_component_name_to_qt_component(qt_component ${component})
set(Qt4or5_${component}_PKGCONFIG_DEP "Qt5${qt_component}")
unset(qt_component)
endforeach()
elseif (${QT_VERSION} STREQUAL "4")
set(Qt4or5_MIN_VERSION "${Qt4_MIN_VERSION}")
if (NOT Qt4or5_FIND_QUIETLY)
message(STATUS "Using Qt4 (min: ${Qt4or5_MIN_VERSION})")
endif()
# Find Qt4
set(QT_USE_IMPORTED_TARGETS TRUE)
find_package(Qt4 ${Qt4_MIN_VERSION} ${_Qt4or5_FIND_PACKAGE_ARGS})
set(_Qt4or5_FOUND ${Qt4_FOUND})
# set Qt4or5_Foo_FOUND
foreach (qt_component ${_Qt4or5_FIND_COMPONENTS})
string(TOUPPER ${qt_component} u_qt_component)
if (QT_QT${u_qt_component}_FOUND)
_qt4or5_component_name_from_qt_component(component ${qt_component})
set (Qt4or5_${component}_FOUND TRUE)
# special case for QtWidgets, which is part of QtGui in Qt4
if (${component} STREQUAL "Gui")
set(Qt4or5_Widgets_FOUND TRUE)
endif()
unset(component)
endif()
unset(u_qt_component)
endforeach()
# define or include qt4_use_modules()
if (CMAKE_VERSION VERSION_LESS 2.8.10)
# copy-paste from Qt4Macros, just to support cmake 2.8.9
function(qt4_use_modules _target _link_type)
if ("${_link_type}" STREQUAL "LINK_PUBLIC" OR "${_link_type}" STREQUAL "LINK_PRIVATE")
set(modules ${ARGN})
set(link_type ${_link_type})
else()
set(modules ${_link_type} ${ARGN})
endif()
foreach(_module ${modules})
string(TOUPPER ${_module} _ucmodule)
if (NOT QT_QT${_ucmodule}_FOUND)
message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
endif()
if ("${_ucmodule}" STREQUAL "MAIN")
message(FATAL_ERROR "Can not use \"${_module}\" module with qt4_use_modules.")
endif()
target_link_libraries(${_target} ${link_type} ${QT_QT${_ucmodule}_LIBRARY})
set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES
${QT_QT${_ucmodule}_INCLUDE_DIR} ${QT_HEADERS_DIR} ${QT_MKSPECS_DIR}/default)
set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS
${QT_QT${_ucmodule}_COMPILE_DEFINITIONS})
endforeach()
endfunction()
else()
include(Qt4Macros)
endif()
# Set pkg-config package names
foreach(component Core Gui Widgets Quick1 Quick2 Test OpenGL)
_qt4or5_component_name_to_qt_component(qt_component ${component})
set(Qt4or5_${component}_PKGCONFIG_DEP "Qt${qt_component}")
unset(qt_component)
endforeach()
else()
message(WARNING "Unsupported QT_VERSION specified: ${QT_VERSION}")
set (_Qt4or5_FOUND FALSE)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Qt4or5 FOUND_VAR Qt4or5_FOUND REQUIRED_VARS _Qt4or5_FOUND HANDLE_COMPONENTS)
# qt4or5_use_modules(target [ LINK_PUBLIC | LINK_PRIVATE ] <modules>)
# Supported modules: Core, Gui, Widgets, Quick1, Quick2, Test, OpenGL
function(qt4or5_use_modules _target _link_type)
if ("${_link_type}" STREQUAL "LINK_PUBLIC" OR "${_link_type}" STREQUAL "LINK_PRIVATE")
set(modules ${ARGN})
set(link_type ${_link_type})
else()
set(modules ${_link_type} ${ARGN})
endif()
_qt4or5_component_names_to_qt_components(real_modules ${modules})
# Verify that Qt5 was found before using qt5_* macros,
# otherwise cmake will bail out if they are undefined.
if (${QT_VERSION} STREQUAL "5" AND Qt5Core_FOUND)
qt5_use_modules(${_target} ${link_type} ${real_modules})
elseif (${QT_VERSION} STREQUAL "4")
qt4_use_modules(${_target} ${link_type} ${real_modules})
endif()
endfunction()
# qt4or5_wrap_ui(outfiles inputfile ... )
macro(qt4or5_wrap_ui)
if (${QT_VERSION} STREQUAL "5" AND Qt5Core_FOUND)
qt5_wrap_ui(${ARGV})
elseif (${QT_VERSION} STREQUAL "4")
qt4_wrap_ui(${ARGV})
endif()
endmacro()
# qt4or5_add_resources(outfiles inputfile ... )
macro(qt4or5_add_resources)
if (${QT_VERSION} STREQUAL "5" AND Qt5Core_FOUND)
qt5_add_resources(${ARGV})
elseif (${QT_VERSION} STREQUAL "4")
qt4_add_resources(${ARGV})
endif()
endmacro()
|