project(java)

include(GNUInstallDirs)

find_package(Doxygen)
if(Doxygen_FOUND)
  set(DOXYGEN ${DOXYGEN_EXECUTABLE})
else()
  message(STATUS "Doxygen could not be found, pogo will therefore not be able to generate documentation")
endif()

if (NOT WIN32)
    set(SHELL_SCRIPTS astor
                    jive
                    pogo
                    atkpanel
                    logviewer
                    atktuning
                    jdraw
                    synopticappli
                    atkmoni
		    tg_dbdiff
		    tg_devinfo
		    tg_devstate
		    tg_devunexport
		    tg_server
		    tg_dbupdate
		    tg_devping
		    tg_devstatus
		    tg_pool_threads
		    tg_serverinfo
		    tg_dbview
		    tg_devpoll
		    tg_devtest
		    tg_profiler
		    tg_subdevice
                    TangoVers
                    TangoRestServer)

    foreach(input ${SHELL_SCRIPTS})
        configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${input}.in ${input} @ONLY)
        install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${input}
                DESTINATION ${CMAKE_INSTALL_BINDIR})
    endforeach()
else()
    set(BATCH_SCRIPTS
        start-astor.bat
        start-atkmoni.bat
        start-atkpanel.bat
        start-atktuning.bat
        start-jdraw.bat
        start-jive.bat
        start-logviewer.bat
        start-pogo.bat
        start-synoptic.bat
        tg_dbdiff.bat
        tg_devinfo.bat
        tg_devstate.bat
        tg_devunexport.bat
        tg_server.bat
        tg_dbupdate.bat
        tg_devping.bat
        tg_devstatus.bat
        tg_pool_threads.bat
        tg_serverinfo.bat
        tg_dbview.bat
        tg_devpoll.bat
        tg_devtest.bat
        tg_profiler.bat
        tg_subdevice.bat
        atktuning_attributes.txt)

    foreach(input ${BATCH_SCRIPTS})
        install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/${input}
                DESTINATION ${CMAKE_INSTALL_BINDIR})
    endforeach()
endif()

set(CONFIG_XML logback-server.xml
               logback.xml)

foreach(input ${CONFIG_XML})
  install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${input}
          DESTINATION ${CMAKE_INSTALL_DATADIR}/tango)
endforeach()

# the following list of filenames is replaced with the real names by
# prepare-assets in build.xml, see also https://ant.apache.org/manual/Types/filterset.html
set(JAR_FILES Astor-7.6.0.jar
              ATKCore-9.4.11.jar
              ATKPanel-5.11.jar
              ATKTuning-4.8.jar
              ATKWidget-9.4.11.jar
              DBBench-1.4.jar
              Jive-7.45.jar
              JSSHTerminal-1.18.jar
              JTango-9.6.6.jar
              LogViewer-2.2.1.jar
              Pogo-9.10.6.jar)
if (NOT WIN32)
    list(APPEND JAR_FILES RestServer-1.22.jar)
endif()

foreach(input ${JAR_FILES})
  string(REGEX REPLACE "^([^-]+)-.*(\.jar)$" "\\1\\2" output ${input})
  install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${input}
          RENAME ${output}
          DESTINATION ${CMAKE_INSTALL_DATADIR}/java)
endforeach()
