https://www.cnblogs.com/linuxAndMcu/p/14458427.html
https://blog.csdn.net/developerof/article/details/108525160

CMakeLists.txt文件添加模块

  1. cmake_minimum_required(VERSION 3.5)
  2. project(tcpTranslate VERSION 0.1 LANGUAGES CXX)
  3. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  4. set(CMAKE_AUTOUIC ON) #开启uic.exe 编译.ui文件
  5. set(CMAKE_AUTOMOC ON) #开启moc.exe 编译头文件含有Q_OBJECT且是QObject对象的子类的类,实现一些信号槽相关实现代码
  6. set(CMAKE_AUTORCC ON) #讲资源文件进行编译 编译成cpp文件
  7. set(CMAKE_CXX_STANDARD 17) #cmake 标准
  8. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  9. find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
  10. find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
  11. #Add the module name to be added here
  12. find_package(Qt5 COMPONENTS Network)
  13. //项目中代码文件
  14. set(PROJECT_SOURCES
  15. main.cpp
  16. widget.cpp
  17. widget.h
  18. widget.ui
  19. )
  20. if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
  21. qt_add_executable(tcpTranslate
  22. MANUAL_FINALIZATION
  23. ${PROJECT_SOURCES}
  24. )
  25. # Define target properties for Android with Qt 6 as:
  26. # set_property(TARGET tcpTranslate APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
  27. # ${CMAKE_CURRENT_SOURCE_DIR}/android)
  28. # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
  29. else()
  30. if(ANDROID)
  31. add_library(tcpTranslate SHARED
  32. ${PROJECT_SOURCES}
  33. )
  34. # Define properties for Android with Qt 5 after find_package() calls as:
  35. # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
  36. else()
  37. add_executable(tcpTranslate
  38. ${PROJECT_SOURCES}
  39. )
  40. endif()
  41. endif()
  42. #Add the module library link to be added here 在这里添加需要添加的模块库链接
  43. target_link_libraries(tcpTranslate PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
  44. Qt${QT_VERSION_MAJOR}::Network )
  45. set_target_properties(tcpTranslate PROPERTIES
  46. MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
  47. MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
  48. MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
  49. MACOSX_BUNDLE TRUE
  50. WIN32_EXECUTABLE TRUE
  51. )
  52. if(QT_VERSION_MAJOR EQUAL 6)
  53. qt_finalize_executable(tcpTranslate)
  54. endif()