unset(extra_generator_args)
if(TARGET Qt::Qml)
    list(APPEND extra_generator_args QML)
endif()

qt6_protobuf_generate(GENERATED_TARGET tst_protobuf_basictypes_gen
    PROTO_FILES
        proto/basicmessages.proto
    FIELDENUM
    ${extra_generator_args}
    OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated"
)

qt_internal_add_test(tst_protobuf_basictypes
    SOURCES
        basictypes.cpp
    INCLUDE_DIRECTORIES
        ../../shared
    LIBRARIES
        Qt::Test
        Qt::Protobuf
)
_qt_internal_link_protobuf_objects(tst_protobuf_basictypes tst_protobuf_basictypes_gen)

qt6_protobuf_generate(GENERATED_TARGET tst_protobuf_repeatedtypes_gen
    PROTO_FILES
        proto/repeatedmessages.proto
    FIELDENUM
    ${extra_generator_args}
    OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated"
)

qt_internal_add_test(tst_protobuf_repeatedtypes
    SOURCES
        repeatedtypes.cpp
    INCLUDE_DIRECTORIES
        ../../shared
    LIBRARIES
        Qt::Test
        Qt::Protobuf
)
_qt_internal_link_protobuf_objects(tst_protobuf_repeatedtypes
    tst_protobuf_basictypes_gen
    tst_protobuf_repeatedtypes_gen
)

qt6_protobuf_generate(GENERATED_TARGET tst_protobuf_maptypes_gen
    PROTO_FILES
        proto/mapmessages.proto
    FIELDENUM
    ${extra_generator_args}
    OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated"
)
qt_internal_add_test(tst_protobuf_maptypes
    SOURCES
        maptypes.cpp
    INCLUDE_DIRECTORIES
        ../../shared
    LIBRARIES
        Qt::Test
        Qt::Protobuf
)
_qt_internal_link_protobuf_objects(tst_protobuf_maptypes
    tst_protobuf_basictypes_gen
    tst_protobuf_maptypes_gen
)

qt6_protobuf_generate(GENERATED_TARGET tst_protobuf_fieldindexrange_gen
    PROTO_FILES
        proto/fieldindexrange.proto
    FIELDENUM
    ${extra_generator_args}
    OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated"
)

qt_internal_add_test(tst_protobuf_serialization_basictypes
    SOURCES
        serializationbasictypes.cpp
    LIBRARIES
        Qt::Test
        Qt::Protobuf
)
_qt_internal_link_protobuf_objects(tst_protobuf_serialization_basictypes
    tst_protobuf_basictypes_gen
    tst_protobuf_fieldindexrange_gen
)

qt_internal_add_test(tst_protobuf_serialization_repeatedtypes
    SOURCES
        serializationrepeatedtypes.cpp
    LIBRARIES
        Qt::Test
        Qt::Protobuf
)
_qt_internal_link_protobuf_objects(tst_protobuf_serialization_repeatedtypes
    tst_protobuf_basictypes_gen
    tst_protobuf_repeatedtypes_gen
)

qt_internal_add_test(tst_protobuf_serialization_maptypes
    SOURCES
        serializationmaptypes.cpp serializationmaptypes.h
        serializationcomplexmaptypes.cpp
    LIBRARIES
        Qt::Test
        Qt::Protobuf
)
_qt_internal_link_protobuf_objects(tst_protobuf_serialization_maptypes
    tst_protobuf_basictypes_gen
    tst_protobuf_maptypes_gen
)

qt_internal_add_test(tst_protobuf_deserialization_basictypes
    SOURCES
        deserializationbasictypes.cpp
    LIBRARIES
        Qt::Test
        Qt::Protobuf
)
_qt_internal_link_protobuf_objects(tst_protobuf_deserialization_basictypes
    tst_protobuf_basictypes_gen
    tst_protobuf_fieldindexrange_gen
)

qt_internal_add_test(tst_protobuf_deserialization_repeatedtypes
    SOURCES
        deserializationrepeatedtypes.cpp
    LIBRARIES
        Qt::Test
        Qt::Protobuf
)
_qt_internal_link_protobuf_objects(tst_protobuf_deserialization_repeatedtypes
    tst_protobuf_basictypes_gen
    tst_protobuf_repeatedtypes_gen
)

qt_internal_add_test(tst_protobuf_deserialization_maptypes
    SOURCES
        deserializationmaptypes.cpp deserializationmaptypes.h
        deserializationcomplexmaptypes.cpp
    LIBRARIES
        Qt::Test
        Qt::Protobuf
)
_qt_internal_link_protobuf_objects(tst_protobuf_deserialization_maptypes
    tst_protobuf_basictypes_gen
    tst_protobuf_maptypes_gen
)

if(UNIX AND NOT CMAKE_CROSSCOMPILING)
    qt_internal_add_test(tst_protobuf_internals
        SOURCES
            internalstest.cpp
        LIBRARIES
            Qt::Test
            Qt::Protobuf
    )
    _qt_internal_link_protobuf_objects(tst_protobuf_internals tst_protobuf_basictypes_gen)
endif()

#if(QT_FEATURE_protobuf_json_serializer)
    add_subdirectory(json)
#endif()

if(TARGET Qt::QuickTest)
    add_subdirectory(qml)
endif()
