#
#  satnogs-flowgraphs: SatNOGS GNU Radio flowgraphs
#
#  Copyright (C) 2020, 2024, 2025.
#  Libre Space Foundation <http://libre.space>
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>
#

include(GNUInstallDirs)

# Define list of entry-scripts
set(entry_scripts
    flowgraph_dispatcher.py
    zmq_frame_decoder_sub.py
)

set(install_dir "../${CMAKE_INSTALL_DATAROOTDIR}/flowgraph_dispatcher")

add_custom_target(flowgraph_dispatcher ALL)

foreach(fname ${entry_scripts})
    cmake_path(REMOVE_EXTENSION fname LAST_ONLY OUTPUT_VARIABLE fname_stripped)
    add_custom_command(
        TARGET flowgraph_dispatcher
        COMMAND ln -sf ${install_dir}/${fname}
       		${CMAKE_CURRENT_BINARY_DIR}/${fname_stripped}
        BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${fname_stripped}
    )
    install(
        PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${fname_stripped}
        DESTINATION bin
    )
endforeach()

install(
    DIRECTORY ${CMAKE_SOURCE_DIR}/flowgraph_dispatcher
    DESTINATION ${CMAKE_INSTALL_DATAROOTDIR} # typically /usr/share
    USE_SOURCE_PERMISSIONS
    PATTERN "CMakeLists.txt" EXCLUDE
)
