CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. #-----------------------------------------------------------------------------
  2. # 工程属性设置
  3. #-----------------------------------------------------------------------------
  4. # 指定所需cmake的最低版本
  5. cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
  6. # 设置项目名称 语言
  7. project(GJDM)
  8. #-----------------------------------------------------------------------------
  9. # 编译系统设置
  10. #-----------------------------------------------------------------------------
  11. # c++语言标准
  12. set(CMAKE_CXX_STANDARD 11)
  13. # 指定是否使用编译器特定的扩展
  14. set(CMAKE_CXX_EXTENSIONS OFF)
  15. # 是否强制要求C++标准为${CMAKE_CXX_STANDARD},如果为OFF则可能使用旧的标准
  16. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  17. # 默认编译动态库
  18. set(BUILD_SHARED_LIBS ON)
  19. #-----------------------------------------------------------------------------
  20. # 检测操作系统
  21. #-----------------------------------------------------------------------------
  22. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  23. set(SYS_LINUX True)
  24. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  25. set(CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}" CACHE PATH "${PROJECT_NAME}的安装路径" FORCE)
  26. endif()
  27. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  28. set(SYS_WIN True)
  29. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  30. set(CMAKE_INSTALL_PREFIX "c:/Program Files/${PROJECT_NAME}" CACHE PATH "${PROJECT_NAME}的安装路径" FORCE)
  31. endif()
  32. else()
  33. message(SEND_ERROR "No Support System!")
  34. endif()
  35. if (NOT DEFINED Qt5_DIR)
  36. if(SYS_LINUX)
  37. set(Qt5_DIR "/opt/Qt5.14.2/5.14.2/gcc_64/lib/cmake/Qt5" CACHE PATH "Qt5Config.cmake所在目录" FORCE)
  38. elseif(SYS_WIN)
  39. set(Qt5_DIR "D:/Tools/Qt/5.15.2/msvc2019_64/lib/cmake/Qt5" CACHE PATH "Qt5Config.cmake所在目录" FORCE)
  40. endif()
  41. endif()
  42. #-----------------------------------------------------------------------------
  43. # 测试环境定义(如果在支持cmake系统的IDE中编写代码,可以打开以下注释,并将路径修改为自己的Qt路径)
  44. #-----------------------------------------------------------------------------
  45. #[[set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install")
  46. message(STATUS "${PROJECT_NAME} will be installed to ${CMAKE_INSTALL_PREFIX}")
  47. if (NOT DEFINED Qt5_DIR)
  48. if(SYS_LINUX)
  49. set(Qt5_DIR "/opt/Qt5.14.2/5.14.2/gcc_64/lib/cmake/Qt5" CACHE PATH "Qt5Config.cmake所在目录" FORCE)
  50. elseif(SYS_WIN)
  51. set(Qt5_DIR "D:/software/Qt/Qt5.14.2/5.14.2/msvc2017_64/lib/cmake/Qt5" CACHE PATH "Qt5Config.cmake所在目录" FORCE)
  52. endif()
  53. endif()]]
  54. #-----------------------------------------------------------------------------
  55. # 编译选项设置
  56. #-----------------------------------------------------------------------------
  57. # 是否需要编译调试程序
  58. option(GJDM_ENABLE_DEV "ON:开启代码调试,OFF:仅安装程序" ON)
  59. # 是否自动下载依赖库
  60. option(GJDM_AUTO_DOWNLOAD "如果extlib不存在,则自动下载(git)依赖库" ON)
  61. option(GJDM_ENABLE_OPENMP "使用OpenMP" OFF)
  62. option(GJDM_ENABLE_MPI "使用MPI" OFF)
  63. option(GJDM_DOXYGEN_DOC "生成Doxygen文档" OFF)
  64. option(GJDM_INSTALLATION_PACKAGE "生成${PROJECT_NAME}安装包" ON)
  65. option(GJDM_DEBUG_INFO "输出调试信息" OFF)
  66. #-----------------------------------------------------------------------------
  67. # 指定编译选项
  68. #-----------------------------------------------------------------------------
  69. # 仅对单配制编译器(Makefile Generators or Ninja)生效
  70. if(NOT CMAKE_BUILD_TYPE)
  71. set(CMAKE_BUILD_TYPE "Release")
  72. endif()
  73. if (POLICY CMP0091)
  74. cmake_policy(SET CMP0091 NEW)
  75. endif (POLICY CMP0091)
  76. if(MSVC)
  77. add_definitions(-DUNICODE -D_UNICODE)
  78. add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
  79. add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
  80. add_compile_options(
  81. $<$<CONFIG:>:/MD>
  82. $<$<CONFIG:Debug>:/MDd>
  83. $<$<CONFIG:Release>:/MD>
  84. )
  85. endif()
  86. #-----------------------------------------------------------------------------
  87. # 从系统查找OpenMP(动态库引入使用:OpenMP::OpenMP_CXX)
  88. #-----------------------------------------------------------------------------
  89. if(GJDM_ENABLE_OPENMP)
  90. find_package(OpenMP)
  91. if(OpenMP_CXX_FOUND)
  92. add_definitions(-DFASTCAE_HAS_OPENMP)
  93. endif()
  94. endif()
  95. #-----------------------------------------------------------------------------
  96. # 从系统查找MPI(头文件路径:${MPI_CXX_INCLUDE_DIRS} 动态库引入使用:MPI::MPI_CXX)
  97. #-----------------------------------------------------------------------------
  98. if(GJDM_ENABLE_MPI)
  99. find_package(MPI)
  100. if(MPI_CXX_FOUND)
  101. add_definitions(-DFASTCAE_HAS_MPI)
  102. endif()
  103. endif()
  104. #-----------------------------------------------------------------------------
  105. # 输出调试信息
  106. #-----------------------------------------------------------------------------
  107. if(GJDM_DEBUG_INFO)
  108. add_definitions(-DOUTPUT_DEBUG_INFO)
  109. endif()
  110. #-----------------------------------------------------------------------------
  111. # 从系统查找Qt模块,开启Qt中间文件的自动生成
  112. #-----------------------------------------------------------------------------
  113. set(CMAKE_AUTOUIC ON) #自动处理用户界面文件 .ui 的代码生成
  114. set(CMAKE_AUTOMOC ON) #自动处理Qt元对象编译器MOC的代码生成
  115. set(CMAKE_AUTORCC ON) #自动处理Qt资源文件 .qrc 的代码生成
  116. list(APPEND QtNeededModules
  117. Core
  118. Widgets
  119. Gui
  120. Xml
  121. Svg # Qwt
  122. OpenGL # Qwt
  123. PrintSupport # QwtPolar
  124. DBus
  125. )
  126. if(SYS_LINUX)
  127. list(APPEND QtNeededModules XcbQpa)
  128. endif()
  129. find_package(Qt5 COMPONENTS ${QtNeededModules} REQUIRED)
  130. if(Qt5_FOUND)
  131. message(STATUS "Found Qt5: ${Qt5_DIR}")
  132. if(Qt5_POSITION_INDEPENDENT_CODE)
  133. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  134. endif()
  135. else()
  136. set(Qt5_DIR "Qt5_DIR-NOTFOUND" CACHE PATH "Qt5_DIR")
  137. endif()
  138. #-----------------------------------------------------------------------------
  139. # 从远程检索依赖库
  140. #-----------------------------------------------------------------------------
  141. if(GJDM_AUTO_DOWNLOAD AND NOT EXISTS ${CMAKE_SOURCE_DIR}/extlib)
  142. if(SYS_WIN)
  143. set(_extlibGitAddr "http://47.101.131.235:3000/wzj/Sources_For_Win.git")
  144. elseif(SYS_LINUX)
  145. set(_extlibGitAddr "http://47.101.131.235:3000/wzj/Sources_For_Linux.git")
  146. endif()
  147. find_package(Git REQUIRED)
  148. if(Git_FOUND)
  149. execute_process(
  150. COMMAND
  151. ${GIT_EXECUTABLE} clone ${_extlibGitAddr} extlib
  152. WORKING_DIRECTORY
  153. ${CMAKE_CURRENT_SOURCE_DIR}
  154. RESULT_VARIABLE _status
  155. )
  156. else()
  157. message(FATAL_ERROR "Not Found Git")
  158. message(STATUS "Please execute the command[git clone ${_extlibGitAddr} extlib] under the directory ${CMAKE_SOURCE_DIR}")
  159. endif()
  160. endif()
  161. #-----------------------------------------------------------------------------
  162. # 引入GJDM的依赖库
  163. #-----------------------------------------------------------------------------
  164. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
  165. # VTK
  166. find_package(VTK REQUIRED)
  167. # OpenCASCADE
  168. find_package(OpenCASCADE REQUIRED)
  169. # Qwt
  170. find_package(Qwt REQUIRED)
  171. # HDF5
  172. find_package(HDF5 REQUIRED)
  173. # CGNS
  174. find_package(CGNS REQUIRED)
  175. # TecIO
  176. find_package(TecIO REQUIRED)
  177. # QuaZIP
  178. find_package(QuaZIP REQUIRED)
  179. # Gmsh
  180. find_package(Gmsh REQUIRED)
  181. # Python
  182. find_package(Python REQUIRED)
  183. # CFD
  184. find_package(CFD REQUIRED)
  185. # IR
  186. find_package(IR REQUIRED)
  187. # licensecc
  188. set(LICENSECC_LOCATION "${CMAKE_CURRENT_LIST_DIR}/extlib/Licensecc/cmake/licensecc/")
  189. set(LCC_PROJECT_NAME "GJDM")
  190. find_package(licensecc 2.0.0 REQUIRED)
  191. find_package(CART REQUIRED)
  192. find_package(MODTRAN REQUIRED)
  193. find_package(PARAVIEW REQUIRED)
  194. #-----------------------------------------------------------------------------
  195. # 检索系统python(需要修改cmake搜索路径)
  196. #-----------------------------------------------------------------------------
  197. #find_package(PythonInterp REQUIRED)
  198. #find_package(Python COMPONENTS Interpreter Development REQUIRED)
  199. # 项目生成的二进制目录
  200. message(STATUS ${PROJECT_BINARY_DIR})
  201. # 项目源码目录
  202. message(STATUS ${PROJECT_SOURCE_DIR})
  203. #-----------------------------------------------------------------------------
  204. # 开启项目分组
  205. #-----------------------------------------------------------------------------
  206. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  207. # 可以修改cmake预定义的target分组名称
  208. #set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "Predefined")
  209. #-----------------------------------------------------------------------------
  210. # 定义GNU标准的安装目录(GNUInstallDirs.cmake)
  211. #-----------------------------------------------------------------------------
  212. include(GNUInstallDirs)
  213. set(CMAKE_INSTALL_LIBDIR "lib")
  214. #-----------------------------------------------------------------------------
  215. # 定义项目构建中间文件的生成目录
  216. #-----------------------------------------------------------------------------
  217. if(SYS_WIN)
  218. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug)
  219. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug)
  220. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug)
  221. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release)
  222. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release)
  223. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release)
  224. if(GJDM_ENABLE_DEV)
  225. set(DEVRUNTIME_BINDIR_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG})
  226. set(DEVRUNTIME_BINDIR_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE})
  227. endif()
  228. elseif(SYS_LINUX)
  229. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
  230. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
  231. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
  232. if(GJDM_ENABLE_DEV)
  233. set(DEVRUNTIME_BINDIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  234. set(DEVRUNTIME_LIBDIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
  235. endif()
  236. endif()
  237. #-----------------------------------------------------------------------------
  238. # 定义变量作为项目的安装路径
  239. #-----------------------------------------------------------------------------
  240. set(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
  241. if(SYS_WIN)
  242. set(INSTALL_LIBDIR ${CMAKE_INSTALL_BINDIR})
  243. else()
  244. set(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
  245. endif()
  246. #set(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})
  247. #-----------------------------------------------------------------------------
  248. # 编译位置无关的代码
  249. #-----------------------------------------------------------------------------
  250. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  251. # 定义源码路径
  252. add_subdirectory(src)
  253. #-----------------------------------------------------------------------------
  254. # 生成文档(Doxygen + Breathe + Sphinx)
  255. #-----------------------------------------------------------------------------
  256. if(GJDM_DOXYGEN_DOC)
  257. find_package(Doxygen REQUIRED)
  258. if(DOXYGEN_FOUND)
  259. message(STATUS "Found doc generate Tool: Doxygen")
  260. include(UseDoxygen)
  261. endif()
  262. endif()
  263. #-----------------------------------------------------------------------------
  264. # 安装包生成(windows环境光需要NSIS 3.03+)
  265. #-----------------------------------------------------------------------------
  266. if(GJDM_INSTALLATION_PACKAGE)
  267. if (SYS_WIN)
  268. find_program(NSIS_EXECUTABLE NSIS.exe)
  269. if(NSIS_EXECUTABLE)
  270. include(${CMAKE_SOURCE_DIR}/cmake/CMakePack.cmake)
  271. endif()
  272. else()
  273. include(${CMAKE_SOURCE_DIR}/cmake/CMakePack.cmake)
  274. endif ()
  275. # 以下include必须放在主CMakeLists.txt文件最后面,否则在Visual Studio中不会生成PACKAGE(打包)目标
  276. include(CPack)
  277. endif()