#----------------------------------------------------------------------------- # 工程属性设置 #----------------------------------------------------------------------------- # 指定所需cmake的最低版本 cmake_minimum_required(VERSION 3.21 FATAL_ERROR) # 设置项目名称 语言 project(GJDM) #----------------------------------------------------------------------------- # 编译系统设置 #----------------------------------------------------------------------------- # 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(SYS_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(SYS_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() if (NOT DEFINED Qt5_DIR) if(SYS_LINUX) set(Qt5_DIR "/opt/Qt5.14.2/5.14.2/gcc_64/lib/cmake/Qt5" CACHE PATH "Qt5Config.cmake所在目录" FORCE) elseif(SYS_WIN) set(Qt5_DIR "D:/Tools/Qt/5.15.2/msvc2019_64/lib/cmake/Qt5" CACHE PATH "Qt5Config.cmake所在目录" FORCE) endif() 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(SYS_LINUX) set(Qt5_DIR "/opt/Qt5.14.2/5.14.2/gcc_64/lib/cmake/Qt5" CACHE PATH "Qt5Config.cmake所在目录" FORCE) elseif(SYS_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(GJDM_ENABLE_DEV "ON:开启代码调试,OFF:仅安装程序" ON) # 是否自动下载依赖库 option(GJDM_AUTO_DOWNLOAD "如果extlib不存在,则自动下载(git)依赖库" ON) option(GJDM_ENABLE_OPENMP "使用OpenMP" OFF) option(GJDM_ENABLE_MPI "使用MPI" OFF) option(GJDM_DOXYGEN_DOC "生成Doxygen文档" OFF) option(GJDM_INSTALLATION_PACKAGE "生成${PROJECT_NAME}安装包" ON) option(GJDM_DEBUG_INFO "输出调试信息" OFF) #----------------------------------------------------------------------------- # 指定编译选项 #----------------------------------------------------------------------------- # 仅对单配制编译器(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("$<$:/utf-8>") add_compile_options("$<$:/utf-8>") add_compile_options( $<$:/MD> $<$:/MDd> $<$:/MD> ) endif() #----------------------------------------------------------------------------- # 从系统查找OpenMP(动态库引入使用:OpenMP::OpenMP_CXX) #----------------------------------------------------------------------------- if(GJDM_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(GJDM_ENABLE_MPI) find_package(MPI) if(MPI_CXX_FOUND) add_definitions(-DFASTCAE_HAS_MPI) endif() endif() #----------------------------------------------------------------------------- # 输出调试信息 #----------------------------------------------------------------------------- if(GJDM_DEBUG_INFO) add_definitions(-DOUTPUT_DEBUG_INFO) endif() #----------------------------------------------------------------------------- # 从系统查找Qt模块,开启Qt中间文件的自动生成 #----------------------------------------------------------------------------- set(CMAKE_AUTOUIC ON) #自动处理用户界面文件 .ui 的代码生成 set(CMAKE_AUTOMOC ON) #自动处理Qt元对象编译器MOC的代码生成 set(CMAKE_AUTORCC ON) #自动处理Qt资源文件 .qrc 的代码生成 list(APPEND QtNeededModules Core Widgets Gui Xml Svg # Qwt OpenGL # Qwt PrintSupport # QwtPolar DBus ) if(SYS_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(GJDM_AUTO_DOWNLOAD AND NOT EXISTS ${CMAKE_SOURCE_DIR}/extlib) if(SYS_WIN) set(_extlibGitAddr "http://47.101.131.235:3000/wzj/Sources_For_Win.git") elseif(SYS_LINUX) set(_extlibGitAddr "http://47.101.131.235:3000/wzj/Sources_For_Linux.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() #----------------------------------------------------------------------------- # 引入GJDM的依赖库 #----------------------------------------------------------------------------- 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) # CFD find_package(CFD REQUIRED) # IR find_package(IR REQUIRED) # licensecc set(LICENSECC_LOCATION "${CMAKE_CURRENT_LIST_DIR}/extlib/Licensecc/cmake/licensecc/") set(LCC_PROJECT_NAME "GJDM") find_package(licensecc 2.0.0 REQUIRED) find_package(CART REQUIRED) find_package(MODTRAN REQUIRED) find_package(PARAVIEW REQUIRED) #----------------------------------------------------------------------------- # 检索系统python(需要修改cmake搜索路径) #----------------------------------------------------------------------------- #find_package(PythonInterp REQUIRED) #find_package(Python COMPONENTS Interpreter Development REQUIRED) # 项目生成的二进制目录 message(STATUS ${PROJECT_BINARY_DIR}) # 项目源码目录 message(STATUS ${PROJECT_SOURCE_DIR}) #----------------------------------------------------------------------------- # 开启项目分组 #----------------------------------------------------------------------------- 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(SYS_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(GJDM_ENABLE_DEV) set(DEVRUNTIME_BINDIR_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG}) set(DEVRUNTIME_BINDIR_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE}) endif() elseif(SYS_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(GJDM_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(SYS_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) #----------------------------------------------------------------------------- # 生成文档(Doxygen + Breathe + Sphinx) #----------------------------------------------------------------------------- if(GJDM_DOXYGEN_DOC) find_package(Doxygen REQUIRED) if(DOXYGEN_FOUND) message(STATUS "Found doc generate Tool: Doxygen") include(UseDoxygen) endif() endif() #----------------------------------------------------------------------------- # 安装包生成(windows环境光需要NSIS 3.03+) #----------------------------------------------------------------------------- if(GJDM_INSTALLATION_PACKAGE) if (SYS_WIN) find_program(NSIS_EXECUTABLE NSIS.exe) 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()