CMakeLists.txt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. cmake_minimum_required(VERSION 3.5)
  2. project(clienttutorial LANGUAGES CXX)
  3. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  4. set(CMAKE_AUTOUIC ON)
  5. set(CMAKE_AUTOMOC ON)
  6. set(CMAKE_AUTORCC ON)
  7. find_package(Qt6 COMPONENTS Core Quick REQUIRED)
  8. set(CMAKE_POSITION_INDEPENDENT_CODE ${Qt6_POSITION_INDEPENDENT_CODE})
  9. set(QT_PROTOBUF_NAMESPACE QtProtobuf)
  10. if(NOT TARGET ${QT_PROTOBUF_NAMESPACE}::qtprotobufgen)
  11. find_package(${QT_PROTOBUF_NAMESPACE} COMPONENTS ProtobufGenerator CONFIG REQUIRED)
  12. endif()
  13. if(NOT TARGET ${QT_PROTOBUF_NAMESPACE}::Protobuf)
  14. find_package(${QT_PROTOBUF_NAMESPACE} COMPONENTS Protobuf CONFIG REQUIRED)
  15. endif()
  16. if(NOT TARGET ${QT_PROTOBUF_NAMESPACE}::Grpc)
  17. find_package(${QT_PROTOBUF_NAMESPACE} COMPONENTS Grpc CONFIG REQUIRED)
  18. endif()
  19. add_executable(clienttutorial main.cpp echoclientengine.cpp qml.qrc)
  20. qt6_protobuf_generate(TARGET clienttutorial
  21. PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tutorial.proto
  22. QML TRUE)
  23. target_compile_definitions(clienttutorial
  24. PRIVATE "$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>")
  25. if(QT_PROTOBUF_STATIC)
  26. add_definitions(-DQT_PROTOBUF_STATIC)# add_definitions is used because old cmake versions
  27. # compatibility
  28. endif()
  29. target_link_libraries(clienttutorial PRIVATE Qt6::Core
  30. Qt6::Quick
  31. ${QT_PROTOBUF_NAMESPACE}::Grpc
  32. ${QT_PROTOBUF_NAMESPACE}::Protobuf)