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

if (ENABLE_SWIG_OCTAVE)
    include(${SWIG_USE_FILE})
    include_directories("/usr/include")
    include_directories(${OCTAVE_INCLUDE_DIRS})
    include_directories(${HDF5_INCLUDE_DIRS})
    include_directories(${CMAKE_CURRENT_SOURCE_DIR})
    include_directories(${PROJECT_BINARY_DIR}/src/client)
    include_directories(${PROJECT_BINARY_DIR}/swig/common/module)
    include_directories(${PROJECT_SOURCE_DIR}/swig/common/module)

    if( NOT OCTAVE_INSTALL_DIR )
        set( OCTAVE_INSTALL_DIR ${CMAKE_INSTALL_LIBEXECDIR}/nds2-client/octave CACHE PATH "Installation directory for Octave modules" )
    endif( NOT OCTAVE_INSTALL_DIR )

    set(INTERFACE_FILE "nds_octave.i")

    set(CMAKE_SWIG_FLAGS "-O")
    set_source_files_properties(${INTERFACE_FILE} PROPERTIES
        CPLUSPLUS ON
        SWIG_FLAGS "-includeall"
    )
    set_source_files_properties(nds2OCTAVE_wrap.cxx PROPERTIES
        GENERATED true
    )
    swig_add_module(nds2_octave octave ${INTERFACE_FILE})
    swig_link_libraries(nds2_octave ${OCTAVE_LIBRARIES} ndswrapcxx)
    set_target_properties(nds2_octave PROPERTIES
        OUTPUT_NAME nds2
        LINKER_LANGUAGE CXX
    )
    if ( ${OCTAVE_VERSION_STRING} VERSION_GREATER "4.0" )
        target_compile_features(nds2_octave PRIVATE
            cxx_variadic_macros
            )
    elseif ( ${OCTAVE_VERSION_STRING} VERSION_EQUAL "4.0" )
        target_compile_features(nds2_octave PRIVATE
            cxx_variadic_macros
            )
    endif ( ${OCTAVE_VERSION_STRING} VERSION_GREATER "4.0" )

  #======================================================================
  # Configuration information
  #======================================================================
  configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/nds2-client-octave.cfg.in
      ${CMAKE_CURRENT_BINARY_DIR}/nds2-client-octave.cfg
      @ONLY )
  #======================================================================
  # Installation Rules
  #======================================================================
  cpack_add_component(Octave
      DISPLAY_NAME "Octave extensions"
      DESCRIPTION
        "Pieces needed to use the nds2 client from Octave"
      GROUP Runtime)
  get_swig_property( nds2_module_filename MODULE_OUTPUT_NAME nds2_octave )

  install(
      FILES ${CMAKE_CURRENT_BINARY_DIR}/nds2-client-octave.cfg
      DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${PROJECT_NAME}
      COMPONENT Octave
      )

  install(
    FILES ${CMAKE_CURRENT_BINARY_DIR}/${nds2_module_filename}
    DESTINATION ${OCTAVE_INSTALL_DIR}
    COMPONENT Octave
  )


endif(ENABLE_SWIG_OCTAVE)
