-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
218 lines (182 loc) · 11.7 KB
/
CMakeLists.txt
File metadata and controls
218 lines (182 loc) · 11.7 KB
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
cmake_minimum_required(VERSION 3.10)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(Red "${Esc}[32m")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# module setup options
option(BASE "BASE" OFF)
option(FORCING "FORCING" OFF)
option(FORCINGPET "FORCINGPET" OFF)
option(AETROOTZONE "AETROOTZONE" OFF)
option(NGEN "NGEN" OFF)
# A numeric verbosity level can be set for debug output printed/logged during execution
# Use 1 by default when build type is "Debug"
if (NOT DEFINED DEBUG_VERBOSITY AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(DEBUG_VERBOSITY 1)
# Use 0 by default for any build types other than "Debug"
elseif (NOT DEFINED DEBUG_VERBOSITY)
set(DEBUG_VERBOSITY 0)
# Catch any "ON" or equivalent, excluding all integers other than "1" (which we want to handle separately)
elseif (${DEBUG_VERBOSITY} AND NOT ${DEBUG_VERBOSITY} GREATER "1" AND NOT ${DEBUG_VERBOSITY} LESS_EQUAL "0")
set(DEBUG_VERBOSITY 1)
# Should catch any other values except an integer greater than 1 (which we want to use directly)
elseif (NOT ${DEBUG_VERBOSITY} GREATER "1")
set(DEBUG_VERBOSITY 0)
endif ()
# While not an explicit condition, DEBUG_VERBOSITY is left alone if set to some integer greater than 1
# TODO: this should ideally be applied to a specific target, but how targets are defined and set up probably needs to be adjusted first
add_compile_definitions(CFE_DEBUG=${DEBUG_VERBOSITY})
if( (NOT BASE) AND (NOT FORCING) AND (NOT FORCINGPET) AND (NOT AETROOTZONE) AND (NOT NGEN) AND (NOT UNITTEST) )
message("${Red}Options: BASE, FORCING, FORCINGPET, AETROOTZONE, NGEN, UNITTEST" ${ColourReset})
message(FATAL_ERROR "Invalid option is provided, CMake will exit." )
endif()
if (BASE)
message("${Red} CFE BUILD 'BASE' CASE!${ColourReset}")
set(exe_name "cfe_base")
elseif (FORCING)
message("${Red} CFE BUILD 'FORCING' CASE!${ColourReset}")
set(exe_name "cfe_forcing")
elseif (FORCINGPET)
message("${Red} CFE BUILD 'FORCING AND PET' CASE!${ColourReset}")
set(exe_name "cfe_forcingpet")
elseif (AETROOTZONE)
message("${Red} CFE BUILD 'FORCING AND PET AND ROOTZONE-BASED AET' CASE!${ColourReset}")
set(exe_name "cfe_aet_rootzone")
elseif (NGEN)
message("${Red} CFE BUILD NGEN CASE!${ColourReset}")
endif ()
# set the project name
project(cfebmi VERSION 1.0.0 DESCRIPTION "OWP CFE BMI Module Shared Library")
IF (CMAKE_BUILD_TYPE MATCHES Debug)
message("Debug build.")
ENDIF (CMAKE_BUILD_TYPE MATCHES Debug)
message(CMAKE_CXX_COMPILER " ${CMAKE_CXX_COMPILER}")
message(CMAKE_C_COMPILER " ${CMAKE_C_COMPILER}")
message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
# add the executable
## cfe + aorc + pet + smp
if (AETROOTZONE)
add_executable(${exe_name} ./src/main_cfe_aorc_pet_rz_aet.cxx ./src/cfe.c ./src/bmi_cfe.c ./src/giuh.c
./src/conceptual_reservoir.c ./src/nash_cascade.c ./extern/aorc_bmi/src/aorc.c
./extern/aorc_bmi/src/bmi_aorc.c ./extern/evapotranspiration/src/pet.c
./extern/evapotranspiration/src/bmi_pet.c)
add_library(cfelib ./extern/SoilMoistureProfiles/src/bmi_soil_moisture_profile.cxx
./extern/SoilMoistureProfiles/src/soil_moisture_profile.cxx
./extern/SoilMoistureProfiles/include/bmi_soil_moisture_profile.hxx
./extern/SoilMoistureProfiles/include/soil_moisture_profile.hxx)
target_link_libraries(${exe_name} LINK_PUBLIC cfelib)
elseif (FORCING)
add_executable(${exe_name} ./src/main_pass_forcings.c ./src/cfe.c ./src/bmi_cfe.c ./src/giuh.c ./src/conceptual_reservoir.c
./src/nash_cascade.c ./extern/aorc_bmi/src/aorc.c ./extern/aorc_bmi/src/bmi_aorc.c)
elseif (FORCINGPET)
add_executable(${exe_name} ./src/main_cfe_aorc_pet.c ./src/cfe.c ./src/bmi_cfe.c ./src/giuh.c ./src/conceptual_reservoir.c
./src/nash_cascade.c ./extern/aorc_bmi/src/aorc.c ./extern/aorc_bmi/src/bmi_aorc.c
./extern/evapotranspiration/src/pet.c ./extern/evapotranspiration/src/bmi_pet.c)
elseif (BASE)
add_executable(${exe_name} ./src/main.c ./src/cfe.c ./src/bmi_cfe.c ./src/giuh.c ./src/conceptual_reservoir.c
./src/nash_cascade.c)
endif ()
if (NOT NGEN)
target_link_libraries(${exe_name} PRIVATE m)
target_include_directories(${exe_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
endif ()
# ngen CFE (add shared library)
if (NGEN)
set(CFE_LIB_NAME_CMAKE cfebmi)
set(CFE_LIB_DESC_CMAKE "OWP CFE BMI Module Shared Library")
# Make sure these are compiled with this directive
add_compile_definitions(BMI_ACTIVE)
if (WIN32)
add_library(cfebmi ./src/bmi_cfe.c ./src/cfe.c ./src/giuh.c ./src/conceptual_reservoir.c ./src/nash_cascade.c)
else ()
add_library(cfebmi SHARED ./src/bmi_cfe.c ./src/cfe.c ./src/giuh.c ./src/conceptual_reservoir.c ./src/nash_cascade.c)
endif ()
# On some platforms, the linker needs to be explicitly told to search for defs for standard C math functions
#target_link_options(cfebmi PRIVATE -lm)
target_link_libraries(cfebmi PRIVATE m)
target_include_directories(cfebmi PRIVATE include)
set_target_properties(cfebmi PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(cfebmi PROPERTIES PUBLIC_HEADER ./include/bmi_cfe.h)
# Add unit testing using CMake and CTests, and custom test code
enable_testing()
####################################################################################################################
####################################################################################################################
# Include executable and (single) test for the legacy batch test file
add_executable(combined_bmi_funcs_test test/combined_bmi_funcs_test.c)
target_include_directories(combined_bmi_funcs_test PUBLIC ${PROJECT_SOURCE_DIR}/include test/include)
target_link_libraries(combined_bmi_funcs_test cfebmi)
add_test(NAME combined_bmi_funcs_test_1 COMMAND combined_bmi_funcs_test ${PROJECT_SOURCE_DIR}/configs/cfe_config_cat_87_pass.txt)
# End combined_bmi_funcs_test tests
####################################################################################################################
####################################################################################################################
####################################################################################################################
# Include executable and individual, isolated unit tests for BMI related functions
# Control which test is run via custom implemented arg parsing within the executable
add_executable(test_bmi_model ./test/test_bmi_model.c test/bmi_test_utils.c test/bmi_test_utils.c test/general_test_utils.c)
target_include_directories(test_bmi_model PUBLIC ${PROJECT_SOURCE_DIR}/include test/include)
target_link_libraries(test_bmi_model cfebmi)
target_compile_definitions(test_bmi_model PUBLIC BMI_INIT_CONFIG_EX_1="${PROJECT_SOURCE_DIR}/configs/cfe_config_cat_87_pass.txt")
#set(BMI_CONFIG_1 ${PROJECT_SOURCE_DIR}/configs/cfe_config_cat_87_pass.txt)
# For the 'test_bmi_model' executable, the test example can be explicitly passed (although for now there is only 1)
add_test(NAME test_initialize_1 COMMAND test_bmi_model test_initialize 1)
# Note that, when using the first test example, the value be left off/implied for convenience
add_test(NAME test_initialize_1_a COMMAND test_bmi_model test_initialize)
add_test(NAME test_update_1 COMMAND test_bmi_model test_update)
add_test(NAME test_update_until_1 COMMAND test_bmi_model test_update_until)
add_test(NAME test_finalize_1 COMMAND test_bmi_model test_finalize)
add_test(NAME test_get_component_name_1 COMMAND test_bmi_model test_get_component_name)
add_test(NAME test_get_input_item_count_1 COMMAND test_bmi_model test_get_input_item_count)
add_test(NAME test_get_input_var_names_1 COMMAND test_bmi_model test_get_input_var_names)
add_test(NAME test_get_output_item_count_1 COMMAND test_bmi_model test_get_output_item_count)
add_test(NAME test_get_output_var_names_1 COMMAND test_bmi_model test_get_output_var_names)
add_test(NAME test_get_var_grid_1 COMMAND test_bmi_model test_get_var_grid)
add_test(NAME test_get_var_itemsize_1 COMMAND test_bmi_model test_get_var_itemsize)
add_test(NAME test_get_var_location_1 COMMAND test_bmi_model test_get_var_location)
add_test(NAME test_get_var_units_1 COMMAND test_bmi_model test_get_var_units)
add_test(NAME test_get_var_type_1 COMMAND test_bmi_model test_get_var_type)
# TODO: While others could also benefit, get_var_nbytes in particular needs a second test example that covers the
# TODO: other case for the "soil_moisture_profile" variable (see comments in test_get_var_nbytes function)
add_test(NAME test_get_var_nbytes_1 COMMAND test_bmi_model test_get_var_nbytes)
add_test(NAME test_get_grid_rank_1 COMMAND test_bmi_model test_get_grid_rank)
add_test(NAME test_get_grid_size_1 COMMAND test_bmi_model test_get_grid_size)
add_test(NAME test_get_grid_type_1 COMMAND test_bmi_model test_get_grid_type)
add_test(NAME test_get_start_time_1 COMMAND test_bmi_model test_get_start_time)
# TODO: (later) get_end_time probably needs another test scenario when the module is handling it's own forcings
add_test(NAME test_get_end_time_1 COMMAND test_bmi_model test_get_end_time)
add_test(NAME test_get_time_step_1 COMMAND test_bmi_model test_get_time_step)
add_test(NAME test_get_time_units_1 COMMAND test_bmi_model test_get_time_units)
add_test(NAME test_get_current_time_1 COMMAND test_bmi_model test_get_current_time)
add_test(NAME test_set_value_1 COMMAND test_bmi_model test_set_value)
add_test(NAME test_set_value_at_indices_1 COMMAND test_bmi_model test_set_value_at_indices)
add_test(NAME test_get_value_1 COMMAND test_bmi_model test_get_value)
add_test(NAME test_get_value_at_indices_1 COMMAND test_bmi_model test_get_value_at_indices)
add_test(NAME test_get_value_ptr_1 COMMAND test_bmi_model test_get_value_ptr)
# These are effectively not implemented, but they should strictly speaking be implemented and return a failure code
add_test(NAME test_get_grid_edge_count_1 COMMAND test_bmi_model test_get_grid_edge_count)
add_test(NAME test_get_grid_edge_nodes_1 COMMAND test_bmi_model test_get_grid_edge_nodes)
add_test(NAME test_get_grid_face_count_1 COMMAND test_bmi_model test_get_grid_face_count)
add_test(NAME test_get_grid_face_edges_1 COMMAND test_bmi_model test_get_grid_face_edges)
add_test(NAME test_get_grid_face_nodes_1 COMMAND test_bmi_model test_get_grid_face_nodes)
add_test(NAME test_get_grid_node_count_1 COMMAND test_bmi_model test_get_grid_node_count)
add_test(NAME test_get_grid_nodes_per_face_1 COMMAND test_bmi_model test_get_grid_nodes_per_face)
add_test(NAME test_get_grid_origin_1 COMMAND test_bmi_model test_get_grid_origin)
add_test(NAME test_get_grid_shape_1 COMMAND test_bmi_model test_get_grid_shape)
add_test(NAME test_get_grid_spacing_1 COMMAND test_bmi_model test_get_grid_spacing)
add_test(NAME test_get_grid_x_1 COMMAND test_bmi_model test_get_grid_x)
add_test(NAME test_get_grid_y_1 COMMAND test_bmi_model test_get_grid_y)
add_test(NAME test_get_grid_z_1 COMMAND test_bmi_model test_get_grid_z)
# End test_bmi_model tests
####################################################################################################################
include(GNUInstallDirs)
install(TARGETS cfebmi
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
configure_file(cfebmi.pc.in cfebmi.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/cfebmi.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
endif ()
unset(BASE CACHE)
unset(FORCING CACHE)
unset(FORCINGPET CACHE)
unset(AETROOTZONE CACHE)
unset(NGEN CACHE)