-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
245 lines (206 loc) · 8.51 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
# TODO: There are a few things in here that are either no longer needed or need
# to be further understood. Some obvious things have been removed so far
# (anything related to Legion and Eigen).
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0074 NEW) # use <PackageName>_ROOT over <PackageName>_DIR
# Set the default build type to be debug for now
set(CMAKE_BUILD_TYPE Release)
# Set dynamic library name depending on operating system
if(APPLE)
set(so "dylib")
else()
set(so "so")
endif()
# profile build time
# set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
# run path for installed executables
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# some variables to help find external libraries.
if(GPU_BUILD)
set(METIS_ROOT "${CMAKE_SOURCE_DIR}/build_gpu/build_externals/metis/install" CACHE PATH "METIS root")
else()
set(METIS_ROOT "${CMAKE_SOURCE_DIR}/build_cpu/build_externals/metis/install" CACHE PATH "METIS root")
endif()
#if(DEFINED ENV{HDF5_DIR})
# message(STATUS "HDF5 obtained via environment")
# set(HDF5_ROOT "$ENV{HDF5_DIR}")
#else()
message(STATUS "HDF5 obtained via dg-mpi/externals folder")
set(HDF5_ROOT "${CMAKE_SOURCE_DIR}/externals/hdf5-download/install/" CACHE PATH "HDF5 root")
message(STATUS "${CMAKE_SOURCE_DIR}/externals/hdf5_download/install")
#endif()
if(DEFINED ENV{MPI_DIR})
set(MPI_ROOT "$ENV{MPI_DIR}")
else()
message(STATUS "Using local installs for mpich")
endif()
if(GPU_BUILD)
set(Kokkos_ROOT "${CMAKE_SOURCE_DIR}/build_gpu/build_externals/kokkos/build/install" CACHE PATH "Kokkos root")
set(KokkosKernels_ROOT "${CMAKE_SOURCE_DIR}/build_gpu/build_externals/kokkos-kernels/build/install" CACHE PATH "Kokkos-kernels root")
else()
set(Kokkos_ROOT "${CMAKE_SOURCE_DIR}/build_cpu/build_externals/kokkos/build/install" CACHE PATH "Kokkos root")
set(KokkosKernels_ROOT "${CMAKE_SOURCE_DIR}/build_cpu/build_externals/kokkos-kernels/build/install" CACHE PATH "Kokkos-kernels root")
endif()
# Use the MPI compilers
if(NOT APPLE)
# set(CMAKE_C_COMPILER "${Kokkos_ROOT}/bin/kokkos_launch_compiler")
# set(CMAKE_CXX_COMPILER "${Kokkos_ROOT}/bin/kokkos_launch_compiler")
if(DEFINED ENV{MPI_DIR})
set(CMAKE_C_COMPILER "${MPI_ROOT}/bin/mpicc")
set(CMAKE_CXX_COMPILER "${MPI_ROOT}/bin/mpicxx")
else()
set(CMAKE_C_COMPILER "mpicc")
set(CMAKE_CXX_COMPILER "mpicxx")
endif()
endif()
# Trying to make MPI CUDA-aware
# TODO: This doesn't really do anything because MPI needs to be compiled with
# CUDA awareness
set(MPICH_CXX "${CMAKE_SOURCE_DIR}/externals/kokkos/build/install/bin/nvcc_wrapper")
# Set the project info (done after setting compilers to avoid infinite loop)
project(DG VERSION 1.0)
# specify default cmake options
option(USE_DOUBLES "Use double precision" ON)
option(USE_OMP "Use OpenMP" ON)
# option(USE_MS_CLIPPING "Clip negative mass fractions in the physics object" ON)
# option(USE_OLD_OUTPUT "Use old output info at every time-step" ON)
# option(USE_1D "Trick to fake 1D calculation" OFF)
# option(USE_MKL "Use MKL libraries" OFF)
# option(USE_KOKKOS "Use Kokkos" OFF)
# option(BUILD_TESTS "Build the tests" OFF)
# option(BUILD_BENCHMARKS "Build benchmarks" OFF)
# option(BUILD_EXAMPLES "Build examples" OFF)
# Sets the number of species if using more than one.
# Defaults to 1 (or air)
# If user increases above 1, user is responsible for either
# cleaning the cache or specifically setting the NUM_SPECIES var
# back to 1 if they wish to go back to the default build.
if(DEFINED NUM_SPECIES)
set(CMAKE_NUM_SPECIES ${NUM_SPECIES})
else()
set(CMAKE_NUM_SPECIES 1)
endif()
# MKL libraries to link against
# set(MKL_LIBRARIES mkl_intel_lp64 mkl_sequential mkl_core)
# -- Hard external requirements -- #
# METIS
set(METIS_INCLUDE_DIRS "${METIS_ROOT}/include")
set(METIS_LIBRARIES "${METIS_ROOT}/lib/libmetis.a")
if(NOT METIS_LIBRARIES)
message(FATAL_ERROR "The METIS library could not be found. Please provide -DMETIS_ROOT.")
endif()
# HDF5
set(HDF5_INCLUDE_DIRS "${HDF5_ROOT}/include")
set(HDF5_LIBRARIES "${HDF5_ROOT}/lib/libhdf5.a")
if(NOT HDF5_LIBRARIES)
message(FATAL_ERROR "The HDF5 library could not be found. Please provide -DHDF5_ROOT.")
endif()
# MPI
include_directories("${MPI_ROOT}/include")
link_directories("${MPI_ROOT}/lib/libmpich.${so}")
# Kokkos
include_directories("${Kokkos_ROOT}/include")
include_directories("${KokkosKernels_ROOT}/include")
##############
# googletest #
##############
# ----------------------------------------------------------------------------------------------- #
# For the googletest dependency we use CMakes googletest module.
# For more information see the following links:
#
# Googletest github: https://github.com/google/googletest
# Googletest + cmake tutorial: https://google.github.io/googletest/quickstart-cmake.html
# CMake Googletest module: https://cmake.org/cmake/help/git-stage/module/GoogleTest.html
#
# ----------------------------------------------------------------------------------------------- #
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929 # release-1.11.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# ----------------------------------------------------------------------------------------------- #
find_package(Kokkos REQUIRED)
find_package(KokkosKernels REQUIRED)
find_package(OpenMP REQUIRED)
# Specify compiler information. This has to be done after finding Kokkos, since
# Kokkos modifies these.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
if(GPU_BUILD)
set(warning_flags "-Wall -Wextra -Wno-deprecated-gpu-targets")
else()
set(warning_flags "-Wall -Wextra")
endif()
set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG -O0 ${warning_flags}")
set(CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG -O0 ${warning_flags}")
set(CMAKE_CUDA_FLAGS_DEBUG "-g -DDEBUG -O0 ${warning_flags}")
set(CMAKE_C_FLAGS_RELEASE "-O3 ${warning_flags}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 ${warning_flags}")
set(CMAKE_CUDA_FLAGS_RELEASE "-O3 ${warning_flags}")
set(CMAKE_EXE_LINKER_FLAGS "-lz")
# set preprocessor definitions
if(USE_DOUBLES)
add_compile_definitions(USE_DOUBLES)
endif()
add_compile_definitions(CMAKE_NUM_SPECIES)
# global include
include_directories("${PROJECT_SOURCE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/src")
include_directories("${PROJECT_SOURCE_DIR}/externals")
# temporary fix for compiling on MacOS
# the first step is to install llvm and libomp via homebrew
if(APPLE)
include_directories("/usr/local/include" "/usr/local/opt/llvm/include")
link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib")
endif()
# Add source directory for use in the code (for example, for finding input files
# for tests)
add_definitions(-DPROJECT_ROOT="${CMAKE_SOURCE_DIR}")
###########################
# project sub-directories #
###########################
# building blocks
add_subdirectory(src/io)
add_subdirectory(src/memory)
add_subdirectory(src/numerics)
add_subdirectory(src/physics)
add_subdirectory(src/mesh)
add_subdirectory(src/solver)
add_subdirectory(src/utils)
add_subdirectory(test)
add_subdirectory(src/post)
# executables
add_subdirectory(src/exec)
###########
# summary #
###########
message(STATUS "-----------------------------------------------------------")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "METIS root: ${METIS_ROOT}")
message(STATUS "METIS include: ${METIS_INCLUDE_DIRS}")
message(STATUS "METIS lib: ${METIS_LIBRARIES}")
message(STATUS "HDF5 root: ${HDF5_ROOT}")
message(STATUS "Kokkos root: ${Kokkos_ROOT}")
message(STATUS "MPI root: ${MPI_ROOT}")
message(STATUS "NUMBER OF SPECIES: ${CMAKE_NUM_SPECIES}")
message(STATUS "")
# message(STATUS "Kokkos kernels root: ${KokkosKernels_ROOT}")
# if(BUILD_BENCHMARKS)
# message(STATUS "sltbench root: ${SLTBENCH_ROOT}")
# endif()
message(STATUS "")
message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "")
message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}")
message(STATUS "")
# if(USE_MKL)
# message(STATUS "")
# message(STATUS "MKL enabled")
# endif()
message(STATUS "-----------------------------------------------------------")