FreeCAD
88 строк · 3.8 Кб
1# ADAPTED FOR FREECAD FROM VTK'S vtkQt.cmake
2# ORIGINAL VTK COPYRIGHT NOTICE FOLLOWS (BSD 3-CLAUSE)
3#
4# /*=========================================================================
5#
6# Program: Visualization Toolkit
7# Module: Copyright.txt
8#
9# Copyright (c) 1993-2015 Ken Martin, Will Schroeder, Bill Lorensen
10# All rights reserved.
11#
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions are met:
14#
15# * Redistributions of source code must retain the above copyright notice,
16# this list of conditions and the following disclaimer.
17#
18# * Redistributions in binary form must reproduce the above copyright notice,
19# this list of conditions and the following disclaimer in the documentation
20# and/or other materials provided with the distribution.
21#
22# * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
23# of any contributors may be used to endorse or promote products derived
24# from this software without specific prior written permission.
25#
26# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
27# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
30# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36#
37# =========================================================================*/
38
39
40# FREECAD_QT_VERSION is used to choose between Qt5 and Qt6.
41
42# If it is set to Auto(default), FreeCAD finds and uses the
43# version installed on the system. If both versions are
44# found, Qt5 is preferred.
45
46# The output variable is FREECAD_QT_MAJOR_VERSION, which will be either 5 or 6
47
48macro(ChooseQtVersion)
49set(freecad_supported_qt_versions "Auto" 5 6)
50
51# The following `if` check can be removed once CMake 3.21 is required and
52# the policy CMP0126 is set to NEW.
53if (NOT DEFINED FREECAD_QT_VERSION)
54set(FREECAD_QT_VERSION "Auto" CACHE
55STRING "Expected Qt major version. Valid values are Auto, 5, 6.")
56set_property(CACHE FREECAD_QT_VERSION PROPERTY STRINGS "${freecad_supported_qt_versions}")
57endif()
58
59if(FREECAD_LIBPACK_USE)
60if (NOT Qt5_DIR OR Qt5_DIR STREQUAL "Qt5_DIR-NOTFOUND")
61message(STATUS "Using Qt5 directory from LibPack in ${FREECAD_LIBPACK_DIR}/lib/cmake/Qt5")
62set(Qt5_DIR ${FREECAD_LIBPACK_DIR}/lib/cmake/Qt5)
63endif()
64endif()
65
66if (NOT FREECAD_QT_VERSION STREQUAL "Auto")
67if (NOT FREECAD_QT_VERSION IN_LIST freecad_supported_qt_versions)
68message(FATAL_ERROR
69"Supported Qt versions are \"${freecad_supported_qt_versions}\". But "
70"FREECAD_QT_VERSION is set to ${FREECAD_QT_VERSION}.")
71endif ()
72set(_FREECAD_QT_VERSION "${FREECAD_QT_VERSION}")
73else ()
74find_package(Qt5 QUIET COMPONENTS Core)
75set(_FREECAD_QT_VERSION 5)
76if (NOT Qt5_FOUND)
77find_package(Qt6 QUIET COMPONENTS Core)
78if (NOT Qt6_FOUND)
79message(FATAL_ERROR
80"Could not find a valid Qt installation. Consider setting Qt5_DIR or Qt6_DIR (as needed).")
81endif ()
82set(_FREECAD_QT_VERSION 6)
83endif ()
84endif ()
85set(FREECAD_QT_MAJOR_VERSION "${_FREECAD_QT_VERSION}" CACHE INTERNAL
86"Major version number for the Qt installation used.")
87message(STATUS "Compiling with Qt ${FREECAD_QT_MAJOR_VERSION}")
88endmacro()