build - QBS 中的构建后步骤

标签 build qbs nrf51

我正在尝试将 nRF51822(Arm Cortex 微 Controller )构建过程从 Make 转换为 QBS。我的编译过程工作正常(有很多硬编码路径,但我稍后会修复它)。不过,最后一步是使用 objcopy 将链接器生成的 .out 文件转换为 .hex 文件。除了创建另一个像这样的 Application (效果不太好)之外,我无法弄清楚如何让我的规则运行:

import qbs
import qbs.FileInfo

Project {
    CppApplication {
        type: "application" // To suppress bundle generation on Mac

        name: "nrf51_template"

        files: ["main.cpp",
            "nrf51822/Source/nrf_delay/nrf_delay.c"]

        Group {
            name: "Startup files"
            files: ["nrf51822/Source/Templates/system_" + deviceSeries + ".c",
            "nrf51822/Source/Templates/gcc/gcc_startup_" + deviceSeries + ".s"]
        }


        // The chip variant can be:
        //
        // "xxaa": The 256 kB version
        // "xxbb": The 128 kB version
        //
        // RFduino is xxaa.
        property string deviceVariant: "xxaa"

        // Must be "nrf51"
        property string deviceSeries: "nrf51"

        // The softdevice (radio firmware) to use. Can be:
        //
        // "": For no radio.
        // "s110": For BLE slave/peripheral
        // "s120": For BLE host/central
        // "s130": For BLE central and peripheral
        property string softDevice: "s110"

        // Must be cortex-m0
        property string cpu: "cortex-m0"

        cpp.includePaths: ["nrf51822/Include", "nrf51822/Include/gcc"]
        cpp.compilerName: ["arm-none-eabi-g++.exe"]
        cpp.compilerPath: ["C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-g++.exe"]
        cpp.linkerName: ["arm-none-eabi-g++.exe"]
        cpp.linkerPath: ["C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-g++.exe"]

        cpp.cxxFlags: ["-mcpu=" + cpu, "-mthumb", "-mabi=aapcs", "--std=c++11", "-mfloat-abi=soft"]
        cpp.linkerFlags: ["-L\"C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/arm-none-eabi/lib/armv6-m\"",
            "-L\"C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/lib/gcc/arm-none-eabi/4.8.3/armv6-m\"",
            "-Xlinker",
            "-Map=C:/Users/thutt/nRF51_Template/output_filename.map",
            "-mcpu=" + cpu,
            "-mthumb",
            "-mabi=aapcs",
            "-L", "C:/Users/thutt/nRF51_Template/nrf51822/Source/templates/gcc/",
            "-Tgcc_" + deviceSeries + "_" + softDevice + "_" + deviceVariant + ".ld"]

        cpp.defines: ["BOARD_PCA10001", "NRF51"]

        // Suppresses -m32 compiler option.
        cpp.architecture: "arm"

        // Suppress windows definitions and compiler options.
        cpp.minimumWindowsVersion: undefined

        cpp.executableSuffix: ".out"

        // To flash:

        // nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex

    }

    Application {
        name: "nrf51_template_hex"

        Group {
            files: "C:/Users/thutt/nRF51_Template-build/qtc_Desktop2-debug/nrf51_template.out"
            fileTags: ["out"]
        }

        Depends {
            name: "nrf51_template"
        }


        Rule {
            id: hex
            inputs: ["out"]

            Artifact {
                fileTags: ["application"]
                fileName: ".obj/" + product.name + "/" + input.baseDir + "/" + input.fileName + ".hex"
            }

            prepare: {
    //          var compilerPath = ModUtils.moduleProperty(product, "compilerPath");

                var objCopyPath = "C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-objcopy.exe";
                var args = ["-O", "ihex", input.filePath, output.filePath];
                var cmd = new Command(objCopyPath, args);

                cmd.description = "converting to hex: " + FileInfo.fileName(input.filePath);
                cmd.highlight = "linker";
                return cmd;
            }
        }
    }
}

是否可以在 CppApplication 中使用链接后步骤,而不是像这样的两个 Application ?我是否最好使用自己的规则来定义一个全新的Application来进行编译和链接?

还有一个额外的问题,是否可以在 QBS 文件中指定“运行”可执行文件,以便当我在 QtCreator 中单击运行时,它实际上运行 nrfjprog.exe 并将代码刷新到芯片? (您可以在 IDE 中执行此操作,但我更希望能够在 QBS 文件中执行此操作。)

最佳答案

搞清楚了,最终的目标是由 Application 中的 type: 行决定的,所以只需将其更改为:

import qbs
import qbs.FileInfo

Project {
    CppApplication {

        // The filetag to generate.
        type: "hex"

        name: "nrf51_template"

        files: ["main.cpp",
            "SaneSPI.cpp",
            "SaneSPI.h",
            "Timer.cpp",
            "Timer.h",
            "Delay.cpp",
            "Delay.h",
            "GPIO.cpp",
            "GPIO.h"]

        Group {
            name: "Startup files"
            files: ["nrf51822/Source/Templates/system_" + deviceSeries + ".c",
            "nrf51822/Source/Templates/gcc/gcc_startup_" + deviceSeries + ".s"]
        }


        // The chip variant can be:
        //
        // "xxaa": The 256 kB version
        // "xxbb": The 128 kB version
        //
        // RFduino is xxaa.
        property string deviceVariant: "xxaa"

        // Must be "nrf51"
        property string deviceSeries: "nrf51"

        // The softdevice (radio firmware) to use. Can be:
        //
        // "": For no radio.
        // "s110": For BLE slave/peripheral
        // "s120": For BLE host/central
        // "s130": For BLE central and peripheral
        property string softDevice: "s110"

        // Must be cortex-m0
        property string cpu: "cortex-m0"

        cpp.includePaths: ["nrf51822/Include",
            "nrf51822/Include/gcc",
            "nrf51822/Include/" + softDevice]
        cpp.compilerName: ["arm-none-eabi-g++.exe"]
        cpp.compilerPath: ["C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-g++.exe"]
        cpp.linkerName: ["arm-none-eabi-g++.exe"]
        cpp.linkerPath: ["C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-g++.exe"]

        cpp.cxxFlags: ["-mcpu=" + cpu, "-mthumb", "-mabi=aapcs", "--std=c++11", "-mfloat-abi=soft"]
        cpp.linkerFlags: ["-L\"C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/arm-none-eabi/lib/armv6-m\"",
            "-L\"C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/lib/gcc/arm-none-eabi/4.8.3/armv6-m\"",
            "-Xlinker",
            "-Map=C:/Users/thutt/nRF51_Template/output_filename.map",
            "-mcpu=" + cpu,
            "-mthumb",
            "-mabi=aapcs",
            "-L", "C:/Users/thutt/nRF51_Template/nrf51822/Source/templates/gcc/",
            "-Tgcc_" + deviceSeries + "_" + softDevice + "_" + deviceVariant + ".ld"]

        cpp.defines: ["BOARD_PCA10001", "NRF51"]

        // Suppresses -m32 compiler option.
        cpp.architecture: "arm"

        // Suppress windows definitions and compiler options.
        cpp.minimumWindowsVersion: undefined

        cpp.executableSuffix: ".out"

        Rule {
            id: hex
            inputs: ["application"]

            Artifact {
                fileTags: ["hex"]
                fileName: ".obj/" + product.name + "/" + input.baseDir + "/" + input.fileName + ".hex"
            }

            prepare: {
    //          var compilerPath = ModUtils.moduleProperty(product, "compilerPath");

                var objCopyPath = "C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-objcopy.exe";
                var args = ["-O", "ihex", input.filePath, output.filePath];
                var cmd = new Command(objCopyPath, args);

                cmd.description = "converting to hex: " + FileInfo.fileName(input.filePath);
                cmd.highlight = "linker";
                return cmd;
            }
        }

        // To flash:

        // nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex

    }
}

关于build - QBS 中的构建后步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23607457/

相关文章:

android - 建立Android ionic 项目时发生错误

android - 使用命令提示符构建 Android 应用程序

c++ - 在 Android NDK 项目中使用我自己的预构建共享库

c++ - qt qbs中如何引用外部库依赖?

debugging - CLion 中的 J-Link GDB 调试

c - 使错误 : make (e=2): The system cannot find the file specified

java - eclipse 中 "Build Automatically"选项的用途

qt - 从 qmake 迁移到 qbs,类似 .pri 文件和安装技术

qt - qbs QML 调试不起作用

debugging - nrf51822 + ST-Link V2 调试