CMakeLists.txt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. address/addressfactory.cpp
  48. address/addresspage.cpp
  49. pagefactory.cpp
  50. components/MultiSelectComboBox.cpp
  51. blastProject/blastprojectfactory.cpp
  52. blastProject/blastprojectpage.cpp
  53. blastProject/projectdialog.cpp
  54. blastProject/hproject.cpp
  55. blastProject/hprojectdao.cpp
  56. components/buttondelegate.cpp
  57. utils/databasemanager.cpp
  58. detInfo/detinfofactory.cpp
  59. detInfo/detinfopage.cpp
  60. detInfo/detdialog.cpp
  61. equipment/equipmentfactory.cpp
  62. equipment/equipmentpage.cpp
  63. utils/global.cpp
  64. utils/httpclient.cpp
  65. utils/logger.cpp
  66. login/loginwindow.cpp
  67. main.cpp
  68. mainwindow/mainwindow.cpp
  69. utils/jobs.cpp
  70. registryManager/registrymanager.cpp
  71. mqtt/mqttclient.cpp
  72. blastRecord/blastrecordfactory.cpp
  73. blastRecord/blastrecord.cpp
  74. blastRecord/hblastrecord.cpp
  75. blastRecord/hblastrecorddao.cpp
  76. blastRecordDet/hblastrecorddet.cpp
  77. blastRecordDet/hblastrecorddetdao.cpp
  78. blastRegRecord/hblastregrecord.cpp
  79. blastRegRecord/hblastregrecorddao.cpp
  80. fireWidget/firingwidget.cpp
  81. fireWidget/navprogress.cpp
  82. blastJob/countdownwidget.cpp
  83. serial/serialtool.cpp
  84. serial/serialgps.cpp
  85. serial/serialgpsthread.cpp
  86. serial/paregnrmc.cpp
  87. worker/timeupdatethread.cpp
  88. components/loadingWidget.cpp
  89. components/custommessagebox.cpp
  90. components/SafetyInspectDialog.cpp
  91. utils/backendapimanager.cpp
  92. homepage/homepage.cpp
  93. homepage/homepagefactory.cpp
  94. )
  95. # 定义头文件列表
  96. set(HEADERS
  97. PageWidget.h
  98. blastJob/blastoperationfactory.h
  99. blastJob/blastopepage.h
  100. blastJob/faceverification.h
  101. address/addressfactory.h
  102. address/addresspage.h
  103. pagefactory.h
  104. components/MultiSelectComboBox.h
  105. blastProject/blastprojectfactory.h
  106. blastProject/blastprojectpage.h
  107. blastProject/hproject.h
  108. blastProject/hprojectdao.h
  109. blastProject/projectdialog.h
  110. components/components/
  111. utils/databasemanager.h
  112. detInfo/detinfofactory.h
  113. detInfo/detinfopage.h
  114. detInfo/detdialog.h
  115. equipment/equipmentfactory.h
  116. equipment/equipmentpage.h
  117. utils/global.h
  118. utils/httpclient.h
  119. utils/logger.h
  120. login/loginwindow.h
  121. mainwindow/mainwindow.h
  122. utils/jobs.h
  123. registryManager/registrymanager.h
  124. mqtt/mqttclient.h
  125. blastRecord/blastrecordfactory.h
  126. blastRecord/blastrecord.h
  127. blastRecord/hblastrecord.h
  128. blastRecord/hblastrecorddao.h
  129. blastRecordDet/hblastrecorddet.h
  130. blastRecordDet/hblastrecorddetdao.h
  131. blastRegRecord/hblastregrecord.h
  132. blastRegRecord/hblastregrecorddao.h
  133. fireWidget/firingwidget.h
  134. fireWidget/navprogress.h
  135. blastJob/countdownwidget.h
  136. serial/serialtool.h
  137. serial/serialgps.h
  138. serial/serialgpsthread.h
  139. serial/paregnrmc.h
  140. homepage/homepage.h
  141. worker/timeupdatethread.h
  142. components/loadingWidget.h
  143. components/custommessagebox.h
  144. components/SafetyInspectDialog.h
  145. utils/backendapimanager.h
  146. )
  147. # 定义 UI 文件列表
  148. set(FORMS
  149. homepage/homepage.ui
  150. PageWidget.ui
  151. address/addresspage.ui
  152. blastProject/blastprojectpage.ui
  153. detInfo/detinfopage.ui
  154. detInfo/detdialog.ui
  155. equipment/equipmentpage.ui
  156. login/loginwindow.ui
  157. mainwindow/mainwindow.ui
  158. blastProject/projectdialog.ui
  159. blastJob/blastopepage.ui
  160. blastRecord/blastrecord.ui
  161. fireWidget/firingwidget.ui
  162. )
  163. # 定义资源文件列表
  164. set(RESOURCES
  165. media.qrc
  166. )
  167. # 添加可执行文件
  168. add_executable(${PROJECT_NAME}
  169. ${SOURCES}
  170. ${HEADERS}
  171. ${FORMS}
  172. ${RESOURCES}
  173. logo.rc
  174. )
  175. # 创建测试可执行文件
  176. add_executable(test_database
  177. tests/test_database.cpp
  178. utils/databasemanager.cpp
  179. utils/logger.cpp
  180. )
  181. # 链接测试可执行文件的库
  182. target_link_libraries(test_database
  183. Qt${QT_VERSION_MAJOR}::Core
  184. Qt${QT_VERSION_MAJOR}::Widgets
  185. Qt${QT_VERSION_MAJOR}::Sql
  186. ${OPENSSL_LIBRARIES}
  187. )
  188. # 设置测试可执行文件的输出目录
  189. set_target_properties(test_database PROPERTIES
  190. RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
  191. )
  192. set_target_properties(${PROJECT_NAME} PROPERTIES
  193. WIN32_EXECUTABLE FALSE
  194. )
  195. target_link_libraries(pc_system Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui
  196. Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Sql Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Charts
  197. Qt${QT_VERSION_MAJOR}::Mqtt Qt${QT_VERSION_MAJOR}::WebEngineWidgets OpenSSL::Crypto OpenSSL::SSL Qt${QT_VERSION_MAJOR}::SerialPort)
  198. include(GNUInstallDirs)
  199. install(TARGETS pc_system
  200. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  201. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  202. )