Skip to content

hicknhack-software/Qbs-OnlineSource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qbs Online Source

Qbs-OnlineSource allows to download third party sources directly using the Qbs build system.

Usage

You can download any source code from Git or Archive.

Header Only Library from Github

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

Consume another Qbs project

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.

Use custom Qbs product

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" }
  }
}

Installing OnlineSource

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.

Source Properties

Input properties

  • name a string defining the folder for the download in the sourceCache. 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.
  • uri a string containing the project that is downloaded. Use file:// to specify local files. gh: to specify Github repositories. .git urls to specify any Git repository. For Git you can specify the version tag after @ and any tag, branch or full SHA after #.
  • projectFile a 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.
  • sourceCache a path that allows you to customize the base directory for all downloaded sources. By default its ${TEMP}/qbs-source-cache. Prefer the QBS_SOURCE_CACHE environment variable to customize it.
  • buildDirectory a path that allows you to override the build directory, which is used to store probe results.

Environment variables

  • QBS_SOURCE_CACHE allows you to override the sourceCache if the property was not present at Source component.
  • QBS_<NAME>_SOURCE allows you to specify the sourceDirectory for the Source with name in upper case letters.

Result properties

  • found the probe boolean that is true on success
  • sourceDirectory the path where the project is placed
  • projectFilePath the path to the qbs project in the sourceDirectory if it exists.

Contributing

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.

About

Add online source dependencies to your Qbs projects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors