forked from microhh/microhh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
181 lines (161 loc) · 6.09 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
#
# MicroHH
# Copyright (c) 2011-2024 Chiel van Heerwaarden
# Copyright (c) 2011-2024 Thijs Heus
# Copyright (c) 2014-2024 Bart van Stratum
#
# This file is part of MicroHH
#
# MicroHH is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# MicroHH is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MicroHH. If not, see <http://www.gnu.org/licenses/>.
#
cmake_minimum_required (VERSION 3.18)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/config)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_CXX_STANDARD 17)
# Set the precision of the build.
if(NOT USESP)
set(USESP FALSE)
endif()
if(USESP)
add_compile_definitions(FLOAT_SINGLE)
add_compile_definitions(RTE_USE_SP)
message(STATUS "Precision: Single (32-bits floats)")
else()
message(STATUS "Precision: Double (64-bits floats)")
endif()
# Check whether USEMPI and USECUDA are set, if not, set to FALSE.
if(NOT USEMPI)
set(USEMPI FALSE)
endif()
if(NOT USECUDA)
set(USECUDA FALSE)
endif()
# Crash on using CUDA and MPI together, not implemented yet.
if(USEMPI AND USECUDA)
message(FATAL_ERROR "MPI support for CUDA runs is not supported yet")
endif()
# Load system specific settings if not set, force default.cmake.
if(NOT SYST)
set(SYST default)
endif()
include(${SYST} OPTIONAL RESULT_VARIABLE SYSTINC)
# Trigger fatal error if illegal module is loaded.
if(${SYSTINC} STREQUAL "NOTFOUND")
message(FATAL_ERROR "Config file config/" ${SYST} ".cmake does not exist.")
endif()
# Set the default build type to RELEASE.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE CACHE STRING
"Choose the type of build, options are: None Debug Release." FORCE)
else()
string(TOUPPER ${CMAKE_BUILD_TYPE} TEMP)
set(CMAKE_BUILD_TYPE ${TEMP} CACHE STRING
"Choose the type of build, options are: None Debug Release." FORCE)
endif()
# Start the project only after the system specific settings are loaded.
if(USECUDA)
project(microhhc CXX CUDA Fortran)
else()
project(microhhc CXX Fortran)
endif()
# Display status messages for MPI set precompiler flags.
if(USEMPI)
message(STATUS "MPI: Enabled.")
# add the necessary precompiler flag
add_definitions("-DUSEMPI")
else()
message(STATUS "MPI: Disabled.")
endif()
# Load the CUDA module in case CUDA is enabled and display status message.
if(USECUDA)
message(STATUS "CUDA: Enabled.")
add_definitions("-DUSECUDA")
find_package(CUDAToolkit REQUIRED)
else()
message(STATUS "CUDA: Disabled.")
endif()
# Only set the compiler flags when the cache is created
# to enable editing of the flags in the CMakeCache.txt file.
if(NOT HASCACHE)
set(CMAKE_C_FLAGS ${USER_C_FLAGS} CACHE STRING
"Flags used by the C-compiler during all build types." FORCE)
set(CMAKE_C_FLAGS_DEBUG ${USER_C_FLAGS_DEBUG} CACHE STRING
"Flags used by the C-compiler during debug builds." FORCE)
set(CMAKE_C_FLAGS_RELEASE ${USER_C_FLAGS_RELEASE} CACHE STRING
"Flags used by the C-compiler during release builds." FORCE)
set(CMAKE_CXX_FLAGS ${USER_CXX_FLAGS} CACHE STRING
"Flags used by the CXX-compiler during all build types." FORCE)
set(CMAKE_CXX_FLAGS_DEBUG ${USER_CXX_FLAGS_DEBUG} CACHE STRING
"Flags used by the CXX-compiler during debug builds." FORCE)
set(CMAKE_CXX_FLAGS_RELEASE ${USER_CXX_FLAGS_RELEASE} CACHE STRING
"Flags used by the CXX-compiler during release builds." FORCE)
set(CMAKE_Fortran_FLAGS ${USER_FC_FLAGS} CACHE STRING
"Flags used by the Fortran-compiler during all build types." FORCE)
set(CMAKE_Fortran_FLAGS_DEBUG ${USER_FC_FLAGS_DEBUG} CACHE STRING
"Flags used by the Fortran-compiler during debug builds." FORCE)
set(CMAKE_Fortran_FLAGS_RELEASE ${USER_FC_FLAGS_RELEASE} CACHE STRING
"Flags used by the Fortran-compiler during release builds." FORCE)
if(USECUDA)
set(CMAKE_CUDA_FLAGS ${USER_CUDA_NVCC_FLAGS} CACHE STRING
"Flags used by NVCC during all build types." FORCE)
set(CMAKE_CUDA_FLAGS_DEBUG ${USER_CUDA_NVCC_FLAGS_DEBUG} CACHE STRING
"Flags used by NVCC during debug builds." FORCE)
set(CMAKE_CUDA_FLAGS_RELEASE ${USER_CUDA_NVCC_FLAGS_RELEASE} CACHE STRING
"Flags used by NVCC during release builds." FORCE)
endif()
message(STATUS "Build Type: " ${CMAKE_BUILD_TYPE})
set(HASCACHE TRUE CACHE BOOL "CMakeCache.txt created." FORCE)
# Make sure that ccmake only contains build type.
mark_as_advanced(HASCACHE)
mark_as_advanced(CMAKE_INSTALL_PREFIX)
endif()
# Print the C++ and CUDA compiler flags to the screen.
if(CMAKE_BUILD_TYPE STREQUAL "RELEASE")
message(STATUS "Compiler flags: " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_RELEASE})
else()
message(STATUS "Compiler flags: " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_DEBUG})
endif()
if(USECUDA)
# Add CUDA debug definition, to enforce CUDA API and kernel checks.
if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
# add_definitions("-DCUDACHECKS")
message(STATUS "NVCC flags: " ${CMAKE_CUDA_FLAGS} " " ${CMAKE_CUDA_FLAGS_DEBUG})
else()
message(STATUS "NVCC flags: " ${CMAKE_CUDA_FLAGS} " " ${CMAKE_CUDA_FLAGS_RELEASE})
endif()
endif()
add_subdirectory(rte-rrtmgp-cpp/src_kernels)
if(USECUDA)
add_subdirectory(rte-rrtmgp-cpp/src_kernels_cuda)
add_subdirectory(rte-rrtmgp-cpp/src_kernels_cuda_rt)
endif()
add_subdirectory(rte-rrtmgp-cpp/src)
if(USECUDA)
add_subdirectory(rte-rrtmgp-cpp/src_cuda)
add_subdirectory(rte-rrtmgp-cpp/src_cuda_rt)
endif()
if(USECUDA)
if(USEKERNELLAUNCHER)
# Set `clang-tidy` flag for Kernel Launcher
if (NOT USECLANGTIDY)
set(DISABLE_CLANG_TIDY TRUE)
else()
set(DISABLE_CLANG_TIDY FALSE)
endif()
add_compile_definitions(ENABLE_KERNEL_LAUNCHER)
add_subdirectory(external/kernel_launcher)
endif()
endif()
add_subdirectory(src)
add_subdirectory(main)