CMakeLists.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. cmake_minimum_required(VERSION 3.16)
  2. project(pc_system LANGUAGES CXX)
  3. # 启用 Qt 的自动 UI、MOC 和资源处理
  4. set(CMAKE_AUTOUIC ON)
  5. set(CMAKE_AUTOMOC ON)
  6. set(CMAKE_AUTORCC ON)
  7. # 设置 C++ 标准
  8. set(CMAKE_CXX_STANDARD 17)
  9. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  10. set(CMAKE_CXX_EXTENSIONS OFF)
  11. if (APPLE)
  12. message(STATUS "Compiling for macOS")
  13. execute_process(
  14. COMMAND xcrun --sdk macosx --show-sdk-path
  15. OUTPUT_VARIABLE SDK_PATH
  16. OUTPUT_STRIP_TRAILING_WHITESPACE
  17. )
  18. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  19. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ")
  20. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-nonportable-include-path")
  21. elseif(WIN32)
  22. message(STATUS "Compiling for Windows")
  23. set(CMAKE_PREFIX_PATH "C:/Qt/6.9.0/msvc2022_64")
  24. # 设置 OpenSSL 安装路径
  25. set(OPENSSL_ROOT_DIR "C:/Qt/Tools/OpenSSLv3/Win_x64")
  26. # Windows MSVC 默认不需要特别设置,但你也可以切换成 clang-cl:
  27. # set(CMAKE_C_COMPILER "clang-cl")
  28. # set(CMAKE_CXX_COMPILER "clang-cl")
  29. # 推荐使用 vcpkg 来管理 Windows 下的库路径
  30. # set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
  31. endif()
  32. # 查找 OpenSSL 库
  33. find_package(OpenSSL REQUIRED)
  34. if(OpenSSL_FOUND)
  35. message(STATUS "OpenSSL found: ${OpenSSL_VERSION}")
  36. else()
  37. message(FATAL_ERROR "OpenSSL not found. Please install OpenSSL development libraries.")
  38. endif()
  39. find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui Widgets Mqtt Sql Network WebEngineWidgets SerialPort Charts)
  40. find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets Mqtt Sql Network WebEngineWidgets SerialPort Charts) # 添加 Widgets
  41. # 定义源文件列表
  42. set(SOURCES
  43. PageWidget.cpp
  44. blastJob/blastoperationfactory.cpp
  45. blastJob/blastopepage.cpp
  46. blastJob/faceverification.cpp
  47. blastJob/sequenceselectorwidget.cpp
  48. blastJob/dragdroptablewidget.cpp
  49. address/addressfactory.cpp
  50. address/addresspage.cpp
  51. pagefactory.cpp
  52. components/MultiSelectComboBox.cpp
  53. blastProject/blastprojectfactory.cpp
  54. blastProject/blastprojectpage.cpp
  55. blastProject/projectdialog.cpp
  56. blastProject/hproject.cpp
  57. blastProject/hprojectdao.cpp
  58. components/buttondelegate.cpp
  59. utils/databasemanager.cpp
  60. detInfo/detinfofactory.cpp
  61. detInfo/detinfopage.cpp
  62. detInfo/detdialog.cpp
  63. equipment/equipmentfactory.cpp
  64. equipment/equipmentpage.cpp
  65. utils/global.cpp
  66. utils/httpclient.cpp
  67. utils/logger.cpp
  68. login/loginwindow.cpp
  69. main.cpp
  70. mainwindow/mainwindow.cpp
  71. utils/jobs.cpp
  72. registryManager/registrymanager.cpp
  73. mqtt/mqttclient.cpp
  74. blastRecord/blastrecordfactory.cpp
  75. blastRecord/blastrecord.cpp
  76. blastRecord/hblastrecord.cpp
  77. blastRecord/hblastrecorddao.cpp
  78. blastRecordDet/hblastrecorddet.cpp
  79. blastRecordDet/hblastrecorddetdao.cpp
  80. blastRegRecord/hblastregrecord.cpp
  81. blastRegRecord/hblastregrecorddao.cpp
  82. fireWidget/firingwidget.cpp
  83. fireWidget/navprogress.cpp
  84. blastJob/countdownwidget.cpp
  85. serial/serialtool.cpp
  86. serial/serialgps.cpp
  87. serial/serialgpsthread.cpp
  88. serial/paregnrmc.cpp
  89. worker/timeupdatethread.cpp
  90. components/loadingWidget.cpp
  91. components/custommessagebox.cpp
  92. components/SafetyInspectDialog.cpp
  93. utils/backendapimanager.cpp
  94. homepage/homepage.cpp
  95. homepage/homepagefactory.cpp
  96. )
  97. # 定义头文件列表
  98. set(HEADERS
  99. PageWidget.h
  100. blastJob/blastoperationfactory.h
  101. blastJob/blastopepage.h
  102. blastJob/faceverification.h
  103. blastJob/sequenceselectorwidget.h
  104. blastJob/dragdroptablewidget.h
  105. address/addressfactory.h
  106. address/addresspage.h
  107. pagefactory.h
  108. components/MultiSelectComboBox.h
  109. blastProject/blastprojectfactory.h
  110. blastProject/blastprojectpage.h
  111. blastProject/hproject.h
  112. blastProject/hprojectdao.h
  113. blastProject/projectdialog.h
  114. components/components/
  115. utils/databasemanager.h
  116. detInfo/detinfofactory.h
  117. detInfo/detinfopage.h
  118. detInfo/detdialog.h
  119. equipment/equipmentfactory.h
  120. equipment/equipmentpage.h
  121. utils/global.h
  122. utils/httpclient.h
  123. utils/logger.h
  124. login/loginwindow.h
  125. mainwindow/mainwindow.h
  126. utils/jobs.h
  127. registryManager/registrymanager.h
  128. mqtt/mqttclient.h
  129. blastRecord/blastrecordfactory.h
  130. blastRecord/blastrecord.h
  131. blastRecord/hblastrecord.h
  132. blastRecord/hblastrecorddao.h
  133. blastRecordDet/hblastrecorddet.h
  134. blastRecordDet/hblastrecorddetdao.h
  135. blastRegRecord/hblastregrecord.h
  136. blastRegRecord/hblastregrecorddao.h
  137. fireWidget/firingwidget.h
  138. fireWidget/navprogress.h
  139. blastJob/countdownwidget.h
  140. serial/serialtool.h
  141. serial/serialgps.h
  142. serial/serialgpsthread.h
  143. serial/paregnrmc.h
  144. homepage/homepage.h
  145. worker/timeupdatethread.h
  146. components/loadingWidget.h
  147. components/custommessagebox.h
  148. components/SafetyInspectDialog.h
  149. utils/backendapimanager.h
  150. )
  151. # 定义 UI 文件列表
  152. set(FORMS
  153. homepage/homepage.ui
  154. PageWidget.ui
  155. address/addresspage.ui
  156. blastProject/blastprojectpage.ui
  157. detInfo/detinfopage.ui
  158. detInfo/detdialog.ui
  159. equipment/equipmentpage.ui
  160. login/loginwindow.ui
  161. mainwindow/mainwindow.ui
  162. blastProject/projectdialog.ui
  163. blastJob/blastopepage.ui
  164. blastRecord/blastrecord.ui
  165. fireWidget/firingwidget.ui
  166. )
  167. # 定义资源文件列表
  168. set(RESOURCES
  169. media.qrc
  170. )
  171. # 添加可执行文件
  172. add_executable(${PROJECT_NAME}
  173. ${SOURCES}
  174. ${HEADERS}
  175. ${FORMS}
  176. ${RESOURCES}
  177. logo.rc
  178. )
  179. # 创建测试可执行文件
  180. add_executable(test_database
  181. tests/test_database.cpp
  182. utils/databasemanager.cpp
  183. utils/logger.cpp
  184. )
  185. # 链接测试可执行文件的库
  186. target_link_libraries(test_database
  187. Qt${QT_VERSION_MAJOR}::Core
  188. Qt${QT_VERSION_MAJOR}::Widgets
  189. Qt${QT_VERSION_MAJOR}::Sql
  190. ${OPENSSL_LIBRARIES}
  191. )
  192. # 设置测试可执行文件的输出目录
  193. set_target_properties(test_database PROPERTIES
  194. RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
  195. )
  196. set_target_properties(${PROJECT_NAME} PROPERTIES
  197. WIN32_EXECUTABLE FALSE
  198. )
  199. target_link_libraries(pc_system Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui
  200. Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Sql Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Charts
  201. Qt${QT_VERSION_MAJOR}::Mqtt Qt${QT_VERSION_MAJOR}::WebEngineWidgets OpenSSL::Crypto OpenSSL::SSL Qt${QT_VERSION_MAJOR}::SerialPort)
  202. include(GNUInstallDirs)
  203. install(TARGETS pc_system
  204. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  205. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  206. )