Qbs-OnlineSource allows to download third party sources directly using the Qbs build system.
You can download any source code from Git or Archive.
import qbs.FileInfo
import online
CppApplication {
name: "json_example"
consoleApplication: true
files: ["main.cpp"]
cpp.includePaths: FileInfo.joinPaths(jsonSource.sourceDirectory, "include")
online.Source {
id: jsonSource
name: "nlohmann_json"
uri: "gh:nlohmann/json@3.12.0"
}
Depends { name: "cpp" }
}online.Source is a Qbs Probe that will download the uri. In this case clone the Git repository from Github in the specified version.
It will store the folder as sourceDirectory
This works best when the Qbs project is well prepared for external inclusion.
import online
Project {
id: root
online.Source {
id: sourceMap
name: "SourceMap"
uri: "gh:hicknhack-software/SourceMap-Cpp#ee4759af5e939a2f40420915b26c3abcfca6e797"
}
online.QbsProject {
source: sourceMap
}
// Use the SourceMapLibrary product...
}online.QbsProject expects the Probe at the source property.
You define how the downloaded code is compiled and used in Qbs.
import qbs.FileInfo
import online
StaticLibrary {
name: "catch2-with-main"
readonly property path sourcePath: source.sourceDirectory
condition: source.found
files: ["catch2/catch_user_config.hpp"] // config is required
cpp.combineCxxSources: true
cpp.includePaths: [
FileInfo.joinPaths(sourcePath, "src"),
".",
]
online.Source {
id: source
name: "catch2"
uri: "gh:catchorg/catch2@3.12.0"
}
Group {
name: "src/catch2"
prefix: FileInfo.joinPaths(sourcePath, "src", "catch2") + "/"
files: [
"**/*.cpp",
"**/*.hpp"
]
}
Depends { name: "cpp" }
Export {
cpp.includePaths: [
FileInfo.joinPaths(exportingProduct.sourcePath, "src"),
exportingProduct.sourceDirectory,
]
Depends { name: "cpp" }
}
}The easiest path is to copy the qbs/ folder of this repository into your code repository and add the folder to the qbsSearchPaths and use a third_party.qbs project for all online dependencies.
Alternatively you can copy the files in qbs/import/online and import them relative using import "./Source.qbs" as OnlineSource. This has the advantage that you can directly use it, without referencing another project.
namea string defining the folder for the download in thesourceCache. Note: Only the first Source probe with a given name will download anything. Later Source probes will give the same results. This allows you to override versions in downstream projects.uria string containing the project that is downloaded. Usefile://to specify local files.gh:to specify Github repositories..giturls to specify any Git repository. For Git you can specify the version tag after@and any tag, branch or full SHA after#.projectFilea string that allows you to specify the name of the qbs project in the downloaded source. Use this option if there are multiple qbs files a root level.sourceCachea path that allows you to customize the base directory for all downloaded sources. By default its${TEMP}/qbs-source-cache. Prefer theQBS_SOURCE_CACHEenvironment variable to customize it.buildDirectorya path that allows you to override the build directory, which is used to store probe results.
QBS_SOURCE_CACHEallows you to override thesourceCacheif the property was not present atSourcecomponent.QBS_<NAME>_SOURCEallows you to specify thesourceDirectoryfor theSourcewithnamein upper case letters.
foundthe probe boolean that is true on successsourceDirectorythe path where the project is placedprojectFilePaththe path to the qbs project in thesourceDirectoryif it exists.
If you use and like this project please leave a ⭐ star. If you have suggestions feel free to add an issue or better create a pull request. If you need paid support or coaching or an Qbs expert just reach out to contact HicknHack Software.