Skip to content

Commit

Permalink
Update CMakeLists.txt files to use imported targets (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
DusanJovic-NOAA authored Jul 28, 2020
1 parent 5f5735e commit cdc7915
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 61 deletions.
110 changes: 72 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
if(CCPP)
add_definitions(-DCCPP)
add_definitions(-DCCPP)
endif()

add_subdirectory(cpl)
add_subdirectory(gfsphysics)
add_subdirectory(ipd)
add_subdirectory(io)

# fv3core library

###############################################################################
### fv3dycore
###############################################################################
if(NOT CCPP)
set(FAST_PHYSICS_SRCS_F90 atmos_cubed_sphere/model/fv_cmp.F90)
set(FAST_PHYSICS_SRCS_F90 atmos_cubed_sphere/model/fv_cmp.F90)
endif()

add_library(
fv3core
fv3dycore

atmos_cubed_sphere/model/a2b_edge.F90
atmos_cubed_sphere/model/multi_gases.F90
Expand Down Expand Up @@ -61,37 +62,46 @@ add_library(
set_property(SOURCE atmos_cubed_sphere/model/nh_utils.F90 APPEND_STRING PROPERTY COMPILE_FLAGS "${FAST}")
set_property(SOURCE atmos_cubed_sphere/model/fv_mapz.F90 APPEND_STRING PROPERTY COMPILE_FLAGS "${FAST}")

target_link_libraries(fv3core PRIVATE fms)
target_link_libraries(fv3core PRIVATE gfsphysics)
target_link_libraries(fv3core PRIVATE ipd)
set_target_properties(fv3dycore PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(fv3dycore PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>)

target_include_directories(fv3core PRIVATE atmos_cubed_sphere ${ESMF_MOD})
target_link_libraries(fv3dycore PRIVATE fms)
target_link_libraries(fv3dycore PRIVATE gfsphysics)
target_link_libraries(fv3dycore PRIVATE ipd)
target_link_libraries(fv3dycore PRIVATE esmf)

# end of fv3core
target_include_directories(fv3dycore PRIVATE atmos_cubed_sphere ${ESMF_MOD})

###############################################################################
### ccpp
###############################################################################
if(CCPP)
add_subdirectory(ccpp)
add_subdirectory(ccpp/driver)
add_dependencies(gfsphysics ccpp ccppphys)
add_dependencies(ccppdriver ccpp ccppphys)
add_dependencies(ccppphys ccpp)

target_include_directories(fv3core PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/framework/src)
target_include_directories(fv3core PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/driver)
endif()
add_subdirectory(ccpp)
add_subdirectory(ccpp/driver)

add_dependencies(gfsphysics ccpp ccppphys)
add_dependencies(ccppdriver ccpp ccppphys)
add_dependencies(ccppphys ccpp)

set_target_properties(fv3core PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(fv3core PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(fv3dycore PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/framework/src)
target_include_directories(fv3dycore PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/driver)

target_link_libraries(ccppphys PRIVATE sp::sp_d)
target_link_libraries(ccppphys PRIVATE w3nco::w3nco_d)
endif()

###############################################################################
### stochastic_physics
###############################################################################
# When specifying an out-of-tree source a binary directory must be explicitly specified.
#add_subdirectory(../stochastic_physics stochastic_physics)
add_subdirectory(stochastic_physics)

###############################################################################
### fv3atm
###############################################################################
add_library(
fv3cap
fv3atm

atmos_model.F90
fv3_cap.F90
Expand All @@ -100,21 +110,45 @@ add_library(
time_utils.F90
)

set_target_properties(fv3atm PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(fv3atm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>)

if(CCPP)
target_include_directories(fv3cap PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ccpp/driver/mod)
add_dependencies(fv3cap ccppdriver ccppphys)
target_include_directories(fv3atm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ccpp/driver/mod)
set(CCPP_LIBRARIES ccppdriver ccppphys ccpp)
add_dependencies(fv3atm ccppdriver ccppphys ccpp)
target_link_libraries(fv3atm PUBLIC ccppdriver ccppphys ccpp)
endif()
target_include_directories(fv3atm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/stochastic_physics)
target_compile_definitions(fv3atm PRIVATE -DESMF_VERSION_MAJOR=${ESMF_VERSION_MAJOR})

target_link_libraries(fv3atm PUBLIC fms)
target_link_libraries(fv3atm PUBLIC cpl)
target_link_libraries(fv3atm PUBLIC gfsphysics)
target_link_libraries(fv3atm PUBLIC ipd)
target_link_libraries(fv3atm PUBLIC io)
target_link_libraries(fv3atm PUBLIC fv3dycore)
target_link_libraries(fv3atm PUBLIC stochastic_physics)

target_link_libraries(fv3atm PUBLIC
nemsio::nemsio w3emc::w3emc_d w3nco::w3nco_d sp::sp_d bacio::bacio_4)
if(INLINE_POST)
target_link_libraries(fv3atm PUBLIC nceppost::nceppost)
endif()
target_include_directories(fv3cap PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/stochastic_physics)
target_compile_definitions(fv3cap PRIVATE -DESMF_VERSION_MAJOR=${ESMF_VERSION_MAJOR})
target_include_directories(fv3cap PRIVATE ${ESMF_MOD})

target_link_libraries(fv3cap PRIVATE fms)
target_link_libraries(fv3cap PRIVATE fv3cpl)
target_link_libraries(fv3cap PRIVATE gfsphysics)
target_link_libraries(fv3cap PRIVATE ipd)
target_link_libraries(fv3cap PRIVATE io)
target_link_libraries(fv3cap PRIVATE fv3core)
target_link_libraries(fv3cap PRIVATE stochastic_physics)

set_target_properties(fv3cap PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(fv3cap PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/mod)

target_link_libraries(fv3atm PUBLIC esmf)

###############################################################################
### Install
###############################################################################
install(
TARGETS fv3atm fv3dycore io ipd gfsphysics ${CCPP_LIBRARIES} cpl stochastic_physics
EXPORT fv3atm-config
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod DESTINATION ${CMAKE_INSTALL_PREFIX})

install(EXPORT fv3atm-config
DESTINATION lib/cmake
)

2 changes: 1 addition & 1 deletion ccpp/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ target_link_libraries(ccppdriver ccppphys)
target_include_directories(ccppdriver PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/framework/src)

set_target_properties(ccppdriver PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(ccppdriver PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(ccppdriver PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>)
9 changes: 4 additions & 5 deletions cpl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

add_library(
fv3cpl
cpl

module_cplfields.F90
module_cap_cpl.F90
)
target_link_libraries(cpl PRIVATE esmf)

target_include_directories(fv3cpl PRIVATE ${ESMF_MOD})

set_target_properties(fv3cpl PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(fv3cpl PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/mod)
set_target_properties(cpl PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(cpl PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>)
7 changes: 4 additions & 3 deletions gfsphysics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
string (REPLACE "-i4 -real-size 32" "-i4 -real-size 64 -no-prec-div -no-prec-sqrt" CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
endif()
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdefault-real-8 -fdefault-double-8")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdefault-real-8")
endif()
endif()

Expand Down Expand Up @@ -202,6 +202,7 @@ if(CCPP)
add_library(gfsphysics ${CCPP_SOURCES})
target_include_directories(gfsphysics PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/framework/src)
target_include_directories(gfsphysics PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/physics)
target_link_libraries(gfsphysics PRIVATE ccppphys ccpp)
else()
add_library(gfsphysics ${IPD_SOURCES})
endif()
Expand All @@ -216,7 +217,7 @@ endif()
set_property(SOURCE GFS_layer/GFS_diagnostics.F90 APPEND_STRING PROPERTY COMPILE_FLAGS "-O0")

target_compile_definitions(gfsphysics PRIVATE -DNEMS_GSM)
target_include_directories(gfsphysics PRIVATE ${NETCDF_INC_DIR})
target_link_libraries(gfsphysics PRIVATE NetCDF::NetCDF_Fortran)

set_target_properties(gfsphysics PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(gfsphysics PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(gfsphysics PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>)
19 changes: 10 additions & 9 deletions io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ add_library(
${POST_SRC}
)

set_source_files_properties(post_gfs.F90 post_nems_routines.F90
PROPERTIES
COMPILE_FLAGS "-I${POST_INC}")
target_link_libraries(io PRIVATE fms)
target_link_libraries(io PRIVATE gfsphysics)
target_link_libraries(io PRIVATE ipd)

target_link_libraries(io fms)
target_link_libraries(io gfsphysics)
target_link_libraries(io ipd)
if(INLINE_POST)
target_link_libraries(io PRIVATE nceppost::nceppost)
endif()

if(CCPP)
target_include_directories(io PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/framework/src)
target_include_directories(io PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/physics)
endif()
target_include_directories(io PRIVATE ${ESMF_MOD})
target_include_directories(io PRIVATE ${NEMSIO_INC})

target_link_libraries(io PRIVATE nemsio::nemsio)
target_link_libraries(io PRIVATE esmf)

set_target_properties(io PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(io PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(io PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>)
5 changes: 3 additions & 2 deletions ipd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ add_library(
IPD_driver.F90
IPD_typedefs.F90
)
target_link_libraries(ipd gfsphysics)
target_link_libraries(ipd PRIVATE gfsphysics)

if(CCPP)
target_include_directories(ipd PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/framework/src)
target_include_directories(ipd PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/physics)
endif()

set_target_properties(ipd PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(ipd PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(ipd PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>)
7 changes: 4 additions & 3 deletions stochastic_physics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ if(CCPP)
target_include_directories(stochastic_physics PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/framework/src)
target_include_directories(stochastic_physics PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/physics)
endif()
target_link_libraries(stochastic_physics fms)
target_link_libraries(stochastic_physics gfsphysics)
target_link_libraries(stochastic_physics fv3core)
target_link_libraries(stochastic_physics PRIVATE fms)
target_link_libraries(stochastic_physics PRIVATE gfsphysics)
target_link_libraries(stochastic_physics PRIVATE fv3dycore)
target_link_libraries(stochastic_physics PRIVATE sp::sp_d)

0 comments on commit cdc7915

Please sign in to comment.