Skip to content
d-random-contributor edited this page Jun 21, 2016 · 2 revisions

C/C++ support

Introduction

DUB started out as a pure D tool. Compiling files of other languages would have to be realized using custom build commands. While this works in general, it has the obvious drawback of either complicating the package description, or requiring additional build tools, such as "make", to be installed.

This proposal adds built-in support for building C and C++ files. While other important glue languages, such as Objective-C, Java or C# are not part of this document, it lays the groundwork for adding additional languages.

Three new build settings are added: "language", "cflags" and "cxxflags".

name "test-package"

language "C++"
cxxflags "-pie" platform="posix-gxx"
sourceFiles "source/**.CC"

Platform specifications stay the same as for D builds, except that the compiler names are those of the C/C++ compiler.

Build settings affected by language selection

The selected language influences the behavior of certain build settings:

  • "dflags": These flags are ignored for building packages with a language other than "D" (the default). However, they are still subject to inheritance to other packages in the package hierarchy.
  • "cflags"/"cxxflags": Similarly, these fields only have an effect if they match the selected language. These fields are generally not subject to inheritance.
  • "sourcePaths": Depending on the selected language, the file extensions that are searched differ:
    • D: "*.d"
    • C: "*.c"
    • C++: "*.cpp", "*.cc"
  • "buildOptions"/"buildRequirements": Build options are matched as good as possible to the current compiler. Not all build options have a corresponding command line flag for every compiler, in which case they will be ignored.
  • "stringImportPaths": Ignored for package with a language other than "D", but inherited to upstream projects.

Compiler selection

The C/C++ compiler will be selected according to the selected D compiler (Windows+DMD=DMC/VC?).

Open questions

  • How is target type "sourceLibrary" handled? Probably forbidden for the time being
Clone this wiki locally