set(PACKAGE data_converters-protox)

message(STATUS ${PACKAGE})

include(FindProtobuf)
include(GoogleTest)
include(FetchContent)
find_package(Protobuf REQUIRED)
find_package(vaisala-wr-common-dto REQUIRED)

FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG release-1.12.1)
FetchContent_MakeAvailable(googletest)

set(APP_NAMES protox)

set(PROTOX_SOURCE_FILES protox.C protox.hpp)

add_subdirectory(templates)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../lib)

link_libraries(misc-iris himath-iris user-iris dl m bsd boost_regex dspi-iris dsp-iris exthdr-iris irisscan-iris sws-iris wrdata tirpc antenna-iris config-iris)

add_definitions(-DPROTOX_TEST_FILE=\"${CMAKE_CURRENT_SOURCE_DIR}/test_files/test_common_dto.pb\")

add_executable(protox protox_main.C ${PROTOX_SOURCE_FILES})
add_executable(protox-tests protox_tests.C protox_tests.hpp ${PROTOX_SOURCE_FILES})

target_link_libraries(protox vaisala-wr-common-dto::common-dto ${PROTOBUF_LIBRARIES} boost_program_options boost_filesystem boost_system boost_date_time rscan-iris lz4)

target_link_libraries(protox-tests vaisala-wr-common-dto::common-dto ${PROTOBUF_LIBRARIES} boost_program_options boost_filesystem boost_system boost_date_time lz4 rscan-iris GTest::gtest_main)

include(GoogleTest)
gtest_discover_tests(protox-tests)

enable_testing()

file(DOWNLOAD
        ${CMAKE_CURRENT_SOURCE_DIR}/test_files/test_common_dto.pb
        ${CMAKE_CURRENT_BINARY_DIR}/test_common_dto.pb)        

# disable temporarily to speed up CI, enable when tests are fixed
# add_custom_target(
#   protox-tests ALL
#   DEPENDS protox-tests
#   COMMENT "Run protox tests"
#   COMMAND ctest --test-dir ${CMAKE_CURRENT_BINARY_DIR})

install(
  TARGETS ${APP_NAMES}
  DESTINATION ${IRIS_BIN}
  COMPONENT protobuf)

