about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorAndersonTorres <torres.anderson.85@protonmail.com>2022-11-15 21:00:57 -0300
committerAndersonTorres <torres.anderson.85@protonmail.com>2022-12-06 23:09:36 -0300
commit762f0a599e0e022739ad50a5a972a656f026db18 (patch)
tree833f4306a01ac9f7a79c09865766d11894945689 /lib
parentfa01623a880c73ae98939f19e0872023f789a4c3 (diff)
lib/strings.nix: add mesonOption utility function
And some friends, to help write Meson commandline invocations.
Diffstat (limited to 'lib')
-rw-r--r--lib/strings.nix55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index b5f5a4d9060ba..96dfb779cd6f5 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -661,6 +661,61 @@ rec {
       name = head (splitString sep filename);
     in assert name != filename; name;
 
+  /* Create a -D<feature>=<value> string that can be passed to typical Meson
+     invocations.
+
+    Type: mesonOption :: string -> string -> string
+
+     @param feature The feature to be set
+     @param value The desired value
+
+     Example:
+       mesonOption "engine" "opengl"
+       => "-Dengine=opengl"
+  */
+  mesonOption = feature: value:
+    assert (lib.isString feature);
+    assert (lib.isString value);
+    "-D${feature}=${value}";
+
+  /* Create a -D<condition>={true,false} string that can be passed to typical
+     Meson invocations.
+
+    Type: mesonBool :: string -> bool -> string
+
+     @param condition The condition to be made true or false
+     @param flag The controlling flag of the condition
+
+     Example:
+       mesonBool "hardened" true
+       => "-Dhardened=true"
+       mesonBool "static" false
+       => "-Dstatic=false"
+  */
+  mesonBool = condition: flag:
+    assert (lib.isString condition);
+    assert (lib.isBool flag);
+    mesonOption condition (lib.boolToString flag);
+
+  /* Create a -D<feature>={enabled,disabled} string that can be passed to
+     typical Meson invocations.
+
+    Type: mesonEnable :: string -> bool -> string
+
+     @param feature The feature to be enabled or disabled
+     @param flag The controlling flag
+
+     Example:
+       mesonEnable "docs" true
+       => "-Ddocs=enabled"
+       mesonEnable "savage" false
+       => "-Dsavage=disabled"
+  */
+  mesonEnable = feature: flag:
+    assert (lib.isString feature);
+    assert (lib.isBool flag);
+    mesonOption feature (if flag then "enabled" else "disabled");
+
   /* Create an --{enable,disable}-<feat> string that can be passed to
      standard GNU Autoconf scripts.