Search code examples
qbs

qbs avr compiling


I try to build simple project with qbs

import qbs
Project {
    name: "simple"
    Product {
        name: "micro"
        type: "obj"
        Group {
            name: "sources"
            files: ["main.c", "*.h", "*.S"]
            fileTags: ['c']
        }
        Rule {
            inputs: ["c"]
            Artifact {
                fileTags: ['obj']
                filePath: input.fileName + '.o'
            }
            prepare: {
                var args = [];
                args.push("-g")
                args.push("-Os")
                args.push("-w")
                args.push("-fno-exceptions")
                args.push("-ffunction-sections")
                args.push("-fdata-sections")
                args.push("-MMD")
                args.push("-mmcu=atmega328p")
                args.push("-DF_CPU=16000000L")
                args.push("-DARDUINO=152")
                args.push("-IC:/Programs/arduino/hardware/arduino/avr/cores/arduino")
                args.push("-IC:/Programs/arduino/hardware/arduino/avr/variants/standard")
                args.push("-c")
                args.push(input.fileName)
                args.push("-o")
                args.push(input.fileName + ".o")
                var compilerPath = "C:/Programs/arduino/hardware/tools/avr/bin/avr-g++.exe"
                var cmd = new Command(compilerPath, args);
                cmd.description = 'compiling ' + input.fileName;
                cmd.highlight = 'compiler';
                cmd.silent = false;
                console.error(input.baseDir + '/' + input.fileName);
                return cmd;
            }
        }
    }
}

And I get error

compiling main.c
C:/Programs/arduino/hardware/tools/avr/bin/avr-g++.exe -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD "-mmcu=atmega328p" "-DF_CPU=16000000L" "-DARDUINO=152" -IC:/Programs/arduino/hardware/arduino/avr/cores/arduino -IC:/Programs/arduino/hardware/arduino/avr/variants/standard -c main.c -o main.c.o
avr-g++.exe: main.c: No such file or directory
avr-g++.exe: no input files
Process failed with exit code 1.
The following products could not be built for configuration qtc_avr_f84c45e7-release:
    micro

What do I wrong?

File main.c present in project and in directory.

If I start this command from command prompt I do not get error.


Solution

  • In short, you need to pass input.filePath after -c and -o, not input.fileName. There's no guarantee that the working directory of the command invoked will be that of your source directory.

    You can set the workingDirectory of a Command object, but that is not generally recommended as your commands should be independent of the working directory unless absolutely necessary.

    Furthermore, you appear to be duplicating the functionality of the cpp module. Instead, your project should look like this:

    import qbs
    Project {
        name: "simple"
        Product {
            Depends { name: "cpp" }
            name: "micro"
            type: "obj"
            Group {
                name: "sources"
                files: ["main.c", "*.h", "*.S"]
                fileTags: ['c']
            }
            cpp.debugInformation: true // passes -g
            cpp.optimization: "small" // passes -Os
            cpp.warningLevel: "none" // passes -w
            cpp.enableExceptions: false // passes -fno-exceptions
            cpp.commonCompilerFlags: [
                "-ffunction-sections",
                "-fdata-sections",
                "-MMD",
                "-mmcu=atmega328p"
            ]
            cpp.defines: [
                "F_CPU=16000000L",
                "ARDUINO=152"
            ]
            cpp.includePaths: [
                "C:/Programs/arduino/hardware/arduino/avr/cores/arduino",
                "C:/Programs/arduino/hardware/arduino/avr/variants/standard
            ]
            cpp.toolchainInstallPath: "C:/Programs/arduino/hardware/tools/avr/bin"
            cpp.cxxCompilerName: "avr-g++.exe"
        }
    }