-
Notifications
You must be signed in to change notification settings - Fork 69
/
CMakeLists.txt
157 lines (132 loc) · 4.29 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
cmake_minimum_required(VERSION 3.18)
project(
rte-rrtmgp
VERSION 1.9.0
LANGUAGES Fortran
)
option(BUILD_TESTING "Build tests" OFF)
option(RTE_ENABLE_SP "Enable single-precision floating-point model" OFF)
set(PREFERRED_KERNEL_MODES "default" "accel" "extern")
set(KERNEL_MODE
"default"
CACHE STRING "Select the kernel mode: ${PREFERRED_KERNEL_MODES}"
)
set_property(CACHE KERNEL_MODE PROPERTY STRINGS ${PREFERRED_KERNEL_MODES})
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# GNUInstallDirs issues a warning if CMAKE_SIZEOF_VOID_P is not defined, which
# is the case with NAG. One way to circumvent that is to enable C language for
# the project:
if(CMAKE_Fortran_COMPILER_ID STREQUAL NAG)
enable_language(C)
endif()
include(GNUInstallDirs)
add_compile_options(
$<$<COMPILE_LANG_AND_ID:Fortran,GNU>:-ffree-line-length-none>
)
set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/modules)
add_subdirectory(rte-kernels)
add_subdirectory(rte-frontend)
add_subdirectory(rrtmgp-kernels)
add_subdirectory(rrtmgp-frontend)
include(CTest)
if(BUILD_TESTING)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
if(NOT _RTE_RRTMGP_HAVE_PY_PACKAGES)
include(CheckPython3Package)
check_python3_package(numpy)
check_python3_package(
"netCDF4 or h5netcdf+scipy"
CODE "try:
import netCDF4
except:
import h5netcdf
import scipy
"
)
check_python3_package(
"xarray>=0.12.2"
CODE "import xarray
exit(tuple(map(int, xarray.__version__.split('.'))) < (0, 12, 2))"
)
check_python3_package(dask.array)
set(_RTE_RRTMGP_HAVE_PY_PACKAGES
TRUE
CACHE INTERNAL
"RTE-RRTMGP found all Python packages required for testing"
)
endif()
find_package(NetCDF_Fortran REQUIRED)
if(RRTMGP_DATA)
add_test(NAME fetch_rrtmgp_data COMMAND ${CMAKE_COMMAND} -E true)
message(
NOTICE
"Using an external dataset from ${RRTMGP_DATA}: the data files will not be installed"
)
else()
set(RRTMGP_DATA "${PROJECT_BINARY_DIR}/rrtmgp-data")
include(ExternalProject)
ExternalProject_Add(
rrtmgp-data
GIT_REPOSITORY https://github.com/earth-system-radiation/rrtmgp-data.git
GIT_TAG "v1.8.2"
GIT_SHALLOW True
EXCLUDE_FROM_ALL True
PREFIX rrtmgp-data-cmake
SOURCE_DIR ${RRTMGP_DATA}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
set(fetch_rrtmgp_data_command
${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR} --config
"$<CONFIG>" --target rrtmgp-data
)
add_test(NAME fetch_rrtmgp_data COMMAND ${fetch_rrtmgp_data_command})
install(CODE "execute_process(COMMAND ${fetch_rrtmgp_data_command})")
install(
FILES # cmake-format: sort
${RRTMGP_DATA}/rrtmgp-aerosols-merra-lw.nc
${RRTMGP_DATA}/rrtmgp-aerosols-merra-sw.nc
${RRTMGP_DATA}/rrtmgp-clouds-lw.nc
${RRTMGP_DATA}/rrtmgp-clouds-sw.nc
${RRTMGP_DATA}/rrtmgp-gas-lw-g128.nc
${RRTMGP_DATA}/rrtmgp-gas-lw-g256.nc
${RRTMGP_DATA}/rrtmgp-gas-sw-g112.nc
${RRTMGP_DATA}/rrtmgp-gas-sw-g224.nc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/rte-rrtmgp/
)
endif()
set_tests_properties(
fetch_rrtmgp_data PROPERTIES FIXTURES_SETUP fetch_rrtmgp_data
)
add_subdirectory(examples)
add_subdirectory(tests)
else()
# Allow for 'make test' even if the tests are disabled:
enable_testing()
endif()
export(
EXPORT rte-rrtmgp-targets FILE ${PROJECT_BINARY_DIR}/rte-rrtmgp-targets.cmake
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/config.cmake.in
${PROJECT_BINARY_DIR}/rte-rrtmgp-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/rte-rrtmgp/cmake
NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/rte-rrtmgp-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMinorVersion
)
install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ TYPE INCLUDE)
install(
EXPORT rte-rrtmgp-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/rte-rrtmgp/cmake
)
install(
FILES ${PROJECT_BINARY_DIR}/rte-rrtmgp-config.cmake
${PROJECT_BINARY_DIR}/rte-rrtmgp-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/rte-rrtmgp/cmake
)