Menu

cpp-build-tuner

Purpose

The plugin provides basic build tuning according to the current profile (Debug/Release) and used toolchain. Also, some customization is available via the plugin configuration section.

Required plugins

The cpp-build-tuner require to work another Gradle core plugins: cpp-application/cpp-library/cpp-unit-test.

Usage

plugins {
    id 'cpp-library'
    id 'cpp-unit-test'
    id 'loggersoft.cpp-build-tuner' version '2.3'
}

Supported toolchains

MSVC and GCC compatible toolchains (CLang).

Profit

The plugin tries to reduce build time for the Debug variant and save maximum information for debugging. In opposite, for Release variant debug information is disabled and maximum speed optimizations (include link-time optimizations) are enabled.

Configuration

buildTuner {

    lto = false

    gtest = '1.8.1'

    libraries {
        common = ['cutils.lib']
        windows = ['ole32', 'user32']
        linux = ['pthread', 'z']
    }

    libDirs.common = ['../build/debug', '../release']

    defines {
        common = ['DEF_COMMON_1', ' DEF_COMMON_2 =  7 ']
        windows = [' DEF_WINDOWS_1', ' DEF_WINDOWS_2=9']
        linux = ['DEF_LINUX_1  ', ' DEF_LINUX_2  =3 ']
    }

    dependencies.common = ['loggersoft.jvm:class-reader:0.1']
    preferCLang = true
    standard = 17
    generateCompileCommands = true
}
  • lto (boolean) - disable or enable LTO (link-time optimizations) on Release. By default LTO is enabled.
  • gtest (string) - the version of Google Test for test binary. At the moment only version 1.8.1 for GCC, MinGW-W64, and MSVC is supported.
  • libraries (container) - the list of libraries for the linker. The field has three parameters (list of strings) inside: common - libraries which will be used on any platform, windows - only on Windows and linux - only on Linux.
  • libDirs (container) - the list of directories on the local file system to search the linker libraries. Inside has the same platform-specific structure as the libraries container (see above).
  • dependencies (container) - the list of dependencies.
  • defines (container) - the list of defines (macros).
  • preferCLang (boolean) - prefers the CLang version of artifacts from the dependencies list if possible ('-2' suffix of version).
  • standard (integer) - is a revision number of the standard for the C++ programming language (e.g. 17).
  • generateCompileCommands (boolean) - generate compile commands into compile_commands.json according to clang specification

Run application

The plugin provides an extension for cpp-application which allow running application via Gradle (like as Java Application plugin).
For application projects, a plugin adds tasks: run, runDebug (same as run) and runRelease. Those tasks depend on assemble, assembleDebug and assembleRelease correspondently.
Also, you can pass command-line arguments as in Java Application plugin:

gradle run --args="arg1 arg2 ..."

Supported system properties (via command-line interface)

  • toolchain - override default toolchain. Possible values are: gcc, mingw, clang, visualcpp (msvc).
  • version - override project version.

How to use Gradle command-line interface to change Java system properties:

gradle -D<property name>=<value>

Examples:

gradle build -Dtoolchain=mingw
gradle publish -Dversion=0.5
gradle publish -Dversion=0.5-?

Variate version

Variate version can be used to publish artifacts are built by different toolchains.
Version format is: <version>-<variant></variant></version>

Variants:

  • 1 - MinGW
  • 2 - CLang
  • ? - Auto choose according current toolchain.

Example:

version = 0.1-?

The final version will be:

  • GCC/MSVC: 0.1
  • MinGW: 0.1-1
  • CLang: 0.1-2

So all binaries can be stored in single Artifactory at the same time.


Related

Commit: [e7771a]

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.