How to do run script and copy bundle resources in Qt Creator?

Hi
I am trying to compile the ofxAvCodec example from @kritzikratzi with Qt Creator. In one step after building the app it should copy the compiled dylib files from ffmpeg into the Contents/Resources folder of the app.
In XCode you can just run something like:

cp -f …/…/…/libs/fmodex/lib/osx/libfmodex.dylib “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libfmodex.dylib”; install_name_tool -change ./libfmodex.dylib @executable_path/libfmodex.dylib “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME”;
mkdir -p “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Resources/”
cp -f “$ICON_FILE” “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Resources/”

cp -fR …/…/…/addons/ofxAvCodec/libs/avcodec/lib/osx/libavcodec.56.dylib “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS” 2>/dev/null | echo -n
cp -fR …/…/…/addons/ofxAvCodec/libs/avcodec/lib/osx/libavutil.dylib “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS” 2>/dev/null | echo -n
cp -fR …/…/…/addons/ofxAvCodec/libs/avcodec/lib/osx/libavformat.56.dylib “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS” 2>/dev/null | echo -n

or add a “Copy Bundle Resources” Step, but in Qt Creator I do not know how to handle it?

I know that you can set a “Custom Process Step” and add a script, but how could I specify variables like TARGET_BUILD_DIR and alike in Qt Creator?

Thanks
Jakob

1 Like

sorry, no idea how qtcreator works.

to see if it works at all you could just build and then copy the dylibs into the package manually.

Yes thanks, the manual copying of the dylibs had worked fine.

I just wanted to automate certain things. I knew how to do it in XCode, but Qt Creator is a whole different story.

google says:

Thanks for the link. Unfortunately I have not been able to make it work properly.
What did work is to add a bash script as a custom process step after the build, which is executed. In this script I had to hardcode the variables as the only arguments available to pass on to the script are not the ones I need.
It should also be possible to add this step in the qbs file itself. There all needed variables (http://doc.qt.io/qt-5/qmake-variable-reference.html) are available. I have not figured out yet, how and where to put it in the qbs file.

I have now added a transform to the ofApp.qbs file to copy some resources into the built app file. As I am new to qt creator and qbs, I had to make it super cumbersome.

Is there anyone who can help me simplifying this? @arturo maybe?
Essentially what I would like to do, is, after the build process, to copy a list of resources into the app package.

Here the cumbersome “solution”

// Copy osx ffmpeg dylibs
Transformer {
    condition: qbs.targetOS.contains("osx")
    Artifact {
        filePath: FileInfo.joinPaths(parent.destinationDirectory, parent.targetName + ".app", "Contents/MacOS/libavcodec.56.dylib")
        fileTags: "preprocessed_file"
    }
    Artifact {
        filePath: FileInfo.joinPaths(parent.destinationDirectory, parent.targetName + ".app", "Contents/MacOS/libavdevice.56.dylib")
        fileTags: "preprocessed_file"
    }
    Artifact {
        filePath: FileInfo.joinPaths(parent.destinationDirectory, parent.targetName + ".app", "Contents/MacOS/libavfilter.5.dylib")
        fileTags: "preprocessed_file"
    }
    Artifact {
        filePath: FileInfo.joinPaths(parent.destinationDirectory, parent.targetName + ".app", "Contents/MacOS/libavformat.56.dylib")
        fileTags: "preprocessed_file"
    }
    Artifact {
        filePath: FileInfo.joinPaths(parent.destinationDirectory, parent.targetName + ".app", "Contents/MacOS/libavutil.54.dylib")
        fileTags: "preprocessed_file"
    }
    Artifact {
        filePath: FileInfo.joinPaths(parent.destinationDirectory, parent.targetName + ".app", "Contents/MacOS/libswresample.1.dylib")
        fileTags: "preprocessed_file"
    }
    Artifact {
        filePath: FileInfo.joinPaths(parent.destinationDirectory, parent.targetName + ".app", "Contents/MacOS/libswscale.3.dylib")
        fileTags: "preprocessed_file"
    }
    prepare: {
        var cpLibsCmd = new JavaScriptCommand();
        cpLibsCmd.description = "copying dynamic libraries";
        cpLibsCmd.silent = false;
        cpLibsCmd.highlight = 'filegen';
        cpLibsCmd.sourceCode = function(){
             var ofxAvCodecLibDir;
            if(FileInfo.isAbsolutePath(project.of_root)){
                ofxAvCodecLibDir = Helpers.normalize(FileInfo.joinPaths(project.of_root, "addons/ofxAvCodec/libs/avcodec/lib", product.platform));
            }else{
                ofxAvCodecLibDir = Helpers.normalize(FileInfo.joinPaths(project.path, project.of_root, "addons/ofxAvCodec/libs/avcodec/lib", product.platform));
            }
            File.copy(FileInfo.joinPaths(ofxAvCodecLibDir,"libavcodec.56.dylib"), FileInfo.joinPaths(product.destinationDirectory, product.targetName + ".app", "Contents/MacOS/libavcodec.56.dylib"));
            File.copy(FileInfo.joinPaths(ofxAvCodecLibDir,"libavdevice.56.dylib"), FileInfo.joinPaths(product.destinationDirectory, product.targetName + ".app", "Contents/MacOS/libavdevice.56.dylib"));
            File.copy(FileInfo.joinPaths(ofxAvCodecLibDir,"libavfilter.5.dylib"), FileInfo.joinPaths(product.destinationDirectory, product.targetName + ".app", "Contents/MacOS/libavfilter.5.dylib"));
            File.copy(FileInfo.joinPaths(ofxAvCodecLibDir,"libavformat.56.dylib"), FileInfo.joinPaths(product.destinationDirectory, product.targetName + ".app", "Contents/MacOS/libavformat.56.dylib"));
            File.copy(FileInfo.joinPaths(ofxAvCodecLibDir,"libavutil.54.dylib"), FileInfo.joinPaths(product.destinationDirectory, product.targetName + ".app", "Contents/MacOS/libavutil.54.dylib"));
            File.copy(FileInfo.joinPaths(ofxAvCodecLibDir,"libswresample.1.dylib"), FileInfo.joinPaths(product.destinationDirectory, product.targetName + ".app", "Contents/MacOS/libswresample.1.dylib"));
            File.copy(FileInfo.joinPaths(ofxAvCodecLibDir,"libswscale.3.dylib"), FileInfo.joinPaths(product.destinationDirectory, product.targetName + ".app", "Contents/MacOS/libswscale.3.dylib"));
        }
        return [cpLibsCmd];

    }
}
1 Like