summaryrefslogtreecommitdiff
path: root/src/tools/ivigenerator/qface_internal_build.pri
blob: 1fd226b6f7d77008facf356663317b0aa533473e (plain)
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
QFACE_SOURCE_DIR = $$QTIVI_ROOT/src/3rdparty/qface

# only create the environment once
debug_and_release:build_pass:CONFIG(release, debug|release) {
    return();
}

!exists($$QFACE_SOURCE_DIR): error("Couldn't find $$QFACE_SOURCE_DIR: Please make sure all submodules are initialized")

message("Checking for a valid python & pip installation")

PYTHON3_PATH = $$(PYTHON3_PATH)
PYTHON3_NAMES = "python3" "python"
for (python3_exe, PYTHON3_NAMES) {
    !isEmpty(PYTHON3_PATH): python3_exe = $$shell_path($$PYTHON3_PATH/$$python3_exe)
    win32: python3_exe = $${python3_exe}.exe
    message("Checking for python executable: $$python3_exe")
    py_major_version = $$system("$$python3_exe -c \"import platform; print(platform.python_version_tuple()[0])\"")
    equals(py_major_version, 3) {
        PYTHON3_EXE = $$python3_exe
        break()
    }
}

isEmpty(PYTHON3_EXE) {
    error("Didn't find a valid python3 installation in PATH or PYTHON3_PATH $$escape_expand(\n)Please make sure it is setup accordingly.")
}

message("Checking for pip installation")
pip_version = $$system("$$PYTHON3_EXE -m pip --version")
isEmpty(pip_version) {
    error("Didn't find pip with your python installation at: $$PYTHON3_EXE $$escape_expand(\n)Please make sure it is installed.")
}

VIRTUALENV_EXE = "$$PYTHON3_EXE -m virtualenv"
!isEmpty(PIP3_PATH): VIRTUALENV_EXE = $$shell_path($$PIP3_PATH/virtualenv)
!isEmpty(PIP3_PATH):win32: VIRTUALENV_EXE = $${VIRTUALENV_EXE}.exe

# virtualenv is always using the default interpreter, which is python2 on many systems"
# by adding -p we enforce that the python3 interpreter is used and make sure python3 is installed in the virtualenv
VIRTUALENV_EXE += " -p $$PYTHON3_EXE"

# Use a Python virtualenv for installing qface, so we don't pollute the user environment
qtivi_qface_virtualenv.target = qtivi_qface_virtualenv
qtivi_qface_virtualenv.commands = \
    $$VIRTUALENV_EXE $${qtivi_qface_virtualenv.target} $$escape_expand(\n\t) \
    $$VIRTUALENV_EXE --relocatable $${qtivi_qface_virtualenv.target} $$escape_expand(\n\t) \
    @echo "Set up virtualenv for qface, name: $$qtivi_qface_virtualenv.target"
QMAKE_EXTRA_TARGETS += qtivi_qface_virtualenv

win32: VIRTUALENV_ACTIVATION = $${qtivi_qface_virtualenv.target}\Scripts\activate &&
else: VIRTUALENV_ACTIVATION = . $${qtivi_qface_virtualenv.target}/bin/activate &&

# Create the forceRebuild file during the qmake run.
# This file is used as a dependency in other Makefiles.
# Once the virtualenv is created and setup the file will
# be touched to recreate theses Makefiles.
write_file($$OUT_PWD/forceRebuild)

# Always run this target
qtivi_qface_install.target = qtivi_qface_virtualenv/pip-selfcheck.json
qtivi_qface_install.depends = qtivi_qface_virtualenv
qtivi_qface_install.depends += $$QFACE_SOURCE_DIR/setup.py
qtivi_qface_install.depends += $$QFACE_SOURCE_DIR/requirements.txt
qtivi_qface_install.commands = $$VIRTUALENV_ACTIVATION \
        pip3 install $$shell_path($$QFACE_SOURCE_DIR) $$escape_expand(\n\t) \
        @echo "Installed qface development version into qtivi_qface_virtualenv" $$escape_expand(\n\t)
win32: qtivi_qface_install.commands += @COPY /B $$shell_path($$OUT_PWD/forceRebuild)+,, $$shell_path($$OUT_PWD/forceRebuild)
else: qtivi_qface_install.commands += @touch $$OUT_PWD/forceRebuild
QMAKE_EXTRA_TARGETS += qtivi_qface_install

PRE_TARGETDEPS += $${qtivi_qface_install.target}

virtualenv.files = $$OUT_PWD/qtivi_qface_virtualenv
virtualenv.path = $$[QT_HOST_BINS]/ivigenerator
virtualenv.CONFIG = no_check_exist directory no_build

INSTALLS += virtualenv

# On osx the hidden .Python file is needed in the installed virtualenv as well
# this file is not installed by the directory config, so we need to install it manually
osx {
    virtualenv-python.files = $$OUT_PWD/qtivi_qface_virtualenv/.Python
    virtualenv-python.path = $$[QT_HOST_BINS]/ivigenerator/qtivi_qface_virtualenv
    # In case the file doesn't exist, touch creates it and fixes the install target
    virtualenv-python.extra = @touch $$OUT_PWD/qtivi_qface_virtualenv/.Python
    virtualenv-python.CONFIG = no_check_exist
    INSTALLS += virtualenv-python
}