-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
150 lines (122 loc) · 5.39 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
cmake_minimum_required(VERSION 3.17.0)
message(STATUS "Configuring with build type: ${CMAKE_BUILD_TYPE}")
# We rely on Haero for basic data structures and third-party libraries.
if (NOT TARGET haero)
if (NOT MAM4XX_HAERO_DIR)
message(FATAL_ERROR "MAM4XX_HAERO_DIR is not specified! Please provide a path to Haero.")
elseif (NOT EXISTS ${MAM4XX_HAERO_DIR}/share)
message(FATAL_ERROR "Invalid MAM4XX_HAERO_DIR. Please provide a valid path to Haero.")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${MAM4XX_HAERO_DIR}/share/")
include(haero)
if(HAERO_ENABLE_GPU)
message(STATUS "Building for GPU")
else() #CPU
message(STATUS "Building for CPU")
endif()
endif()
#----------------------
# Configurable options
#----------------------
option(ENABLE_COVERAGE "Enable code coverage instrumentation" OFF)
option(ENABLE_SKYWALKER "Enable Skywalker cross validation" ON)
option(ENABLE_TESTS "Enable unit tests" ON)
if( NOT DEFINED SCREAM_NUM_VERTICAL_LEV)
# Set the default number of level
set(NUM_VERTICAL_LEVELS 72 CACHE STRING "the number of vertical levels per column")
else()
# Use the same number of levels as EAMxx if MAM4xx is run under EAMxx (or SCREAM)
set(NUM_VERTICAL_LEVELS ${SCREAM_NUM_VERTICAL_LEV} CACHE STRING "the number of vertical levels per column equals scream num levels")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
# Blessed version of clang-format.
set(CLANG_FORMAT_VERSION 14)
# Set compilers, linkers, and flags from Haero.
set(CMAKE_CXX_STANDARD ${HAERO_CXX_STANDARD})
set(CMAKE_CXX_COMPILER ${HAERO_CXX_COMPILER})
set(CMAKE_CXX_FLAGS ${HAERO_CXX_FLAGS})
set(CMAKE_C_STANDARD ${HAERO_C_STANDARD})
set(CMAKE_C_COMPILER ${HAERO_C_COMPILER})
set(CMAKE_C_FLAGS ${HAERO_C_FLAGS})
enable_language(CXX)
project (mam4xx)
set(CMAKE_EXE_LINKER_FLAGS ${HAERO_EXE_LINKER_FLAGS})
message(STATUS "Generating project files in build directory: ${PROJECT_BINARY_DIR}")
message(STATUS "C++ compiler is ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION})")
message(STATUS "C compiler is ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION})")
# Version numbers.
set(MAM4XX_MAJOR_VERSION 0)
set(MAM4XX_MINOR_VERSION 1)
set(MAM4XX_PATCH_VERSION 0)
set(MAM4XX_VERSION "${MAM4XX_MAJOR_VERSION}.${MAM4XX_MINOR_VERSION}.${MAM4XX_PATCH_VERSION}")
message(STATUS "Configuring MAM4xx v${MAM4XX_VERSION}")
# Precision of floating point numbers.
message(STATUS "Using ${HAERO_PRECISION} precision floating point numbers")
# Report the installation prefix.
message(STATUS "Installation prefix is ${CMAKE_INSTALL_PREFIX}")
set(MAM4XX_LIBRARIES ${HAERO_LIBRARIES})
# We look for headers in these directories.
include_directories(${HAERO_INCLUDE_DIRS})
include_directories("${PROJECT_BINARY_DIR}")
include_directories("${MAM4XX_HAERO_DIR}/include")
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_BINARY_DIR}/src)
link_directories("${MAM4XX_HAERO_DIR}/lib")
# Code coverage
if (ENABLE_COVERAGE)
message(STATUS "Enabling code coverage instrumentation")
find_program(LCOV_EXE lcov DOC "Lcov code coverage tool")
if (LCOV_EXE MATCHES "NOTFOUND")
message(FATAL_ERROR "Could not find lcov for code coverage reporting!")
endif()
# Add code coverage compiler/linker flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
# Add a "make coverage" target.
add_custom_target(coverage ${LCOV_EXE} --capture --directory . -o unfiltered_coverage.info
COMMAND ${LCOV_EXE} --remove unfiltered_coverage.info -o coverage.info '*/external/*' '*/tests/*' '*/validation/*'
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "Generating coverage report (coverage.info)")
endif()
# Support for valgrind (Linux only)
if (NOT TARGET memcheck)
include(add_memcheck_target)
add_memcheck_target()
endif()
# Testing
if (ENABLE_TESTS OR ENABLE_SKYWALKER)
include(CTest)
enable_testing()
endif()
# Third-party libraries.
add_subdirectory(ext)
# Source directories.
add_subdirectory(src)
# Formatting and format checking using clang-format.
if (NOT TARGET format-cxx)
find_program(CLANG_FORMAT clang-format)
if (NOT CLANG_FORMAT STREQUAL "CLANG_FORMAT-NOTFOUND")
# Is this the blessed version? If not, we create targets that warn the user
# to obtain the right version.
execute_process(COMMAND clang-format --version
OUTPUT_VARIABLE CF_VERSION)
string(STRIP ${CF_VERSION} CF_VERSION)
if (NOT ${CF_VERSION} MATCHES ${CLANG_FORMAT_VERSION})
add_custom_target(format-cxx
echo "You have clang-format version ${CF_VERSION}, but ${CLANG_FORMAT_VERSION} is required."
"Please make sure this version appears in your path and rerun config.sh.")
add_custom_target(format-cxx-check
echo "You have clang-format version ${CF_VERSION}, but ${CLANG_FORMAT_VERSION} is required."
"Please make sure this version appears in your path and rerun config.sh.")
else()
add_custom_target(format-cxx
find ${PROJECT_SOURCE_DIR}/src -name "*.[hc]pp" -exec ${CLANG_FORMAT} -i {} \+;
VERBATIM
COMMENT "Auto-formatting C++ code...")
add_custom_target(format-cxx-check
find ${PROJECT_SOURCE_DIR}/src -name "*.[hc]pp" -exec ${CLANG_FORMAT} -n --Werror -ferror-limit=1 {} \+;
VERBATIM
COMMENT "Checking C++ formatting...")
endif()
endif()
endif()