[QBS] How to override product properties?
-
Suppose there is a product (library) which build process can be customised, and there is some property which is supposed to be set outside of product itself:
// Library.qbs StaticLibrary { property string test_property: “something” }
How do I change test_property’s value outside of Library.qbs?
For Projects there is SubProject item, which lets to do that, but it does not work for Products.
A workaround would be to wrap Product in Project:
// Library.qbs Project { property string test_property: “something” StaticLibrary { property string test_property: project.test_property } }
Then this could be done:
// Build.qbs Project { SubProject { filePath: “Library.qbs” Properties { test_property: “something else” } } }
But that does not feel right at all.
It appears another way is to do it is to use QBS from command line, but I work with Qt Creator, so I guess this is not an option in my case.
Is there a better mechanism to override properties? Ideally something similar to what SubProject does.
-
See documentation: https://doc.qt.io/qbs/language-introduction.html#overriding-property-values-from-the-command-line
StaticLibrary { name: "my-library" property string test_property: “something” }
like this:
$qbs products.my-library.test_property:"foo"
You can pass this also and in QtCreator "Qbs build step" properties field of your project, just as
products.my-library.test_property:"foo"
.PS: You can also ask a Qbs question on a Discord server: https://discord.gg/ZXT6YKq (right now all Qbs developers and users live there). ;)
-
Thank you, what you suggested does work, but I am not sure this is quite what I am looking for.
As far as I understand, I will have to manually enter all the product properties that I need to override in the “QBS build steps” submenu each time I reinstall Qt Creator / Operating System or move project to a new machine.
Is there any way to alter these build steps from within the project file itself? I am currently enjoying the fact that I can just open my project file in Qt Creator and immediately build it without having to manually set anything up, I would like to keep it that way.
When talking about “QBS build steps”, you were referring to this article, correct?
Also thanks for that discord link, I will make sure to ask my next questions there as well.
-
@Clint-Westwood said in [QBS] How to override product properties?:
Is there any way to alter these build steps from within the project file itself?
AFAIK, No
I need to override in the “QBS build steps” submenu each time I reinstall Qt Creator / Operating System or move project to a new machine.
Well, these settings are stored in the
*.qbs.user
file which is created by QtCreator automatically.When talking about “QBS build steps”, you were referring to this article, correct?
Yes.
UPD: Alternativelly, you can use the VSCode IDE with the Qbs extension instead of the QtCreator. In the version 1.0.3 was added support for the
qbs-configurations.json
file in which you can specify the desired build configurations with the overridden properties. ;) -
@kuzulis said in [QBS] How to override product properties?:
Well, these settings are stored in the
*.qbs.user
file which is created by QtCreator automatically.But this file is not transferable across machines as far as I remember (I delete it every time I move my project elsewhere). So after moving project to another environment I would still have to set all the properties manually again I suppose.
UPD: Alternativelly, you can use the VSCode IDE with the Qbs extension instead of the QtCreator. In the version 1.0.3 was added support for the
qbs-configurations.json
file in which you can specify the desired build configurations with the overridden properties. ;)That looks like another good idea, I always wanted to try this IDE out ever since that QBS extension had been released, but I am just not bold enough to switch from Qt Creator in the middle of development of my project unfortunately.
There has got to be some way to do it from QBS file, if it can be done from the command line then all the functionality is already there.
-
@Clint-Westwood said in [QBS] How to override product properties?:
here has got to be some way to do it from QBS file
I'm not sure. But you may ask the question on the discord chat, because there are more peoples. ;)