From 6c0819491ac27bee7c6654a57c879cc4373f3045 Mon Sep 17 00:00:00 2001 From: Niklas Hambüchen Date: Sun, 23 Jun 2024 17:09:36 +0000 Subject: gtest: Allow specifying a newer C++ standard --- pkgs/development/libraries/gtest/default.nix | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'pkgs/development') 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; { -- cgit 1.4.1