Skip to content
Permalink
Browse files

Merge branch 'dev/12.6.0' into feature/het-chem-updates-combined

  • Loading branch information...
msulprizio committed Aug 16, 2019
2 parents 5497400 + 8301f69 commit 7f70aa6a5ff28630e4ffb93e78e82859e73f7d1f
@@ -22,3 +22,4 @@ GIGC
*.ppk
*.log
bin/*
build/
@@ -0,0 +1,128 @@
cmake_minimum_required(VERSION 3.5)
project(GEOS_Chem VERSION 12.4.0 LANGUAGES Fortran)

# Set policies
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0057 NEW)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
if(POLICY CMP0079)
cmake_policy(SET CMP0079 NEW)
endif()

# Add CMakeScripts/ to the module path and import helper functions
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/CMakeScripts)
include(GC-Helpers)

# Declare the BaseTarget. All GEOS-Chem targets depend on BaseTarget.
# This is used to control the compiler options and definitions for GEOS-Chem
# targets (via inheritance).
add_library(BaseTarget INTERFACE)

# Put all of GEOS-Chem's mod files in a subdirectory of the build directory called mod
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(BaseTarget
INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/mod
)

# Link NetCDF-F to BaseTarget
find_package(NetCDF REQUIRED)
target_link_libraries(BaseTarget INTERFACE NetCDF-F)

# Use the NC_HAS_COMPRESSION definition if nf_def_var_deflate is in netcdf.inc
if(EXISTS ${NETCDF_F77_INCLUDE_DIR}/netcdf.inc)
file(READ ${NETCDF_F77_INCLUDE_DIR}/netcdf.inc NCINC)
if("${NCINC}" MATCHES ".*nf_def_var_deflate.*")
target_compile_definitions(BaseTarget INTERFACE "NC_HAS_COMPRESSION")
endif()
endif()

# Print a description of the source code repo's version
get_repo_version(GC_REPO_VERSION ${CMAKE_SOURCE_DIR})
message(STATUS "GEOS-Chem version: ${GC_REPO_VERSION}")

if(NOT GC_EXTERNAL_CONFIG)
# This conditional block configures the GEOS-Chem build for GEOS-Chem
# Classic. As mentioned above, it sets GCCLASSIC_EXE_TARGETS, RRTMG, GTMM
# TOMAS, MECH, and GCHP, and it configures the BaseTarget.

# Set CMAKE_BUILD_TYPE to Release by default
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release"
CACHE STRING
"Choose the type of build, options are: Debug Release."
FORCE
)
endif()

# Display CMAKE_PREFIX_PATH and CMAKE_BUILD_TYPE
gc_message(SECTION "Useful CMake variables")
gc_message(VARIABLE CMAKE_PREFIX_PATH)
set_dynamic_option(CMAKE_BUILD_TYPE # making CMAKE_BUILD_TYPE an option restricts it to Release and Debug
DEFAULT ${CMAKE_BUILD_TYPE}
OPTIONS "Release" "Debug"
LOG CMAKE_VAR_LOG
)
dump_log(CMAKE_VAR_LOG)

# Get the run directory
gc_message(SECTION "Run directory setup")
set(RUNDIR_DEFAULT "..")
set_dynamic_default(RUNDIR DEFAULT "${RUNDIR_DEFAULT}"
LOG RUNDIR_LOG
IS_DIRECTORY
)
dump_log(RUNDIR_LOG)
message(STATUS "Bootstrapping ${RUNDIR}")
get_filename_component(RUNDIR "${RUNDIR}" ABSOLUTE) # Make RUNDIR an absolute path

# Configure the GEOS-Chem build for GCHP or GC-Classic
if(EXISTS ${RUNDIR}/input.geos)
file(STRINGS ${RUNDIR}/input.geos GCHP REGEX ": *gchp_*")
elseif(EXISTS ${RUNDIR}/getRunInfo)
set(GCHP FALSE) # getRunInfo is only in GC-Classic run direcotries
else()
message(FATAL_ERROR "Your run directory doesn't have an input.geos or getRunInfo! Set RUNDIR to a valid run directory.")
endif()
if(GCHP)
add_subdirectory(GCHP)
else()
# Configure for GCClassic
include(GC-ConfigureClassic)
configureGCClassic()
endif()

# Use the default compiler options
include(GC-DefaultCompilerOptions)
endif()

# Add all the subdirectories. Each subdirectory specifies how it should be built.
add_subdirectory(KPP)
add_subdirectory(Headers)
add_subdirectory(GeosUtil)
add_subdirectory(NcdfUtil)
add_subdirectory(History)
add_subdirectory(ObsPack)
add_subdirectory(HEMCO)
add_subdirectory(ISORROPIA)
add_subdirectory(GeosRad)
add_subdirectory(GTMM)
add_subdirectory(GeosCore)

# Write BaseTarget's configuration to a file
get_target_property(BT_DEFINITIONS BaseTarget INTERFACE_COMPILE_DEFINITIONS)
get_target_property(BT_OPTIONS BaseTarget INTERFACE_COMPILE_OPTIONS)
get_target_property(BT_LIBRARIES BaseTarget INTERFACE_LINK_LIBRARIES)
get_target_property(BT_INCLUDES BaseTarget INTERFACE_INCLUDE_DIRECTORIES)
file(WRITE ${CMAKE_BINARY_DIR}/BaseTarget.txt
"# This file shows the BaseTarget's configuration.\n"
"\n"
"BaseTarget::INTERFACE_COMPILE_DEFINITIONS:${BT_DEFINITIONS}\n"
"BaseTarget::INTERFACE_COMPILE_OPTIONS:${BT_OPTIONS}\n"
"BaseTarget::INTERFACE_LINK_LIBRARIES:${BT_LIBRARIES}\n"
"BaseTarget::INTERFACE_INCLUDE_DIRECTORIES:${BT_INCLUDES}\n"
"CMAKE_Fortran_FLAGS_RELEASE:${CMAKE_Fortran_FLAGS_RELEASE}\n"
"CMAKE_Fortran_FLAGS_DEBUG:${CMAKE_Fortran_FLAGS_DEBUG}\n"
"CMAKE_Fortran_FLAGS:${CMAKE_Fortran_FLAGS}\n\n"
)
@@ -0,0 +1,191 @@
#[[ FindNetCDF.cmake

This module finds NetCDF-C and NetCDF-F. It uses nc-config and nf-config to
get HINTS for the find_xxxx's that are used to find the files/directories
listed below.

If a file or directory cannot be found, the user should add the appropriate
directories to CMAKE_PREFIX_PATH.

Resulting variables:
NETCDF_F_LIBRARY: Path to libnetcdff.so
NETCDF_C_LIBRARY: Path to libnetcdf.so
NETCDF_C_INCLUDE_DIR: Path to the directory containing netcdf.h
NETCDF_F90_INCLUDE_DIR: Path to the directory containing netcdf.mod
NETCDF_F77_INCLUDE_DIR: Path to the directory containing netcdf.inc

NETCDF_LIBRARIES: Paths to all of NetCDF's libraries
NETCDF_INCLUDE_DIRS: Paths to all of NetCDF's include directories.

]]


# Find the nc-config and nf-config programs
find_program(NC_CONFIG NAMES "nc-config" DOC "Location of nc-config utility")
find_program(NF_CONFIG NAMES "nf-config" DOC "Location of nf-config utility")


# A function to call nx-config with an argument, and append the resulting path to a list
function(inspect_netcdf_config VAR NX_CONFIG ARG)
execute_process(
COMMAND ${NX_CONFIG} ${ARG}
RESULT_VARIABLE NX_CONFIG_RET
OUTPUT_VARIABLE NX_CONFIG_OUTPUT
ERROR_VARIABLE NX_CONFIG_STDERR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(EXISTS "${NX_CONFIG_OUTPUT}")
list(APPEND ${VAR} ${NX_CONFIG_OUTPUT})
set(${VAR} ${${VAR}} PARENT_SCOPE)
endif()
endfunction()

# Determine HINTS for netcdf.h
set(NC_INC_HINTS "")
inspect_netcdf_config(NC_INC_HINTS "${NC_CONFIG}" --includedir)
inspect_netcdf_config(NC_INC_HINTS "${NC_CONFIG}" --prefix)
# Find netcdf.h
find_path(NETCDF_C_INCLUDE_DIR
netcdf.h
DOC "Directory containing \"netcdf.h\""
HINTS
${NC_INC_HINTS}
$ENV{NetCDF_C_ROOT} $ENV{NETCDF_C_ROOT} # Check for NetCDF-C environment variables
$ENV{NetCDF_ROOT} $ENV{NETCDF_ROOT} # Check for NetCDF_ROOT environment variables
$ENV{GC_INCLUDE} # Use old GEOS-Chem environment variables as a last resort
PATH_SUFFIXES
"include"
)

# Determine HINTS for netcdf.mod
set(NF_INC_HINTS "")
inspect_netcdf_config(NF_INC_HINTS "${NF_CONFIG}" --includedir)
inspect_netcdf_config(NF_INC_HINTS "${NF_CONFIG}" --prefix)
# Find netcdf.mod
find_path(NETCDF_F90_INCLUDE_DIR
netcdf.mod
DOC "Directory containing \"netcdf.mod\""
HINTS
${NF_INC_HINTS}
$ENV{NetCDF_F_ROOT} $ENV{NETCDF_F_ROOT} # Check for NetCDF-F environment variables
$ENV{NetCDF_Fortran_ROOT} $ENV{NETCDF_FORTRAN_ROOT}
$ENV{NetCDF_ROOT} $ENV{NETCDF_ROOT} # Check for NetCDF_ROOT environment variables
$ENV{GC_F_INCLUDE} $ENV{GC_INCLUDE} # Use old GEOS-Chem environment variables as a last resort
PATH_SUFFIXES
"include"
"mod"
"module"
)
# Find netcdf.inc
find_path(NETCDF_F77_INCLUDE_DIR
netcdf.inc
DOC "Directory containing \"netcdf.inc\""
HINTS
${NF_INC_HINTS}
$ENV{NetCDF_F_ROOT} $ENV{NETCDF_F_ROOT} # Check for NetCDF-F environment variables
$ENV{NetCDF_Fortran_ROOT} $ENV{NETCDF_FORTRAN_ROOT}
$ENV{NetCDF_ROOT} $ENV{NETCDF_ROOT} # Check for NetCDF_ROOT environment variables
$ENV{GC_F_INCLUDE} $ENV{GC_INCLUDE} # Use old GEOS-Chem environment variables as a last resort
PATH_SUFFIXES
"include"
"mod"
"module"
)

# Determine HINTS for NetCDF-C's library
set(NC_LIBDIR_HINTS "")
inspect_netcdf_config(NC_LIBDIR_HINTS "${NC_CONFIG}" --libdir)
inspect_netcdf_config(NC_LIBDIR_HINTS "${NC_CONFIG}" --prefix)
# Find libnetcdf.so
find_library(NETCDF_C_LIBRARY
netcdf
DOC "Path to \"libnetcdf\""
HINTS
${NC_LIBDIR_HINTS}
$ENV{NetCDF_C_ROOT} $ENV{NETCDF_C_ROOT} # Check for NetCDF-C environment variables
$ENV{NetCDF_ROOT} $ENV{NETCDF_ROOT} # Check for NetCDF_ROOT environment variables
$ENV{GC_LIB} # Use old GEOS-Chem environment variables as a last resort
PATH_SUFFIXES
"lib"
)

# Determine HINTS for NetCDF-F's library
set(NF_LIBDIR_HINTS "")
inspect_netcdf_config(NF_LIBDIR_HINTS "${NF_CONFIG}" --libdir)
inspect_netcdf_config(NF_LIBDIR_HINTS "${NF_CONFIG}" --prefix)
# Find libnetcdff.so
find_library(NETCDF_F_LIBRARY
netcdff
DOC "Path to \"libnetcdff\""
HINTS
${NF_LIBDIR_HINTS}
$ENV{NetCDF_F_ROOT} $ENV{NETCDF_F_ROOT} # Check for NetCDF-F environment variables
$ENV{NetCDF_Fortran_ROOT} $ENV{NETCDF_FORTRAN_ROOT}
$ENV{NetCDF_ROOT} $ENV{NETCDF_ROOT} # Check for NetCDF_ROOT environment variables
$ENV{GC_F_LIB} $ENV{GC_LIB} # Use old GEOS-Chem environment variables as a last resort
PATH_SUFFIXES
"lib"
)

# Make a readable error message
set(GFTL_ERRMSG "\nCounldn't find one or more of NetCDF's files! The following files/directories weren't found:")
if(NOT NETCDF_F_LIBRARY)
set(NetCDF_ERRMSG "${NetCDF_ERRMSG}
NETCDF_F_LIBRARY: Path to \"libnetcdff.so\"")
endif()
if(NOT NETCDF_C_LIBRARY)
set(NetCDF_ERRMSG "${NetCDF_ERRMSG}
NETCDF_C_LIBRARY: Path to \"libnetcdf.so\"")
endif()
if(NOT NETCDF_C_INCLUDE_DIR)
set(NetCDF_ERRMSG "${NetCDF_ERRMSG}
NETCDF_C_INCLUDE_DIR: Directory containing \"netcdf.h\"")
endif()
if(NOT NETCDF_F90_INCLUDE_DIR)
set(NetCDF_ERRMSG "${NetCDF_ERRMSG}
NETCDF_F90_INCLUDE_DIR: Directory containing \"netcdf.mod\"")
endif()
if(NOT NETCDF_F77_INCLUDE_DIR)
set(NetCDF_ERRMSG "${NetCDF_ERRMSG}
NETCDF_F77_INCLUDE_DIR: Directory containing \"netcdf.inc\"")
endif()
set(NetCDF_ERRMSG "${NetCDF_ERRMSG}\nFind the directories/files that are listed above. Specify the directories you want CMake to search with the CMAKE_PREFIX_PATH variable (or the NetCDF_ROOT environment variable).\n")

# Conform to the find_package standards
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args(NetCDF
REQUIRED_VARS
NETCDF_F_LIBRARY
NETCDF_C_LIBRARY
NETCDF_C_INCLUDE_DIR
NETCDF_F90_INCLUDE_DIR
NETCDF_F77_INCLUDE_DIR
FAIL_MESSAGE "${NetCDF_ERRMSG}"
)

# Set NETCDF_LIBRARIES NETCDF_INCLUDE_DIRS
set(NETCDF_LIBRARIES ${NETCDF_F_LIBRARY} ${NETCDF_C_LIBRARY})
set(NETCDF_INCLUDE_DIRS ${NETCDF_F90_INCLUDE_DIR} ${NETCDF_F77_INCLUDE_DIR} ${NETCDF_C_INCLUDE_DIR})

if(NOT TARGET NetCDF-C)
add_library(NetCDF-C SHARED IMPORTED)
set_property(TARGET NetCDF-C
PROPERTY IMPORTED_LOCATION ${NETCDF_C_LIBRARY}
)
set_property(TARGET NetCDF-C
PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NETCDF_C_INCLUDE_DIR}
)
endif()

if(NOT TARGET NetCDF-F)
add_library(NetCDF-F SHARED IMPORTED)
set_property(TARGET NetCDF-F
PROPERTY IMPORTED_LOCATION ${NETCDF_F_LIBRARY}
)
set_property(TARGET NetCDF-F
PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NETCDF_F90_INCLUDE_DIR} ${NETCDF_F77_INCLUDE_DIR}
)
set_property(TARGET NetCDF-F
PROPERTY INTERFACE_LINK_LIBRARIES NetCDF-C
)
endif()
@@ -0,0 +1,29 @@
function(configureGCClassic)
# Find OpenMP if we're building a multithreaded executable
gc_message(SECTION "Threading")
set_dynamic_option(OMP
DEFAULT "TRUE"
SELECT_EXACTLY 1
OPTIONS "TRUE" "FALSE"
LOG THREADING_LOG
)
dump_log(THREADING_LOG)
if("${OMP}")
find_package(OpenMP REQUIRED)
target_compile_options(BaseTarget INTERFACE ${OpenMP_Fortran_FLAGS})
target_link_libraries(BaseTarget INTERFACE ${OpenMP_Fortran_FLAGS})
else()
target_compile_definitions(BaseTarget INTERFACE "NO_OMP")
endif()

# Configure the build based on the run directory. Propagate the configuration variables.
include(GC-ConfigureForClassicRunDirectory)
configureForClassicRunDirectory()
set(GCCLASSIC_EXE_TARGETS ${GCCLASSIC_EXE_TARGETS} PARENT_SCOPE)
set(GCHP FALSE PARENT_SCOPE)
set(MECH ${MECH} PARENT_SCOPE)
set(TOMAS ${TOMAS} PARENT_SCOPE)
set(RRTMG ${RRTMG} PARENT_SCOPE)
set(GTMM ${GTMM} PARENT_SCOPE)
set(RUNDIR ${RUNDIR} PARENT_SCOPE)
endfunction()

0 comments on commit 7f70aa6

Please sign in to comment.
You can’t perform that action at this time.