-
Notifications
You must be signed in to change notification settings - Fork 11
/
qt.cmake
116 lines (96 loc) · 5.1 KB
/
qt.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
###############################################################################
## Copyright (C) 2009-2023 Arzel Jérôme <[email protected]>
## Copyright (C) 2023 Julian Xhokaxhiu <https://julianxhokaxhiu.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
###############################################################################
if(NOT DEFINED QT_VERSION_TO_FIND)
SET(QT_VERSION_TO_FIND 6)
endif()
find_package(QT NAMES Qt6 QUIET)
# Auto-Detect Qt installation
if(NOT QT_FOUND)
find_program(QT_QMAKE_EXECUTABLE "qmake")
if(NOT QT_QMAKE_EXECUTABLE MATCHES "QT_QMAKE_EXECUTABLE-NOTFOUND")
# ../../
get_filename_component(QT_PATH "${QT_QMAKE_EXECUTABLE}" DIRECTORY)
get_filename_component(QT_PATH "${QT_PATH}" DIRECTORY)
else()
if(WIN32)
# look for user-registry pointing to Qt installation
cmake_host_system_information(RESULT QT_INSTALLATION_PATH QUERY WINDOWS_REGISTRY "HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Uninstall/{89c4e30e-3a1a-47c7-80d7-013ba3e25e57}" VALUE "InstallLocation")
if(QT_INSTALLATION_PATH STREQUAL "")
# look for user-registry pointing to qtcreator
cmake_host_system_information(RESULT QT_INSTALLATION_PATH QUERY WINDOWS_REGISTRY "HKEY_CURRENT_USER/Software/Classes/Applications/QtProject.QtCreator.cpp/shell/Open/Command")
string(REPLACE " -client \"%1\"" "" QT_INSTALLATION_PATH ${QT_INSTALLATION_PATH})
if(QT_INSTALLATION_PATH STREQUAL "")
message(FATAL_ERROR "Please set QT_INSTALLATION_PATH or Qt${QT_VERSION_TO_FIND}_DIR")
endif()
message("-- QtCreator Auto-Detected at ${QT_INSTALLATION_PATH}")
# ../../../../
get_filename_component(QT_INSTALLATION_PATH "${QT_INSTALLATION_PATH}" DIRECTORY)
get_filename_component(QT_INSTALLATION_PATH "${QT_INSTALLATION_PATH}" DIRECTORY)
get_filename_component(QT_INSTALLATION_PATH "${QT_INSTALLATION_PATH}" DIRECTORY)
get_filename_component(QT_INSTALLATION_PATH "${QT_INSTALLATION_PATH}" DIRECTORY)
endif()
elseif(NOT QT_INSTALLATION_PATH)
message(FATAL_ERROR "Please set QT_INSTALLATION_PATH or Qt${QT_VERSION_TO_FIND}_DIR")
endif()
file(GLOB QT_VERSIONS "${QT_INSTALLATION_PATH}/${QT_VERSION_TO_FIND}.*")
list(SORT QT_VERSIONS)
# assume the latest version will be last alphabetically
list(REVERSE QT_VERSIONS)
list(GET QT_VERSIONS 0 QT_VERSION)
message("-- Last Qt version ${QT_VERSION}")
if(MSVC)
if(MSVC_TOOLSET_VERSION MATCHES 143)
set(QT_MSVC "2019") # Qt does not yet provide an official 2022 toolset
elseif(MSVC_TOOLSET_VERSION MATCHES 142)
set(QT_MSVC "2019")
elseif(MSVC_TOOLSET_VERSION MATCHES 141)
set(QT_MSVC "2017")
endif()
set(QT_PATH "${QT_VERSION}/msvc${QT_MSVC}_64")
elseif(MINGW)
file(GLOB QT_COMPILERS "${QT_VERSION}/mingw*")
list(SORT QT_COMPILERS)
list(REVERSE QT_COMPILERS)
list(GET QT_COMPILERS 0 QT_PATH)
else()
# For some reason GLOB also list files on Mac OSX
file(GLOB QT_COMPILERS "${QT_VERSION}/*/lib")
list(SORT QT_COMPILERS)
list(REVERSE QT_COMPILERS)
list(GET QT_COMPILERS 0 QT_PATH)
# ../
get_filename_component(QT_PATH "${QT_PATH}" DIRECTORY)
endif()
set(QT_QMAKE_EXECUTABLE "${QT_PATH}/bin/qmake")
endif()
set(Qt${QT_VERSION_TO_FIND}_DIR "${QT_PATH}/lib/cmake/Qt${QT_VERSION_TO_FIND}")
set(QT_DIR "${Qt${QT_VERSION_TO_FIND}_DIR}")
find_package(QT NAMES Qt${QT_VERSION_TO_FIND} REQUIRED)
message("-- Qt Auto-Detected at ${QT_PATH}")
message("-- Qt${QT_VERSION_MAJOR}_DIR: ${Qt${QT_VERSION_MAJOR}_DIR}")
endif()
if(NOT DEFINED QT_QMAKE_EXECUTABLE OR QT_QMAKE_EXECUTABLE MATCHES "QT_QMAKE_EXECUTABLE-NOTFOUND")
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
get_target_property(QT_QMAKE_EXECUTABLE Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION)
endif()
message("-- QT_QMAKE_EXECUTABLE: ${QT_QMAKE_EXECUTABLE}")
get_filename_component(_qt_bin_dir "${QT_QMAKE_EXECUTABLE}" DIRECTORY)
get_filename_component(_qt_dir "${_qt_bin_dir}" DIRECTORY)
set(_qt_translations_dir "${_qt_dir}/translations")
# Add the QT_PATH to the resolution paths
list(APPEND CMAKE_PREFIX_PATH "${QT_PATH}")