-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
194 lines (171 loc) · 7.71 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
#############################################################################################################################################
# Saras
#
# Copyright (C) 2019, Mahendra K. Verma
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
############################################################################################################################################
##
##! \file CMakeLists.txt
#
# \brief Root level CMakeLists file.
#
# \author Roshan Samuel
# \date Nov 2019
# \copyright New BSD License
#
############################################################################################################################################
##
# Cmake setup
cmake_minimum_required (VERSION 2.8.12)
project (saras)
if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
MESSAGE(FATAL_ERROR "\nERROR! ${PROJECT_NAME} does not support in-source builds!\n"
"CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}\n"
"CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}\n"
"NEXT STEPS:\n"
"(1) Delete the CMakeCache.txt file and the CMakeFiles/ directory"
" under the source directory for ${PROJECT_NAME}, otherwise you"
" will not be able to configure ${PROJECT_NAME} correctly!\n"
" * For example, on linux machines do:\n"
" $ rm -r CMakeCache.txt CMakeFiles/\n"
"(2) Create a different directory and configure ${PROJECT_NAME} in that directory.\n"
" * For example, on linux machines do:\n"
" $ mkdir MY_BUILD\n"
" $ cd MY_BUILD\n"
" $ cmake [OPTIONS] ..\n")
endif ()
set (PARENT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set (HEADER_DIR ${PARENT_DIR}/lib)
message (STATUS "The parent directory is ${PARENT_DIR}")
message (STATUS "Install folder is ${CMAKE_CURRENT_BINARY_DIR}")
message (STATUS "All headers are in ${HEADER_DIR}")
include_directories (${HEADER_DIR}/parallel
${HEADER_DIR}/boundary
${HEADER_DIR}/timestep
${HEADER_DIR}/initial
${HEADER_DIR}/poisson
${HEADER_DIR}/force
${HEADER_DIR}/field
${HEADER_DIR}/grid
${HEADER_DIR}/les
${HEADER_DIR}/io)
# Search for Blitz++ library
find_library(BLITZPP_FOUND NAMES blitz blitzpp libblitz)
if (BLITZPP_FOUND)
message (STATUS "Found Blitz++")
else ()
message (WARNING "Could not find Blitz++")
endif ()
# Search for yaml-cpp library
find_package(yaml-cpp)
if (yaml-cpp_FOUND)
if (yaml-cpp_VERSION GREATER 0.3)
message (STATUS "Found YAML Cpp ${yaml-cpp_VERSION}")
else ()
message (STATUS "Found YAML Cpp ${yaml-cpp_VERSION}. Using deprecated YAML parsing commands.")
add_definitions(-DYAML_LEGACY)
endif ()
else ()
find_library(YAML_FOUND yaml-cpp libyaml-cpp)
if (YAML_FOUND)
message (STATUS "Found YAML Cpp with find_library(). You may have to configure with DYAML_LEGACY")
else ()
message (WARNING "Could not determine YAML-Cpp version. You may have to configure with DYAML_LEGACY")
endif ()
endif ()
# Search for MPI library
find_package(MPI REQUIRED)
if (MPI_FOUND)
message (STATUS "Found MPI ${MPI_VERSION}")
else ()
message (WARNING "Could not find MPI")
endif ()
# Search for HDF5 package
find_package(HDF5 REQUIRED)
if (HDF5_FOUND)
message (STATUS "Found HDF5 ${MPI_VERSION}")
else ()
message (WARNING "Could not find HDF5")
endif ()
# Search for OpenMP package to enable hybrid parallelization and set the correct OpenMP compiler flag
find_package (OpenMP)
message (STATUS "Compiler flag for OpenMP is ${OpenMP_C_FLAGS}")
# Add compiler flag to use older yaml-cpp commands
if (YAML_LEGACY)
message (STATUS "Compiling Saras for older YAML Cpp library")
add_definitions(-DYAML_LEGACY)
endif()
# Add compiler flag for 2D/3D runs as requested by user while running cmake
if (PLANAR)
message (STATUS "Compiling Saras for 2D simulations")
add_definitions(-DPLANAR)
else ()
message (STATUS "Compiling Saras for 3D simulations")
endif ()
# Add compiler flag for using single precision calculations
if (REAL_SINGLE)
message (STATUS "Compiling Saras to solve with single precision calculations")
add_definitions(-DREAL_SINGLE)
else ()
message (STATUS "Compiling Saras to solve with double precision calculations")
add_definitions(-DREAL_DOUBLE)
endif ()
# Add compiler flag for post-processing runs as requested by user while running cmake
if (POST_RUN)
message (STATUS "Compiling Saras for post-processing runs")
add_definitions(-DPOST_RUN)
endif ()
# Add compiler flag for testing the Poisson library
if (TEST_POISSON)
message (STATUS "Compiling Saras to test the Poisson library")
add_definitions(-DTEST_POISSON)
endif ()
# Set compiler flags for normal and debug runs
#set (CMAKE_CXX_FLAGS "-Wall ${OpenMP_C_FLAGS} -O3 -fprofile-generate -fprofile-dir=${PARENT_DIR}")
#set (CMAKE_CXX_FLAGS "-Wall ${OpenMP_C_FLAGS} -O3 -fprofile-use -fprofile-correction")
set (CMAKE_CXX_FLAGS "-Wall ${OpenMP_C_FLAGS} -O3")
set (CMAKE_CXX_FLAGS_DEBUG "-Wall -g ${OpenMP_C_FLAGS} -DBZ_DEBUG")
add_subdirectory (lib)
add_subdirectory (src)
# Remove the PLANAR variable from cache to force user to manually set the PLANAR flag each time a 2D run is needed
unset (PLANAR CACHE)
# Remove the POST_RUN variable from cache to force user to manually set the POST_RUN flag each time post-processing must be performed
unset (POST_RUN CACHE)
# Remove the REAL_DOUBLE variable from cache to force user to manually set the precision each time the solver is compiled
unset (REAL_DOUBLE CACHE)
# Remove the REAL_SINGLE variable from cache to force user to manually set the precision each time the solver is compiled
unset (REAL_SINGLE CACHE)
# Remove the TEST_POISSON variable from cache to force user to manually set the flag for testing Poisson solver
unset (TEST_POISSON CACHE)
# Remove variables associated with finding different libraries
unset (yaml-cpp_FOUND CACHE)
unset (yaml-cpp_VERSION CACHE)
unset (YAML_LEGACY CACHE)
unset (YAML_FOUND CACHE)
unset (BLITZPP_FOUND CACHE)
unset (MPI_FOUND CACHE)
unset (HDF5_FOUND CACHE)