CMakeLists.txt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. # macOS Clang 配置
  14. set(CMAKE_C_COMPILER /opt/homebrew/opt/llvm/bin/clang)
  15. set(CMAKE_CXX_COMPILER /opt/homebrew/opt/llvm/bin/clang++)
  16. execute_process(
  17. COMMAND xcrun --sdk macosx --show-sdk-path
  18. OUTPUT_VARIABLE SDK_PATH
  19. OUTPUT_STRIP_TRAILING_WHITESPACE
  20. )
  21. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  22. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ")
  23. elseif(WIN32)
  24. message(STATUS "Compiling for Windows")
  25. # Windows MSVC 默认不需要特别设置,但你也可以切换成 clang-cl:
  26. # set(CMAKE_C_COMPILER "clang-cl")
  27. # set(CMAKE_CXX_COMPILER "clang-cl")
  28. # 推荐使用 vcpkg 来管理 Windows 下的库路径
  29. # set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
  30. endif()
  31. #set(CMAKE_PREFIX_PATH "C:/Qt/6.9.0/msvc2022_64")
  32. # # 设置 OpenSSL 安装路径
  33. # set(OPENSSL_ROOT_DIR "C:/Qt/Tools/OpenSSLv3/Win_x64")
  34. # 查找 OpenSSL 库
  35. find_package(OpenSSL REQUIRED)
  36. if(OpenSSL_FOUND)
  37. message(STATUS "OpenSSL found: ${OpenSSL_VERSION}")
  38. else()
  39. message(FATAL_ERROR "OpenSSL not found. Please install OpenSSL development libraries.")
  40. endif()
  41. find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui Widgets Mqtt Sql Network WebEngineWidgets SerialPort Charts)
  42. find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets Mqtt Sql Network WebEngineWidgets SerialPort Charts) # 添加 Widgets
  43. # 定义源文件列表
  44. set(SOURCES
  45. PageWidget.cpp
  46. blastJob/blastoperationfactory.cpp
  47. blastJob/blastopepage.cpp
  48. address/addressfactory.cpp
  49. address/addresspage.cpp
  50. pagefactory.cpp
  51. components/MultiSelectComboBox.cpp
  52. blastProject/blastprojectfactory.cpp
  53. blastProject/blastprojectpage.cpp
  54. blastProject/projectdialog.cpp
  55. blastProject/hproject.cpp
  56. blastProject/hprojectdao.cpp
  57. components/buttondelegate.cpp
  58. utils/databasemanager.cpp
  59. detInfo/detinfofactory.cpp
  60. detInfo/detinfopage.cpp
  61. detInfo/detdialog.cpp
  62. equipment/equipmentfactory.cpp
  63. equipment/equipmentpage.cpp
  64. utils/global.cpp
  65. utils/httpclient.cpp
  66. utils/logger.cpp
  67. login/loginwindow.cpp
  68. main.cpp
  69. mainwindow/mainwindow.cpp
  70. utils/jobs.cpp
  71. registryManager/registrymanager.cpp
  72. mqtt/mqttclient.cpp
  73. blastRecord/blastrecordfactory.cpp
  74. blastRecord/blastrecord.cpp
  75. blastRecord/hblastrecord.cpp
  76. blastRecord/hblastrecorddao.cpp
  77. blastRecordDet/hblastrecorddet.cpp
  78. blastRecordDet/hblastrecorddetdao.cpp
  79. blastRegRecord/hblastregrecord.cpp
  80. blastRegRecord/hblastregrecorddao.cpp
  81. fireWidget/firingwidget.cpp
  82. fireWidget/navprogress.cpp
  83. blastJob/countdownwidget.cpp
  84. serial/serialtool.cpp
  85. serial/serialgps.cpp
  86. serial/serialgpsthread.cpp
  87. serial/paregnrmc.cpp
  88. worker/timeupdatethread.cpp
  89. components/loadingWidget.cpp
  90. components/custommessagebox.cpp
  91. components/SafetyInspectDialog.cpp
  92. utils/backendapimanager.cpp
  93. homepage/homepage.cpp
  94. homepage/homepagefactory.cpp
  95. )
  96. # 定义头文件列表
  97. set(HEADERS
  98. PageWidget.h
  99. blastJob/blastoperationfactory.h
  100. blastJob/blastopepage.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. )