imagelol: fix darwin and use system libpng (#454413)

This commit is contained in:
Ben Siraphob
2025-10-24 05:48:39 +00:00
committed by GitHub
2 changed files with 52 additions and 18 deletions

View File

@@ -4,6 +4,8 @@
fetchFromGitHub, fetchFromGitHub,
fetchpatch, fetchpatch,
cmake, cmake,
libpng,
stb,
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
@@ -25,10 +27,11 @@ stdenv.mkDerivation rec {
url = "https://github.com/MCredstoner2004/ImageLOL/commit/013fb1f901d88f5fd21a896bfab47c7fff0737d7.patch"; url = "https://github.com/MCredstoner2004/ImageLOL/commit/013fb1f901d88f5fd21a896bfab47c7fff0737d7.patch";
hash = "sha256-RVaG2xbUqE4CxqI2lhvug2qihT6A8vN+pIfK58CXLDw="; hash = "sha256-RVaG2xbUqE4CxqI2lhvug2qihT6A8vN+pIfK58CXLDw=";
includes = [ "imagelol/ImageLOL.inl" ]; includes = [ "imagelol/ImageLOL.inl" ];
# change lib/ for imagelol
stripLen = 2; stripLen = 2;
extraPrefix = "imagelol/"; extraPrefix = "imagelol/";
}) })
# use system libraries instead of bundled versions
./use-system-libs.patch
]; ];
# fix for case-sensitive filesystems # fix for case-sensitive filesystems
@@ -36,28 +39,28 @@ stdenv.mkDerivation rec {
postPatch = '' postPatch = ''
mv imagelol src mv imagelol src
substituteInPlace CMakeLists.txt \ substituteInPlace CMakeLists.txt \
--replace 'add_subdirectory("imagelol")' 'add_subdirectory("src")' --replace-fail 'add_subdirectory("imagelol")' 'add_subdirectory("src")'
substituteInPlace External/zlib-no-examples/CMakeLists.txt \ # use system stb headers
--replace-fail "cmake_minimum_required(VERSION 2.4.4)" "cmake_minimum_required(VERSION 3.10)" substituteInPlace External/stb_image-cmake/CMakeLists.txt \
substituteInPlace External/libpng/CMakeLists.txt \ --replace-fail '"''${CMAKE_CURRENT_SOURCE_DIR}/../stb"' '"${stb}/include/stb"'
--replace-fail "cmake_minimum_required(VERSION 3.1)" "cmake_minimum_required(VERSION 3.10)" \
--replace-fail "cmake_policy(VERSION 3.1)" "cmake_policy(VERSION 3.10)" # remove bundled libraries
rm -r External/zlib External/zlib-no-examples External/libpng External/stb
''; '';
nativeBuildInputs = [ cmake ]; nativeBuildInputs = [ cmake ];
installPhase = '' buildInputs = [
mkdir -p $out/bin libpng
cp ./ImageLOL $out/bin stb
''; ];
cmakeFlags = [ installPhase = ''
(lib.cmakeFeature "CMAKE_C_FLAGS" "-std=gnu90") runHook preInstall
] install -Dm755 ImageLOL -t $out/bin
++ lib.optional ( runHook postInstall
stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64 '';
) "-DPNG_ARM_NEON=off";
meta = with lib; { meta = with lib; {
homepage = "https://github.com/MCredstoner2004/ImageLOL"; homepage = "https://github.com/MCredstoner2004/ImageLOL";
@@ -65,7 +68,6 @@ stdenv.mkDerivation rec {
license = licenses.mit; license = licenses.mit;
maintainers = [ ]; maintainers = [ ];
platforms = platforms.unix; platforms = platforms.unix;
broken = stdenv.hostPlatform.isDarwin;
mainProgram = "ImageLOL"; mainProgram = "ImageLOL";
}; };
} }

View File

@@ -0,0 +1,32 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,26 +3,12 @@
project(ImageLOL VERSION 0.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
-include_directories("External/zlib" "External/libpng")
add_subdirectory("External/stb_image-cmake")
-set(SKIP_INSTALL_ALL ON CACHE BOOL "")
-add_subdirectory("External/zlib-no-examples")
-
-set(PNG_BUILD_ZLIB ON CACHE BOOL "")
-link_libraries(zlibstatic)
-get_target_property(ZLIB_INCLUDE_DIRECTORIES zlibstatic INCLUDE_DIRECTORIES)
-include_directories(${ZLIB_INCLUDE_DIRECTORIES})
-set(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIRECTORIES} CACHE PATH "")
-set(PNG_SHARED OFF CACHE BOOL "")
-set(PNG_EXECUTABLES OFF CACHE BOOL "")
-add_subdirectory("External/libpng")
-add_dependencies(png_static zlibstatic zlib)
-add_dependencies(genfiles zlibstatic)
-unset(SKIP_INSTALL_ALL CACHE)
-get_target_property(LIBPNG_INCLUDE_DIRECTORIES png_static INCLUDE_DIRECTORIES)
+find_package(PNG REQUIRED)
+set(LIBPNG_INCLUDE_DIRECTORIES ${PNG_INCLUDE_DIRS})
add_subdirectory("imagelol")
add_executable(ImageLOL main.cpp)
target_include_directories(ImageLOL PRIVATE ${LIBPNG_INCLUDE_DIRECTORIES})
-target_link_libraries(ImageLOL PRIVATE stb_image png_static zlibstatic libimagelol)
+target_link_libraries(ImageLOL PRIVATE stb_image PNG::PNG libimagelol)