
set (MESHMOON_TRITON_SDK_DETECTED FALSE)

macro (configure_triton)
    if (NOT MESHMOON_TRITON_SDK_DETECTED)
        if (MSVC)
            string (TOLOWER ${VC_VER}/${VS_PLATFORM} PLATFORM_PATH_LOWER)
            set (TRITON_FOUND 0)
            if (NOT "$ENV{TRITON_PATH}" STREQUAL "")
                file (TO_CMAKE_PATH "$ENV{TRITON_PATH}" TRITON_SDK)
                set (TRITON_LIBS ${TRITON_SDK}/lib/${PLATFORM_PATH_LOWER})
                set (TRITON_FOUND 1)
            else ()
                message (FATAL_ERROR "Environment variable TRITON_PATH is empty!")
            endif ()
        elseif (APPLE)
            if (NOT "$ENV{TRITON_PATH}" STREQUAL "")
                file (TO_CMAKE_PATH "$ENV{TRITON_PATH}" TRITON_SDK)
                set (TRITON_LIBS ${TRITON_SDK}/lib)
            else ()
                message (FATAL_ERROR "Environment variable TRITON_PATH is empty!")
            endif ()
        elseif (UNIX)
            if (NOT "$ENV{TRITON_PATH}" STREQUAL "")
                file (TO_CMAKE_PATH "$ENV{TRITON_PATH}" TRITON_SDK)
                set (TRITON_LIBS ${TRITON_SDK}/lib/Linux)
            else ()
                message (FATAL_ERROR "Environment variable TRITON_PATH is empty!")
            endif ()
        endif ()
        set (MESHMOON_TRITON_SDK_DETECTED TRUE)
    endif ()
endmacro ()

macro (use_triton)
    configure_triton ()

    if (NOT APPLE)
        include_directories ("${TRITON_SDK}/Public Headers")
    else ()
        include_directories ("${TRITON_SDK}/Headers")
    endif ()
endmacro ()

macro (link_triton)
    configure_triton ()

    if (MSVC)
        target_link_libraries (${TARGET_NAME} debug ${TRITON_LIBS}/Triton-MTD-DLL.lib optimized ${TRITON_LIBS}/Triton-MT-DLL.lib)
    elseif (APPLE)
        target_link_libraries (${TARGET_NAME} debug ${TRITON_LIBS}/libTriton.a optimized ${TRITON_LIBS}/libTriton.a)
        target_link_libraries (${TARGET_NAME} optimized "$ENV{TUNDRA_DEP_PATH}/fftss/lib/libfftss.a")
    elseif (UNIX)
        target_link_libraries (${TARGET_NAME} ${TRITON_LIBS}/libTriton.a dl GLU)
        target_link_libraries (${TARGET_NAME} "$ENV{TUNDRA_DEP_PATH}/lib/libfftss.so")
    endif ()
endmacro ()
