Unverified Commit c9f97ce3 authored by Ben Siraphob's avatar Ben Siraphob Committed by GitHub
Browse files

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

parents 00af231d 9da8ee8d
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@
  fetchFromGitHub,
  fetchpatch,
  cmake,
  libpng,
  stb,
}:

stdenv.mkDerivation rec {
@@ -25,10 +27,11 @@ stdenv.mkDerivation rec {
      url = "https://github.com/MCredstoner2004/ImageLOL/commit/013fb1f901d88f5fd21a896bfab47c7fff0737d7.patch";
      hash = "sha256-RVaG2xbUqE4CxqI2lhvug2qihT6A8vN+pIfK58CXLDw=";
      includes = [ "imagelol/ImageLOL.inl" ];
      # change lib/ for imagelol
      stripLen = 2;
      extraPrefix = "imagelol/";
    })
    # use system libraries instead of bundled versions
    ./use-system-libs.patch
  ];

  # fix for case-sensitive filesystems
@@ -36,36 +39,35 @@ stdenv.mkDerivation rec {
  postPatch = ''
    mv imagelol src
    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 \
      --replace-fail "cmake_minimum_required(VERSION 2.4.4)" "cmake_minimum_required(VERSION 3.10)"
    substituteInPlace External/libpng/CMakeLists.txt \
      --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)"
    # use system stb headers
    substituteInPlace External/stb_image-cmake/CMakeLists.txt \
      --replace-fail '"''${CMAKE_CURRENT_SOURCE_DIR}/../stb"' '"${stb}/include/stb"'

    # remove bundled libraries
    rm -r External/zlib External/zlib-no-examples External/libpng External/stb
  '';

  nativeBuildInputs = [ cmake ];

  buildInputs = [
    libpng
    stb
  ];

  installPhase = ''
    mkdir -p $out/bin
    cp ./ImageLOL $out/bin
    runHook preInstall
    install -Dm755 ImageLOL -t $out/bin
    runHook postInstall
  '';

  cmakeFlags = [
    (lib.cmakeFeature "CMAKE_C_FLAGS" "-std=gnu90")
  ]
  ++ lib.optional (
    stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64
  ) "-DPNG_ARM_NEON=off";

  meta = with lib; {
    homepage = "https://github.com/MCredstoner2004/ImageLOL";
    description = "Simple program to store a file into a PNG image";
    license = licenses.mit;
    maintainers = [ ];
    platforms = platforms.unix;
    broken = stdenv.hostPlatform.isDarwin;
    mainProgram = "ImageLOL";
  };
}
+32 −0
Original line number Diff line number Diff line
--- 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)