# https://libjpeg-turbo.org/
# https://github.com/libjpeg-turbo/libjpeg-turbo
# For ANDROID - https://github.com/DeviceFarmer/android-libjpeg-turbo
#
# https://sourceforge.net/projects/libjpeg-turbo/files/1.5.3/libjpeg-turbo-1.5.3.tar.gz
# https://sourceforge.net/projects/libjpeg-turbo/files/2.1.0/libjpeg-turbo-2.1.0.tar.gz
# https://downloads.sourceforge.net/libjpeg-turbo/libjpeg-turbo-1.5.3.tar.gz


### VERSION ###
#DKSET(JPEG_VERSION 1.5.0)
#DKSET(JPEG_VERSION 1.5.3)
#DKSET(JPEG_VERSION 2.0.0)
DKSET(JPEG_VERSION 2.1.1)
DKSET(JPEG_NAME libjpeg-turbo-${JPEG_VERSION})
DKSET(JPEG_DL https://sourceforge.net/projects/libjpeg-turbo/files/${JPEG_VERSION}/${JPEG_NAME}.tar.gz)
#DKSET(JPEG_DL https://downloads.sourceforge.net/libjpeg-turbo/${JPEG_NAME}.tar.gz)
DKSET(JPEG ${3RDPARTY}/${JPEG_NAME})


### INSTALL ###
DKINSTALL(${JPEG_DL} libjpeg-turbo ${JPEG} NOPATCH)


### DKPLUGINS LINK ###
DKINCLUDE(${JPEG})
DKINCLUDE(${JPEG}/${OS})
ANDROID_INCLUDE(${JPEG}/${OS}/$(BUILD_TYPE)/jni)
WIN_DEBUG_LIB(${JPEG}/${OS}/${DEBUG_DIR}/turbojpeg-static.lib)
WIN_RELEASE_LIB(${JPEG}/${OS}/${RELEASE_DIR}/turbojpeg-static.lib)
APPLE_DEBUG_LIB(${JPEG}/${OS}/${DEBUG_DIR}/libturbojpeg.a)
APPLE_RELEASE_LIB(${JPEG}/${OS}/${RELEASE_DIR}/libturbojpeg.a)
LINUX_DEBUG_LIB(${JPEG}/${OS}/${DEBUG_DIR}/libturbojpeg.a)
LINUX_RELEASE_LIB(${JPEG}/${OS}/${RELEASE_DIR}/libturbojpeg.a)
RASPBERRY_DEBUG_LIB(${JPEG}/${OS}/${DEBUG_DIR}/libturbojpeg.a)
RASPBERRY_RELEASE_LIB(${JPEG}/${OS}/${RELEASE_DIR}/libturbojpeg.a)
##ANDROID_DEBUG_LIB(${JPEG}/${OS}/${DEBUG_DIR}/obj/local/armeabi-v7a/libturbojpeg.a)
##ANDROID_RELEASE_LIB(${JPEG}/${OS}/${RELEASE_DIR}/obj/local/armeabi-v7a/libturbojpeg.a)
ANDROID_DEBUG_LIB(${JPEG}/${OS}/${DEBUG_DIR}/libturbojpeg.a)
ANDROID_RELEASE_LIB(${JPEG}/${OS}/${RELEASE_DIR}/libturbojpeg.a)


### 3RDPARTY LINK ###
DKSET(JPEG_WIN -DJPEG_INCLUDE_DIR=${JPEG} -DJPEG_INCLUDE_DIR2=${JPEG}/${OS} -DJPEG_LIBRARY_RELEASE=${JPEG}/${OS}/${RELEASE_DIR}/turbojpeg-static.lib)
DKSET(JPEG_APPLE -DJPEG_INCLUDE_DIR=${JPEG} -DJPEG_INCLUDE_DIR2=${JPEG}/${OS} -DJPEG_LIBRARY_RELEASE=${JPEG}/${OS}/${RELEASE_DIR}/libturbojpeg.a)
DKSET(JPEG_LINUX -DJPEG_INCLUDE_DIR=${JPEG} -DJPEG_INCLUDE_DIR2=${JPEG}/${OS}/${RELEASE_DIR} -DJPEG_LIBRARY=${JPEG}/${OS}/${RELEASE_DIR}/libturbojpeg.a)
DKSET(JPEG_RASPBERRY -DJPEG_INCLUDE_DIR=${JPEG} -DJPEG_INCLUDE_DIR2=${JPEG}/${OS}/${RELEASE_DIR} -DJPEG_LIBRARY=${JPEG}/${OS}/${RELEASE_DIR}/libturbojpeg.a)
DKSET(JPEG_ANDROID -DJPEG_INCLUDE_DIR=${JPEG} -DJPEG_INCLUDE_DIR2=${JPEG}/${OS} -DJPEG_LIBRARY=${JPEG}/${OS}/${RELEASE_DIR}/libturbojpeg.a)


### COMPILE ###
WIN_PATH(${JPEG}/${OS})
WIN32_COMMAND(${DKCMAKE_WIN32} -DWITH_SIMD=OFF ${JPEG})
WIN64_COMMAND(${DKCMAKE_WIN64} -DWITH_SIMD=OFF ${JPEG})
WIN_VS(${JPEG_NAME} libjpeg-turbo.sln turbojpeg-static)


MAC_PATH(${JPEG}/${OS})
MAC32_COMMAND(${DKCMAKE_MAC32} ${JPEG})
MAC64_COMMAND(${DKCMAKE_MAC64} ${JPEG})
MAC_XCODE(${JPEG_NAME} turbojpeg-static)


IOS_PATH(${JPEG}/${OS})
IOS64_COMMAND(${DKCMAKE_IOS64} ${JPEG})
IOS_XCODE(${JPEG_NAME} turbojpeg-static)


IOSSIM_PATH(${JPEG}/${OS})
IOSSIM32_COMMAND(${DKCMAKE_IOSSIM32} ${JPEG})
IOSSIM64_COMMAND(${DKCMAKE_IOSSIM64} ${JPEG})
IOSSIM_XCODE(${JPEG_NAME} turbojpeg-static)


LINUX_DEBUG_PATH(${JPEG}/${OS}/${DEBUG_DIR})
LINUX_DEBUG_COMMAND(${DKCMAKE_LINUX_DEBUG} ${JPEG})
LINUX_DEBUG_COMMAND(make turbojpeg-static)

LINUX_RELEASE_PATH(${JPEG}/${OS}/${RELEASE_DIR})
LINUX_RELEASE_COMMAND(${DKCMAKE_LINUX_RELEASE} ${JPEG})
LINUX_RELEASE_COMMAND(make turbojpeg-static)


RASPBERRY_DEBUG_PATH(${JPEG}/${OS}/${DEBUG_DIR})
RASPBERRY_DEBUG_COMMAND(${DKCMAKE_RASPBERRY_DEBUG} ${JPEG})
RASPBERRY_DEBUG_COMMAND(make turbojpeg-static)

RASPBERRY_RELEASE_PATH(${JPEG}/${OS}/${RELEASE_DIR})
RASPBERRY_RELEASE_COMMAND(${DKCMAKE_RASPBERRY_RELEASE} ${JPEG})
RASPBERRY_RELEASE_COMMAND(make turbojpeg-static)


#ANDROID_NDK(${JPEG_NAME})
ANDROID_PATH(${JPEG}/${OS})
ANDROID32_COMMAND(${DKCMAKE_ANDROID32} -DWITH_SIMD=OFF ${JPEG})
ANDROID64_COMMAND(${DKCMAKE_ANDROID64} -DWITH_SIMD=OFF ${JPEG})
ANDROID_VS(${JPEG_NAME} libjpeg-turbo.sln turbojpeg-static)
