include(ExternalProject)

set(OCIO_GIT_REPOSITORY "https://github.com/AcademySoftwareFoundation/OpenColorIO.git")
set(OCIO_GIT_TAG "ffddc3341f5775c7866fe2c93275e1d5e0b0540f") # tag: v2.1.0

set(OCIO_ARGS
    ${TLR_EXTERNAL_ARGS}
    -DCMAKE_INSTALL_LIBDIR=lib
    -DOCIO_BUILD_APPS=OFF
    -DOCIO_BUILD_TESTS=OFF
    -DOCIO_BUILD_GPU_TESTS=OFF
    -DOCIO_BUILD_PYTHON=OFF
    -DOCIO_INSTALL_EXT_PACKAGES=ALL)
cmake_host_system_information(RESULT HAS_SSE2 QUERY HAS_SSE2)
set(OCIO_ARGS ${OCIO_ARGS} -DOCIO_USE_SSE=${HAS_SSE2})
if(APPLE)
    execute_process(
        COMMAND uname -m
        RESULT_VARIABLE result
        OUTPUT_VARIABLE OCIO_OSX_NATIVE_ARCH
        OUTPUT_STRIP_TRAILING_WHITESPACE)
    set(OCIO_ARGS ${OCIO_ARGS} -DCMAKE_OSX_ARCHITECTURES=${OCIO_OSX_NATIVE_ARCH})
endif()

ExternalProject_Add(
    OCIO
    PREFIX ${CMAKE_CURRENT_BINARY_DIR}/OCIO
    DEPENDS Imath
    GIT_REPOSITORY ${OCIO_GIT_REPOSITORY}
    GIT_TAG ${OCIO_GIT_TAG}
    PATCH_COMMAND
        ${CMAKE_COMMAND} -E tar xf
        ${CMAKE_SOURCE_DIR}/OCIO-patch.tar.gz
    LIST_SEPARATOR |
    CMAKE_ARGS ${OCIO_ARGS})
