CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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:/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 "输出调试信息" ON)
  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 "https://gitee.com/DISOGitee/FastCAEWinExtlib.git")
  144. elseif(SYS_LINUX)
  145. set(_extlibGitAddr "https://gitee.com/DISOGitee/FastCAELinuxExtlib.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. # 引入FastCAE的依赖库
  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. #-----------------------------------------------------------------------------
  184. # 检索系统python(需要修改cmake搜索路径)
  185. #-----------------------------------------------------------------------------
  186. #find_package(PythonInterp REQUIRED)
  187. #find_package(Python COMPONENTS Interpreter Development REQUIRED)
  188. #-----------------------------------------------------------------------------
  189. # 开启项目分组
  190. #-----------------------------------------------------------------------------
  191. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  192. # 可以修改cmake预定义的target分组名称
  193. #set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "Predefined")
  194. #-----------------------------------------------------------------------------
  195. # 定义GNU标准的安装目录(GNUInstallDirs.cmake)
  196. #-----------------------------------------------------------------------------
  197. include(GNUInstallDirs)
  198. set(CMAKE_INSTALL_LIBDIR "lib")
  199. #-----------------------------------------------------------------------------
  200. # 定义项目构建中间文件的生成目录
  201. #-----------------------------------------------------------------------------
  202. if(SYS_WIN)
  203. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug)
  204. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug)
  205. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug)
  206. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release)
  207. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release)
  208. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release)
  209. if(GJDM_ENABLE_DEV)
  210. set(DEVRUNTIME_BINDIR_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG})
  211. set(DEVRUNTIME_BINDIR_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE})
  212. endif()
  213. elseif(SYS_LINUX)
  214. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
  215. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
  216. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
  217. if(GJDM_ENABLE_DEV)
  218. set(DEVRUNTIME_BINDIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  219. set(DEVRUNTIME_LIBDIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
  220. endif()
  221. endif()
  222. #-----------------------------------------------------------------------------
  223. # 定义变量作为项目的安装路径
  224. #-----------------------------------------------------------------------------
  225. set(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
  226. if(SYS_WIN)
  227. set(INSTALL_LIBDIR ${CMAKE_INSTALL_BINDIR})
  228. else()
  229. set(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
  230. endif()
  231. #set(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})
  232. #-----------------------------------------------------------------------------
  233. # 编译位置无关的代码
  234. #-----------------------------------------------------------------------------
  235. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  236. # 定义源码路径
  237. add_subdirectory(src)
  238. #-----------------------------------------------------------------------------
  239. # 生成文档(Doxygen + Breathe + Sphinx)
  240. #-----------------------------------------------------------------------------
  241. if(GJDM_DOXYGEN_DOC)
  242. find_package(Doxygen REQUIRED)
  243. if(DOXYGEN_FOUND)
  244. message(STATUS "Found doc generate Tool: Doxygen")
  245. include(UseDoxygen)
  246. endif()
  247. endif()
  248. #-----------------------------------------------------------------------------
  249. # 安装包生成(windows环境光需要NSIS 3.03+)
  250. #-----------------------------------------------------------------------------
  251. if(GJDM_INSTALLATION_PACKAGE)
  252. if (SYS_WIN)
  253. find_program(NSIS_EXECUTABLE NSIS.exe)
  254. if(NSIS_EXECUTABLE)
  255. include(${CMAKE_SOURCE_DIR}/cmake/CMakePack.cmake)
  256. endif()
  257. else()
  258. include(${CMAKE_SOURCE_DIR}/cmake/CMakePack.cmake)
  259. endif ()
  260. # 以下include必须放在主CMakeLists.txt文件最后面,否则在Visual Studio中不会生成PACKAGE(打包)目标
  261. include(CPack)
  262. endif()