diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ed4cbc..5f21be7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/nix/default.nix b/nix/default.nix index 0db0819..093cf00 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -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,31 +26,36 @@ customStdenv = foldl' (acc: adapter: adapter acc) stdenv adapters; in - customStdenv.mkDerivation { - pname = "hyprutils" + optionalString debug "-debug"; - inherit version doCheck; - src = ../.; +customStdenv.mkDerivation { + pname = "hyprutils" + optionalString debug "-debug"; + inherit version doCheck; + src = ../.; - nativeBuildInputs = [ - cmake - pkg-config - ]; + nativeBuildInputs = [ + cmake + pkg-config + ]; - buildInputs = [ - pixman - ]; + 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"; - meta = with lib; { - homepage = "https://github.com/hyprwm/hyprutils"; - description = "Small C++ library for utilities used across the Hypr* ecosystem"; - license = licenses.bsd3; - platforms = platforms.linux; - }; - } + cmakeFlags = mapAttrsToList cmakeBool { + "DISABLE_TESTING" = !doCheck; + }; + + meta = with lib; { + homepage = "https://github.com/hyprwm/hyprutils"; + description = "Small C++ library for utilities used across the Hypr* ecosystem"; + license = licenses.bsd3; + platforms = platforms.linux; + }; +}