message("\n${BoldGreen}Now configuring src/cli for ${PROJECT_NAME}${ColourReset}\n")

# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

add_executable(
    mzml2mzcbor
    mzml2mzcborcli.cpp
)

target_include_directories(
    mzml2mzcbor
    PUBLIC ${PappsoMSpp_INCLUDE_DIRS}
)

target_link_libraries(
    mzml2mzcbor Qt6::Core Qt6::Qml Core
)

add_dependencies(mzml2mzcbor Core)

install(
    PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/mzml2mzcbor
    DESTINATION bin
)

########################## The man page ##########################

if(UNIX AND NOT APPLE)

    find_program(rst2man_program rst2man)
    if(NOT rst2man_program)
        message(FATAL_ERROR "rst2man not found!")
    endif()

set(mzml2mzcbor_manpage ${CMAKE_CURRENT_BINARY_DIR}/mzml2mzcbor.1)

add_custom_command(
    OUTPUT ${mzml2mzcbor_manpage}
    COMMAND ${rst2man_program} ${CMAKE_CURRENT_SOURCE_DIR}/mzml2mzcbor.1.rst ${mzml2mzcbor_manpage}
    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/mzml2mzcbor.1.rst
    COMMENT "Generating man page mzml2mzcbor.1 from mzml2mzcbor.rst"
    VERBATIM
)

add_custom_target(manpage ALL DEPENDS ${mzml2mzcbor_manpage})

# Install the generated file
install(
    FILES ${mzml2mzcbor_manpage}
    DESTINATION share/man/man1
)

endif()

message("\n${BoldGreen}Done configuring src/cli for ${PROJECT_NAME}${ColourReset}\n")
