forked from QtWorks/FastCAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
329 lines (288 loc) · 11.5 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#-----------------------------------------------------------------------------
# 工程属性设置
#-----------------------------------------------------------------------------
# 指定所需cmake的最低版本
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
# 设置项目名称 语言
project(FastCAE
VERSION 2.5.0
LANGUAGES CXX
DESCRIPTION "FastCAE,一款免费的CAE仿真软件研发支撑平台。"
HOMEPAGE_URL "http://www.fastcae.com/"
)
#-----------------------------------------------------------------------------
# 编译系统设置
#-----------------------------------------------------------------------------
# c++语言标准
set(CMAKE_CXX_STANDARD 11)
# 指定是否使用编译器特定的扩展
set(CMAKE_CXX_EXTENSIONS OFF)
# 是否强制要求C++标准为${CMAKE_CXX_STANDARD},如果为OFF则可能使用旧的标准
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 默认编译动态库
set(BUILD_SHARED_LIBS ON)
#-----------------------------------------------------------------------------
# 检测操作系统
#-----------------------------------------------------------------------------
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(FASTCAE_LINUX True)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}" CACHE PATH "${PROJECT_NAME}的安装路径" FORCE)
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(FASTCAE_WIN True)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "c:/Program Files/${PROJECT_NAME}" CACHE PATH "${PROJECT_NAME}的安装路径" FORCE)
endif()
else()
message(SEND_ERROR "No Support System!")
endif()
#-----------------------------------------------------------------------------
# 测试环境定义(如果在支持cmake系统的IDE中编写代码,可以打开以下注释,并将路径修改为自己的Qt路径)
#-----------------------------------------------------------------------------
#[[set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install")
message(STATUS "${PROJECT_NAME} will be installed to ${CMAKE_INSTALL_PREFIX}")
if (NOT DEFINED Qt5_DIR)
if(FASTCAE_LINUX)
set(Qt5_DIR "/opt/Qt5.14.2/5.14.2/gcc_64/lib/cmake/Qt5" CACHE PATH "Qt5Config.cmake所在目录" FORCE)
elseif(FASTCAE_WIN)
set(Qt5_DIR "D:/software/Qt/Qt5.14.2/5.14.2/msvc2017_64/lib/cmake/Qt5" CACHE PATH "Qt5Config.cmake所在目录" FORCE)
endif()
endif()]]
#-----------------------------------------------------------------------------
# 编译选项设置
#-----------------------------------------------------------------------------
# 是否需要编译调试程序
option(FASTCAE_ENABLE_DEV "ON:开启代码调试,OFF:仅安装程序" ON)
# 是否自动下载依赖库
option(FASTCAE_AUTO_DOWNLOAD "如果extlib不存在,则自动下载(git)依赖库" ON)
option(FASTCAE_ENABLE_OPENMP "使用OpenMP" OFF)
option(FASTCAE_ENABLE_MPI "使用MPI" OFF)
option(FASTCAE_DOXYGEN_DOC "生成Doxygen文档" OFF)
option(FASTCAE_INSTALLATION_PACKAGE "生成${PROJECT_NAME}安装包" ON)
option(FASTCAE_DEBUG_INFO "输出调试信息" ON)
#-----------------------------------------------------------------------------
# 指定编译选项
#-----------------------------------------------------------------------------
# 仅对单配制编译器(Makefile Generators or Ninja)生效
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
if (POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif (POLICY CMP0091)
if(MSVC)
add_definitions(-DUNICODE -D_UNICODE)
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options(
$<$<CONFIG:>:/MD>
$<$<CONFIG:Debug>:/MDd>
$<$<CONFIG:Release>:/MD>
)
endif()
#-----------------------------------------------------------------------------
# 从系统查找OpenMP(动态库引入使用:OpenMP::OpenMP_CXX)
#-----------------------------------------------------------------------------
if(FASTCAE_ENABLE_OPENMP)
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
add_definitions(-DFASTCAE_HAS_OPENMP)
endif()
endif()
#-----------------------------------------------------------------------------
# 从系统查找MPI(头文件路径:${MPI_CXX_INCLUDE_DIRS} 动态库引入使用:MPI::MPI_CXX)
#-----------------------------------------------------------------------------
if(FASTCAE_ENABLE_MPI)
find_package(MPI)
if(MPI_CXX_FOUND)
add_definitions(-DFASTCAE_HAS_MPI)
endif()
endif()
#-----------------------------------------------------------------------------
# 输出调试信息
#-----------------------------------------------------------------------------
if(FASTCAE_DEBUG_INFO)
add_definitions(-DOUTPUT_DEBUG_INFO)
endif()
#-----------------------------------------------------------------------------
# 从系统查找Qt模块,开启Qt中间文件的自动生成
#-----------------------------------------------------------------------------
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
list(APPEND QtNeededModules
Core
Widgets
Gui
Xml
Svg # Qwt
OpenGL # Qwt
PrintSupport # QwtPolar
DBus
)
if(FASTCAE_LINUX)
list(APPEND QtNeededModules XcbQpa)
endif()
find_package(Qt5 COMPONENTS ${QtNeededModules} REQUIRED)
if(Qt5_FOUND)
message(STATUS "Found Qt5: ${Qt5_DIR}")
if(Qt5_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
else()
set(Qt5_DIR "Qt5_DIR-NOTFOUND" CACHE PATH "Qt5_DIR")
endif()
#-----------------------------------------------------------------------------
# 从远程检索依赖库
#-----------------------------------------------------------------------------
if(FASTCAE_AUTO_DOWNLOAD AND NOT EXISTS ${CMAKE_SOURCE_DIR}/extlib)
if(FASTCAE_WIN)
set(_extlibGitAddr "https://gitee.com/DISOGitee/FastCAEWinExtlib.git")
elseif(FASTCAE_LINUX)
set(_extlibGitAddr "https://gitee.com/DISOGitee/FastCAELinuxExtlib.git")
endif()
find_package(Git REQUIRED)
if(Git_FOUND)
execute_process(
COMMAND
${GIT_EXECUTABLE} clone ${_extlibGitAddr} extlib
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE _status
)
else()
message(FATAL_ERROR "Not Found Git")
message(STATUS "Please execute the command[git clone ${_extlibGitAddr} extlib] under the directory ${CMAKE_SOURCE_DIR}")
endif()
endif()
#-----------------------------------------------------------------------------
# 引入FastCAE的依赖库
#-----------------------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# VTK
find_package(VTK REQUIRED)
# OpenCASCADE
find_package(OpenCASCADE REQUIRED)
# Qwt
find_package(Qwt REQUIRED)
# HDF5
find_package(HDF5 REQUIRED)
# CGNS
find_package(CGNS REQUIRED)
# TecIO
find_package(TecIO REQUIRED)
# QuaZIP
find_package(QuaZIP REQUIRED)
# Gmsh
find_package(Gmsh REQUIRED)
# Python
find_package(Python REQUIRED)
#-----------------------------------------------------------------------------
# 检索系统python(需要修改cmake搜索路径)
#-----------------------------------------------------------------------------
#find_package(PythonInterp REQUIRED)
#find_package(Python COMPONENTS Interpreter Development REQUIRED)
#-----------------------------------------------------------------------------
# 开启项目分组
#-----------------------------------------------------------------------------
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# 可以修改cmake预定义的target分组名称
#set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "Predefined")
#-----------------------------------------------------------------------------
# 定义GNU标准的安装目录(GNUInstallDirs.cmake)
#-----------------------------------------------------------------------------
include(GNUInstallDirs)
set(CMAKE_INSTALL_LIBDIR "lib")
#-----------------------------------------------------------------------------
# 定义项目构建中间文件的生成目录
#-----------------------------------------------------------------------------
if(FASTCAE_WIN)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release)
if(FASTCAE_ENABLE_DEV)
set(DEVRUNTIME_BINDIR_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG})
set(DEVRUNTIME_BINDIR_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE})
endif()
elseif(FASTCAE_LINUX)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
if(FASTCAE_ENABLE_DEV)
set(DEVRUNTIME_BINDIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(DEVRUNTIME_LIBDIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
endif()
endif()
#-----------------------------------------------------------------------------
# 定义变量作为项目的安装路径
#-----------------------------------------------------------------------------
set(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
if(FASTCAE_WIN)
set(INSTALL_LIBDIR ${CMAKE_INSTALL_BINDIR})
else()
set(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
endif()
#set(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})
#-----------------------------------------------------------------------------
# 编译位置无关的代码
#-----------------------------------------------------------------------------
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# 定义源码路径
add_subdirectory(src)
#-----------------------------------------------------------------------------
# 单元测试Ctest
#-----------------------------------------------------------------------------
option(FASTCAE_ENABLE_TEST "开启单元测试(尚未开发完成)" OFF)
if(FASTCAE_ENABLE_TEST)
# 开启测试
enable_testing()
#添加测试项目
add_subdirectory(test)
endif()
#-----------------------------------------------------------------------------
# 生成文档(Doxygen + Breathe + Sphinx)
#-----------------------------------------------------------------------------
if(FASTCAE_DOXYGEN_DOC)
find_package(Doxygen REQUIRED)
if(DOXYGEN_FOUND)
message(STATUS "Found doc generate Tool: Doxygen")
include(UseDoxygen)
# 文档生成依赖Python解释器、Sphinx
#[[find_package(PythonInterp)
find_package(Sphinx)
if(PYTHONINTERP_FOUND AND SPHINX_FOUND)
message(STATUS "Found doc generate Tool: Sphinx")
include(FindPythonModule)
# Python的breathe模块负责协调Doxygen和Sphinx
find_python_module(breathe REQUIRED)
if(breathe_FOUND)
message(STATUS "Python module(breathe) version: ${breathe_VERSION}")
include(UseSphinx)
else()
message(STATUS "Generate sphinx documentation need python module: breathe")
endif()
endif()]]
endif()
endif()
#-----------------------------------------------------------------------------
# 安装包生成(windows环境光需要NSIS 3.03+)
#-----------------------------------------------------------------------------
if(FASTCAE_INSTALLATION_PACKAGE)
if (FASTCAE_WIN)
find_program(NSIS_EXECUTABLE NSIS.exe)
# WIX尚未调试,暂时取消
#find_program(WIX_EXECUTABLE candle.exe)
#if(NSIS_EXECUTABLE OR WIX_EXECUTABLE)
if(NSIS_EXECUTABLE)
include(${CMAKE_SOURCE_DIR}/cmake/CMakePack.cmake)
endif()
else()
include(${CMAKE_SOURCE_DIR}/cmake/CMakePack.cmake)
endif ()
# 以下include必须放在主CMakeLists.txt文件最后面,否则在Visual Studio中不会生成PACKAGE(打包)目标
include(CPack)
endif()