1
+ cmake_minimum_required (VERSION 3.0.2 )
2
+ cmake_policy (SET CMP0048 NEW )
3
+
4
+ project (opencfd LANGUAGES Fortran )
5
+
6
+ set (AUTHOR "Li Xinliang" )
7
+ set (AUTHOR_DETAILS "lixl@imech.ac.cn" )
8
+ set (DESCRIPTION "Building opencfd using cmake" )
9
+
10
+ message (STATUS "building ${PROJECT_NAME} " )
11
+
12
+ include (GNUInstallDirs )
13
+ set (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR} /${CMAKE_INSTALL_LIBDIR} )
14
+ set (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR} /${CMAKE_INSTALL_BINDIR} )
15
+ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
16
+ set (CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR} /opt" CACHE PATH "..." FORCE )
17
+ endif ()
18
+
19
+ # Add support for CMAKE_DEPENDENT_OPTION
20
+ INCLUDE (CMakeDependentOption )
21
+ INCLUDE (CMakeParseArguments )
22
+
23
+ # Find the modules included with opencfd
24
+ #SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
25
+
26
+ # make sure that the default is a RELEASE
27
+ if (NOT CMAKE_BUILD_TYPE )
28
+ set (CMAKE_BUILD_TYPE RELEASE CACHE STRING
29
+ "Choose the type of build, options are: None Debug Release."
30
+ FORCE )
31
+ endif (NOT CMAKE_BUILD_TYPE )
32
+
33
+ set (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER_ID} )
34
+ message (STATUS "COMP ID ${Fortran_COMPILER_NAME} " )
35
+ message (STATUS "Fortran compiler name ${Fortran_COMPILER_NAME} " )
36
+ message (STATUS "Fortran compiler version ${CMAKE_Fortran_COMPILER_VERSION} " )
37
+ if (Fortran_COMPILER_NAME MATCHES "GNU" )
38
+ # gfortran
39
+ message (STATUS "Setting gfortran flags" )
40
+ set (CMAKE_Fortran_FLAGS "-cpp -funroll-loops -floop-optimize -g -fcray-pointer -fbacktrace -ffree-line-length-none" )
41
+ if (CMAKE_Fortran_COMPILER_VERSION GREATER_EQUAL "10" )
42
+ message (STATUS "Set New Fortran basic flags" )
43
+ set (CMAKE_Fortran_FLAGS "-cpp -funroll-loops -floop-optimize -g -fcray-pointer -fbacktrace -ffree-line-length-none -fallow-argument-mismatch" )
44
+ endif (CMAKE_Fortran_COMPILER_VERSION GREATER_EQUAL "10" )
45
+ set (CMAKE_Fortran_FLAGS_RELEASE "-funroll-all-loops -fno-f2c -O3" )
46
+ set (CMAKE_Fortran_FLAGS_DEBUG "-DDEBG -O0 -g" )
47
+ elseif (Fortran_COMPILER_NAME MATCHES "Intel" )
48
+ message (STATUS "Setting ifort flags" )
49
+ set (CMAKE_Fortran_FLAGS "-fpp -xHost -heaparrays -safe-cray-ptr -g -traceback" )
50
+ set (CMAKE_Fortran_FLAGS_RELEASE "-O3 -ipo" )
51
+ set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -DDEBG" )
52
+ #set(CMAKE_Fortran_FLAGS "-cpp xSSE4.2 -axAVX,CORE-AVX-I,CORE-AVX2 -ipo -fp-model fast=2 -mcmodel=large -safe-cray-ptr")
53
+ elseif (Fortran_COMPILER_NAME MATCHES "NAG" )
54
+ message (STATUS "Setting nagfor flags" )
55
+ set (CMAKE_Fortran_FLAGS "-fpp" )
56
+ set (CMAKE_Fortran_FLAGS_RELEASE "-O3" )
57
+ set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g" )
58
+ elseif (Fortran_COMPILER_NAME MATCHES "Cray" )
59
+ message (STATUS "Setting cray fortran flags" )
60
+ set (CMAKE_Fortran_FLAGS "-eF -g -N 1023" )
61
+ set (CMAKE_Fortran_FLAGS_RELEASE "-O3" )
62
+ set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g" )
63
+ elseif (Fortran_COMPILER_NAME MATCHES "PGI" )
64
+ message (STATUS "Setting PGI fortran flags" )
65
+ set (CMAKE_Fortran_FLAGS "-cpp -acc -Mfree -Kieee -Minfo=accel -g" )
66
+ set (CMAKE_Fortran_FLAGS_RELEASE "-O3" )
67
+ set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -DDEBG" )
68
+ elseif (Fortran_COMPILER_NAME MATCHES "Fujitsu" )
69
+ message (STATUS "Setting Fujitsu fortran flags" )
70
+ set (CMAKE_Fortran_FLAGS "-Cpp" )
71
+ set (CMAKE_Fortran_FLAGS_RELEASE "-O3" )
72
+ set (CMAKE_Fortran_FLAGS_DEBUG "-O0" )
73
+ else (Fortran_COMPILER_NAME MATCHES "GNU" )
74
+ message ("CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER} )
75
+ message ("Fortran compiler: " ${Fortran_COMPILER_NAME} )
76
+ message ("No optimized Fortran compiler flags are known, we just try -O2..." )
77
+ set (CMAKE_Fortran_FLAGS_RELEASE "-O2" )
78
+ set (CMAKE_Fortran_FLAGS_DEBUG "-O0 -g" )
79
+ endif (Fortran_COMPILER_NAME MATCHES "GNU" )
80
+
81
+ if (CMAKE_BUILD_TYPE MATCHES "DEBUG" )
82
+ add_definitions ("-DDEBG" )
83
+ endif (CMAKE_BUILD_TYPE MATCHES "DEBUG" )
84
+
85
+
86
+ find_package (MPI REQUIRED )
87
+ # Stop if there is no MPI_Fortran_Compiler
88
+ if (MPI_Fortran_COMPILER )
89
+ message (STATUS "MPI_Fortran_COMPILER found: ${MPI_Fortran_COMPILER} " )
90
+ else (MPI_Fortran_COMPILER )
91
+ message (SEND_ERROR "This application cannot compile without MPI" )
92
+ endif (MPI_Fortran_COMPILER )
93
+ # Warning if Include are not found => can be fixed with more recent cmake version
94
+ if (MPI_FOUND )
95
+ message (STATUS "MPI FOUND: ${MPI_FOUND} " )
96
+ include_directories (SYSTEM ${MPI_INCLUDE_PATH} )
97
+ message (STATUS "MPI INCL : ${MPI_INCLUDE_PATH} " )
98
+ else (MPI_FOUND )
99
+ message (STATUS "NO MPI include have been found. The executable won't be targeted with MPI include" )
100
+ message (STATUS "Code will compile but performaces can be compromised" )
101
+ message (STATUS "Using a CMake vers > 3.10 should solve the problem" )
102
+ message (STATUS "Alternatively use ccmake to manually set the include if available" )
103
+ endif (MPI_FOUND )
104
+
105
+
106
+ set (OCFD_ROOT ${CMAKE_CURRENT_SOURCE_DIR} )
107
+ message (STATUS "OCFD directory: ${OCFD_ROOT} " )
108
+ set (CMAKE_INSTALL_PREFIX ${OCFD_ROOT} )
109
+
110
+ # Create the OCFD executable
111
+ add_subdirectory (src )
112
+
113
+ # Create an example dir with all input.i3d example files
114
+ option (BUILD_TESTING "Build with tests" ON )
115
+ set (test_dir "${PROJECT_BINARY_DIR} /test" )
116
+ add_subdirectory (examples )
117
+ message (STATUS "Before test main ${test_dir} " )
118
+ set (osub "--oversubscribe" )
119
+
120
+
121
+ if (${BUILD_TESTING} )
122
+ include (CTest )
123
+ message (STATUS "MPI INCL ALSO FOUND: ${MPI_INCLUDE_PATH} " )
124
+ message (STATUS "MPI EXEC: ${MPIEXEC_EXECUTABLE} " )
125
+ add_test (NAME blunt-cylinder COMMAND ${MPIEXEC_EXECUTABLE} -n 8 ${osub} ${CMAKE_INSTALL_PREFIX} /bin/opencfd WORKING_DIRECTORY ${test_dir} /blunt-cylinder )
126
+ add_test (NAME isotropic COMMAND ${MPIEXEC_EXECUTABLE} -n 8 ${osub} ${CMAKE_INSTALL_PREFIX} /bin/opencfd WORKING_DIRECTORY ${test_dir} /isotropic )
127
+ add_test (NAME TGV COMMAND ${MPIEXEC_EXECUTABLE} -n 8 ${osub} ${CMAKE_INSTALL_PREFIX} /bin/opencfd WORKING_DIRECTORY ${test_dir} /TGV )
128
+ endif ()
0 commit comments