-
Notifications
You must be signed in to change notification settings - Fork 11
/
CMakeLists.txt
95 lines (82 loc) · 3.36 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
cmake_minimum_required(VERSION 3.15.5)
foreach(env_var IN ITEMS CMAKE_C_COMPILER CMAKE_CXX_COMPILER CMAKE_Fortran_COMPILER)
if(NOT DEFINED ENV{${env_var}})
message(FATAL_ERROR "${env_var} is not defined")
endif()
endforeach()
set(CMAKE_C_COMPILER $ENV{CMAKE_C_COMPILER})
set(CMAKE_CXX_COMPILER $ENV{CMAKE_CXX_COMPILER})
set(CMAKE_Fortran_COMPILER $ENV{CMAKE_Fortran_COMPILER})
set(CMAKE_Platform $ENV{CMAKE_Platform})
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
project(NASA-Land-Coupler
VERSION 1.0
LANGUAGES Fortran)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
# NLC executable
list(APPEND nlc_app_files
src/driver/app.F90
src/driver/driver.F90
src/driver/fields.F90
src/driver/flags.F90
src/driver/mediator.F90
)
add_executable(NLC.exe ${nlc_app_files})
# link ESMF
find_package(ESMF MODULE REQUIRED)
if (NOT ESMF_FOUND)
message(FATAL_ERROR "ESMF library not found. Please set environment variable ESMFMKFILE.")
endif (NOT ESMF_FOUND)
target_link_libraries(NLC.exe PUBLIC ESMF)
list(APPEND nlc_defs_private ESMF_VERSION_MAJOR=${ESMF_VERSION_MAJOR})
list(APPEND nlc_defs_private ESMF_VERSION_MINOR=${ESMF_VERSION_MINOR})
if (COMPONENT_LIST)
string(REPLACE "," ";" COMPONENT_LIST "${COMPONENT_LIST}")
foreach (component IN ITEMS ${COMPONENT_LIST})
string(TOUPPER ${component} component)
set(ENABLE_${component} ON)
endforeach()
else()
set(ENABLE_LIS ON)
set(ENABLE_WRFHYDRO ON)
endif()
# link LIS
if (ENABLE_LIS)
set(NLC_LIS_INST ${CMAKE_INSTALL_PREFIX}/LIS)
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/LISF/lis/make/configure.lis")
message(FATAL_ERROR "LIS configuration missing.")
endif()
message("Build LIS:")
message(" run: ${CMAKE_BUILD_TOOL} nuopcinstall INSTPATH=${NLC_LIS_INST} BUILD_TYPE=${CMAKE_BUILD_TYPE} COMPILER=${CMAKE_Fortran_COMPILER_ID}")
message(" in: ${CMAKE_CURRENT_SOURCE_DIR}/src/LISF/lis/runmodes/nuopc_cpl_mode")
message("")
add_custom_target(lis_nuopc
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/LISF/lis/runmodes/nuopc_cpl_mode"
COMMAND ${CMAKE_BUILD_TOOL} nuopcinstall INSTPATH=${NLC_LIS_INST} BUILD_TYPE=${CMAKE_BUILD_TYPE} COMPILER=${CMAKE_Fortran_COMPILER_ID})
add_dependencies(NLC.exe lis_nuopc)
target_link_libraries(NLC.exe PUBLIC ${NLC_LIS_INST}/liblis_nuopc.a)
target_include_directories(NLC.exe PUBLIC ${NLC_LIS_INST})
list(APPEND nlc_defs_private NUOPCCAP_LIS=LIS_NUOPC)
# link LIS dependencies
include(lis_dependencies)
target_link_lis_dependencies(NLC.exe)
endif (ENABLE_LIS)
# link WFHYDRO
if (ENABLE_WRFHYDRO)
message("Build WRFHYDRO:")
message(" add_subdirectory: ${CMAKE_CURRENT_SOURCE_DIR}/src/wrf_hydro_nwm/trunk/NDHMS")
message("")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/wrf_hydro_nwm/trunk/NDHMS)
add_dependencies(NLC.exe wrfhydro_nuopc)
target_link_libraries(NLC.exe PUBLIC wrfhydro_nuopc)
target_include_directories(NLC.exe PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/wrf_hydro_nwm/trunk/NDHMS/mods>)
list(APPEND nlc_defs_private NUOPCCAP_WRFHYDRO=WRFHydro_NUOPC)
# link WRFHYDRO dependencies
include(wrfhydro_dependencies)
target_link_wrfhydro_dependencies(NLC.exe)
endif (ENABLE_WRFHYDRO)
# add flags
target_compile_definitions(NLC.exe PRIVATE "${nlc_defs_private}")
# NLC install
install(TARGETS NLC.exe DESTINATION .)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/driver/fd_nlc.yaml DESTINATION .)