www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Get compile time string of dmd command line options "-os" & "-target"

reply An Pham <home home.com> writes:
pragma(msg, os.stringof...?);
pragma(msg, target.stringof...?);

what is use case for this? mixin & import

     Long list of version.....
     version(Windows)
         mixin(import("foo_windows.enum."));
     else version(AArch64)
         mixin(import("foo_aarch64.enum"));
     else
         static assert(0);

Shorter with one line
mixin(import("foo_" ~ os.stringof ~ ".enum."));
mixin(import("foo_" ~ target.stringof ~ ".enum."));
Jul 31
parent reply Dennis <dkorpel gmail.com> writes:
On Thursday, 1 August 2024 at 04:00:08 UTC, An Pham wrote:
 pragma(msg, os.stringof...?);
 pragma(msg, target.stringof...?);
There's no built-in way, but you can define it yourself in a helper module: ```D version(Windows) enum os = "windows"; else version(AArch64) enum os = "aarch64"; else static assert(0, "unsupported os"); ```
Aug 03
parent Steven Schveighoffer <schveiguy gmail.com> writes:
On Saturday, 3 August 2024 at 12:15:46 UTC, Dennis wrote:
 On Thursday, 1 August 2024 at 04:00:08 UTC, An Pham wrote:
 pragma(msg, os.stringof...?);
 pragma(msg, target.stringof...?);
There's no built-in way, but you can define it yourself in a helper module: ```D version(Windows) enum os = "windows"; else version(AArch64) enum os = "aarch64"; else static assert(0, "unsupported os"); ```
First, I will note that "windows" and "aarch64" are not in the same category... Second, there are some already-built parts in phobos: https://dlang.org/phobos/std_compiler.html https://dlang.org/phobos/std_system.html I also went ahead and did some for arch and runtime flavor, in a project where I needed these, feel free to steal (Boost licensed): https://github.com/schveiguy/raylib-d/blob/master/install/source/app.d#L135-L154 -Steve
Aug 03