class JpegTurbo < Formula desc "JPEG image codec that aids compression and decompression" homepage "https://www.libjpeg-turbo.org/" url "https://github.com/libjpeg-turbo/libjpeg-turbo/releases/download/3.1.0/libjpeg-turbo-3.1.0.tar.gz" sha256 "9564c72b1dfd1d6fe6274c5f95a8d989b59854575d4bbee44ade7bc17aa9bc93" license all_of: [ "IJG", # libjpeg API library and programs "Zlib", # libjpeg-turbo SIMD source code "BSD-3-Clause", # TurboJPEG API library and programs ] head "https://github.com/libjpeg-turbo/libjpeg-turbo.git", branch: "main" livecheck do url :stable strategy :github_latest end depends_on "cmake" => :build on_intel do # Required only for x86 SIMD extensions. depends_on "nasm" => :build end # These conflict with `jpeg`, which is now keg-only. link_overwrite "bin/cjpeg", "bin/djpeg", "bin/jpegtran", "bin/rdjpgcom", "bin/wrjpgcom" link_overwrite "include/jconfig.h", "include/jerror.h", "include/jmorecfg.h", "include/jpeglib.h" link_overwrite "lib/libjpeg.dylib", "lib/libjpeg.so", "lib/libjpeg.a", "lib/pkgconfig/libjpeg.pc" link_overwrite "share/man/man1/cjpeg.1", "share/man/man1/djpeg.1", "share/man/man1/jpegtran.1", "share/man/man1/rdjpgcom.1", "share/man/man1/wrjpgcom.1" def install args = ["-DWITH_JPEG8=1", "-DCMAKE_EXE_LINKER_FLAGS=-Wl,-rpath,#{rpath}"] if Hardware::CPU.arm? && OS.mac? if MacOS.version >= :ventura # https://github.com/libjpeg-turbo/libjpeg-turbo/issues/709 args += ["-DFLOATTEST8=fp-contract", "-DFLOATTEST12=fp-contract"] elsif MacOS.version == :monterey # https://github.com/libjpeg-turbo/libjpeg-turbo/issues/734 args << "-DFLOATTEST12=no-fp-contract" end end args += std_cmake_args.reject { |arg| arg["CMAKE_INSTALL_LIBDIR"].present? } system "cmake", "-S", ".", "-B", "build", *args system "cmake", "--build", "build" system "ctest", "--test-dir", "build", "--rerun-failed", "--output-on-failure", "--parallel", ENV.make_jobs system "cmake", "--install", "build" # Avoid rebuilding dependents that hard-code the prefix. inreplace [lib/"pkgconfig/libjpeg.pc", lib/"pkgconfig/libturbojpeg.pc"], prefix, opt_prefix end test do system bin/"jpegtran", "-crop", "1x1", "-transpose", "-perfect", "-outfile", "out.jpg", test_fixtures("test.jpg") assert_predicate testpath/"out.jpg", :exist? end end