Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated community support PR #57

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3233304
inital version of ESMA_cmake for GCHP
LiamBindle Aug 7, 2019
68f6d3a
removed ESMF_INCLUDE_DIR (which was .inc files); added ESMF_VERSION v…
LiamBindle Aug 29, 2019
df28735
fixed whitespace in ESMF_VERSION regex
LiamBindle Aug 29, 2019
a9b2ad9
fixing FindBaselibs.cmake
LiamBindle Sep 14, 2019
517b366
Changes s.t. esma.cmake can be loaded in generic build environments.
LiamBindle Aug 7, 2019
53d0f11
Added a Baselibs target that links all ESMA dependencies
LiamBindle Sep 18, 2019
94e0824
Removed FindFLAP.cmake since FLAP's build creates a FLAPConfig.cmake …
LiamBindle Sep 30, 2019
36806e5
Merge pull request #41 from GEOS-ESM/develop
tclune Oct 1, 2019
d04df00
Merge pull request #44 from GEOS-ESM/develop
bena-nasa Nov 14, 2019
84e2702
Merge pull request #49 from GEOS-ESM/develop
bena-nasa Dec 5, 2019
5aac037
Removed gFTL from mandatory Baselibs
LiamBindle Dec 12, 2019
e615fc8
Merge pull request #1 from geoschem/feature/gFTL-submodule
lizziel Dec 17, 2019
dec0618
Merge branch 'master' synced with upstream 'master' into dev/gchp
lizziel Dec 17, 2019
431e658
minor updates to fix upstream merge
LiamBindle Dec 17, 2019
8eda874
Merge pull request #52 from GEOS-ESM/develop
bena-nasa Jan 2, 2020
f4c321b
Merge pull request #54 from GEOS-ESM/develop
bena-nasa Jan 7, 2020
667a643
Duplicate ESMF_INCLUDE_DIRS and FindGFTL.cmake were causing problems …
LiamBindle Jan 9, 2020
1d2b06a
removed old files that aren't necessary anymore
LiamBindle Jan 9, 2020
5e4b6f7
Updated FindBaselibs.cmake community support to work with current MAP…
LiamBindle Jan 9, 2020
0815d7f
Fix Intel compiler flags de-duplication issue
LiamBindle Jan 10, 2020
df6e079
Merge pull request #56 from GEOS-ESM/develop
bena-nasa Jan 23, 2020
7b5a7ff
Merge remote-tracking branch 'upstream/master' into HEAD
lizziel Feb 7, 2020
33d4351
Merge branch 'dev/13.0.0' into feature/latest_gmao_libraries
LiamBindle Feb 7, 2020
2409792
Removed legacy CMake FLAP variables
LiamBindle Feb 13, 2020
cca5310
Use NATIVE_COMMAND in separate_arguments()
LiamBindle Feb 13, 2020
c88b541
Readded OSX logic to link against libstdc++.dylib
LiamBindle Feb 24, 2020
9ee1e28
Removed monolithic interface target 'Baselibs'; added GEOS_BuildPrope…
LiamBindle Feb 24, 2020
7805c68
Added a cached variable to control which ESMF library is searched for
LiamBindle Feb 24, 2020
4f35ffd
Added missing ${NETCDF_INCLUDE_DIRS} to imported ESMF's interface inc…
LiamBindle Mar 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 64 additions & 83 deletions FindBaselibs.cmake
Original file line number Diff line number Diff line change
@@ -1,89 +1,68 @@

# Set BASEDIR to non-existant path if it is not already set
set (BASEDIR /does-not-exist CACHE PATH "Path to installed baselibs _including_ OS subdirectory (Linux or Darwin).")

if (NOT EXISTS ${BASEDIR})
# If BASEDIR evaluates to TRUE but it isn't a valid path throw an error
# This lets BASEDIR be skipped if BASEDIR is set to a false value (e.g. setting BASEDIR to IGNORE)
if (BASEDIR AND NOT EXISTS ${BASEDIR})
message (FATAL_ERROR "ERROR: Must specify a value for BASEDIR with cmake ... -DBASEDIR=<path>.")
elseif(EXISTS ${BASEDIR})
# Add path to GFE packages
list (APPEND CMAKE_PREFIX_PATH ${BASEDIR}

# Add BASEDIR's include directories
${BASEDIR}/include/netcdf
${BASEDIR}/include/hdf5
${BASEDIR}/include/hdf
${BASEDIR}/include/esmf
${BASEDIR}/include/FLAP
)
endif ()
if (ESMA_SDF)
message (FATAL_ERROR "ERROR: -hdf option was thought to be obsolete when CMake was crafted.")
endif ()

link_directories (${BASEDIR}/lib)

# Add path to GFE packages
list (APPEND CMAKE_PREFIX_PATH ${BASEDIR})

#------------------------------------------------------------------
# netcdf
# The following command provides the list of libraries that netcdf
# uses. Unfortunately it also includes the library path and "-l"
# prefixes, which CMake handles in a different manner. So we need so
# strip off that item from the list
execute_process (
COMMAND ${BASEDIR}/bin/nf-config --flibs
OUTPUT_VARIABLE LIB_NETCDF
)

string(REGEX MATCHALL " -l[^ ]*" _full_libs "${LIB_NETCDF}")
set (NETCDF_LIBRARIES_OLD)
foreach (lib ${_full_libs})
string (REPLACE "-l" "" _tmp ${lib})
string (STRIP ${_tmp} _tmp)
list (APPEND NETCDF_LIBRARIES_OLD ${_tmp})
endforeach()

list (REVERSE NETCDF_LIBRARIES_OLD)
list (REMOVE_DUPLICATES NETCDF_LIBRARIES_OLD)
list (REVERSE NETCDF_LIBRARIES_OLD)

add_definitions(-DHAS_NETCDF4)
add_definitions(-DHAS_NETCDF3)
add_definitions(-DH5_HAVE_PARALLEL)
add_definitions(-DNETCDF_NEED_NF_MPIIO)
add_definitions(-DHAS_NETCDF3)
#------------------------------------------------------------------

set (INC_HDF5 ${BASEDIR}/include/hdf5)
set (INC_NETCDF ${BASEDIR}/include/netcdf)
set (INC_HDF ${BASEDIR}/include/hdf)
set (INC_ESMF ${BASEDIR}/include/esmf)

find_package(GFTL REQUIRED)
find_package(GFTL_SHARED QUIET)
find_package(FARGPARSE QUIET)

find_package(FLAP REQUIRED)

if (APPLE)
if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
execute_process (COMMAND ${CMAKE_C_COMPILER} --print-file-name=libgcc.a OUTPUT_VARIABLE libgcc OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()
execute_process (COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libstdc++.dylib OUTPUT_VARIABLE stdcxx OUTPUT_STRIP_TRAILING_WHITESPACE)
else ()
execute_process (COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libstdc++.so OUTPUT_VARIABLE stdcxx OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()

# For OS X - use the gcc stdc++ library - not clang
#find_library (STDCxx
# stdc++
# HINTS "/opt/local/lib/gcc5"
# )

# We must statically link ESMF on Apple due mainly to an issue with how Baselibs is built.
# Namely, the esmf dylib libraries end up with the full *build* path on Darwin (which is in
# src/esmf/lib/libO...) But we copy the dylib to $BASEDIR/lib. Thus, DYLD_LIBRARY_PATH gets
# hosed. yay.

if (APPLE)
set (ESMF_LIBRARY ${BASEDIR}/lib/libesmf.a)
else ()
set (ESMF_LIBRARY esmf_fullylinked)
endif ()

#find_package (NetCDF REQUIRED COMPONENTS Fortran)
#set (INC_NETCDF ${NETCDF_INCLUDE_DIRS})

set (NETCDF_LIBRARIES ${NETCDF_LIBRARIES_OLD})
set (ESMF_LIBRARIES ${ESMF_LIBRARY} ${NETCDF_LIBRARIES} ${MPI_Fortran_LIBRARIES} ${MPI_CXX_LIBRARIES} ${stdcxx} ${libgcc})
# Find NetCDF
find_package(NetCDF REQUIRED COMPONENTS C Fortran)
# Set non-standard expected variables
set(INC_NETCDF ${NETCDF_INCLUDE_DIRS})
set(LIB_NETCDF ${NETCDF_LIBRARIES})

# If BASEDIR exists, set the expected HDF and HDF5 variables
if(EXISTS ${BASEDIR}/include/hdf5)
set (INC_HDF5 ${BASEDIR}/include/hdf5)
endif()
if(EXISTS ${BASEDIR}/include/hdf)
set (INC_HDF ${BASEDIR}/include/hdf)
endif()

# Find GFTL
set(GFTL_IS_REQUIRED_ARG "REQUIRED" CACHE STRING "Argument in GFTL's find_package call")
mark_as_advanced(GFTL_IS_REQUIRED_ARG)
find_package(GFTL ${GFTL_IS_REQUIRED_ARG} CONFIG)

# Find GFTL_SHARED
set(GFTL_SHARED_IS_REQUIRED_ARG "" CACHE STRING "Argument in GFTL_SHARED's find_package call")
mark_as_advanced(GFTL_SHARED_IS_REQUIRED_ARG)
find_package(GFTL_SHARED ${GFTL_SHARED_IS_REQUIRED_ARG} CONFIG)

# Find FARGPARSE
set(FARGPARSE_IS_REQUIRED_ARG "" CACHE STRING "Argument in FARGPARSE's find_package call")
mark_as_advanced(FARGPARSE_IS_REQUIRED_ARG)
find_package(FARGPARSE ${FARGPARSE_IS_REQUIRED_ARG} CONFIG)

# Find FLAP
set(FLAP_IS_REQUIRED_ARG "REQUIRED" CACHE STRING "Argument in FLAP's find_package call")
mark_as_advanced(FLAP_IS_REQUIRED_ARG)
find_package(FLAP ${FLAP_IS_REQUIRED_ARG} CONFIG)

# Find ESMF
find_package(ESMF REQUIRED)
# Set non-standard expected variables
set(INC_ESMF ${ESMF_INCLUDE_DIRS})

# Find MPI
find_package(MPI REQUIRED COMPONENTS C CXX Fortran)

# Unit testing
# option (PFUNIT "Activate pfunit based tests" OFF)
Expand All @@ -92,10 +71,12 @@ if (PFUNIT_FOUND)
add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND})
endif ()

# BASEDIR.rc file does not have the arch
string(REPLACE "/${CMAKE_SYSTEM_NAME}" "" BASEDIR_WITHOUT_ARCH ${BASEDIR})
set(BASEDIR_WITHOUT_ARCH ${BASEDIR_WITHOUT_ARCH} CACHE STRING "BASEDIR without arch")
mark_as_advanced(BASEDIR_WITHOUT_ARCH)
if(BASEDIR)
# BASEDIR.rc file does not have the arch
string(REPLACE "/${CMAKE_SYSTEM_NAME}" "" BASEDIR_WITHOUT_ARCH ${BASEDIR})
set(BASEDIR_WITHOUT_ARCH ${BASEDIR_WITHOUT_ARCH} CACHE STRING "BASEDIR without arch")
mark_as_advanced(BASEDIR_WITHOUT_ARCH)
endif()

# Set the site variable
include(DetermineSite)
include(DetermineSite)
117 changes: 117 additions & 0 deletions FindESMF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
function(append_globbed_directories VAR)
cmake_parse_arguments(ARGS
""
""
"PATTERNS;PATHS"
${ARGN}
)
set(MATCHED_LIST "")
foreach(PREFIX ${ARGS_PATHS})
foreach(PATTERN ${ARGS_PATTERNS})
if(IS_ABSOLUTE ${PREFIX})
file(GLOB MATCHED ${PREFIX}/${PATTERN})
else()
file(GLOB MATCHED ${CMAKE_BINARY_DIR}/${PREFIX}/${PATTERN})
endif()
foreach(MATCHED_FILE ${MATCHED})
get_filename_component(MATCHED_DIR ${MATCHED_FILE} DIRECTORY)
list(APPEND MATCHED_LIST ${MATCHED_DIR})
endforeach()
endforeach()
endforeach()
if("${MATCHED_LIST}")
list(REMOVE_DUPLICATES MATCHED_LIST)
endif()
list(APPEND ${VAR} ${MATCHED_LIST})
set(${VAR} ${${VAR}} PARENT_SCOPE)
endfunction()

# Add globbed directories to CMAKE_PREFIX_PATH for upcoming find_paths
append_globbed_directories(CMAKE_PREFIX_PATH
PATTERNS
mod/mod*/*.*.*.*.*/esmf.mod
lib/lib*/*.*.*.*.*/libesmf.a
PATHS
${CMAKE_PREFIX_PATH}
)

# Find the installed ESMF files
find_path(ESMF_HEADERS_DIR
ESMC.h
DOC "The path to the directory containing \"ESMC.h\"."
PATH_SUFFIXES "include"
)

find_path(ESMF_MOD_DIR
esmf.mod
DOC "The path to the directory containing \"esmf.mod\"."
PATH_SUFFIXES "mod" "include"
)

set(FIND_ESMF_LIBRARY_SEARCH_NAMES "esmf;esmf_fullylinked" CACHE STRING "ESMF library names that are searched for.")
find_library(ESMF_LIBRARY
NAMES ${FIND_ESMF_LIBRARY_SEARCH_NAMES}
DOC "The path to the ESMF library."
PATH_SUFFIXES "lib"
)

# Get ESMF's versions number
if(EXISTS ${ESMF_HEADERS_DIR}/ESMC_Macros.h)
file(READ ${ESMF_HEADERS_DIR}/ESMC_Macros.h ESMC_MACROS)
if("${ESMC_MACROS}" MATCHES "#define[ \t]+ESMF_VERSION_MAJOR[ \t]+([0-9]+)")
set(ESMF_VERSION_MAJOR "${CMAKE_MATCH_1}")
endif()
if("${ESMC_MACROS}" MATCHES "#define[ \t]+ESMF_VERSION_MINOR[ \t]+([0-9]+)")
set(ESMF_VERSION_MINOR "${CMAKE_MATCH_1}")
endif()
if("${ESMC_MACROS}" MATCHES "#define[ \t]+ESMF_VERSION_REVISION[ \t]+([0-9]+)")
set(ESMF_VERSION_REVISION "${CMAKE_MATCH_1}")
endif()
set(ESMF_VERSION "${ESMF_VERSION_MAJOR}.${ESMF_VERSION_MINOR}.${ESMF_VERSION_REVISION}")
else()
set(ESMF_VERSION "NOTFOUND")
endif()

# Throw an error if anything went wrong
find_package_handle_standard_args(ESMF
REQUIRED_VARS
ESMF_HEADERS_DIR
ESMF_MOD_DIR
ESMF_LIBRARY
VERSION_VAR ESMF_VERSION
FAIL_MESSAGE "${ESMF_ERRMSG}"
)

# Specify the other libraries that need to be linked for ESMF
find_package(NetCDF REQUIRED)
find_package(MPI REQUIRED)

set(ESMF_REQUIRED_CPP_STD_LIBRARIES "")
if (APPLE)
execute_process (COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libstdc++.dylib OUTPUT_VARIABLE stdcxx OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND ESMF_REQUIRED_CPP_STD_LIBRARIES ${stdcxx})
if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
execute_process (COMMAND ${CMAKE_C_COMPILER} --print-file-name=libgcc.a OUTPUT_VARIABLE libgcc OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND ESMF_REQUIRED_CPP_STD_LIBRARIES ${libgcc})
endif ()
else ()
execute_process (COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libstdc++.so OUTPUT_VARIABLE stdcxx OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND ESMF_REQUIRED_CPP_STD_LIBRARIES ${stdcxx})
endif ()

set(ESMF_LIBRARIES ${ESMF_LIBRARY} ${NETCDF_LIBRARIES} MPI::MPI_Fortran MPI::MPI_CXX rt ${ESMF_REQUIRED_CPP_STD_LIBRARIES})
set(ESMF_INCLUDE_DIRS ${ESMF_HEADERS_DIR} ${ESMF_MOD_DIR})

# Make an imported target for ESMF
if(NOT TARGET ESMF)
add_library(ESMF STATIC IMPORTED)
set_target_properties(ESMF PROPERTIES
IMPORTED_LOCATION ${ESMF_LIBRARY}
)
target_link_libraries(ESMF
INTERFACE
${NETCDF_LIBRARIES}
MPI::MPI_Fortran MPI::MPI_CXX rt ${ESMF_REQUIRED_CPP_STD_LIBRARIES}
)
target_include_directories(ESMF INTERFACE ${ESMF_INCLUDE_DIRS} ${NETCDF_INCLUDE_DIRS})
endif()
5 changes: 3 additions & 2 deletions GenericCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ set (GEOS_Fortran_FLAGS_DEBUG "${GEOS_Fortran_Debug_Flags} ${common_Fortran_fl
set (GEOS_Fortran_FLAGS_RELEASE "${GEOS_Fortran_Release_Flags} ${common_Fortran_flags} ${GEOS_Fortran_Release_FPE_Flags} ${ALIGNCOM}")
set (GEOS_Fortran_FLAGS_VECT "${GEOS_Fortran_Vect_Flags} ${common_Fortran_flags} ${GEOS_Fortran_Vect_FPE_Flags} ${ALIGNCOM}")

set (CMAKE_Fortran_FLAGS_DEBUG "${GEOS_Fortran_FLAGS_DEBUG}" CACHE STRING "Debug Fortran flags" FORCE )
set (CMAKE_Fortran_FLAGS_RELEASE "${GEOS_Fortran_FLAGS_RELEASE}" CACHE STRING "Release Fortran flags" FORCE )
# Use separate_arguments to split options into semicolon separated list
separate_arguments(GEOS_Fortran_FLAGS_RELEASE NATIVE_COMMAND ${GEOS_Fortran_FLAGS_RELEASE})
separate_arguments(GEOS_Fortran_FLAGS_DEBUG NATIVE_COMMAND ${GEOS_Fortran_FLAGS_DEBUG})
15 changes: 10 additions & 5 deletions Intel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ set (OPTREPORT5 "-qopt-report5")
set (FREAL8 "-r8")
set (FINT8 "-i8")

# [lrb,2020-01-10]
# Use SHELL: prefix and quotes around multi-word arguments to
# prevent de-duplication from breaking things. See
# https://cmake.org/cmake/help/latest/command/target_compile_options.html

set (PP "-fpp")
set (MISMATCH "")
set (BIG_ENDIAN "-convert big_endian")
Expand All @@ -32,14 +37,14 @@ set (DISABLE_GLOBAL_NAME_WARNING "-diag-disable 5462")
set (CRAY_POINTER "")
set (MCMODEL "-mcmodel medium -shared-intel")
set (HEAPARRAYS "-heap-arrays 32")
set (BYTERECLEN "-assume byterecl")
set (ALIGNCOM "-align dcommons")
set (BYTERECLEN "\"SHELL:-assume byterecl\"")
set (ALIGNCOM "\"SHELL:-align dcommons\"")
set (TRACEBACK "-traceback")
set (NOOLD_MAXMINLOC "-assume noold_maxminloc")
set (REALLOC_LHS "-assume realloc_lhs")
set (NOOLD_MAXMINLOC "\"SHELL:-assume noold_maxminloc\"")
set (REALLOC_LHS "\"SHELL:-assume realloc_lhs\"")
set (ARCH_CONSISTENCY "-fimf-arch-consistency=true")
set (FTZ "-ftz")
set (ALIGN_ALL "-align all")
set (ALIGN_ALL "\"SHELL:-align all\"")
set (NO_ALIAS "-fno-alias")

set (NO_RANGE_CHECK "")
Expand Down
26 changes: 23 additions & 3 deletions esma.cmake
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if (APPLE)
endif ()

# OpenMP support
find_package (OpenMP)
find_package (OpenMP REQUIRED COMPONENTS Fortran)

# Threading support
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
Expand All @@ -65,10 +65,12 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(MPI_DETERMINE_LIBRARY_VERSION TRUE)
find_package (MPI REQUIRED)

set(MKL_IS_REQUIRED_ARG "REQUIRED" CACHE STRING "Argument in MKL's find_package call")
mark_as_advanced(MKL_IS_REQUIRED_ARG)
if (APPLE)
if (DEFINED ENV{MKLROOT})
set (MKL_Fortran)
find_package (MKL REQUIRED)
find_package (MKL ${MKL_IS_REQUIRED_ARG})
else ()
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
#USE FRAMEWORK
Expand All @@ -77,14 +79,32 @@ if (APPLE)
endif ()
endif ()
else ()
find_package (MKL REQUIRED)
find_package (MKL ${MKL_IS_REQUIRED_ARG})
endif ()

option (ESMA_ALLOW_DEPRECATED "suppress warnings about deprecated features" ON)

# Baselibs ...
include (FindBaselibs)

# Create an interface target for GEOS build properties
add_library(GEOS_BuildProperties INTERFACE)
target_compile_options(GEOS_BuildProperties INTERFACE
$<$<COMPILE_LANGUAGE:Fortran>:
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>,$<CONFIG:MinSizeRel>>:${GEOS_Fortran_FLAGS_RELEASE}>
$<$<CONFIG:Debug>:${GEOS_Fortran_FLAGS_DEBUG}>
>
""
)
target_compile_definitions(GEOS_BuildProperties INTERFACE
HAS_NETCDF4
HAS_NETCDF3
H5_HAVE_PARALLEL
NETCDF_NEED_NF_MPIIO
HAS_NETCDF3
)
install(TARGETS GEOS_BuildProperties EXPORT MAPL-targets)

enable_testing()
set (CMAKE_INSTALL_MESSAGE LAZY)

Expand Down