r0n9
r0n9

Reputation: 2759

qbs qestion about library relative path and how to reuse a property string

I am trying to use several libraries in a project generated by qbs 1.5.1, Qt 5.6.1, Qt Creator 4.0.1

I currently have several questions regarding the qt building suit.

First question: how can I reuse a property string? e.g I tried to define a Product which contains some string properties And trying to reuse those properties in other places within the project.

// defines the qbs file in subfolder settings/settings.qbs
import qbs

Product
{
  name: 'config'
  property string p1    : 'path1'         // <- define p1
  property string p2: p1 + '/path2'       // <- define p2
}

and to try to use the properties:

i. Added the settings.qbs to root project.qbs

import qbs
import qbs.File

Project{
  references:{
  ...,
  "settings/settings.qbs"
  }
}

ii. In another folder, which is holding the application

// application/app.qbs
import qbs 

CppApplication{
  type: "application"
  name: "myapp"

  Depends {name: "cpp"}
  Depends {name: "config"}

  cpp.libraryPaths [config.p1, config.p2] // <- use p1 and p2 in a different qbs file
}

But when I run

qbs debug

in the repository root, the property string value is 'undefined'.

The second question is the relative path. It seems that I can use a relative path in files:[], but when I use the relative path in cpp.dynamicLibraries or cpp.staticLibraries the compiler can not find the libraries based on the relative path. But if I use an absolute path, it works. Did I missed something?

Thanks for your help :)

Rong

Upvotes: 0

Views: 596

Answers (1)

Jake Petroules
Jake Petroules

Reputation: 24190

You can't reference properties like that. You'll need to use QML inheritance or import a JavaScript file. For example, you can put JS code into separate .js files and then import them.

---helpers.js---
function planetsCorrectlyAligned()
{
    // implementation
}

---myproject.qbs---
import qbs 1.0
import "helpers.js" as Helpers

Product {
    name: "myproject"
    Group {
        condition: Helpers.planetsCorrectlyAligned()
        file: "magic_hack.cpp"
    }
    // ...
}

This syntax for this is detailed in the Qbs documentation at: https://doc.qt.io/qbs/language-introduction.html#reusing-project-file-code


Didn't I answer the libraries question elsewhere? Also, please don't add multiple questions to the same post; that's not how Stack Overflow works.

Upvotes: 1

Related Questions