set(PACKAGE data_converters-ngpipes-protobuf)

message(STATUS ${PACKAGE})

find_package(Protobuf REQUIRED)
find_package(gRPC REQUIRED)
find_package(Boost 1.53
        COMPONENTS
        date_time
        program_options
        system
        filesystem
        REQUIRED)
find_package(vaisala-wr-common-dto REQUIRED)
find_package(vaisala-wr-input-dto REQUIRED)
find_package(spdlog REQUIRED)
find_package(PROJ REQUIRED)

# Data-manager is optional - only required when BUILD_DM=ON
if(BUILD_DM)
  find_package(vaisala-fire-data-manager REQUIRED)
endif()

set(PIPE_NAMES pb2iris iris2pb)
set(PIPE_NAMES_DM iris2dm)
set(PIPE_NAME_INPUT_DTO raw2pb_input_dto)
set(CONF_FILES pb2iris.conf iris2pb.conf)
set(CONF_FILES_DM iris2dm.conf)

include_directories(
                ${HDF5_INCLUDE_DIR}
                ${CMAKE_SOURCE_DIR}/ngpipes
                ${CMAKE_SOURCE_DIR}/sigmet
                ${IRIS_INCLUDE}/common-dto)

if(BUILD_DM)
  include_directories(
                ${CMAKE_SOURCE_DIR}/ngpipes/data_manager_lib
                ${IRIS_INCLUDE}/data-manager)
endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)

link_libraries(wrdata sws-iris siglog boost_program_options boost_system tirpc
        boost_filesystem boost_regex boost_date_time m dsp-iris antenna-iris config-iris exthdr-iris misc-iris himath-iris spdlog::spdlog)
        
add_executable(iris2pb iris2pb.cpp iris_conversion.cpp pbio.cpp ${CMAKE_SOURCE_DIR}/sigmet/iris_utils.c)
target_link_libraries(iris2pb user-iris rscan-iris vaisala-wr-common-dto::common-dto siglog ${Boost_LIBRARIES} m z lz4 ${PROTOBUF_LIBRARIES} PROJ::proj)

# Data-manager dependent binary - only build when BUILD_DM=ON
if(BUILD_DM)
  add_executable(iris2dm iris2dm.cpp iris_conversion.cpp pbio.cpp ${CMAKE_SOURCE_DIR}/sigmet/iris_utils.c)
  target_link_libraries(iris2dm user-iris rscan-iris gRPC::grpc++ vaisala-wr-common-dto::common-dto data-manager
          data-manager-iris siglog ${Boost_LIBRARIES} m z lz4 ${PROTOBUF_LIBRARIES} PROJ::proj)
  
  install(TARGETS ${PIPE_NAMES_DM} DESTINATION ${IRIS_PIPES} COMPONENT protobuf-dm)
  install(FILES ${CONF_FILES_DM} DESTINATION ${IRIS_CONFIG_TMPL} COMPONENT protobuf-dm)
else()
  message(STATUS "Skipping iris2dm binary (BUILD_DM=OFF)")
endif()

add_executable(pb2iris pb2iris.cpp pbio.cpp pbio.hpp ${CMAKE_SOURCE_DIR}/sigmet/iris_utils.c)
target_link_libraries(pb2iris user-iris rscan-iris vaisala-wr-common-dto::common-dto siglog ${Boost_LIBRARIES} m z lz4 ${PROTOBUF_LIBRARIES} PROJ::proj)

add_executable(raw2pb_input_dto raw2pb_input_dto.cpp)
target_link_libraries(raw2pb_input_dto user-iris rscan-iris vaisala-wr-input-dto::input-dto siglog ${Boost_LIBRARIES} m z lz4 ${PROTOBUF_LIBRARIES})

install(TARGETS ${PIPE_NAMES} DESTINATION ${IRIS_PIPES} COMPONENT protobuf)
install(TARGETS ${PIPE_NAME_INPUT_DTO} DESTINATION ${IRIS_PIPES} COMPONENT protobuf-input-dto)
install(FILES ${CONF_FILES} DESTINATION ${IRIS_CONFIG_TMPL} COMPONENT protobuf)
