On Wednesday, 30 October 2013 at 20:19:11 UTC, Adam D. Ruppe
wrote:
It won't really work on the command line alone, but the way I
do it is a two step thing. First, make the thing use a config
module:
import myproject.config;
alias Thing Thing_Impl!dim;
then you go ahead and use Thing, which is instantiated with the
dimension. Then the user makes a file:
module myproject.config;
enum dim = 10; // or whatever
and compiles it all:
dmd main.d yourlib.d config.d
and it works out. They can swap out config.d for other files
with other values and definitions on the command line to
customize it.
It would also be possible to provide a default if you go with
the whole library route, compiling the default into the .lib
and giving the default in the project include path, both of
which would be overridden by the user's explicit config source
file on the command line.
So not as simple as -Ddim=10, but gets the job done. You can
also use this technique with static if to version stuff out
they don't want and other similar tasks; I actually like it
better than -version for the most part.
This should work for what I want, and I was thinking of something
along these lines, but was hoping there might be a simpler
solution.
Craig