summaryrefslogtreecommitdiff
path: root/mkspecs/features/configure.prf
blob: 934a18a9249048d81ce363461f718230f0501568 (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
# Ensure that a cache is present. If none was found on startup, this will create
# one in the build directory of the project which loads this feature.
cache()

load(configure_base)

isEmpty(QMAKE_CONFIG_VERBOSE): QMAKE_CONFIG_VERBOSE = false

QMAKE_CONFIG_LOG = $$dirname(_QMAKE_CACHE_)/config.log
recheck: write_file($$QMAKE_CONFIG_LOG, "")

isEmpty(QMAKE_CONFIG_TESTS_DIR): QMAKE_CONFIG_TESTS_DIR = $$_PRO_FILE_PWD_/config.tests

# Try to build the test project in $$QMAKE_CONFIG_TESTS_DIR/$$1
# ($$_PRO_FILE_PWD_/config.tests/$$1 by default).
#
# If the test passes, config_$$1 will be added to CONFIG.
# The result is automatically cached. Use of cached results
# can be suppressed by passing CONFIG+=recheck to qmake.
#
# Returns: true iff the test passes
defineTest(qtCompileTest) {
    positive = config_$$1
    done = done_config_$$1

    $$done:!recheck {
        $$positive:return(true)
        return(false)
    }

    log("Checking for $${1}... ")
    msg = "executing config test $$1"
    write_file($$QMAKE_CONFIG_LOG, msg, append)

    test_dir = $$QMAKE_CONFIG_TESTS_DIR/$$1
    test_out_dir = $$shadowed($$test_dir)
    test_cmd_base = "$$QMAKE_CD $$system_quote($$system_path($$test_out_dir)) &&"

    # Disable qmake features which are typically counterproductive for tests
    qmake_configs = "\"CONFIG -= qt debug_and_release app_bundle lib_bundle\""

    # On WinRT we need to change the entry point as we cannot create windows
    # applications
    winrt {
        qmake_configs += " \"QMAKE_LFLAGS+=/ENTRY:main\""
    }

    # Clean up after previous run
    exists($$test_out_dir/Makefile):qtRunLoggedCommand("$$test_cmd_base $$QMAKE_MAKE distclean")

    mkpath($$test_out_dir)|error()

    !isEmpty (QMAKE_QTCONF): qtconfarg = -qtconf $$QMAKE_QTCONF

    qtRunLoggedCommand("$$test_cmd_base $$system_quote($$system_path($$QMAKE_QMAKE)) $$qtconfarg -spec $$QMAKESPEC $$qmake_configs $$shell_quote($$test_dir)") {
        qtRunLoggedCommand("$$test_cmd_base $$QMAKE_MAKE") {
            log("yes$$escape_expand(\\n)")
            msg = "test $$1 succeeded"
            write_file($$QMAKE_CONFIG_LOG, msg, append)

            !$$positive {
                CONFIG += $$positive
                cache(CONFIG, add, positive)
            }
            !$$done {
                CONFIG += $$done
                cache(CONFIG, add, done)
            }
            export(CONFIG)
            return(true)
        }
    }

    log("no$$escape_expand(\\n)")
    msg = "test $$1 FAILED"
    write_file($$QMAKE_CONFIG_LOG, msg, append)

    $$positive {
        CONFIG -= $$positive
        cache(CONFIG, sub, positive)
    }
    !$$done {
        CONFIG += $$done
        cache(CONFIG, add, done)
    }
    export(CONFIG)
    return(false)
}