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

CMake DA Core #2092

Open
wants to merge 42 commits into
base: release-v4.6.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5b024c0
Force fail on genexp in defines
islas May 31, 2024
7c6e773
Rewrite the defines to not use genexp
islas May 31, 2024
980aca8
Move internal flags and compile definitions to variables rather than …
islas Apr 24, 2024
6b9d27e
Make sure hydro gets all the flags similar to original cmake build
islas Jul 30, 2024
4dda109
Prepare cmake build to not have core selection
islas Aug 1, 2024
bee8ddd
Make sure appropriate selection of option for non-ARW cores
islas Aug 1, 2024
4e30de1
Shortcut selections for other cores
islas Aug 1, 2024
5598e7c
Generalize the sanitization logic for stanzas
islas Aug 1, 2024
96930f5
Create properties for flag and defines organization
islas Jul 30, 2024
0203d61
Fine-tuned control of compile flags
islas Aug 1, 2024
86c3707
Don't force specific define able to come from stanza
islas Aug 1, 2024
1769477
Allow for regular defines to be passed in
islas Aug 1, 2024
812acda
Reduce configuration check logic by using try_* functions
islas Aug 6, 2024
b1a8fa1
Purge underscore defs from stanza reading
islas Aug 6, 2024
41df958
Fix default try run setting
islas Aug 6, 2024
64a9e28
Adjust message text for failed checks
islas Aug 6, 2024
55656fe
Add underscore check
islas Aug 6, 2024
b263d5f
Incorporate underscore check into definitions
islas Aug 6, 2024
1728a6b
External folder compilation for da build
islas Jul 12, 2024
0c275d8
Add cmake option for crtm, wavelet, and bufr
islas Jul 24, 2024
bebecac
Add var/ build when core is appropriate
islas Jul 24, 2024
43d1f90
Extract rconfig always to satisfy DA registry
islas Jul 24, 2024
4a5ac51
Compile var lib
islas Jul 24, 2024
4a54b7e
Add compile defs for DA options
islas Jul 30, 2024
1d744a5
Remove addition of non-DA folders
islas Jul 30, 2024
b2c1013
Adjust core folders sources for when da core is being built
islas Jul 30, 2024
e30952c
Set da sources per da.make
islas Jul 30, 2024
c77f9c7
Flip crtm default
islas Aug 2, 2024
176dc42
Print DA suboptions
islas Aug 2, 2024
f05dd33
DA defines always set
islas Aug 2, 2024
8aeb0ff
Link var/external libs
islas Aug 2, 2024
380325e
Add more info to debug messages
islas Aug 2, 2024
f34e19f
Disable double precision setting on blas and lapack files
islas Aug 2, 2024
0ef3060
Adjust flags to var/external libs
islas Aug 2, 2024
f064c03
Remove iargc external using preprocessor directives
islas Aug 2, 2024
380a7fe
DA and gen_be source in respective folders
islas Aug 2, 2024
9ddaf99
Actually these do go into da
islas Aug 5, 2024
72d10d5
Missing sources from DA folder compiltation
islas Aug 5, 2024
95440c1
Wavelet compilation kinda working
islas Aug 5, 2024
edc554c
Make sure dest exists before install commands
islas Aug 5, 2024
fbd93c0
Let underscore def come from confcheck
islas Aug 6, 2024
11ee92f
Place module files in separate locations for da execs
islas Aug 6, 2024
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
687 changes: 471 additions & 216 deletions CMakeLists.txt

Large diffs are not rendered by default.

68 changes: 17 additions & 51 deletions arch/configure_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
osAndArchAlt = re.compile( r"^ARCH[ ]+(\w+)[ ]+(\w+)", re.I )

referenceVar = re.compile( r"[$]([(])?(\w+)(?(1)[)])", re.I )
compileObject = re.compile( r"(\W)-c(\W)" )
compileObject = re.compile( r"(\W|^)-c(\W|$)" )
configureRepl = re.compile( r"(\W|^)CONFIGURE_\w+(\W|$)" )

class Stanza():

Expand Down Expand Up @@ -159,54 +160,14 @@ def sanitize( self ) :
# # Now deref
self.dereference( "FCBASEOPTS" )

# Remove rogue compile commands that should *NOT* even be here
keysToSanitize = [
"ARFLAGS","ARFLAGS",
"CC",
"CFLAGS_LOCAL",
"CFLAGS",
"COMPRESSION_INC",
"COMPRESSION_LIBS",
"CPP",
"CPPFLAGS",
"DM_CC",
"DM_FC",
"ESMF_LDFLAG",
"F77FLAGS",
"FC",
"FCBASEOPTS_NO_G",
"FCBASEOPTS",
"FCOPTIM",
"FCSUFFIX",
"FDEFS",
"FFLAGS",
"FNGFLAGS",
"FORMAT_FIXED",
"FORMAT_FREE",
"LD",
"LDFLAGS_LOCAL",
"LDFLAGS",
"MODULE_SRCH_FLAG",
"RLFLAGS",
"SCC",
"SFC",
"TRADFLAG",
]

for keyToSan in keysToSanitize :
if keyToSan in self.kvPairs_ :
self.kvPairs_[ keyToSan ] = self.kvPairs_[ keyToSan ].replace( "CONFIGURE_COMP_L", "" )
self.kvPairs_[ keyToSan ] = self.kvPairs_[ keyToSan ].replace( "CONFIGURE_COMP_I", "" )
self.kvPairs_[ keyToSan ] = self.kvPairs_[ keyToSan ].replace( "CONFIGURE_FC", "" )
self.kvPairs_[ keyToSan ] = self.kvPairs_[ keyToSan ].replace( "CONFIGURE_CC", "" )
self.kvPairs_[ keyToSan ] = self.kvPairs_[ keyToSan ].replace( "CONFIGURE_FDEFS", "" )
self.kvPairs_[ keyToSan ] = self.kvPairs_[ keyToSan ].replace( "CONFIGURE_MPI", "" )
self.kvPairs_[ keyToSan ] = self.kvPairs_[ keyToSan ].replace( "CONFIGURE_COMPAT_FLAGS", "" )
self.kvPairs_[ keyToSan ] = self.kvPairs_[ keyToSan ].replace( "CONFIGURE_CPPFLAGS", "" )
self.kvPairs_[ keyToSan ] = self.kvPairs_[ keyToSan ].replace( "CONFIGURE_TRADFLAG", "" )

self.kvPairs_[ keyToSan ] = compileObject.sub( r"\1\2", self.kvPairs_[ keyToSan ] ).strip()
definesToRemove = [ "-DUNDERSCORE", "-DNOUNDERSCORE" ]

# Remove rogue compile commands that should *NOT* even be here
for keyToSan in self.kvPairs_.keys() :
self.kvPairs_[ keyToSan ] = configureRepl.sub( r"\1\2", self.kvPairs_[ keyToSan ] ).strip()
self.kvPairs_[ keyToSan ] = compileObject.sub( r"\1\2", self.kvPairs_[ keyToSan ] ).strip()
for cppDef in definesToRemove :
self.kvPairs_[ keyToSan ] = self.kvPairs_[ keyToSan ].replace( cppDef, "" )

# Now fix certain ones that are mixing programs with flags all mashed into one option
self.splitIntoFieldAndFlags( "SFC" )
Expand Down Expand Up @@ -546,6 +507,7 @@ def generateCMakeToolChainFile( cmakeToolChainTemplate, output, stanza, optionsD

configStanza = cmakeToolChainTemplateLines.format(
ARCH_LOCAL=stanza.kvPairs_["ARCH_LOCAL"],
LDFLAGS_LOCAL=stanza.kvPairs_["LDFLAGS_LOCAL"],
BYTESWAPIO=stanza.kvPairs_["BYTESWAPIO"],
CFLAGS_LOCAL=stanza.kvPairs_["CFLAGS_LOCAL"],
DM_CC=stanza.kvPairs_["DM_CC"],
Expand Down Expand Up @@ -575,8 +537,12 @@ def generateCMakeToolChainFile( cmakeToolChainTemplate, output, stanza, optionsD

def projectSpecificOptions( options, stanzaCfg ) :
coreOption = getStringOptionSelection( options.sourceCMakeFile, "WRF_CORE_OPTIONS", "WRF_CORE" )
nestingOption = getStringOptionSelection( options.sourceCMakeFile, "WRF_NESTING_OPTIONS", "WRF_NESTING", 1 )
caseOption = getStringOptionSelection( options.sourceCMakeFile, "WRF_CASE_OPTIONS", "WRF_CASE" )
if coreOption == "ARW" :
nestingOption = getStringOptionSelection( options.sourceCMakeFile, "WRF_NESTING_OPTIONS", "WRF_NESTING", 1 )
caseOption = getStringOptionSelection( options.sourceCMakeFile, "WRF_CASE_OPTIONS", "WRF_CASE" )
else :
nestingOption = "NONE"
caseOption = "NONE"

# These are yes
yesValues = [ "yes", "y", "true", "1" ]
Expand Down Expand Up @@ -625,4 +591,4 @@ def projectSpecificOptions( options, stanzaCfg ) :
return additionalOptions

if __name__ == '__main__' :
main()
main()
15 changes: 14 additions & 1 deletion chem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,17 @@ target_link_libraries(
convert_emiss
PRIVATE
${PROJECT_NAME}_Core
)
)

target_compile_options(
convert_emiss
PRIVATE
${PROJECT_COMPILE_OPTIONS}
)


target_compile_definitions(
convert_emiss
PRIVATE
${PROJECT_COMPILE_DEFINITIONS}
)
12 changes: 5 additions & 7 deletions cmake/c_preproc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,15 @@ macro( wrf_expand_definitions )
set( WRF_EXP_DEFS )
foreach( WRF_EXP_DEF ${WRF_EXP_DEFINITIONS} )
if ( NOT ${WRF_EXP_DEF} MATCHES ".*-D.*" )
# We have a generator expression, inject the -D correctly
# THIS SHOULD ONLY BE USED FOR CONDITIONALLY APPLIED DEFINITIONS
# We have a generator expression, error! no way we can evaluate this correctly
if ( ${WRF_EXP_DEF} MATCHES "^[$]<" )
# Take advantage of the fact that a define is most likely not an expanded variable (i.e. starts with a-zA-Z, adjust if not)
# preceeded by the defining generator expression syntax $<<condition>>:var or <condition>,var
# Yes this is fragile but is probably more robust than the current code if you're relying on this macro :D
string( REGEX REPLACE "(>:|,)([a-zA-Z])" "\\1-D\\2" WRF_EXP_DEF_SANITIZED ${WRF_EXP_DEF} )
list( APPEND WRF_EXP_DEFS ${WRF_EXP_DEF_SANITIZED} )
message( FATAL_ERROR "Generator expressions not allowed in preprocessing defines" )
else()
list( APPEND WRF_EXP_DEFS -D${WRF_EXP_DEF} )
endif()
else()
# Just add it normally
list( APPEND WRF_EXP_DEFS ${WRF_EXP_DEF} )
endif()

endforeach()
Expand Down
139 changes: 41 additions & 98 deletions cmake/confcheck.cmake
Original file line number Diff line number Diff line change
@@ -1,133 +1,76 @@
# WRF Macro for adding configuration checks from source file, default is fortran
# https://cmake.org/cmake/help/latest/module/CheckFortranSourceCompiles.html
# https://github.com/ufs-community/ufs-weather-model/issues/132
include( CheckFortranSourceRuns )
include( CheckFortranSourceCompiles )
include( CheckCSourceRuns )
include( CheckCSourceCompiles )
include( CheckCXXSourceRuns )
include( CheckCXXSourceCompiles )
# include( CheckFortranSourceRuns )
# include( CheckFortranSourceCompiles )
# include( CheckCSourceRuns )
# include( CheckCSourceCompiles )
# include( CheckCXXSourceRuns )
# include( CheckCXXSourceCompiles )

macro( wrf_conf_check )
function( wrf_conf_check )

set( options QUIET RUN REQUIRED )
set( oneValueArgs RESULT_VAR EXTENSION FAIL_REGEX SOURCE MESSAGE SOURCE_TYPE )
set( multiValueArgs ADDITIONAL_FLAGS ADDITIONAL_DEFINITIONS ADDITIONAL_INCLUDES ADDITIONAL_LINK_OPTIONS ADDITIONAL_LIBRARIES )
set( oneValueArgs RESULT_VAR MESSAGE )
set( multiValueArgs SOURCES OPTIONS )

cmake_parse_arguments(
WRF_CFG
"${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
)

get_filename_component( WRF_CFG_SOURCE_FILE ${WRF_CFG_SOURCE} REALPATH )
file( READ ${WRF_CFG_SOURCE_FILE} WRF_CFG_CODE )

# Santize for newlines
string( REPLACE "\\n" "\\\\n" WRF_CFG_CODE "${WRF_CFG_CODE}" )

if ( NOT DEFINED WRF_CFG_SOURCE_TYPE )
set( WRF_CFG_SOURCE_TYPE fortran )
if ( NOT DEFINED WRF_CFG_BINDIR )
set( WRF_CFG_BINDIR ${CMAKE_CURRENT_BINARY_DIR}/confcheck/${WRF_CFG_RESULT_VAR}/ )
endif()

if ( DEFINED WRF_CFG_FAIL_REGEX )
if ( DEFINED WRF_CFG_RUN )
message( WARNING "wrf_conf_check: FAIL_REGEX ignored when running check" )
message( STATUS "Performing Check ${WRF_CFG_RESULT_VAR}" )

if ( DEFINED WRF_CFG_RUN AND "${WRF_CFG_RUN}" )
try_run(
${WRF_CFG_RESULT_VAR}
WRF_CFG_COMPILE_RESULT_VAR
${WRF_CFG_BINDIR}
${WRF_CFG_SOURCES}
${WRF_CFG_OPTIONS}
)
if ( ${WRF_CFG_COMPILE_RESULT_VAR} )
# Did it run successfully
if ( ${${WRF_CFG_RESULT_VAR}} EQUAL 0 )
set( ${WRF_CFG_RESULT_VAR} TRUE )
endif()
else()
set( WRF_CFG_FAIL_REGEX FAIL_REGEX ${WRF_CFG_FAIL_REGEX} )
endif()
endif()

if ( DEFINED WRF_CFG_EXTENSION )
set( WRF_CFG_EXTENSION SRC_EXT ${WRF_CFG_EXTENSION} )
endif()

# Additional options
if ( DEFINED WRF_CFG_QUIET AND ${WRF_CFG_QUIET} )
set( CMAKE_REQUIRED_QUIET ${WRF_CFG_QUIET} )
endif()

if ( DEFINED WRF_CFG_ADDITIONAL_FLAGS )
set( CMAKE_REQUIRED_FLAGS ${WRF_CFG_ADDITIONAL_FLAGS} )
endif()

if ( DEFINED WRF_CFG_ADDITIONAL_DEFINITIONS )
set( CMAKE_REQUIRED_DEFINITIONS ${WRF_CFG_ADDITIONAL_DEFINITIONS} )
endif()

if ( DEFINED WRF_CFG_ADDITIONAL_INCLUDES )
set( CMAKE_REQUIRED_INCLUDES ${WRF_CFG_ADDITIONAL_INCLUDES} )
endif()

if ( DEFINED WRF_CFG_ADDITIONAL_LINK_OPTIONS )
set( CMAKE_REQUIRED_LINK_OPTIONS ${WRF_CFG_ADDITIONAL_LINK_OPTIONS} )
endif()

if ( DEFINED WRF_CFG_ADDITIONAL_LIBRARIES )
set( CMAKE_REQUIRED_LIBRARIES ${WRF_CFG_ADDITIONAL_LIBRARIES} )
endif()

string( TOLOWER "${WRF_CFG_SOURCE_TYPE}" WRF_CFG_SOURCE_TYPE )
if ( DEFINED WRF_CFG_RUN )
if ( ${WRF_CFG_SOURCE_TYPE} STREQUAL "fortran" )
check_fortran_source_runs(
"${WRF_CFG_CODE}"
${WRF_CFG_RESULT_VAR}
${WRF_CFG_FAIL_REGEX}
${WRF_CFG_EXTENSION}
)
elseif ( ${WRF_CFG_SOURCE_TYPE} STREQUAL "c" )
check_c_source_runs(
"${WRF_CFG_CODE}"
${WRF_CFG_RESULT_VAR}
${WRF_CFG_FAIL_REGEX}
${WRF_CFG_EXTENSION}
)
elseif ( ${WRF_CFG_SOURCE_TYPE} STREQUAL "cpp" )
check_cpp_source_runs(
"${WRF_CFG_CODE}"
${WRF_CFG_RESULT_VAR}
${WRF_CFG_FAIL_REGEX}
${WRF_CFG_EXTENSION}
)
set( ${WRF_CFG_RESULT_VAR} FALSE )
endif()
else()
if ( ${WRF_CFG_SOURCE_TYPE} STREQUAL "fortran" )
check_fortran_source_compiles(
"${WRF_CFG_CODE}"
${WRF_CFG_RESULT_VAR}
${WRF_CFG_EXTENSION}
)
elseif ( ${WRF_CFG_SOURCE_TYPE} STREQUAL "c" )
check_c_source_compiles(
"${WRF_CFG_CODE}"
${WRF_CFG_RESULT_VAR}
${WRF_CFG_EXTENSION}
)
elseif ( ${WRF_CFG_SOURCE_TYPE} STREQUAL "cpp" )
check_cpp_source_compiles(
"${WRF_CFG_CODE}"
${WRF_CFG_RESULT_VAR}
${WRF_CFG_EXTENSION}
)
endif()
try_compile(
${WRF_CFG_RESULT_VAR}
${WRF_CFG_BINDIR}
SOURCES ${WRF_CFG_SOURCES}
${WRF_CFG_OPTIONS}
)
endif()

# If it failed - note that since this is a run/compile test we expect pass/true
# to just proceed as normal, but if failure we should do something about it
if ( NOT ( DEFINED ${WRF_CFG_RESULT_VAR} AND "${${WRF_CFG_RESULT_VAR}}" ) )
message( STATUS "Performing Check ${WRF_CFG_RESULT_VAR} - Failure" )
set( WRF_CFG_MSG_TYPE STATUS )
if ( DEFINED WRF_CFG_REQUIRED AND ${WRF_CFG_REQUIRED} )
set( WRF_CFG_MSG_TYPE FATAL_ERROR )
endif()

if ( DEFINED WRF_CFG_MESSAGE )
message( ${WRF_CFG_MSG_TYPE} "${WRF_CFG_MESSAGE}" )
message( ${WRF_CFG_MSG_TYPE} " ${WRF_CFG_MESSAGE}" )
else()
message( ${WRF_CFG_MSG_TYPE} "${WRF_CFG_RESULT_VAR} marked as required, check failed" )
message( ${WRF_CFG_MSG_TYPE} " ${WRF_CFG_RESULT_VAR} check failed" )
endif()
else()
message( STATUS "Performing Check ${WRF_CFG_RESULT_VAR} - Success" )
endif()

endmacro()
set( ${WRF_CFG_RESULT_VAR} ${${WRF_CFG_RESULT_VAR}} PARENT_SCOPE )

endfunction()


Loading