cmake_minimum_required(VERSION 3.16)
project(build_libjpeg-turbo)
include(ExternalProject)

if(NOT DEFINED LIBJPEGTURBO_REPO OR LIBJPEGTURBO_REPO STREQUAL "")
    set(LIBJPEGTURBO_REPO https://github.com/libjpeg-turbo/libjpeg-turbo.git)
endif ()

ExternalProject_Add(libjpegturbo
        GIT_REPOSITORY ${LIBJPEGTURBO_REPO}
        GIT_TAG 3.0.3
        GIT_SHALLOW TRUE
        SOURCE_DIR libjpegturbo
        BINARY_DIR libjpegturbo-build
        CMAKE_GENERATOR ${CMAKE_GENERATOR}
        CMAKE_ARGS
            -DBUILD_SHARED_LIBS:BOOL=OFF
            -DENABLE_SHARED:BOOL=OFF
            -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${TOOLCHAIN_FILE}
            -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/INSTALL
            -DCMAKE_BUILD_TYPE:STRING=Release
        )