forked from copasi/COPASI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChooseQtVersion.cmake
163 lines (132 loc) · 4.77 KB
/
ChooseQtVersion.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
# Copyright (C) 2019 - 2021 by Pedro Mendes, Rector and Visitors of the
# University of Virginia, University of Heidelberg, and University
# of Connecticut School of Medicine.
# All rights reserved.
# Copyright (C) 2017 - 2018 by Pedro Mendes, Virginia Tech Intellectual
# Properties, Inc., University of Heidelberg, and University of
# of Connecticut School of Medicine.
# All rights reserved.
cmake_minimum_required(VERSION 3.1.0)
set(SELECT_QT "Any" CACHE STRING "The prefered Qt version one of: Qt6, Qt5, Qt4 or Any" )
if (DEFINED SELECT_QT)
if (NOT (${SELECT_QT} MATCHES "Qt5" OR
${SELECT_QT} MATCHES "Qt6" OR
${SELECT_QT} MATCHES "Qt4" OR
${SELECT_QT} MATCHES "Any"))
message(WARNING "Unsupported Qt version: ${SELECT_QT}. Selecting best available.")
set(SELECT_QT " Any")
endif ()
else ()
set(SELECT_QT " Any")
endif(DEFINED SELECT_QT)
if (${SELECT_QT} MATCHES "Any")
set(QT_FIND_MODE QUIET)
else ()
set(QT_FIND_MODE REQUIRED)
endif()
macro(QT_FIND_MODULES)
# Local variables
set(_modules_qt4)
set(_modules_qt5)
set(_modules_qt6)
# Prepare modules
foreach(_module ${ARGN})
list(APPEND _modules_qt4 Qt${_module})
list(APPEND _modules_qt5 ${_module})
list(APPEND _modules_qt6 ${_module})
if(_module MATCHES " Core")
list(APPEND _modules_qt6 "CoreTools")
list(APPEND _modules_qt6 "Core5Compat")
endif()
if(_module MATCHES " Gui")
list(APPEND _modules_qt5 "Widgets")
list(APPEND _modules_qt6 "GuiTools")
list(APPEND _modules_qt6 "WidgetsTools")
endif(_module MATCHES " Gui")
endforeach(_module ${ARGN})
list(REMOVE_DUPLICATES _modules_qt4)
list(REMOVE_DUPLICATES _modules_qt5)
list(REMOVE_DUPLICATES _modules_qt6)
set (CMAKE_PREFIX_PATH_TMP ${CMAKE_PREFIX_PATH})
if (DEFINED ENV{QTDIR})
set (CMAKE_PREFIX_PATH $ENV{QTDIR})
endif ()
# Find Qt libraries
if (${SELECT_QT} MATCHES "Qt5" OR
${SELECT_QT} MATCHES "Any")
find_package(Qt5 ${QT_FIND_MODE} COMPONENTS ${_modules_qt5})
endif()
# Find Qt libraries
if (${SELECT_QT} MATCHES "Qt6" OR
${SELECT_QT} MATCHES "Any")
find_package(Qt6 ${QT_FIND_MODE} COMPONENTS ${_modules_qt6})
endif()
if (${SELECT_QT} MATCHES "Qt4" OR
${SELECT_QT} MATCHES "Any")
find_package(Qt4 ${QT_FIND_MODE} COMPONENTS ${_modules_qt4})
endif()
set (CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH_TMP})
if (NOT (Qt5_FOUND OR Qt4_FOUND OR QT4_FOUND OR Qt6_FOUND))
message(FATAL_ERROR " Qt not found, please specify QT_DIR or Qt5_DIR or Qt6_DIR")
endif (NOT (Qt5_FOUND OR Qt4_FOUND OR QT4_FOUND OR Qt6_FOUND))
if (Qt5_FOUND)
message(STATUS "Using Qt5")
set(QT_VERSION ${Qt5_VERSION})
foreach(_m ${_modules_qt5})
set(QT_INCLUDE_DIRS ${QT_INCLUDE_DIRS} ${Qt5${_m}_INCLUDE_DIRS})
set(QT_LIBRARIES ${QT_LIBRARIES} ${Qt5${_m}_LIBRARIES})
endforeach(_m ${_modules_qt5})
list(REMOVE_DUPLICATES QT_INCLUDE_DIRS)
if (${SELECT_QT} MATCHES "Any")
set (SELECT_QT "Qt5")
endif(${SELECT_QT} MATCHES "Any")
endif (Qt5_FOUND)
if (Qt6_FOUND)
message(STATUS "Using Qt6")
set(QT_VERSION ${Qt6_VERSION})
foreach(_m ${_modules_qt6})
set(QT_INCLUDE_DIRS ${QT_INCLUDE_DIRS} ${Qt6${_m}_INCLUDE_DIRS})
set(QT_LIBRARIES ${QT_LIBRARIES} ${Qt6${_m}_LIBRARIES})
endforeach(_m ${_modules_qt6})
list(REMOVE_DUPLICATES QT_INCLUDE_DIRS)
if (${SELECT_QT} MATCHES "Any")
set (SELECT_QT "Qt6")
endif(${SELECT_QT} MATCHES "Any")
endif (Qt6_FOUND)
if (Qt4_FOUND OR QT4_FOUND)
message(STATUS "Using Qt4")
include(${QT_USE_FILE})
set(QT_VERSION ${Qt4_VERSION})
set(QT_INCLUDE_DIRS ${QT_INCLUDES})
if (${SELECT_QT} MATCHES "Any")
set (SELECT_QT "Qt4")
endif(${SELECT_QT} MATCHES "Any")
endif (Qt4_FOUND OR QT4_FOUND)
#message (STATUS "${QT_INCLUDE_DIRS}")
endmacro(QT_FIND_MODULES)
macro(QT_USE_MODULES _target)
QT_FIND_MODULES(${ARGN})
# Enable AUTOMOC
set_target_properties(${_target} PROPERTIES AUTOMOC TRUE)
if (Qt5_FOUND OR Qt6_FOUND)
target_link_libraries(${_target} ${QT_LIBRARIES})
else (Qt5_FOUND OR Qt6_FOUND)
if (Qt4_FOUND OR QT4_FOUND)
include(${QT_USE_FILE})
include_directories(${QT_INCLUDES})
add_definitions(${QT_DEFINITIONS})
endif (Qt4_FOUND OR QT4_FOUND)
endif (Qt5_FOUND OR OR Qt6_FOUND)
endmacro(QT_USE_MODULES)
macro(QT_BIND_TO_TARGET _target)
if (Qt5_FOUND OR Qt6_FOUND)
target_link_libraries(${_target} ${QT_LIBRARIES})
else (Qt5_FOUND OR Qt6_FOUND)
if (Qt4_FOUND OR QT4_FOUND)
include(${QT_USE_FILE})
include_directories(${QT_INCLUDES})
add_definitions(${QT_DEFINITIONS})
target_link_libraries(${_target} ${QT_LIBRARIES})
endif (Qt4_FOUND OR QT4_FOUND)
endif (Qt5_FOUND OR Qt6_FOUND)
endmacro(QT_BIND_TO_TARGET)