Nix: add gtest, cmake: use default var to control tests

This commit is contained in:
Mihai Fufezan 2025-11-09 18:25:43 +02:00
parent 4d24b12a01
commit c4757e57e5
Signed by: fufexan
SSH key fingerprint: SHA256:SdnKmEpJrDu1+2UO1QpB/Eg4HKcdDi6n+xSRqFNJVpg
2 changed files with 41 additions and 31 deletions

View file

@ -53,9 +53,7 @@ set_target_properties(hyprutils PROPERTIES VERSION ${hyprutils_VERSION}
SOVERSION 9)
target_link_libraries(hyprutils PkgConfig::deps)
if (NOT DISABLE_TESTS)
enable_testing()
if(BUILD_TESTING)
# GTest
find_package(GTest CONFIG REQUIRED)
include(GoogleTest)
@ -63,8 +61,12 @@ if (NOT DISABLE_TESTS)
target_compile_definitions(hyprutils_inline_tests PRIVATE HU_UNIT_TESTS=1)
target_compile_options(hyprutils_inline_tests PRIVATE --coverage)
target_link_options(hyprutils_inline_tests PRIVATE --coverage)
target_include_directories(hyprutils_inline_tests PUBLIC "./include" PRIVATE "./src" "./src/include" "./protocols" "${CMAKE_BINARY_DIR}")
target_link_libraries(hyprutils_inline_tests PRIVATE GTest::gtest_main PkgConfig::deps)
target_include_directories(
hyprutils_inline_tests
PUBLIC "./include"
PRIVATE "./src" "./src/include" "./protocols" "${CMAKE_BINARY_DIR}")
target_link_libraries(hyprutils_inline_tests PRIVATE GTest::gtest_main
PkgConfig::deps)
gtest_discover_tests(hyprutils_inline_tests)
endif()

View file

@ -4,6 +4,7 @@
stdenvAdapters,
cmake,
pkg-config,
gtest,
pixman,
version ? "git",
doCheck ? false,
@ -11,10 +12,12 @@
# whether to use the mold linker
# disable this for older machines without SSE4_2 and AVX2 support
withMold ? true,
}: let
}:
let
inherit (builtins) foldl';
inherit (lib.lists) flatten;
inherit (lib.strings) optionalString;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.lists) flatten optional;
inherit (lib.strings) cmakeBool optionalString;
adapters = flatten [
(lib.optional withMold stdenvAdapters.useMoldLinker)
@ -23,7 +26,7 @@
customStdenv = foldl' (acc: adapter: adapter acc) stdenv adapters;
in
customStdenv.mkDerivation {
customStdenv.mkDerivation {
pname = "hyprutils" + optionalString debug "-debug";
inherit version doCheck;
src = ../.;
@ -33,16 +36,21 @@ in
pkg-config
];
buildInputs = [
buildInputs = flatten [
(optional doCheck gtest)
pixman
];
outputs = ["out" "dev"];
outputs = [
"out"
"dev"
];
cmakeBuildType =
if debug
then "Debug"
else "RelWithDebInfo";
cmakeBuildType = if debug then "Debug" else "RelWithDebInfo";
cmakeFlags = mapAttrsToList cmakeBool {
"DISABLE_TESTING" = !doCheck;
};
meta = with lib; {
homepage = "https://github.com/hyprwm/hyprutils";
@ -50,4 +58,4 @@ in
license = licenses.bsd3;
platforms = platforms.linux;
};
}
}