### Install MSan-compiled libc++ Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Helper command to download, compile, and install libc++ and libc++abi with -fsanitize=memory. ```bash ./ci.sh msan_install ``` -------------------------------- ### Install JPEG XL Source: https://github.com/google/jpegli/blob/main/BUILDING.md Installs the compiled JPEG XL library and tools system-wide. ```bash sudo cmake --install . ``` -------------------------------- ### Install llvm-symbolizer Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Installs llvm-symbolizer on a Debian-based system, which is helpful for obtaining stack traces with symbols. ```bash sudo apt install llvm # or llvm-7, etc for a specific version. ``` -------------------------------- ### Install a package Source: https://github.com/google/jpegli/blob/main/doc/developing_in_windows_msys.md Command to install a specific package, optionally specifying the build environment. ```bash pacman -S mingw-w64-x86_64-cmake ``` -------------------------------- ### Reproducing 'cross' workflows locally Source: https://github.com/google/jpegli/blob/main/doc/debugging_workflows.md This snippet shows how to set up a Docker environment to reproduce the 'cross' build and test workflows locally. It includes environment variable setup, package installation, and the build command. ```bash docker run -it -v`pwd`:/jpegli debian:bookworm bash cd /jpegli export ARCH=i386 # arm64 armhf export MAIN_LIST="amd64,${ARCH}" export BUILD_DIR=build export CC=clang-14 export CXX=clang++-14 export BUILD_TARGET=i386-linux-gnu # aarch64-linux-gnu arm-linux-gnueabihf rm -f /var/lib/man-db/auto-update apt-get update -y apt-get install -y ca-certificates debian-ports-archive-keyring python3 dpkg --add-architecture ${ARCH} python3 ./tools/scripts/transform_sources_list.py "${MAIN_LIST}" apt update apt-get install -y \ clang-14 cmake doxygen g++-aarch64-linux-gnu graphviz \ libc6-dev-${ARCH}-cross libgif-dev:${ARCH} libilmbase-dev:${ARCH} \ libjpeg-dev:${ARCH} libopenexr-dev:${ARCH} libpng-dev:${ARCH} \ libstdc++-12-dev-${ARCH}-cross libstdc++-12-dev:${ARCH} libwebp-dev:${ARCH} \ ninja-build pkg-config qemu-user-static unzip xdg-utils xvfb #apt-get install -y binutils-${BUILD_TARGET} gcc-${BUILD_TARGET} #apt-get install -y \ # libgoogle-perftools-dev:${ARCH} libgoogle-perftools4:${ARCH} \ # libtcmalloc-minimal4:${ARCH} libunwind-dev:${ARCH} #export CMAKE_FLAGS "-march=armv8-a+sve" SKIP_TEST=1 ./ci.sh release \ -DJPEGLI_ENABLE_JNI=OFF # -DCMAKE_CROSSCOMPILING_EMULATOR=/usr/bin/qemu-aarch64-static # -DJPEGLI_ENABLE_OPENEXR=off ``` -------------------------------- ### Install Emscripten SDK Source: https://github.com/google/jpegli/blob/main/doc/building_wasm.md Steps to download and install the Emscripten SDK. ```bash cd $OPT # Get the emsdk repo. git clone https://github.com/emscripten-core/emsdk.git # Enter that directory. cd emsdk # Download and install the latest SDK tools. ./emsdk install latest # Make the "latest" SDK "active" for the current user. (writes ~/.emscripten file) ./emsdk activate latest ``` -------------------------------- ### Install Clang and set environment variables Source: https://github.com/google/jpegli/blob/main/BUILDING.md Installs the Clang compiler and sets CC and CXX environment variables for its use. ```bash sudo apt install clang export CC=clang CXX=clang++ ``` -------------------------------- ### Setting Installation Paths Source: https://github.com/google/jpegli/blob/main/lib/CMakeLists.txt This snippet sets the PKGCONFIG_TARGET_INCLUDES and PKGCONFIG_TARGET_LIBS variables based on whether the installation directories are absolute or relative. ```cmake if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") set(PKGCONFIG_TARGET_INCLUDES "${CMAKE_INSTALL_INCLUDEDIR}") else() set(PKGCONFIG_TARGET_INCLUDES "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") endif() if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") set(PKGCONFIG_TARGET_LIBS "${CMAKE_INSTALL_LIBDIR}") else() set(PKGCONFIG_TARGET_LIBS "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") endif() ``` -------------------------------- ### Install LLVM using Homebrew Source: https://github.com/google/jpegli/blob/main/BUILDING_OSX.md Installs the LLVM compiler suite, which might be required for building. ```bash brew install llvm ``` -------------------------------- ### Install Dependencies Source: https://github.com/google/jpegli/blob/main/BUILDING_Haiku.md Installs the necessary build tools and libraries for Jpegli on Haiku using pkgman. ```shell pkgman install llvm9_clang ninja cmake doxygen libjpeg_turbo_devel giflib_devel ``` -------------------------------- ### Install optional dependencies on Debian/Ubuntu Source: https://github.com/google/jpegli/blob/main/BUILDING.md Installs optional dependencies to support additional formats in the `cjxl`/`djxl` tools. ```bash sudo apt install libgif-dev libjpeg-dev libopenexr-dev libpng-dev libwebp-dev ``` -------------------------------- ### Compression Examples Source: https://github.com/google/jpegli/blob/main/doc/man/cjpegli.txt Shows examples of compressing a PNG file to a high-quality JPEG XL version, at a slightly lower quality for web use, and losslessly. ```bash # Compress a PNG file to a high-quality JPEG XL version. $ cjpegli input.png output.jpegli # Compress it at a slightly lower quality, appropriate for web use. $ cjpegli -d 2 input.png output.jpegli # Compress it losslessly. These are equivalent. $ cjpegli -d 0 input.png lossless.jpegli $ cjpegli -q 100 input.png lossless.jpegli # Compress a JPEG file losslessly. $ cjpegli input.jpeg lossless-jpeg.jpegli ``` -------------------------------- ### Build fuzzer targets with oss-fuzz (MSan example) Source: https://github.com/google/jpegli/blob/main/doc/fuzzing.md Example command to build fuzzer targets using MSan with the ci.sh script, mounting the current source directory into the Docker container. ```bash BUILD_DIR=build-fuzzmsan ./ci.sh ossfuzz_msan ``` -------------------------------- ### Set up MING64 environment Source: https://github.com/google/jpegli/blob/main/doc/developing_in_windows_msys.md Commands to install essential development tools and libraries for the MING64 environment. ```bash pacman -S --needed base-devel mingw-w64-x86_64-toolchain pacman -S git mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-gtest mingw-w64-x86_64-giflib mingw-w64-x86_64-libpng mingw-w64-x86_64-libjpeg-turbo ``` -------------------------------- ### Install gtest Source: https://github.com/google/jpegli/blob/main/doc/developing_with_crossroad.md Installs the gtest dependency using Crossroad. ```bash crossroad install gtest ``` -------------------------------- ### Install GIMP package for MSYS2 Source: https://github.com/google/jpegli/blob/main/doc/developing_in_windows_msys.md Commands to install the GIMP package for different MSYS2 architectures. ```bash pacman -S mingw-w64-i686-gimp pacman -S mingw-w64-x86_64-gimp pacman -S mingw-w64-ucrt-x86_64-gimp ``` -------------------------------- ### Basic Usage Examples Source: https://github.com/google/jpegli/blob/main/doc/man/cjpegli.txt Demonstrates basic compression of PNG and JPEG files to JPEG XL format. ```bash cjpegli input.png output.jpegli cjpegli input.jpg output.jpegli cjpegli input.gif output.jpegli ``` -------------------------------- ### Install core dependencies using Homebrew Source: https://github.com/google/jpegli/blob/main/BUILDING_OSX.md Installs essential development libraries and tools required for building. ```bash brew install coreutils cmake giflib jpeg-turbo libpng ninja zlib ``` -------------------------------- ### Install clang packages for MSYS2 Source: https://github.com/google/jpegli/blob/main/doc/developing_in_windows_msys.md Lists the packages to install for using the clang compiler in different MSYS2 environments. ```bash mingw-w64-i686-clang mingw-w64-i86-clang-tools-extra mingw-w64-i686-clang-compiler-rt mingw-w64-x86_64-clang mingw-w64-x86_64-clang-tools-extra mingw-w64-x86_64-clang-compiler-rt mingw-w64-ucrt64-x86_64-clang mingw-w64-ucrt64-x86_64-clang-tools-extra mingw-w64-ucrt64-x86_64-clang-compiler-rt ``` -------------------------------- ### Install build dependencies using vcpkg Source: https://github.com/google/jpegli/blob/main/doc/developing_in_windows_vcpkg.md This command installs the necessary libraries for building the project on Windows using vcpkg. ```bash vcpkg install gtest:x64-windows vcpkg install giflib:x64-windows vcpkg install libjpeg-turbo:x64-windows vcpkg install libpng:x64-windows vcpkg install zlib:x64-windows ``` -------------------------------- ### Install Crossroad Dependencies Source: https://github.com/google/jpegli/blob/main/doc/developing_with_crossroad.md Installs the necessary dependencies for Crossroad, including python3-docutils and mingw-w64, using aptitude. ```bash sudo aptitude install python3-docutils mingw-w64 ``` -------------------------------- ### Install Crossroad Source: https://github.com/google/jpegli/blob/main/doc/developing_with_crossroad.md Installs the Crossroad tool itself using pip3. ```bash pip3 install crossroad ``` -------------------------------- ### Minimum build dependencies Source: https://github.com/google/jpegli/blob/main/doc/developing_in_debian.md Installs the essential tools and libraries required for building the jpegli project on Debian/Ubuntu. ```bash sudo apt install clang cmake doxygen graphviz ninja-build libpng-dev ``` -------------------------------- ### Benchmark with benchmark_xl Source: https://github.com/google/jpegli/blob/main/doc/benchmarking.md Example invocation of the benchmark_xl tool to compare different JPEG XL encoding parameters. ```bash build/tools/benchmark_xl --input "/path/*.png" --codec jxl:wombat:d1,jxl:cheetah:d2 ``` -------------------------------- ### Install required dependencies on Debian/Ubuntu Source: https://github.com/google/jpegli/blob/main/BUILDING.md Installs the essential dependencies for compiling JPEG XL on Debian or Ubuntu-based systems. ```bash sudo apt install cmake pkg-config libbrotli-dev ``` -------------------------------- ### Install zstandard package Source: https://github.com/google/jpegli/blob/main/doc/developing_with_crossroad.md Installs the zstandard python package using pip3 as it's not available in standard repositories. ```bash pip3 install zstandard ``` -------------------------------- ### Start a new branch Source: https://github.com/google/jpegli/blob/main/doc/developing_in_github.md Creates a new local branch 'mybranch' that tracks the 'origin/main' branch. ```bash git checkout origin/main -b mybranch ``` -------------------------------- ### Optional build dependencies Source: https://github.com/google/jpegli/blob/main/doc/developing_in_debian.md Installs additional packages for compiling extra tool support and tests. ```bash sudo apt install extra-cmake-modules g++ libbenchmark-dev libbenchmark-tools \n libgif-dev libgoogle-perftools-dev libgtest-dev libjpeg-dev libopenexr-dev \n libwebp-dev qt6-base-dev xdg-utils ``` -------------------------------- ### Rebuilding and testing a specific fuzzer target Source: https://github.com/google/jpegli/blob/main/doc/fuzzing.md Example command to rebuild and test the 'djxl_fuzzer' in MSan mode. ```bash BUILD_DIR=build-fuzzmsan ./ci.sh ossfuzz_msan djxl_fuzzer && build-fuzzmsan/tools/djxl_fuzzer path/to/testcase.bin ``` -------------------------------- ### Install jpeg-xl using Homebrew Source: https://github.com/google/jpegli/blob/main/BUILDING_OSX.md Installs the JPEG XL library and binaries using the Homebrew package manager. ```bash brew install jpeg-xl ``` -------------------------------- ### Lint/coverage dependencies Source: https://github.com/google/jpegli/blob/main/doc/developing_in_debian.md Installs packages required for linting and coverage commands. ```bash sudo apt install clang-format clang-tidy curl parallel gcovr ``` -------------------------------- ### Install GIMP Development Package Source: https://github.com/google/jpegli/blob/main/doc/developing_with_crossroad.md Installs the gimp development package using Crossroad, which includes most packages required by jpegli. ```bash crossroad install gimp ``` -------------------------------- ### Check clang version Source: https://github.com/google/jpegli/blob/main/doc/developing_in_debian.md Verifies the installed version of the clang compiler. ```bash clang --version ``` -------------------------------- ### Manpage Generation with Asciidoc Source: https://github.com/google/jpegli/blob/main/CMakeLists.txt Finds Asciidoc, determines the Python interpreter to use, and generates man pages if found. Includes custom command for manpage generation and installation. ```cmake if(JPEGLI_ENABLE_MANPAGES) find_program(ASCIIDOC a2x) if(ASCIIDOC) file(STRINGS "${ASCIIDOC}" ASCIIDOC_SHEBANG LIMIT_COUNT 1) if(ASCIIDOC_SHEBANG MATCHES "sh( -e)?$" OR ASCIIDOC_SHEBANG MATCHES "libexec/bin/python$" OR MINGW) set(ASCIIDOC_PY_FOUND ON) # Run the program directly and set ASCIIDOC as empty. set(ASCIIDOC_PY "${ASCIIDOC}") set(ASCIIDOC "") elseif(ASCIIDOC_SHEBANG MATCHES "python2") find_package(Python2 COMPONENTS Interpreter) set(ASCIIDOC_PY_FOUND "${Python2_Interpreter_FOUND}") set(ASCIIDOC_PY Python2::Interpreter) elseif(ASCIIDOC_SHEBANG MATCHES "python3") find_package(Python3 COMPONENTS Interpreter) set(ASCIIDOC_PY_FOUND "${Python3_Interpreter_FOUND}") set(ASCIIDOC_PY Python3::Interpreter) else() find_package(Python COMPONENTS Interpreter QUIET) if(NOT Python_Interpreter_FOUND) find_program(ASCIIDOC_PY python) if(ASCIIDOC_PY) set(ASCIIDOC_PY_FOUND ON) endif() else() set(ASCIIDOC_PY_FOUND "${Python_Interpreter_FOUND}") set(ASCIIDOC_PY Python::Interpreter) endif() endif() if (ASCIIDOC_PY_FOUND) set(MANPAGE_FILES "") set(MANPAGES "") foreach(PAGE IN ITEMS cjpegli djpegli) # Invoking the Python interpreter ourselves instead of running the a2x binary # directly is necessary on MSYS2, otherwise it is run through cmd.exe which # does not recognize it. add_custom_command( OUTPUT "${PAGE}.1" COMMAND "${ASCIIDOC_PY}" ARGS ${ASCIIDOC} --format manpage --destination-dir="${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/doc/man/${PAGE}.txt" MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/doc/man/${PAGE}.txt") list(APPEND MANPAGE_FILES "${CMAKE_CURRENT_BINARY_DIR}/${PAGE}.1") list(APPEND MANPAGES "${PAGE}.1") endforeach() add_custom_target(manpages ALL DEPENDS ${MANPAGES}) install(FILES ${MANPAGE_FILES} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) endif() # ASCIIDOC_PY_FOUND else() message(WARNING "asciidoc was not found, the man pages will not be installed.") endif() # ASCIIDOC endif() # JPEGLI_ENABLE_MANPAGES ``` -------------------------------- ### Basic Build and Unit Tests Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Builds jpegli and runs its unit tests. ```bash ./ci.sh release ``` -------------------------------- ### Build project with MSan in a custom directory Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Builds the project with MSan enabled, specifying a custom build directory. ```bash BUILD_DIR=build-msan ./ci.sh msan ``` -------------------------------- ### Build project with MSan Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Builds the project with Memory Sanitizer enabled. Uses the default 'build' directory. ```bash ./ci.sh msan ``` -------------------------------- ### Cross-compiling for a Target Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Compiles the code for the aarch64-linux-gnu target triplet. ```bash BUILD_TARGET=aarch64-linux-gnu ./ci.sh release ``` -------------------------------- ### Linting and Formatting Source: https://github.com/google/jpegli/blob/main/CONTRIBUTING.md The project follows the Google C++ Coding Style and provides a clang-format configuration file. The `./ci.sh lint` tool can be used to automatically format the code. ```bash ./ci.sh lint ``` -------------------------------- ### Build and test project Source: https://github.com/google/jpegli/blob/main/doc/developing_in_debian.md Builds the jpegli project using CMake and runs unit tests. Binaries are placed in build/tools. ```bash ./ci.sh opt ``` -------------------------------- ### Address Sanitizer (ASan) with Custom Build Directory Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Builds and runs unittests with ASan enabled, separating build files into a custom directory. ```bash BUILD_DIR=build-asan ./ci.sh asan ``` -------------------------------- ### Setting up symbolizer paths and sanitizer options Source: https://github.com/google/jpegli/blob/main/doc/fuzzing.md Environment variables to set for symbolizer paths and sanitizer options (MSan, UBSan, ASan). ```bash symbolizer=$($(realpath "$(which clang)") -print-prog-name=llvm-symbolizer) export MSAN_SYMBOLIZER_PATH="${symbolizer}" export UBSAN_SYMBOLIZER_PATH="${symbolizer}" export ASAN_SYMBOLIZER_PATH="${symbolizer}" export ASAN_OPTIONS=detect_leaks=1 export UBSAN_OPTIONS=print_stacktrace=1 ``` -------------------------------- ### Reconfigure and build GIMP plugin with CMake Source: https://github.com/google/jpegli/blob/main/doc/developing_in_windows_msys.md Navigates to the build directory, removes previous CMake configurations, and reconfigures and builds the GIMP plugin. ```bash cd build rm -r CM* cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF \ -DJPEGLI_ENABLE_BENCHMARK=OFF -DJPEGLI_ENABLE_MANPAGES=OFF \ -DJPEGLI_FORCE_SYSTEM_GTEST=ON .. ``` -------------------------------- ### Set CMAKE_PREFIX_PATH environment variable Source: https://github.com/google/jpegli/blob/main/BUILDING_OSX.md Configures the CMAKE_PREFIX_PATH to help CMake find installed libraries. ```bash export CMAKE_PREFIX_PATH=`brew --prefix giflib`:`brew --prefix jpeg-turbo`:`brew --prefix libpng`:`brew --prefix zlib` ``` -------------------------------- ### Clone the repository Source: https://github.com/google/jpegli/blob/main/BUILDING.md Clones the JPEG XL repository, including necessary submodules for dependencies. ```bash git clone https://github.com/libjxl/libjxl.git --recursive --shallow-submodules ``` -------------------------------- ### Exporting Cross-compiling Environment Variables Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Exports BUILD_TARGET and BUILD_DIR for cross-compiling and custom build directories. ```bash export BUILD_TARGET=x86_64-w64-mingw32 BUILD_DIR=build-foobar ``` -------------------------------- ### Highway Library Configuration Source: https://github.com/google/jpegli/blob/main/third_party/CMakeLists.txt Configures build options for the Highway library, including static linking and disabling contributions, examples, and tests when sanitizers are enabled. ```cmake set(HWY_SYSTEM_GTEST ON CACHE INTERNAL "") set(HWY_FORCE_STATIC_LIBS ON CACHE INTERNAL "") set(HWY_ENABLE_CONTRIB OFF CACHE INTERNAL "") set(HWY_ENABLE_EXAMPLES OFF CACHE INTERNAL "") set(HWY_ENABLE_TESTS OFF CACHE INTERNAL "") if((SANITIZER STREQUAL "asan") OR (SANITIZER STREQUAL "msan")) set(HWY_ENABLE_INSTALL OFF CACHE INTERNAL "") endif() ``` -------------------------------- ### Fetch and rebase shortcut Source: https://github.com/google/jpegli/blob/main/doc/developing_in_github.md A shortcut command to fetch changes from the remote and rebase the current branch onto them. ```bash git pull -r ``` -------------------------------- ### Run All Tests in Parallel Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Manually runs all tests in parallel across all available CPUs. ```bash ./ci.sh test ``` -------------------------------- ### List All Available Tests Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Lists all available tests using ctest with the -N flag. ```bash ./ci.sh test -N ``` -------------------------------- ### Setup tmate session for GitHub Actions debugging Source: https://github.com/google/jpegli/blob/main/doc/debugging_workflows.md This snippet can be added to a GitHub Actions workflow file to set up a tmate session for debugging. It is typically used when a workflow fails. ```yaml - name: Setup tmate session # Or other condition that pin-points a single strategy matrix item if: failure() uses: mxschmitt/action-tmate@a283f9441d2d96eb62436dc46d7014f5d357ac22 # v3.17 timeout-minutes: 15 ``` -------------------------------- ### Search for a package Source: https://github.com/google/jpegli/blob/main/doc/developing_in_windows_msys.md Command to search for a package, showing its organization across different build environments. ```bash pacman -Ss cmake ``` -------------------------------- ### Sync to the latest version Source: https://github.com/google/jpegli/blob/main/doc/developing_in_github.md Fetches the latest changes from the origin remote. ```bash git fetch origin ``` -------------------------------- ### Apply Lint Patch Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Applies the output of the lint command as a patch. ```bash ./ci.sh lint | patch -p1 ``` -------------------------------- ### Full submodule update Source: https://github.com/google/jpegli/blob/main/BUILDING.md Pulls all commits for submodules if full clones are necessary. ```bash git submodule foreach git fetch --unshallow git submodule update --init --recursive ``` -------------------------------- ### libpng Configuration (Bundled with Emscripten) Source: https://github.com/google/jpegli/blob/main/third_party/CMakeLists.txt Configures libpng when bundled with Emscripten. It checks for the existence of libpng, copies a prebuilt configuration header, and sets up ZLIB and PNG variables. ```cmake if (JPEGLI_BUNDLE_LIBPNG AND EMSCRIPTEN) if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libpng/CMakeLists.txt") message(FATAL_ERROR "Please provide libpng or " "run ${PROJECT_SOURCE_DIR}/deps.sh to fetch the build dependencies.") endif() file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/libpng/scripts/pnglibconf.h.prebuilt" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/libpng") file(RENAME "${CMAKE_CURRENT_SOURCE_DIR}/libpng/pnglibconf.h.prebuilt" "${CMAKE_CURRENT_SOURCE_DIR}/libpng/pnglibconf.h") set(ZLIB_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/zlib/") set(ZLIB_LIBRARIES "") set(PNG_FOUND YES PARENT_SCOPE) set(PNG_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/libpng/" PARENT_SCOPE) set(PNG_LIBRARIES "" PARENT_SCOPE) endif() ``` -------------------------------- ### Build jpegli with clang and ci.sh script Source: https://github.com/google/jpegli/blob/main/doc/developing_in_windows_msys.md Builds jpegli using the ci.sh script with clang, specifying build options. ```bash ./ci.sh opt -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF \ -DJPEGLI_ENABLE_BENCHMARK=OFF -DJPEGLI_ENABLE_MANPAGES=OFF \ -DJPEGLI_FORCE_SYSTEM_GTEST=ON ``` -------------------------------- ### skcms Enablement Source: https://github.com/google/jpegli/blob/main/third_party/CMakeLists.txt Includes skcms.cmake and copies the license if JPEGLI_ENABLE_SKCMS is set and skcms.h is found. ```cmake if (JPEGLI_ENABLE_SKCMS) if( NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/skcms/skcms.h" ) message(FATAL_ERROR "Please provide skcms or " "run ${PROJECT_SOURCE_DIR}/deps.sh to fetch the build dependencies.") endif() include(skcms.cmake) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/skcms/LICENSE" ${PROJECT_BINARY_DIR}/LICENSE.skcms COPYONLY) endif () ``` -------------------------------- ### Format Checks (Lint) Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Runs linter checks to verify patch format conformity. ```bash ./ci.sh lint ``` -------------------------------- ### libpng Configuration (Bundled) Source: https://github.com/google/jpegli/blob/main/third_party/CMakeLists.txt Configures libpng when bundled. It checks for libpng, copies a prebuilt header, adds subdirectories for zlib and libpng, sets various PNG and ZLIB related variables, links libraries, and handles license copying. ```cmake elseif (JPEGLI_BUNDLE_LIBPNG) if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libpng/CMakeLists.txt") message(FATAL_ERROR "Please provide libpng or " "run ${PROJECT_SOURCE_DIR}/deps.sh to fetch the build dependencies.") endif() file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/libpng/scripts/pnglibconf.h.prebuilt" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/libpng") file(RENAME "${CMAKE_CURRENT_SOURCE_DIR}/libpng/pnglibconf.h.prebuilt" "${CMAKE_CURRENT_SOURCE_DIR}/libpng/pnglibconf.h") add_subdirectory(zlib) set(PNG_STATIC ON CACHE BOOL "") set(PNG_TOOLS OFF CACHE BOOL "") set(ZLIB_INCLUDE_DIR bing_bong_dir) set(ZLIB_LIBRARY bing_bong_lib) add_library(ZLIB::ZLIB INTERFACE IMPORTED) set(PNG_TESTS OFF CACHE BOOL "") set(SKIP_INSTALL_ALL ON CACHE BOOL "") set(ZLIB_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/zlib/") set(ZLIB_LIBRARIES zlibstatic) add_subdirectory(libpng EXCLUDE_FROM_ALL) set(PNG_FOUND YES PARENT_SCOPE) set(PNG_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/libpng/" PARENT_SCOPE) target_link_libraries(png_static PUBLIC zlibstatic) set(PNG_LIBRARIES png_static PARENT_SCOPE) set_property(TARGET png_static PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET zlibstatic PROPERTY POSITION_INDEPENDENT_CODE ON) if(JPEGLI_DEP_LICENSE_DIR) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libpng/LICENSE" ${PROJECT_BINARY_DIR}/LICENSE.libpng COPYONLY) endif() else() find_package(PNG) if(PNG_FOUND AND JPEGLI_DEP_LICENSE_DIR) configure_file("${JPEGLI_DEP_LICENSE_DIR}/zlib1g-dev/copyright" ${PROJECT_BINARY_DIR}/LICENSE.zlib COPYONLY) configure_file("${JPEGLI_DEP_LICENSE_DIR}/libpng-dev/copyright" ${PROJECT_BINARY_DIR}/LICENSE.libpng COPYONLY) endif() # JPEGLI_DEP_LICENSE_DIR endif() ``` -------------------------------- ### Binary Tools Subdirectory Source: https://github.com/google/jpegli/blob/main/CMakeLists.txt Includes the tools subdirectory, likely containing build configurations for binary tools. ```cmake # Binary tools add_subdirectory(tools) ``` -------------------------------- ### Add cjpegli and djpegli executables Source: https://github.com/google/jpegli/blob/main/tools/CMakeLists.txt Creates cjpegli and djpegli executables if JPEGLI_ENABLE_TOOLS is set. ```cmake if(JPEGLI_ENABLE_TOOLS) add_executable(cjpegli cjpegli.cc) target_link_libraries(cjpegli jpegli-static) add_executable(djpegli djpegli.cc) target_link_libraries(djpegli jpegli-static) list(APPEND INTERNAL_TOOL_BINARIES cjpegli djpegli) endif() ``` -------------------------------- ### Build jpegli with CMake Source: https://github.com/google/jpegli/blob/main/doc/developing_in_windows_msys.md Builds the jpegli library after configuration. ```bash cmake --build . ``` -------------------------------- ### Building downstream projects with Docker Source: https://github.com/google/jpegli/blob/main/doc/release.md Steps to build downstream projects like ImageMagick and FFmpeg using Docker, including setting up the build environment and cloning jpegli. ```bash docker run -it debian:bookworm /bin/bash apt update apt install -y clang cmake git nasm pkg-config ninja-build export CC=clang export CXX=clang++ mkdir -p /src cd /src git clone --recurse-submodules --depth 1 -b v0.9.x \ https://github.com/google/jpegli.git git clone --recurse-submodules --depth 1 \ https://github.com/ImageMagick/ImageMagick.git git clone --recurse-submodules --depth 1 \ https://github.com/FFmpeg/FFmpeg.git cd /src/jpegli cmake -B build -G Ninja . cmake --build build -j`nproc` cmake --install build --prefix="/usr" ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/google/jpegli/blob/main/doc/CMakeLists.txt This snippet shows the CMake configuration for finding Doxygen, setting documentation generation options, and adding a custom target for building the documentation. ```cmake cmake_minimum_required(VERSION 3.16...3.27) project(LIBJPEGLI_DOC LANGUAGES C CXX) find_package(Doxygen OPTIONAL_COMPONENTS dot) if(DOXYGEN_FOUND AND TARGET Doxygen::dot) set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../lib") set(DOXYGEN_GENERATE_HTML "YES") set(DOXYGEN_GENERATE_XML "YES") if(JPEGLI_WARNINGS_AS_ERRORS) set(DOXYGEN_WARN_AS_ERROR "YES") endif() set(DOXYGEN_QUIET "YES") doxygen_add_docs(doc "${CMAKE_CURRENT_SOURCE_DIR}/api.txt" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" COMMENT "Generating C API documentation") else() # DOXYGEN_FOUND message(WARNING "Doxygen or Dot not installed; 'doc' target will FAIL") # Create a "doc" target for compatibility since "doc" is not otherwise added # to the build when doxygen is not installed. add_custom_target(doc false COMMENT "Error: Can't generate doc since Doxygen or Dot not installed.") endif() # DOXYGEN_FOUND ``` -------------------------------- ### Address Sanitizer (ASan) Build and Test Source: https://github.com/google/jpegli/blob/main/doc/building_and_testing.md Builds and runs unittests with Address Sanitizer enabled. ```bash ./ci.sh asan ``` -------------------------------- ### JNI wrapper library creation Source: https://github.com/google/jpegli/blob/main/tools/CMakeLists.txt Creates a shared library for the JNI wrapper, linking it with jpegli-static. ```cmake add_library(jpegli_jni SHARED jni/org/jpeg/jpegli/wrapper/encoder_jni.cc) target_include_directories(jpegli_jni PRIVATE "${JNI_INCLUDE_DIRS}" "${PROJECT_SOURCE_DIR}") target_include_directories(jpegli_jni PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include/jpegli" ) target_link_libraries(jpegli_jni PUBLIC jpegli-static) ``` -------------------------------- ### Uninstall Target Configuration Source: https://github.com/google/jpegli/blob/main/CMakeLists.txt Configures an uninstall target by copying a template CMake file and adding a custom target to execute it. ```cmake # uninstall target if(NOT TARGET uninstall) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) endif() ``` -------------------------------- ### Static Library Configuration Source: https://github.com/google/jpegli/blob/main/CMakeLists.txt Configures build settings for static libraries, including runtime library selection and linker flags for different platforms. ```cmake set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if(JPEGLI_STATIC) set(BUILD_SHARED_LIBS 0) # https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170 # https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html # For debug builds we intentionally link with shared library to ensure that we don’t accidentally # redistribute such binaries anywhere. set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:DebugDLL>" CACHE STRING "") # Clang developers say that in case to use "static" we have to build stdlib # ourselves; for real use case we don't care about stdlib, as it is "granted", # so just linking all other libraries is fine. if (NOT MSVC AND NOT APPLE) string(APPEND CMAKE_EXE_LINKER_FLAGS " -static") endif() if ((NOT WIN32 AND NOT APPLE) OR CYGWIN OR MINGW) set(CMAKE_FIND_LIBRARY_SUFFIXES .a) string(APPEND CMAKE_EXE_LINKER_FLAGS " -static-libgcc -static-libstdc++") endif() endif() # JPEGLI_STATIC ``` -------------------------------- ### Running a fuzzer target locally with help flag Source: https://github.com/google/jpegli/blob/main/doc/fuzzing.md Command to run a fuzzer target locally and display its help options. ```bash build-fuzzmsan/tools/djxl_fuzzer -help=1 ``` -------------------------------- ### Clone and Configure Repository Remotes Source: https://github.com/google/jpegli/blob/main/doc/developing_in_github.md Clones the jpegli repository and configures git remotes for upstream and personal fork. ```bash git clone https://github.com/google/jpegli --recursive cd jpegli git remote set-url --push origin git@github.com:{{USERNAME}}/jpegli.git git remote add myfork git@github.com:{{USERNAME}}/jpegli.git git remote -vv ```