#-------------------------------------------------------------------------------
# Information
#-------------------------------------------------------------------------------

set(name openexr_viewers)

set(pkg openexr_viewers-1.0.1)

#-------------------------------------------------------------------------------
# Output Files
#-------------------------------------------------------------------------------

if (UNIX)

  set(
    bin
    ${djv_build_dir}/bin/exrdisplay
    ${djv_build_dir}/bin/playexr
  )

endif (UNIX)

#-------------------------------------------------------------------------------
# Build Rules
#-------------------------------------------------------------------------------

if (djv_build_third_party)

  if (UNIX)
  
    set(src_dir ${CMAKE_CURRENT_SOURCE_DIR})
    set(bin_dir ${CMAKE_CURRENT_BINARY_DIR})
    set(out_dir ${djv_build_dir})

    # Copy source code to build directory.
  
    set(
      djv_copy_cmd
      cd ${src_dir} && tar cvf ${bin_dir}/tmp.tar ${pkg}
      &&
      cd ${bin_dir} && tar xvf tmp.tar && rm tmp.tar
    )
  
    # Update autoconf files.
  
    if (djv_autoconf)

      set(
        djv_autoconf_cmd
        ${cp} ${djv_autoconf} ${pkg}
      )

    endif (djv_autoconf)

    # Configure, make, and make install.

    set(
      djv_make_cmd
      cd ${pkg}
      &&
      export LD_LIBRARY_PATH=${out_dir}/lib
      &&
      export PKG_CONFIG_PATH=${out_dir}/lib/pkgconfig
      &&
      export PATH=$ENV{PATH}:${out_dir}/bin
      &&
      ./configure
        --prefix=${out_dir}
        --enable-shared
        --disable-static
        CPPFLAGS=-I${out_dir}/include
        LDFLAGS=-L${out_dir}/lib
      &&
      make
      &&
      make install
    )

    add_custom_command(
      OUTPUT ${bin}
      COMMAND ${djv_copy_cmd}
      COMMAND ${djv_autoconf_cmd}
      COMMAND ${djv_make_cmd}
    )

  endif (UNIX)
  
endif (djv_build_third_party)

add_custom_target(
  ${name} ALL
  DEPENDS ${bin}
)

add_dependencies(${name} fltk openexr_ctl)

