build: Set macOS minimum version to Qt min version
[quassel.git] / scripts / build / macosx_qt.py
1 #!/usr/bin/python
2 # -*- coding: iso-8859-1 -*-
3
4 ################################################################################
5 #                                                                              #
6 # 2008 June 27th by Marcus 'EgS' Eggenberger <egs@quassel-irc.org>             #
7 #                                                                              #
8 # The author disclaims copyright to this source code.                          #
9 # This Python Script is in the PUBLIC DOMAIN.                                  #
10 #                                                                              #
11 ################################################################################
12
13 # ==============================
14 #  Imports
15 # ==============================
16 import os
17 from subprocess import Popen, PIPE
18
19 # ==============================
20 #  Global Functions
21 # ==============================
22 def qtProperty(qtProperty):
23     """
24     Query persistent property of Qt via qmake
25     """
26     VALID_PROPERTIES = ['QT_INSTALL_PREFIX',
27                         'QT_INSTALL_DATA',
28                         'QT_INSTALL_DOCS',
29                         'QT_INSTALL_HEADERS',
30                         'QT_INSTALL_LIBS',
31                         'QT_INSTALL_BINS',
32                         'QT_INSTALL_PLUGINS',
33                         'QT_INSTALL_IMPORTS',
34                         'QT_INSTALL_TRANSLATIONS',
35                         'QT_INSTALL_CONFIGURATION',
36                         'QT_INSTALL_EXAMPLES',
37                         'QT_INSTALL_DEMOS',
38                         'QMAKE_MKSPECS',
39                         'QMAKE_VERSION',
40                         'QT_VERSION'
41                         ]
42     if qtProperty not in VALID_PROPERTIES:
43         return None
44
45     qmakeProcess = Popen('qmake -query %s' % qtProperty, shell=True, stdout=PIPE, stderr=PIPE)
46     result = qmakeProcess.stdout.read().strip()
47     qmakeProcess.stdout.close()
48     qmakeProcess.wait()
49     return result
50
51 def qtMakespec(qtMakespec):
52     """
53     Query a Makespec value of Qt via qmake
54     """
55
56     VALID_PROPERTIES = ['QMAKE_MACOSX_DEPLOYMENT_TARGET',
57                         ]
58     if qtMakespec not in VALID_PROPERTIES:
59         return None
60
61     # QMAKE_MACOSX_DEPLOYMENT_TARGET sadly cannot be queried in the traditional way
62     #
63     # Inspired by https://code.qt.io/cgit/pyside/pyside-setup.git/tree/qtinfo.py?h=5.6
64     # Simplified, no caching, etc, as we're just looking for the macOS version.
65     # If a cleaner solution is desired, look into license compatibility in
66     # order to simply copy the above code.
67
68     current_dir = os.getcwd()
69     qmakeFakeProjectFile = os.path.join(current_dir, "qmake_empty_project.txt")
70     qmakeStashFile = os.path.join(current_dir, ".qmake.stash")
71     # Make an empty file
72     open(qmakeFakeProjectFile, 'a').close()
73
74     qmakeProcess = Popen('qmake -E %s' % qmakeFakeProjectFile, shell=True, stdout=PIPE, stderr=PIPE)
75     result = qmakeProcess.stdout.read().strip()
76     qmakeProcess.stdout.close()
77     qmakeProcess.wait()
78
79     # Clean up temporary files
80     try:
81         os.remove(qmakeFakeProjectFile)
82     except OSError:
83         pass
84     try:
85         os.remove(qmakeStashFile)
86     except OSError:
87         pass
88
89     # Result should be like this:
90     # PROPERTY = VALUE\n
91     result_list = result.splitlines()
92     # Clear result so if nothing matches, nothing is returned
93     result = None
94     # Search keys
95     for line in result_list:
96         if not '=' in line:
97             # Ignore lines without '='
98             continue
99
100         # Find property = value
101         parts = line.split('=', 1)
102         prop = parts[0].strip()
103         value = parts[1].strip()
104         if (prop == qtMakespec):
105             result = value
106             break
107
108     return result