class JpegXl < Formula desc "New file format for still image compression" homepage "https://jpeg.org/jpegxl/index.html" url "https://github.com/libjxl/libjxl/archive/refs/tags/v0.11.1.tar.gz" sha256 "1492dfef8dd6c3036446ac3b340005d92ab92f7d48ee3271b5dac1d36945d3d9" license "BSD-3-Clause" livecheck do url :stable regex(/^v?(\d+(?:\.\d+)+)$/i) end depends_on "asciidoc" => :build depends_on "cmake" => :build depends_on "docbook-xsl" => :build depends_on "doxygen" => :build depends_on "pkgconf" => [:build, :test] depends_on "sphinx-doc" => :build depends_on "brotli" depends_on "giflib" depends_on "highway" depends_on "imath" depends_on "jpeg-turbo" depends_on "libpng" depends_on "little-cms2" depends_on "openexr" depends_on "webp" uses_from_macos "libxml2" => :build uses_from_macos "libxslt" => :build # for xsltproc uses_from_macos "python" # These resources are versioned according to the script supplied with jpeg-xl to download the dependencies: # https://github.com/libjxl/libjxl/tree/v#{version}/third_party resource "sjpeg" do url "https://github.com/webmproject/sjpeg.git", revision: "e5ab13008bb214deb66d5f3e17ca2f8dbff150bf" end def install ENV.append_path "XML_CATALOG_FILES", HOMEBREW_PREFIX/"etc/xml/catalog" resources.each { |r| r.stage buildpath/"third_party"/r.name } system "cmake", "-S", ".", "-B", "build", "-DJPEGXL_FORCE_SYSTEM_BROTLI=ON", "-DJPEGXL_FORCE_SYSTEM_LCMS2=ON", "-DJPEGXL_FORCE_SYSTEM_HWY=ON", "-DJPEGXL_ENABLE_DEVTOOLS=ON", "-DJPEGXL_ENABLE_JNI=OFF", "-DJPEGXL_ENABLE_JPEGLI=OFF", "-DJPEGXL_ENABLE_SKCMS=OFF", "-DJPEGXL_VERSION=#{version}", "-DJPEGXL_ENABLE_MANPAGES=ON", "-DCMAKE_INSTALL_RPATH=#{rpath}", "-DPython_EXECUTABLE=#{Formula["asciidoc"].libexec/"bin/python"}", "-DPython3_EXECUTABLE=#{Formula["asciidoc"].libexec/"bin/python3"}", *std_cmake_args system "cmake", "--build", "build" system "cmake", "--build", "build", "--target", "install" # Avoid rebuilding dependents that hard-code the prefix. inreplace (lib/"pkgconfig").glob("*.pc"), prefix, opt_prefix end test do system bin/"cjxl", test_fixtures("test.jpg"), "test.jxl" assert_path_exists testpath/"test.jxl" (testpath/"jxl_test.c").write <<~C #include #include int main() { JxlEncoder* enc = JxlEncoderCreate(NULL); if (enc == NULL) { return EXIT_FAILURE; } JxlEncoderDestroy(enc); return EXIT_SUCCESS; } C jxl_flags = shell_output("pkgconf --cflags --libs libjxl").chomp.split system ENV.cc, "jxl_test.c", *jxl_flags, "-o", "jxl_test" system "./jxl_test" (testpath/"jxl_threads_test.c").write <<~C #include #include int main() { void* runner = JxlThreadParallelRunnerCreate(NULL, 1); if (runner == NULL) { return EXIT_FAILURE; } JxlThreadParallelRunnerDestroy(runner); return EXIT_SUCCESS; } C jxl_threads_flags = shell_output("pkgconf --cflags --libs libjxl_threads").chomp.split system ENV.cc, "jxl_threads_test.c", *jxl_threads_flags, "-o", "jxl_threads_test" system "./jxl_threads_test" end end