June 13, 2018
I want to import a config file at compile time, but also need a way to have multiple configurations.

With gcc you could do something like -DIMPORTFROM='"MyConfigFile.txt"'. Is there any equivalent in D?

Hardcoding the config files for different versions and using that is not an option. Requiring a fixed filename and using different paths to configure with -J wouldn't be a good solution for my specific situation either.

So far my best idea was to write the wanted filename to a file and import twice.
enum config = import(import("importFrom.txt"));

That works, but that is additional work for the build script and feels like a hack.
June 13, 2018
On Wednesday, 13 June 2018 at 10:57:27 UTC, Malte wrote:
> I want to import a config file at compile time, but also need a way to have multiple configurations.
>
> With gcc you could do something like -DIMPORTFROM='"MyConfigFile.txt"'. Is there any equivalent in D?
>
> Hardcoding the config files for different versions and using that is not an option. Requiring a fixed filename and using different paths to configure with -J wouldn't be a good solution for my specific situation either.
>
> So far my best idea was to write the wanted filename to a file and import twice.
> enum config = import(import("importFrom.txt"));
>
> That works, but that is additional work for the build script and feels like a hack.

If you're using dub just specify "stringImportPath" as a folder to the configuration files.

You can't retrieve the files though, so you'd need to know the names of the files you want to use.

However if they're located in the path then you can just do enum config = import("MyconfigFile.txt");