summaryrefslogtreecommitdiffstats
path: root/meta/classes/ccmake.bbclass
blob: df5134a108a19375e80e567eaf82f9f04a481874 (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
90
91
92
93
94
95
96
97
inherit terminal

python do_ccmake() {
    import shutil

    # copy current config for diffing
    config = os.path.join(d.getVar("B"), "CMakeCache.txt")
    if os.path.exists(config):
        shutil.copy(config, config + ".orig")

    oe_terminal(d.expand("ccmake ${OECMAKE_GENERATOR_ARGS} ${OECMAKE_SOURCEPATH} -Wno-dev"),
        d.getVar("PN") + " - ccmake", d)

    if os.path.exists(config) and os.path.exists(config + ".orig"):
        if bb.utils.md5_file(config) != bb.utils.md5_file(config + ".orig"):
            # the cmake class uses cmake --build, which will by default
            # regenerate configuration, simply mark the compile step as tainted
            # to ensure it is re-run
            bb.note("Configuration changed, recompile will be forced")
            bb.build.write_taint('do_compile', d)

}
do_ccmake[depends] += "cmake-native:do_populate_sysroot"
do_ccmake[nostamp] = "1"
do_ccmake[dirs] = "${B}"
addtask ccmake after do_configure

def cmake_parse_config_cache(path):
    with open(path, "r") as f:
        for i in f:
            i = i.rstrip("\n")
            if len(i) == 0 or i.startswith("//") or i.startswith("#"):
                continue # empty or comment
            key, value = i.split("=", 1)
            key, keytype = key.split(":")
            if keytype in ["INTERNAL", "STATIC"]:
                continue # skip internal and static config options
            yield key, keytype, value

def cmake_diff_config_vars(a, b):
    removed, added = [], []

    for ak, akt, av in a:
        found = False
        for bk, bkt, bv in b:
            if bk == ak:
                found = True
                if bkt != akt or bv != av: # changed
                    removed.append((ak, akt, av))
                    added.append((bk, bkt, bv))
                break
        # remove any missing from b
        if not found:
            removed.append((ak, akt, av))

    # add any missing from a
    for bk, bkt, bv in b:
        if not any(bk == ak for ak, akt, av in a):
            added.append((bk, bkt, bv))

    return removed, added

python do_ccmake_diffconfig() {
    import shutil
    config = os.path.join(d.getVar("B"), "CMakeCache.txt")
    if os.path.exists(config) and os.path.exists(config + ".orig"):
        if bb.utils.md5_file(config) != bb.utils.md5_file(config + ".orig"):
            # scan the changed options
            old = list(cmake_parse_config_cache(config + ".orig"))
            new = list(cmake_parse_config_cache(config))
            _, added = cmake_diff_config_vars(old, new)

            if len(added) != 0:
                with open(d.expand("${WORKDIR}/configuration.inc"), "w") as f:
                    f.write("EXTRA_OECMAKE += \" \\\n")
                    for k, kt, v in added:
                        escaped = v if " " not in v else "\"{0}\"".format(v)
                        f.write("    -D{0}:{1}={2} \\\n".format(k, kt, escaped))
                    f.write("    \"\n")
                bb.plain("Configuration recipe fragment written to: {0}".format(d.expand("${WORKDIR}/configuration.inc")))

                with open(d.expand("${WORKDIR}/site-file.cmake"), "w") as f:
                    for k, kt, v in added:
                        f.write("SET({0} \"{1}\" CACHE {2} \"\")\n".format(k, v, kt))
                bb.plain("Configuration cmake fragment written to: {0}".format(d.expand("${WORKDIR}/site-file.cmake")))

                # restore the original config
                shutil.copy(config + ".orig", config)
        else:
            bb.plain("No configuration differences, skipping configuration fragment generation.")
    else:
        bb.fatal("No config files found. Did you run ccmake?")
}
do_ccmake_diffconfig[nostamp] = "1"
do_ccmake_diffconfig[dirs] = "${B}"
addtask ccmake_diffconfig
es? </para> </question> <answer> <para> Refer to the "<link linkend='working-with-your-own-sources'>Working With Your Own Sources</link>" section for information. </para> </answer> </qandaentry> <qandaentry> <question> <para> How do I install/not-install the kernel image on the rootfs? </para> </question> <answer> <para> The kernel image (e.g. <filename>vmlinuz</filename>) is provided by the <filename>kernel-image</filename> package. Image recipes depend on <filename>kernel-base</filename>. To specify whether or not the kernel image is installed in the generated root filesystem, override <filename>RDEPENDS_kernel-base</filename> to include or not include "kernel-image".</para> <para>See the "<ulink url='&YOCTO_DOCS_DEV_URL;#using-bbappend-files'>Using .bbappend Files</ulink>" section in the Yocto Project Development Manual for information on how to use an append file to override metadata. </para> </answer> </qandaentry> <qandaentry> <question> <para> How do I install a specific kernel module? </para> </question> <answer> <para> Linux kernel modules are packaged individually. To ensure a specific kernel module is included in an image, include it in the appropriate machine <ulink url='&YOCTO_DOCS_REF_URL;#var-RRECOMMENDS'><filename>RRECOMMENDS</filename></ulink> variable.</para> <para>These other variables are useful for installing specific modules: <literallayout class='monospaced'> <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RDEPENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RDEPENDS</filename></ulink> <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS'><filename>MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS</filename></ulink> <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RDEPENDS'><filename>MACHINE_EXTRA_RDEPENDS</filename></ulink> <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE_EXTRA_RRECOMMENDS'><filename>MACHINE_EXTRA_RRECOMMENDS</filename></ulink> </literallayout> For example, set the following in the <filename>qemux86.conf</filename> file to include the <filename>ab123</filename> kernel modules with images built for the <filename>qemux86</filename> machine: <literallayout class='monospaced'> MACHINE_EXTRA_RRECOMMENDS += "kernel-module-ab123" </literallayout> For more information, see the "<link linkend='incorporating-out-of-tree-modules'>Incorporating Out-of-Tree Modules</link>" section. </para> </answer> </qandaentry> <qandaentry> <question> <para> How do I change the Linux kernel command line? </para> </question> <answer> <para> The Linux kernel command line is typically specified in the machine config using the <filename>APPEND</filename> variable. For example, you can add some helpful debug information doing the following: <literallayout class='monospaced'> APPEND += "printk.time=y initcall_debug debug" </literallayout> </para> </answer> </qandaentry> </qandaset> </para> </section> </appendix> <!-- vim: expandtab tw=80 ts=4 -->