# https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/3.4.1/opencv-3.4.1.zip
# https://github.com/opencv/opencv/archive/refs/tags/4.5.3.zip

### DEPENDS ###
DKDEPEND(python)
DKDEPEND(libjpeg-turbo)
DKDEPEND(tiff)
DKDEPEND(libpng)


### VERSION ###
DKSET(OPENCV_MAJOR 4)
DKSET(OPENCV_MINOR 5)
DKSET(OPENCV_BUILD 3)
#DKSET(OPENCV_VERSION 3.4.1)
DKSET(OPENCV_VERSION 4.5.3)
DKSET(OPENCV_NAME opencv-${OPENCV_VERSION})
#DKSET(OPENCV_DL https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/${OPENCV_VERSION}/${OPENCV_NAME}.zip)
DKSET(OPENCV_DL https://github.com/opencv/opencv/archive/refs/tags/${OPENCV_VERSION}.zip)
DKSET(OPENCV ${3RDPARTY}/${OPENCV_NAME})


### INSTALL ###
DKINSTALL(${OPENCV_DL} opencv ${OPENCV})


### LINK ###
DKINCLUDE(${OPENCV})
DKINCLUDE(${OPENCV}/modules/core/include)
DKINCLUDE(${OPENCV}/modules/videoio/include)
DKINCLUDE(${OPENCV}/${OS})
DKINCLUDE(${OPENCV}/${OS}/${DEBUG_DIR})
DKINCLUDE(${OPENCV}/${OS}/${RELEASE_DIR})

WIN_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/opencv_core${OPENCV_MAJOR}${OPENCV_MINOR}${OPENCV_BUILD}d.lib)
WIN_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/opencv_core${OPENCV_MAJOR}${OPENCV_MINOR}${OPENCV_BUILD}.lib)
WIN_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/opencv_imgcodecs${OPENCV_MAJOR}${OPENCV_MINOR}${OPENCV_BUILD}d.lib)
WIN_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/opencv_imgcodecs${OPENCV_MAJOR}${OPENCV_MINOR}${OPENCV_BUILD}.lib)
WIN_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/opencv_imgproc${OPENCV_MAJOR}${OPENCV_MINOR}${OPENCV_BUILD}d.lib)
WIN_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/opencv_imgproc${OPENCV_MAJOR}${OPENCV_MINOR}${OPENCV_BUILD}.lib)
WIN_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/opencv_videoio${OPENCV_MAJOR}${OPENCV_MINOR}${OPENCV_BUILD}d.lib)
WIN_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/opencv_videoio${OPENCV_MAJOR}${OPENCV_MINOR}${OPENCV_BUILD}.lib)
#WIN_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/libjasperd.lib)
#WIN_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/libjasper.lib)
WIN_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/ippiwd.lib)
WIN_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/ippiw.lib)
WIN_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/libwebpd.lib)
WIN_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/libwebp.lib)
WIN_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/ittnotifyd.lib)
WIN_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/ittnotify.lib)
WIN_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/IlmImfd.lib)
WIN_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/IlmImf.lib)
#WIN32_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_win/lib/ia32/ippicvmt.lib)
#WIN32_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_win/lib/ia32/ippicvmt.lib)
WIN32_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_win/icv/lib/ia32/ippicvmt.lib)
WIN32_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_win/icv/lib/ia32/ippicvmt.lib)
WIN64_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_win/icv/lib/intel64/ippicvmt.lib)
WIN64_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_win/icv/lib/intel64/ippicvmt.lib)
WIN_LIB(vfw32.lib)

APPLE32_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_mac/icv/lib/intel32/libippicv.a)
APPLE32_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_mac/icv/lib/intel32/libippicv.a)
APPLE64_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_mac/icv/lib/intel64/libippicv.a)
APPLE64_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_mac/icv/lib/intel64/libippicv.a)
APPLE_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/liblibjasper.a)
APPLE_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/liblibjasper.a)
APPLE_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/libippiw.a)
APPLE_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/libippiw.a)
APPLE_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/liblibwebp.a)
APPLE_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/liblibwebp.a)
APPLE_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/libittnotify.a)
APPLE_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/libittnotify.a)
APPLE_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/libIlmImf.a)
APPLE_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/libIlmImf.a)
APPLE_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/libopencv_core.a)
APPLE_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/libopencv_core.a)
APPLE_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/libopencv_imgproc.a)
APPLE_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/libopencv_imgproc.a)
APPLE_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/libopencv_imgcodecs.a)
APPLE_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/libopencv_imgcodecs.a)
APPLE_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/libopencv_videoio.a)
APPLE_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/libopencv_videoio.a)

LINUX32_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/ippicv/ippicv_lnx/lib/ia32/libippicv.a)
LINUX32_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/ippicv/ippicv_lnx/lib/ia32/libippicv.a)
LINUX64_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/ippicv/ippicv_lnx/lib/intel64/libippicv.a)
LINUX64_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/ippicv/ippicv_lnx/lib/intel64/libippicv.a)
#LINUX_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/lib/liblibjasper.a)
#LINUX_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/lib/liblibjasper.a)
LINUX_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/lib/libippiw.a)
LINUX_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/lib/libippiw.a)
LINUX_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/lib/liblibwebp.a)
LINUX_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/lib/liblibwebp.a)
LINUX_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/lib/libittnotify.a)
LINUX_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/lib/libittnotify.a)
LINUX_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/lib/libIlmImf.a)
LINUX_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/lib/libIlmImf.a)
LINUX_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/lib/libopencv_core.a)
LINUX_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/lib/libopencv_core.a)
LINUX_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/lib/libopencv_imgproc.a)
LINUX_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/lib/libopencv_imgproc.a)
LINUX_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/lib/libopencv_imgcodecs.a)
LINUX_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/lib/libopencv_imgcodecs.a)
LINUX_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/lib/libopencv_videoio.a)
LINUX_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/lib/libopencv_videoio.a)


RASPBERRY32_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/ippicv/ippicv_lnx/lib/ia32/libippicv.a)
RASPBERRY32_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/ippicv/ippicv_lnx/lib/ia32/libippicv.a)
RASPBERRY64_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/ippicv/ippicv_lnx/lib/intel64/libippicv.a)
RASPBERRY64_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/ippicv/ippicv_lnx/lib/intel64/libippicv.a)
#RASPBERRY_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/lib/liblibjasper.a)
#RASPBERRY_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/lib/liblibjasper.a)
#RASPBERRY_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/lib/libippiw.a)
#RASPBERRY_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/lib/libippiw.a)
RASPBERRY_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/lib/liblibwebp.a)
RASPBERRY_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/lib/liblibwebp.a)
#RASPBERRY_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/lib/libittnotify.a)
#RASPBERRY_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/lib/libittnotify.a)
RASPBERRY_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/3rdparty/lib/libIlmImf.a)
RASPBERRY_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/3rdparty/lib/libIlmImf.a)
RASPBERRY_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/lib/libopencv_core.a)
RASPBERRY_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/lib/libopencv_core.a)
RASPBERRY_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/lib/libopencv_imgproc.a)
RASPBERRY_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/lib/libopencv_imgproc.a)
RASPBERRY_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/lib/libopencv_imgcodecs.a)
RASPBERRY_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/lib/libopencv_imgcodecs.a)
RASPBERRY_DEBUG_LIB(${OPENCV}/${OS}/${DEBUG_DIR}/lib/libopencv_videoio.a)
RASPBERRY_RELEASE_LIB(${OPENCV}/${OS}/${RELEASE_DIR}/lib/libopencv_videoio.a)


##ANDROID_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/obj/local/armeabi-v7a/libopencv_core.a)
##ANDROID_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/obj/local/armeabi-v7a/libopencv_core.a)
ANDROID32_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_android/lib/arm32/libippicv.a)
ANDROID32_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_android/lib/arm32/libippicv.a)
ANDROID64_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_android/lib/arm64/libippicv.a)
ANDROID64_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/ippicv/ippicv_android/lib/arm64/libippicv.a)
ANDROID_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/liblibjasper.a)
ANDROID_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/liblibjasper.a)
ANDROID_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/libippiw.a)
ANDROID_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/libippiw.a)
ANDROID_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/liblibwebp.a)
ANDROID_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/liblibwebp.a)
ANDROID_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/libittnotify.a)
ANDROID_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/libittnotify.a)
ANDROID_DEBUG_LIB(${OPENCV}/${OS}/3rdparty/lib/${DEBUG_DIR}/libIlmImf.a)
ANDROID_RELEASE_LIB(${OPENCV}/${OS}/3rdparty/lib/${RELEASE_DIR}/libIlmImf.a)
ANDROID_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/libopencv_core.a)
ANDROID_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/libopencv_core.a)
ANDROID_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/libopencv_imgproc.a)
ANDROID_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/libopencv_imgproc.a)
ANDROID_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/libopencv_imgcodecs.a)
ANDROID_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/libopencv_imgcodecs.a)
ANDROID_DEBUG_LIB(${OPENCV}/${OS}/lib/${DEBUG_DIR}/libopencv_videoio.a)
ANDROID_RELEASE_LIB(${OPENCV}/${OS}/lib/${RELEASE_DIR}/libopencv_videoio.a)


### COMPILE ###
WIN_PATH(${OPENCV}/${OS})
WIN32_COMMAND(${DKCMAKE_WIN32} ${OPENCV})
WIN64_COMMAND(${DKCMAKE_WIN64} -DCV_DISABLE_OPTIMIZATION=ON -DCPU_BASELINE="" -DCPU_DISPATCH="" ${OPENCV})
WIN_VS(${OPENCV_NAME} OpenCV.sln)


MAC_PATH(${OPENCV}/${OS})
MAC64_COMMAND(${DKCMAKE_MAC64} "-DCMAKE_CXX_FLAGS=-stdlib=libc++" ${OPENCV})
MAC_XCODE(${OPENCV_NAME} opencv_core)
MAC_XCODE(${OPENCV_NAME} opencv_imgcodecs)
MAC_XCODE(${OPENCV_NAME} opencv_videoio)


IOS_PATH(${OPENCV}/${OS})
IOS64_COMMAND(${DKCMAKE_IOS64} ${OPENCV})
IOS_XCODE(${OPENCV_NAME} opencv_core)
IOS_XCODE(${OPENCV_NAME} opencv_imgcodecs)
IOS_XCODE(${OPENCV_NAME} opencv_videoio)


IOSSIM_PATH(${OPENCV}/${OS})
IOSSIM64_COMMAND(${DKCMAKE_IOSSIM64} ${OPENCV})
IOSSIM_XCODE(${OPENCV_NAME} opencv_core)
IOSSIM_XCODE(${OPENCV_NAME} opencv_imgcodecs)
IOSSIM_XCODE(${OPENCV_NAME} opencv_videoio)


LINUX_DEBUG_PATH(${OPENCV}/${OS}/${DEBUG_DIR})
LINUX_DEBUG_COMMAND(${DKCMAKE_LINUX_DEBUG} ${OPENCV})
LINUX_DEBUG_COMMAND(make opencv_core)
LINUX_DEBUG_COMMAND(make opencv_imgcodecs)
LINUX_DEBUG_COMMAND(make opencv_videoio)

LINUX_RELEASE_PATH(${OPENCV}/${OS}/${RELEASE_DIR})
LINUX_RELEASE_COMMAND(${DKCMAKE_LINUX_RELEASE} ${OPENCV})
LINUX_RELEASE_COMMAND(make opencv_core)
LINUX_RELEASE_COMMAND(make opencv_imgcodecs)
LINUX_RELEASE_COMMAND(make opencv_videoio)


RASPBERRY_DEBUG_PATH(${OPENCV}/${OS}/${DEBUG_DIR})
RASPBERRY_DEBUG_COMMAND(${DKCMAKE_RASPBERRY_DEBUG} -DWITH_IPP=ON ${OPENCV})
RASPBERRY_DEBUG_COMMAND(make opencv_core)
RASPBERRY_DEBUG_COMMAND(make opencv_imgcodecs)
RASPBERRY_DEBUG_COMMAND(make opencv_videoio)

RASPBERRY_RELEASE_PATH(${OPENCV}/${OS}/${RELEASE_DIR})
RASPBERRY_RELEASE_COMMAND(${DKCMAKE_RASPBERRY_RELEASE} -DWITH_IPP=ON ${OPENCV})
RASPBERRY_RELEASE_COMMAND(make opencv_core)
RASPBERRY_RELEASE_COMMAND(make opencv_imgcodecs)
RASPBERRY_RELEASE_COMMAND(make opencv_videoio)


##ANDROID_NDK(${OPENCV_NAME})
ANDROID_PATH(${OPENCV}/${OS})
ANDROID32_COMMAND(${DKCMAKE_ANDROID32} ${OPENCV})
ANDROID64_COMMAND(${DKCMAKE_ANDROID64} ${OPENCV})
ANDROID_VS(${OPENCV_NAME} OpenCV.sln)
