# -*- mode: cmake; coding: utf-8; cmake-tab-width: 4; indent-tabs-mode: nil; -*- vim:fenc=utf-8:ft=cmake:et:sw=4:ts=4:sts=4

#========================================================================
# Discover if Octave is available and usable
#========================================================================
if (APPLE AND UNIX AND NOT DEFINED ENABLE_SWIG_OCTAVE)
    #--------------------------------------------------------------------
    # Currently there is an issue were SWIG and Octave are incompatable
    #   under MacPorts
    #--------------------------------------------------------------------
    set(ENABLE_SWIG_OCTAVE FALSE)
endif()
if ( NOT DEFINED ENABLE_SWIG_OCTAVE OR ENABLE_SWIG_OCTAVE )
    find_package(HDF5)
    find_package(Octave)
endif( )

if (OCTAVE_FOUND AND SWIG_FOUND)
  set( ENABLE_SWIG_OCTAVE "yes"
      CACHE BOOL "Control the building of the SWIG bindings for Octave" )
  set( OCTAVE_VERSION_STRING ${OCTAVE_VERSION_STRING} PARENT_SCOPE )
  find_program( OCTAVE_CONFIG_PROGRAM octive-config )

  if ( OCTAVE_CONFIG_PROGRAM_FOUND )
      execute_process(
          COMMAND ${OCTAVE_CONFIGURE_PROGRAM} --print OCTLIBDIR
          RESULT_VARIABLE OCTAVE_OCTLIBDIR )
  endif( )
  # ---------------------------------------------------------------------
  # Library: octave
  # ---------------------------------------------------------------------
  find_library( OCTAVE_OCTAVE_LIBRARY
                NAMES octave
		            HINTS ${OCTAVE_OCTLIBDIR} ${OCTAVE_LINK_DIRS} )
  if ( OCTAVE_INTERP_LIBRARY_FOUND )
      set( OCTAVE_LIBRARIES ${OCTAVE_LIBRARIES}
          ${OCTAVE_INTERP_LIBRARY} )
  endif( )
  # ---------------------------------------------------------------------
  # Library: octinterp
  # ---------------------------------------------------------------------
  find_library( OCTAVE_INTERP_LIBRARY
                NAMES octinterp
		            HINTS ${OCTAVE_OCTLIBDIR} ${OCTAVE_LINK_DIRS} )
  if ( OCTAVE_OCTAVE_LIBRARY_FOUND )
      set( OCTAVE_LIBRARIES ${OCTAVE_LIBRARIES}
          ${OCTAVE_OCTAVE_LIBRARY} )
  endif( )
else( )
  set( ENABLE_SWIG_OCTAVE "no"
       CACHE BOOL "Control the building of the SWIG bindings for Octave" FORCE )
endif(OCTAVE_FOUND AND SWIG_FOUND)

add_subdirectory(module)
add_subdirectory(test)

#========================================================================
# Provide additional information regarding components
#========================================================================

cpack_add_component(Octave
    DISPLAY_NAME "Octave extensions"
    DESCRIPTION
        "Pieces needed to use the nds2 client from Octave"
    GROUP Runtime)
