about summary refs log tree commit diff
path: root/pkgs/development/libraries/gtest/default.nix
diff options
context:
space:
mode:
authorNiklas Hambüchen <mail@nh2.me>2024-06-23 17:09:36 +0000
committerNiklas Hambüchen <mail@nh2.me>2024-06-23 17:10:23 +0000
commit6c0819491ac27bee7c6654a57c879cc4373f3045 (patch)
treef567cf659113204aa34b61d804a7ccaa17a5415b /pkgs/development/libraries/gtest/default.nix
parenta71e967ef3694799d0c418c98332f7ff4cc5f6af (diff)
gtest: Allow specifying a newer C++ standard
Diffstat (limited to 'pkgs/development/libraries/gtest/default.nix')
-rw-r--r--pkgs/development/libraries/gtest/default.nix24
1 files changed, 17 insertions, 7 deletions
diff --git a/pkgs/development/libraries/gtest/default.nix b/pkgs/development/libraries/gtest/default.nix
index 51e0c685a43d2..7e44794620c03 100644
--- a/pkgs/development/libraries/gtest/default.nix
+++ b/pkgs/development/libraries/gtest/default.nix
@@ -3,6 +3,21 @@
 , fetchFromGitHub
 , cmake
 , ninja
+# Enable C++17 support
+#     https://github.com/google/googletest/issues/3081
+# Projects that require a higher standard can override this package.
+# For an example why that may be necessary, see:
+#     https://github.com/mhx/dwarfs/issues/188#issuecomment-1907574427
+# Setting this to `null` does not pass any flags to set this.
+, cxx_standard ? (
+    if (
+      (stdenv.cc.isGNU && (lib.versionOlder stdenv.cc.version "11.0"))
+      ||
+      (stdenv.cc.isClang && (lib.versionOlder stdenv.cc.version "16.0"))
+    )
+      then "17"
+      else null
+  )
 , static ? stdenv.hostPlatform.isStatic,
 }:
 
@@ -27,13 +42,8 @@ stdenv.mkDerivation rec {
 
   cmakeFlags = [
     "-DBUILD_SHARED_LIBS=${if static then "OFF" else "ON"}"
-  ] ++ lib.optionals (
-    (stdenv.cc.isGNU && (lib.versionOlder stdenv.cc.version "11.0"))
-    || (stdenv.cc.isClang && (lib.versionOlder stdenv.cc.version "16.0"))
-  ) [
-    # Enable C++17 support
-    # https://github.com/google/googletest/issues/3081
-    "-DCMAKE_CXX_STANDARD=17"
+  ] ++ lib.optionals (cxx_standard != null) [
+    "-DCMAKE_CXX_STANDARD=${cxx_standard}"
   ];
 
   meta = with lib; {