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 confcheck switch to try_* functions #2090

Open
wants to merge 13 commits into
base: release-v4.6.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
643 changes: 427 additions & 216 deletions CMakeLists.txt

Large diffs are not rendered by default.

63 changes: 13 additions & 50 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 @@ -160,52 +161,9 @@ def sanitize( self ) :
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()
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()


# Now fix certain ones that are mixing programs with flags all mashed into one option
Expand Down Expand Up @@ -546,6 +504,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 +534,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 +588,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
133 changes: 38 additions & 95 deletions cmake/confcheck.cmake
Original file line number Diff line number Diff line change
@@ -1,121 +1,60 @@
# 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 )
endif()

if ( DEFINED WRF_CFG_FAIL_REGEX )
if ( DEFINED WRF_CFG_RUN )
message( WARNING "wrf_conf_check: FAIL_REGEX ignored when running check" )
else()
set( WRF_CFG_FAIL_REGEX FAIL_REGEX ${WRF_CFG_FAIL_REGEX} )
endif()
if ( NOT DEFINED WRF_CFG_BINDIR )
set( WRF_CFG_BINDIR ${CMAKE_CURRENT_BINARY_DIR}/confcheck/${WRF_CFG_RESULT_VAR}/ )
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()
message( STATUS "Performing Check ${WRF_CFG_RESULT_VAR}" )

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}
)
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_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 )
Expand All @@ -126,8 +65,12 @@ macro( wrf_conf_check )
else()
message( ${WRF_CFG_MSG_TYPE} "${WRF_CFG_RESULT_VAR} marked as required, 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