################################################################################
# Copyright 2018-2025, Barcelona Supercomputing Center (BSC), Spain            #
# Copyright 2015-2025, Johannes Gutenberg Universitaet Mainz, Germany          #
#                                                                              #
# This software was partially supported by the                                 #
# EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).    #
#                                                                              #
# This software was partially supported by the                                 #
# ADA-FS project under the SPPEXA project funded by the DFG.                   #
#                                                                              #
# This file is part of GekkoFS.                                                #
#                                                                              #
# GekkoFS 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.                                          #
#                                                                              #
# GekkoFS 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 GekkoFS.  If not, see <https://www.gnu.org/licenses/>.            #
#                                                                              #
# SPDX-License-Identifier: GPL-3.0-or-later                                    #
################################################################################

add_subdirectory(backend)

# ##############################################################################
# This builds the `gkfs_daemon` executable: the primary GekkoFS daemon.
# ##############################################################################
add_executable(gkfs_daemon)

pkg_check_modules(URING IMPORTED_TARGET liburing)

# We need to add here any files that may have different compile definitions
target_sources(
    gkfs_daemon
    PRIVATE daemon.cpp
    handler/srv_data.cpp
    ../common/rpc/rpc_util.cpp
    ../common/hostfile_management.cpp
    util.cpp
    ops/metadentry.cpp
    ops/data.cpp
    classes/fs_data.cpp
    classes/rpc_data.cpp
    handler/srv_metadata.cpp

    handler/srv_malleability.cpp
    malleability/malleable_manager.cpp
    malleability/rpc/forward_redistribution.cpp
    PUBLIC ${CMAKE_SOURCE_DIR}/include/config.hpp
    ${CMAKE_SOURCE_DIR}/include/version.hpp.in
)
target_link_libraries(
    gkfs_daemon
    PUBLIC # internal libs
    metadata
    metadata_backend
    storage
    distributor
    statistics
    log_util
    env_util
    path_util
    # external libs
    CLI11::CLI11
    fmt::fmt
    thallium
    # others
    Threads::Threads
    ZStd::ZStd
)

if (GKFS_ENABLE_CLIENT_METRICS)
    # for the opt-in LIBGKFS_METRICS_AGGREGATOR test feature (daemon.cpp)
    target_link_libraries(gkfs_daemon PRIVATE cppzmq Msgpack::Msgpack)
    target_compile_definitions(gkfs_daemon PUBLIC GKFS_ENABLE_CLIENT_METRICS)
endif ()

if (GKFS_ENABLE_AGIOS)
    target_sources(gkfs_daemon PRIVATE scheduler/agios.cpp)
    target_compile_definitions(gkfs_daemon PUBLIC GKFS_ENABLE_AGIOS)
    target_link_libraries(gkfs_daemon PRIVATE AGIOS::AGIOS)
endif ()

if (GKFS_ENABLE_CODE_COVERAGE)
    target_code_coverage(gkfs_daemon AUTO)
endif ()

install(TARGETS gkfs_daemon RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

