On Sunday, 9 October 2016 at 01:24:57 UTC, WhatMeWorry wrote:
I've got a little hello_window DUB project which uses these
dependencies:
dependency "derelict-util" version="~>2.0.6"
dependency "derelict-glfw3" version="~>3.1.0"
dependency "derelict-gl3" version="~>1.0.19"
dependency "derelict-fi"version="~>2.0.3"
dependency "derelict-ft"version="~>1.1.2"
dependency "derelict-al"version="~>1.0.1"
dub run --verbose --arch=x86_64 --force
successfully compiles and links hello_window.exe
Going forward, I want to reuse common code, so I created a
sub-directory called appropiately enough: common.
And to quote M. Parker's Learning D, "...for imported modules
to be compiled and linked, they should be passed to the
compiler as well."
So how do I get dub to call dmd with this pattern?
dmd hellow_window.d common/load_libraries.d
Subpackages are useful if you have mutiple projects in the same
git repository. Otherwise, there are several ways to go about
this, depending on what your intentions and what your directory
structure looks like. Is the common subdirectory part of the same
project? Is it an independent project you want to share between
multiple projects? Are you planning on distributing the code
(e.g. on github) or is it only for your local build system?
If common is an independent project with its own dub
configuration, then you might use `dub add-local` to make it
available to all of your other projects or, if you don't plan to
distribute it, use a `path` instead of `version` for any projects
that depend on it (in project A's dub.sdl: dependency "libcommon"
path="../path/to/common").
If common is not an independent project (it has no dub
configuration) then you can use `sourcePaths` (or `sourceFiles`)
in the dub configuration of any projects that need it. Or you
could copy it around into the source directory of any project
that uses it and dub will compile it automatically:
- projectA
-- dub.sdl
--- source
projecta
common