From 5b024c05c19e8855b83f7533bbb785bf6efaf7c9 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Fri, 31 May 2024 15:50:24 -0700 Subject: [PATCH 01/13] Force fail on genexp in defines --- cmake/c_preproc.cmake | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cmake/c_preproc.cmake b/cmake/c_preproc.cmake index 14f7fe9295..4de0a1e7a1 100644 --- a/cmake/c_preproc.cmake +++ b/cmake/c_preproc.cmake @@ -111,14 +111,9 @@ 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 $<>:var or ,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() From 7c6e773bfe104a6e118bac91f3d466040853aa2f Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Fri, 31 May 2024 15:51:35 -0700 Subject: [PATCH 02/13] Rewrite the defines to not use genexp --- CMakeLists.txt | 246 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 173 insertions(+), 73 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1a1297f2f..e719518246 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -619,55 +619,8 @@ add_compile_definitions( DWORDSIZE=${DWORDSIZE} LWORDSIZE=${LWORDSIZE} RWORDSIZE=${RWORDSIZE} - # Only define if set, this is to use #ifdef/#ifndef preprocessors - # in code since cmake cannot handle basically any others :( - # https://gitlab.kitware.com/cmake/cmake/-/issues/17398 - $<$:WRF_CHEM=$> - $<$:BUILD_CHEM=$> - $<$:WRF_CMAQ=$> - $<$,$>:WRF_KPP=$> - $<$:WRF_DFI_RADAR=$> - $<$:WRF_TITAN=$> - $<$:WRF_MARS=$> - $<$:WRF_VENUS=$> - $<$:WRF_HYDRO=$> - - # Because once again we need two defines to control one thing - $<$:WRF_USE_CTSM=$> - $<$>:WRF_USE_CLM> - - # If force classic or no nc-4 support enable classic - $<$,$>>:NETCDF_classic=1> - $<$,$>>:WRFIO_NCD_NO_LARGE_FILE_SUPPORT=1> - # May need a check for WRFIO_ncdpar_LARGE_FILE_SUPPORT - - # Now set the opposite in different defines, because why not :) - $<$>,$>:USE_NETCDF4_FEATURES=1> - $<$>,$>:WRFIO_NCD_LARGE_FILE_SUPPORT=1> - - # Could simplify logic to just check if RPC is available but to be explicit - # Does this actually need to check for EM_CORE (Config.pl:443) - # not enable terran or not rpc_found do - # not ( enable terrain and rpc_found ) - $<$,$>>:LANDREAD_STUB> - $<$:TERRAIN_AND_LANDUSE> - - - $<$:USE_ALLOCATABLES> - $<$:wrfmodel> - $<$:GRIB1> - $<$:INTIO> - $<$:KEEP_INT_AROUND> - $<$:LIMIT_ARGS> - - #!TODO Always defined - fix the ambiguous english in these BUILD_*_FAST defines - BUILD_RRTMG_FAST=$ - BUILD_RRTMK=$ - BUILD_SBM_FAST=$ - SHOW_ALL_VARS_USED=$ - - # Alwasys set - NMM_CORE=$ + + NMM_MAX_DIM=2600 NETCDF @@ -675,33 +628,180 @@ add_compile_definitions( NONSTANDARD_SYSTEM_SUBR EM_CORE=${EM_CORE} - WRFPLUS=$> - DA_CORE=$,$>> - # DFI_RADAR=$ - - # Nesting options - $<$:MOVE_NESTS> - $<$>:VORTEX_CENTER> - - # Configuration checks - $<$>:NO_IEEE_MODULE> - $<$>:NO_ISO_C_SUPPORT> - # If flush fails, check if we can fall back to fflush, and if not no support - $<$>:$,USE_FFLUSH,NO_FLUSH_SUPPORT>> - $<$>:NO_GAMMA_SUPPORT> - - #!TODO Leaving as is in WRF for now but investigate why we don't do this - # https://stackoverflow.com/a/1035713 - # If fseeko64 succeeds, use that, else check if we can fall back to fseeko, and if not just use fseek - $,FSEEKO64_OK,$,FSEEKO_OK,FSEEK_OK>> - - # I don't believe these are used anymore... - # $<$:MPI2_SUPPORT=$> - # $<$:MPI2_THREAD_SUPPORT=$> - ) +# Only define if set, this is to use #ifdef/#ifndef preprocessors +# in code since cmake cannot handle basically any others :( +# https://gitlab.kitware.com/cmake/cmake/-/issues/17398 +if ( ${ENABLE_CHEM} ) + add_compile_definitions( WRF_CHEM=1 ) + if ( ${ENABLE_KPP} ) + add_compile_definitions( WRF_KPP=1 ) + endif() +endif() +if ( ${ENABLE_CHEM} ) + add_compile_definitions( BUILD_CHEM=1 ) +endif() +if ( ${ENABLE_CMAQ} ) + add_compile_definitions( WRF_CMAQ=1 ) +endif() +if ( ${ENABLE_DFI_RADAR} ) + add_compile_definitions( WRF_DFI_RADAR=1 ) +endif() +if ( ${ENABLE_TITAN} ) + add_compile_definitions( WRF_TITAN=1 ) +endif() +if ( ${ENABLE_MARS} ) + add_compile_definitions( WRF_MARS=1 ) +endif() +if ( ${ENABLE_VENUS} ) + add_compile_definitions( WRF_VENUS=1 ) +endif() +if ( ${ENABLE_HYDRO} ) + add_compile_definitions( WRF_HYDRO=1 ) +endif() + +# Because once again we need two defines to control one thing +if ( ${ENABLE_CTSM} ) + add_compile_definitions( WRF_USE_CTSM ) +else() + #!TODO there are some files that rely on this being 1, but that is never set by the legacy make system + add_compile_definitions( WRF_USE_CLM ) +endif() + +# If force classic or no nc-4 support enable classic +if ( ${FORCE_NETCDF_CLASSIC} OR ( NOT ${netCDF_NC4} ) ) + add_compile_definitions( NETCDF_classic=1 ) +endif() +if ( ${WRFIO_NCD_NO_LARGE_FILE_SUPPORT} OR ( NOT ${netCDF_LARGE_FILE_SUPPORT} ) ) + add_compile_definitions( WRFIO_NCD_NO_LARGE_FILE_SUPPORT=1 ) +endif() +# May need a check for WRFIO_ncdpar_LARGE_FILE_SUPPORT + +# Now set the opposite in different defines, because why not :) +if ( ( NOT ${FORCE_NETCDF_CLASSIC} ) AND ${netCDF_NC4} ) + add_compile_definitions( USE_NETCDF4_FEATURES=1 ) +endif() +if ( ( NOT ${WRFIO_NCD_NO_LARGE_FILE_SUPPORT} ) AND ${netCDF_LARGE_FILE_SUPPORT} ) + add_compile_definitions( WRFIO_NCD_LARGE_FILE_SUPPORT=1 ) +endif() + +# Could simplify logic to just check if RPC is available but to be explicit +# Does this actually need to check for EM_CORE (Config.pl:443) +# not enable terran or not rpc_found do +# not ( enable terrain and rpc_found ) +# if ( NOT ( ${ENABLE_TERRAIN} AND ${RPC_FOUND} ) ) # this is wrong, needs fixing +# add_compile_definitions( LANDREAD_STUB ) +# endif() +if ( ${ENABLE_TERRAIN} AND ${MOVE_NESTS} ) + add_compile_definitions( TERRAIN_AND_LANDUSE ) +else () + add_compile_definitions( LANDREAD_STUB ) +endif() + +if ( ${USE_ALLOCATABLES} ) + add_compile_definitions( USE_ALLOCATABLES ) +endif() +if ( ${wrfmodel} ) + add_compile_definitions( wrfmodel ) +endif() +if ( ${GRIB1} ) + add_compile_definitions( GRIB1 ) +endif() +if ( ${INTIO} ) + add_compile_definitions( INTIO ) +endif() +if ( ${KEEP_INT_AROUND} ) + add_compile_definitions( KEEP_INT_AROUND ) +endif() +if ( ${LIMIT_ARGS} ) + add_compile_definitions( LIMIT_ARGS ) +endif() + + +if ( ${BUILD_RRTMG_FAST} ) + add_compile_definitions( BUILD_RRTMG_FAST=1 ) +else() + add_compile_definitions( BUILD_RRTMG_FAST=0 ) +endif() +if ( ${BUILD_RRTMK} ) + add_compile_definitions( BUILD_RRTMK=1 ) +else() + add_compile_definitions( BUILD_RRTMK=0 ) +endif() +if ( ${BUILD_SBM_FAST} ) + add_compile_definitions( BUILD_SBM_FAST=1 ) +else() + add_compile_definitions( BUILD_SBM_FAST=0 ) +endif() +if ( ${SHOW_ALL_VARS_USED} ) + add_compile_definitions( SHOW_ALL_VARS_USED=1 ) +else() + add_compile_definitions( SHOW_ALL_VARS_USED=0 ) +endif() +if ( ${NMM_CORE} ) + add_compile_definitions( NMM_CORE=1 ) +else() + add_compile_definitions( NMM_CORE=0 ) +endif() + +if ( "${WRF_CORE}" STREQUAL "PLUS" ) + add_compile_definitions( WRFPLUS=1 ) +else() + add_compile_definitions( WRFPLUS=0 ) +endif() + +if ( "${WRF_CORE}" STREQUAL "DA_CORE" OR "${WRF_CORE}" STREQUAL "DA_4D_VAR" ) + add_compile_definitions( DA_CORE=1 ) +else() + add_compile_definitions( DA_CORE=0 ) +endif() +# DFI_RADAR=$ + +# Nesting options +if ( ${MOVE_NESTS} ) + add_compile_definitions( MOVE_NESTS ) +endif() +if ( "${WRF_NESTING}" STREQUAL "VORTEX" ) + add_compile_definitions( VORTEX_CENTER ) +endif() + +# Configuration checks +if ( NOT ${Fortran_2003_IEEE} ) + add_compile_definitions( NO_IEEE_MODULE ) +endif() +if ( NOT ${Fortran_2003_ISO_C} ) + add_compile_definitions( NO_ISO_C_SUPPORT ) +endif() +# If flush fails, check if we can fall back to fflush, and if not no support +if ( NOT ${Fortran_2003_FLUSH} ) + if ( "${Fortran_2003_FFLUSH}" ) + add_compile_definitions( USE_FFLUSH ) + else() + add_compile_definitions( NO_FLUSH_SUPPORT ) + endif() +endif() +if ( NOT ${Fortran_2003_GAMMA} ) + add_compile_definitions( NO_GAMMA_SUPPORT ) +endif() + +#!TODO Leaving as is in WRF for now but investigate why we don't do this +# https://stackoverflow.com/a/1035713 +# If fseeko64 succeeds, use that, else check if we can fall back to fseeko, and if not just use fseek +if ( NOT ${FSEEKO64} ) + add_compile_definitions( FSEEKO64_OK ) +elseif( "${FSEEKO}" ) + add_compile_definitions( FSEEKO_OK ) +else() + add_compile_definitions( FSEEK_OK ) +endif() + +# I don't believe these are used anymore... +# $<$:MPI2_SUPPORT=$> +# $<$:MPI2_THREAD_SUPPORT=$> + + # Make core target add_library( ${PROJECT_NAME}_Core From 980aca8bac5cbf50024c2366df9ac0988bd7e7e8 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Wed, 24 Apr 2024 16:06:13 -0700 Subject: [PATCH 03/13] Move internal flags and compile definitions to variables rather than applied globablly --- CMakeLists.txt | 288 ++++++++++++++------------- chem/CMakeLists.txt | 15 +- external/CMakeLists.txt | 4 + external/io_adios2/CMakeLists.txt | 3 +- external/io_netcdf/CMakeLists.txt | 3 +- external/io_netcdfpar/CMakeLists.txt | 3 +- external/io_pnetcdf/CMakeLists.txt | 3 +- frame/CMakeLists.txt | 7 +- main/CMakeLists.txt | 3 + phys/CMakeLists.txt | 3 +- tools/CMakeLists.txt | 5 +- 11 files changed, 184 insertions(+), 153 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e719518246..8bdbbdaf32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -322,21 +322,21 @@ if ( ${USE_MPI} ) # It still technically finds MPI but the output is nonintuitive # saying things like hdf5 or pthread find_package( MPI REQUIRED COMPONENTS Fortran C ) - add_compile_definitions( - USE_MPI=1 - DM_PARALLEL - ) + list( APPEND PROJECT_COMPILE_DEFINITIONS + USE_MPI=1 + DM_PARALLEL + ) if ( DEFINED WRF_MPI_Fortran_FLAGS AND NOT "${WRF_MPI_Fortran_FLAGS}" STREQUAL "" ) - add_compile_options( - $<$:${WRF_MPI_Fortran_FLAGS}> - ) + list( APPEND PROJECT_COMPILE_OPTIONS + $<$:${WRF_MPI_Fortran_FLAGS}> + ) endif() if ( DEFINED WRF_MPI_C_FLAGS AND NOT "${WRF_MPI_C_FLAGS}" STREQUAL "" ) - add_compile_options( - $<$:${WRF_MPI_C_FLAGS}> - ) + list( APPEND PROJECT_COMPILE_OPTIONS + $<$:${WRF_MPI_C_FLAGS}> + ) endif() # Check if MPI in all its glory has forced IPO down our throats due to hard-coding the wrapper flags @@ -365,16 +365,19 @@ if ( ${USE_MPI} ) set( USE_RSL_LITE ON ) # We know NONE is the zero index so compare against that elseif( ${CURRENT_NESTING_IDX} GREATER 0 ) - add_compile_definitions( - DM_PARALLEL - STUBMPI - ) + list( APPEND PROJECT_COMPILE_DEFINITIONS + DM_PARALLEL + STUBMPI + ) set( USE_RSL_LITE ON ) endif() if ( ${USE_OPENMP} ) find_package( OpenMP REQUIRED COMPONENTS Fortran C ) - add_compile_definitions( USE_OPENMP=1 SM_PARALLEL ) + list( APPEND PROJECT_COMPILE_DEFINITIONS + USE_OPENMP=1 + SM_PARALLEL + ) endif() if ( ${USE_M4} ) @@ -541,50 +544,50 @@ endif() # This is really ugly but such is the cost of supporting many ways to say the same thing # https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html -add_compile_options( - # Use "" and ; specifically to evaluate correctly - # "$<$:>" #@ Absoft Fortran - # "$<$:>" #@ Analog VisualDSP++ - # "$<$:>" #@ Apple Clang - # "$<$:>" #@ ARM Compiler - # "$<$:>" #@ ARM Compiler based on Clang - # "$<$:>" #@ Bruce C Compiler - # "$<$:>" #@ Concurrent Fortran - # "$<$:>" #@ LLVM Clang - "$<$:-s;integer32;-s;real${RWORDSIZE_B}>" #@ Cray Compiler - # "$<$:>" #@ Embarcadero - "$<$,$>:-fdefault-real-${RWORDSIZE}>" #@ Classic Flang Fortran Compiler - # "$<$:>" #@ LLVM Flang Fortran Compiler - "$<$:-CcdRR${RWORDSIZE}>" #@ Fujitsu HPC compiler (Trad mode) - # "$<$:>" #@ Fujitsu HPC compiler (Clang mode) - "$<$:-r${RWORDSIZE};-i4>" #@ G95 Fortran - "$<$,$>:-fdefault-real-${RWORDSIZE}>" #@ GNU Compiler Collection - # "$<$:>" #@ Green Hills Software - # "$<$:>" #@ Hewlett-Packard Compiler - # "$<$:>" #@ IAR Systems - "$<$:-real-size;${RWORDSIZE_B};-i4>" #@ Intel Classic Compiler - "$<$:-real-size;${RWORDSIZE_B};-i4>" #@ Intel LLVM-Based Compiler - # "$<$:>" #@ MCST Elbrus C/C++/Fortran Compiler - # "$<$:>" #@ Microsoft Visual Studio - "$<$:-r${RWORDSIZE};-i4>" #@ NVIDIA HPC Compiler - # "$<$:>" #@ NVIDIA CUDA Compiler - # "$<$:>" #@ Open Watcom - "$<$:-r${RWORDSIZE};-i4>" #@ The Portland Group - "$<$:-r${RWORDSIZE};-i4>" #@ PathScale - # "$<$:>" #@ Small Device C Compiler - # "$<$:>" #@ Oracle Solaris Studio - # "$<$:>" #@ Tasking Compiler Toolsets - # "$<$:>" #@ Texas Instruments - # "$<$:>" #@ Tiny C Compiler - "$<$:-qrealsize=${RWORDSIZE};-qintsize=4>" #@ IBM XL - # "$<$:>" #@ IBM Clang-based XL - # "$<$:>" #@ IBM LLVM-based Compiler - # Todo find how to handle default selection or add new compiler IDs - # unknown how to add support for sxf90 - - # line lengths - "$<$:-ffree-line-length-none>" #@ GNU Compiler Collection - ) +list( APPEND PROJECT_COMPILE_OPTIONS + # Use "" and ; specifically to evaluate correctly + # "$<$:>" #@ Absoft Fortran + # "$<$:>" #@ Analog VisualDSP++ + # "$<$:>" #@ Apple Clang + # "$<$:>" #@ ARM Compiler + # "$<$:>" #@ ARM Compiler based on Clang + # "$<$:>" #@ Bruce C Compiler + # "$<$:>" #@ Concurrent Fortran + # "$<$:>" #@ LLVM Clang + "$<$:-s;integer32;-s;real${RWORDSIZE_B}>" #@ Cray Compiler + # "$<$:>" #@ Embarcadero + "$<$,$>:-fdefault-real-${RWORDSIZE}>" #@ Classic Flang Fortran Compiler + # "$<$:>" #@ LLVM Flang Fortran Compiler + "$<$:-CcdRR${RWORDSIZE}>" #@ Fujitsu HPC compiler (Trad mode) + # "$<$:>" #@ Fujitsu HPC compiler (Clang mode) + "$<$:-r${RWORDSIZE};-i4>" #@ G95 Fortran + "$<$,$>:-fdefault-real-${RWORDSIZE}>" #@ GNU Compiler Collection + # "$<$:>" #@ Green Hills Software + # "$<$:>" #@ Hewlett-Packard Compiler + # "$<$:>" #@ IAR Systems + "$<$:-real-size;${RWORDSIZE_B};-i4>" #@ Intel Classic Compiler + "$<$:-real-size;${RWORDSIZE_B};-i4>" #@ Intel LLVM-Based Compiler + # "$<$:>" #@ MCST Elbrus C/C++/Fortran Compiler + # "$<$:>" #@ Microsoft Visual Studio + "$<$:-r${RWORDSIZE};-i4>" #@ NVIDIA HPC Compiler + # "$<$:>" #@ NVIDIA CUDA Compiler + # "$<$:>" #@ Open Watcom + "$<$:-r${RWORDSIZE};-i4>" #@ The Portland Group + "$<$:-r${RWORDSIZE};-i4>" #@ PathScale + # "$<$:>" #@ Small Device C Compiler + # "$<$:>" #@ Oracle Solaris Studio + # "$<$:>" #@ Tasking Compiler Toolsets + # "$<$:>" #@ Texas Instruments + # "$<$:>" #@ Tiny C Compiler + "$<$:-qrealsize=${RWORDSIZE};-qintsize=4>" #@ IBM XL + # "$<$:>" #@ IBM Clang-based XL + # "$<$:>" #@ IBM LLVM-based Compiler + # Todo find how to handle default selection or add new compiler IDs + # unknown how to add support for sxf90 + + # line lengths + "$<$:-ffree-line-length-none>" #@ GNU Compiler Collection + ) # https://stackoverflow.com/a/53155812 @@ -593,98 +596,98 @@ add_compile_options( # Whole project flags -add_compile_options( - # $<$:-cpp> - # Use "" and ; specifically to evaluate correctly - "$<$:-diag-disable;6843>" - $<$,$>:-fallow-argument-mismatch> - $<$,$>:-fallow-invalid-boz> - $<$,$>:-ffree-line-length-none> - - # $,$:-diag-disable;6843> - ) +list( APPEND PROJECT_COMPILE_OPTIONS + # $<$:-cpp> + # Use "" and ; specifically to evaluate correctly + "$<$:-diag-disable;6843>" + $<$,$>:-fallow-argument-mismatch> + $<$,$>:-fallow-invalid-boz> + $<$,$>:-ffree-line-length-none> + + # $,$:-diag-disable;6843> + ) if ( ${PROFILE_COMPILATION} ) message( STATUS "Attemping to add compilation profiling..." ) - add_compile_options( - $<$:-ftime-report> - ) + list( APPEND PROJECT_COMPILE_OPTIONS $<$:-ftime-report> ) endif() -add_compile_definitions( - MAX_DOMAINS_F=${MAX_DOMAINS_F} - CONFIG_BUF_LEN=${CONFIG_BUF_LEN} - MAX_HISTORY=${MAX_HISTORY} - IWORDSIZE=${IWORDSIZE} - DWORDSIZE=${DWORDSIZE} - LWORDSIZE=${LWORDSIZE} - RWORDSIZE=${RWORDSIZE} +list( APPEND PROJECT_COMPILE_DEFINITIONS + MAX_DOMAINS_F=${MAX_DOMAINS_F} + CONFIG_BUF_LEN=${CONFIG_BUF_LEN} + MAX_HISTORY=${MAX_HISTORY} + IWORDSIZE=${IWORDSIZE} + DWORDSIZE=${DWORDSIZE} + LWORDSIZE=${LWORDSIZE} + RWORDSIZE=${RWORDSIZE} - NMM_MAX_DIM=2600 - NETCDF + # Alwasys set + NMM_MAX_DIM=2600 + NETCDF + + #!TODO Change this to a confcheck + NONSTANDARD_SYSTEM_SUBR + + EM_CORE=${EM_CORE} - #!TODO Change this to a confcheck - NONSTANDARD_SYSTEM_SUBR - - EM_CORE=${EM_CORE} - ) + ) # Only define if set, this is to use #ifdef/#ifndef preprocessors # in code since cmake cannot handle basically any others :( # https://gitlab.kitware.com/cmake/cmake/-/issues/17398 if ( ${ENABLE_CHEM} ) - add_compile_definitions( WRF_CHEM=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_CHEM=1 ) if ( ${ENABLE_KPP} ) - add_compile_definitions( WRF_KPP=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_KPP=1 ) endif() endif() if ( ${ENABLE_CHEM} ) - add_compile_definitions( BUILD_CHEM=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_CHEM=1 ) endif() if ( ${ENABLE_CMAQ} ) - add_compile_definitions( WRF_CMAQ=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_CMAQ=1 ) endif() if ( ${ENABLE_DFI_RADAR} ) - add_compile_definitions( WRF_DFI_RADAR=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_DFI_RADAR=1 ) endif() if ( ${ENABLE_TITAN} ) - add_compile_definitions( WRF_TITAN=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_TITAN=1 ) endif() if ( ${ENABLE_MARS} ) - add_compile_definitions( WRF_MARS=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_MARS=1 ) endif() if ( ${ENABLE_VENUS} ) - add_compile_definitions( WRF_VENUS=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_VENUS=1 ) endif() if ( ${ENABLE_HYDRO} ) - add_compile_definitions( WRF_HYDRO=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_HYDRO=1 ) endif() # Because once again we need two defines to control one thing if ( ${ENABLE_CTSM} ) - add_compile_definitions( WRF_USE_CTSM ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_USE_CTSM ) else() #!TODO there are some files that rely on this being 1, but that is never set by the legacy make system - add_compile_definitions( WRF_USE_CLM ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_USE_CLM ) endif() # If force classic or no nc-4 support enable classic if ( ${FORCE_NETCDF_CLASSIC} OR ( NOT ${netCDF_NC4} ) ) - add_compile_definitions( NETCDF_classic=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS NETCDF_classic=1 ) endif() if ( ${WRFIO_NCD_NO_LARGE_FILE_SUPPORT} OR ( NOT ${netCDF_LARGE_FILE_SUPPORT} ) ) - add_compile_definitions( WRFIO_NCD_NO_LARGE_FILE_SUPPORT=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRFIO_NCD_NO_LARGE_FILE_SUPPORT=1 ) endif() # May need a check for WRFIO_ncdpar_LARGE_FILE_SUPPORT # Now set the opposite in different defines, because why not :) if ( ( NOT ${FORCE_NETCDF_CLASSIC} ) AND ${netCDF_NC4} ) - add_compile_definitions( USE_NETCDF4_FEATURES=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS USE_NETCDF4_FEATURES=1 ) endif() if ( ( NOT ${WRFIO_NCD_NO_LARGE_FILE_SUPPORT} ) AND ${netCDF_LARGE_FILE_SUPPORT} ) - add_compile_definitions( WRFIO_NCD_LARGE_FILE_SUPPORT=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRFIO_NCD_LARGE_FILE_SUPPORT=1 ) endif() # Could simplify logic to just check if RPC is available but to be explicit @@ -692,109 +695,109 @@ endif() # not enable terran or not rpc_found do # not ( enable terrain and rpc_found ) # if ( NOT ( ${ENABLE_TERRAIN} AND ${RPC_FOUND} ) ) # this is wrong, needs fixing -# add_compile_definitions( LANDREAD_STUB ) +# list( APPEND PROJECT_COMPILE_DEFINITIONS LANDREAD_STUB ) # endif() if ( ${ENABLE_TERRAIN} AND ${MOVE_NESTS} ) - add_compile_definitions( TERRAIN_AND_LANDUSE ) + list( APPEND PROJECT_COMPILE_DEFINITIONS TERRAIN_AND_LANDUSE ) else () - add_compile_definitions( LANDREAD_STUB ) + list( APPEND PROJECT_COMPILE_DEFINITIONS LANDREAD_STUB ) endif() if ( ${USE_ALLOCATABLES} ) - add_compile_definitions( USE_ALLOCATABLES ) + list( APPEND PROJECT_COMPILE_DEFINITIONS USE_ALLOCATABLES ) endif() if ( ${wrfmodel} ) - add_compile_definitions( wrfmodel ) + list( APPEND PROJECT_COMPILE_DEFINITIONS wrfmodel ) endif() if ( ${GRIB1} ) - add_compile_definitions( GRIB1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS GRIB1 ) endif() if ( ${INTIO} ) - add_compile_definitions( INTIO ) + list( APPEND PROJECT_COMPILE_DEFINITIONS INTIO ) endif() if ( ${KEEP_INT_AROUND} ) - add_compile_definitions( KEEP_INT_AROUND ) + list( APPEND PROJECT_COMPILE_DEFINITIONS KEEP_INT_AROUND ) endif() if ( ${LIMIT_ARGS} ) - add_compile_definitions( LIMIT_ARGS ) + list( APPEND PROJECT_COMPILE_DEFINITIONS LIMIT_ARGS ) endif() if ( ${BUILD_RRTMG_FAST} ) - add_compile_definitions( BUILD_RRTMG_FAST=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_RRTMG_FAST=1 ) else() - add_compile_definitions( BUILD_RRTMG_FAST=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_RRTMG_FAST=0 ) endif() if ( ${BUILD_RRTMK} ) - add_compile_definitions( BUILD_RRTMK=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_RRTMK=1 ) else() - add_compile_definitions( BUILD_RRTMK=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_RRTMK=0 ) endif() if ( ${BUILD_SBM_FAST} ) - add_compile_definitions( BUILD_SBM_FAST=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_SBM_FAST=1 ) else() - add_compile_definitions( BUILD_SBM_FAST=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_SBM_FAST=0 ) endif() if ( ${SHOW_ALL_VARS_USED} ) - add_compile_definitions( SHOW_ALL_VARS_USED=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS SHOW_ALL_VARS_USED=1 ) else() - add_compile_definitions( SHOW_ALL_VARS_USED=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS SHOW_ALL_VARS_USED=0 ) endif() if ( ${NMM_CORE} ) - add_compile_definitions( NMM_CORE=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS NMM_CORE=1 ) else() - add_compile_definitions( NMM_CORE=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS NMM_CORE=0 ) endif() if ( "${WRF_CORE}" STREQUAL "PLUS" ) - add_compile_definitions( WRFPLUS=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRFPLUS=1 ) else() - add_compile_definitions( WRFPLUS=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS WRFPLUS=0 ) endif() if ( "${WRF_CORE}" STREQUAL "DA_CORE" OR "${WRF_CORE}" STREQUAL "DA_4D_VAR" ) - add_compile_definitions( DA_CORE=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS DA_CORE=1 ) else() - add_compile_definitions( DA_CORE=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS DA_CORE=0 ) endif() # DFI_RADAR=$ # Nesting options if ( ${MOVE_NESTS} ) - add_compile_definitions( MOVE_NESTS ) + list( APPEND PROJECT_COMPILE_DEFINITIONS MOVE_NESTS ) endif() if ( "${WRF_NESTING}" STREQUAL "VORTEX" ) - add_compile_definitions( VORTEX_CENTER ) + list( APPEND PROJECT_COMPILE_DEFINITIONS VORTEX_CENTER ) endif() # Configuration checks if ( NOT ${Fortran_2003_IEEE} ) - add_compile_definitions( NO_IEEE_MODULE ) + list( APPEND PROJECT_COMPILE_DEFINITIONS NO_IEEE_MODULE ) endif() if ( NOT ${Fortran_2003_ISO_C} ) - add_compile_definitions( NO_ISO_C_SUPPORT ) + list( APPEND PROJECT_COMPILE_DEFINITIONS NO_ISO_C_SUPPORT ) endif() # If flush fails, check if we can fall back to fflush, and if not no support if ( NOT ${Fortran_2003_FLUSH} ) if ( "${Fortran_2003_FFLUSH}" ) - add_compile_definitions( USE_FFLUSH ) + list( APPEND PROJECT_COMPILE_DEFINITIONS USE_FFLUSH ) else() - add_compile_definitions( NO_FLUSH_SUPPORT ) + list( APPEND PROJECT_COMPILE_DEFINITIONS NO_FLUSH_SUPPORT ) endif() endif() if ( NOT ${Fortran_2003_GAMMA} ) - add_compile_definitions( NO_GAMMA_SUPPORT ) + list( APPEND PROJECT_COMPILE_DEFINITIONS NO_GAMMA_SUPPORT ) endif() #!TODO Leaving as is in WRF for now but investigate why we don't do this # https://stackoverflow.com/a/1035713 # If fseeko64 succeeds, use that, else check if we can fall back to fseeko, and if not just use fseek -if ( NOT ${FSEEKO64} ) - add_compile_definitions( FSEEKO64_OK ) +if ( ${FSEEKO64} ) + list( APPEND PROJECT_COMPILE_DEFINITIONS FSEEKO64_OK ) elseif( "${FSEEKO}" ) - add_compile_definitions( FSEEKO_OK ) + list( APPEND PROJECT_COMPILE_DEFINITIONS FSEEKO_OK ) else() - add_compile_definitions( FSEEK_OK ) + list( APPEND PROJECT_COMPILE_DEFINITIONS FSEEK_OK ) endif() # I don't believe these are used anymore... @@ -808,6 +811,19 @@ add_library( STATIC ) +target_compile_options( + ${PROJECT_NAME}_Core + PRIVATE + ${PROJECT_COMPILE_OPTIONS} + ) + + +target_compile_definitions( + ${PROJECT_NAME}_Core + PRIVATE + ${PROJECT_COMPILE_DEFINITIONS} + ) + # Supplemental to core, or rather should be, some stuff in external is legitimately part of WRF and others # are source code from truly external repositories - albeit old versions add_subdirectory( external ) diff --git a/chem/CMakeLists.txt b/chem/CMakeLists.txt index 9bfbf3d5ac..544b253256 100644 --- a/chem/CMakeLists.txt +++ b/chem/CMakeLists.txt @@ -223,4 +223,17 @@ target_link_libraries( convert_emiss PRIVATE ${PROJECT_NAME}_Core - ) \ No newline at end of file + ) + +target_compile_options( + convert_emiss + PRIVATE + ${PROJECT_COMPILE_OPTIONS} + ) + + +target_compile_definitions( + convert_emiss + PRIVATE + ${PROJECT_COMPILE_DEFINITIONS} + ) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 7036a9debe..e52b1c3fbf 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -20,6 +20,10 @@ # Always build +# Suffice it to say everything under this is WRF-specific while also being external +add_compile_options ( "${PROJECT_COMPILE_OPTIONS}" ) +add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" ) + add_subdirectory( io_int ) add_subdirectory( io_grib1 ) add_subdirectory( io_grib_share ) diff --git a/external/io_adios2/CMakeLists.txt b/external/io_adios2/CMakeLists.txt index dde531a716..2d8efd61e0 100644 --- a/external/io_adios2/CMakeLists.txt +++ b/external/io_adios2/CMakeLists.txt @@ -33,14 +33,13 @@ target_include_directories( ${FOLDER_COMPILE_TARGET} # First preprocess -get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS ) get_target_property ( FOLDER_COMPILE_TARGET_INCLUDES ${FOLDER_COMPILE_TARGET} INCLUDE_DIRECTORIES ) wrf_c_preproc_fortran( TARGET_NAME ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/preproc/ EXTENSION ".f90" INCLUDES ${FOLDER_COMPILE_TARGET_INCLUDES} - DEFINITIONS ${DIR_DEFS} + DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS} SOURCES wrf_io.F90 ) diff --git a/external/io_netcdf/CMakeLists.txt b/external/io_netcdf/CMakeLists.txt index ac93792869..b63a1ae474 100644 --- a/external/io_netcdf/CMakeLists.txt +++ b/external/io_netcdf/CMakeLists.txt @@ -47,14 +47,13 @@ target_include_directories( # First preprocess -get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS ) get_target_property ( FOLDER_COMPILE_TARGET_INCLUDES ${FOLDER_COMPILE_TARGET} INCLUDE_DIRECTORIES ) wrf_c_preproc_fortran( TARGET_NAME ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/preproc/ EXTENSION ".f90" INCLUDES ${FOLDER_COMPILE_TARGET_INCLUDES} - DEFINITIONS ${DIR_DEFS} + DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS} SOURCES wrf_io.F90 ) diff --git a/external/io_netcdfpar/CMakeLists.txt b/external/io_netcdfpar/CMakeLists.txt index 8a0db9b9c9..9536023c58 100644 --- a/external/io_netcdfpar/CMakeLists.txt +++ b/external/io_netcdfpar/CMakeLists.txt @@ -47,14 +47,13 @@ target_include_directories( # First preprocess -get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS ) get_target_property ( FOLDER_COMPILE_TARGET_INCLUDES ${FOLDER_COMPILE_TARGET} INCLUDE_DIRECTORIES ) wrf_c_preproc_fortran( TARGET_NAME ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/preproc/ EXTENSION ".f90" INCLUDES ${FOLDER_COMPILE_TARGET_INCLUDES} - DEFINITIONS ${DIR_DEFS} + DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS} SOURCES wrf_io.F90 ) diff --git a/external/io_pnetcdf/CMakeLists.txt b/external/io_pnetcdf/CMakeLists.txt index 1717f71383..8c7c138233 100644 --- a/external/io_pnetcdf/CMakeLists.txt +++ b/external/io_pnetcdf/CMakeLists.txt @@ -35,14 +35,13 @@ target_include_directories( ${FOLDER_COMPILE_TARGET} # First preprocess -get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS ) get_target_property ( FOLDER_COMPILE_TARGET_INCLUDES ${FOLDER_COMPILE_TARGET} INCLUDE_DIRECTORIES ) wrf_c_preproc_fortran( TARGET_NAME ${FOLDER_COMPILE_TARGET}_c_preproc_wrf_io OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/preproc/ EXTENSION ".f90" INCLUDES ${FOLDER_COMPILE_TARGET_INCLUDES} - DEFINITIONS ${DIR_DEFS} + DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS} SOURCES wrf_io.F90 ) diff --git a/frame/CMakeLists.txt b/frame/CMakeLists.txt index 59f8d2551b..c322d84c9a 100644 --- a/frame/CMakeLists.txt +++ b/frame/CMakeLists.txt @@ -14,7 +14,6 @@ set( # Generate all the combinations dynamically, not a fan of this file breakdown ######################################################################################################################## set( nl_dyn_source ) -get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS ) foreach( n RANGE 0 7 ) wrf_c_preproc_fortran( @@ -25,7 +24,7 @@ foreach( n RANGE 0 7 ) INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/inc DEPENDENCIES registry_code - DEFINITIONS ${DIR_DEFS} NNN=${n} NL_set_ROUTINES + DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS} NNN=${n} NL_set_ROUTINES SOURCES nl_access_routines.F ) wrf_c_preproc_fortran( @@ -36,7 +35,7 @@ foreach( n RANGE 0 7 ) INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/inc DEPENDENCIES registry_code - DEFINITIONS ${DIR_DEFS} NNN=${n} NL_get_ROUTINES + DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS} NNN=${n} NL_get_ROUTINES SOURCES nl_access_routines.F ) @@ -166,4 +165,4 @@ set_source_files_properties( install( FILES ${WRF_INCLUDE_FILES} DESTINATION include/${FOLDER_COMPILE_TARGET} - ) \ No newline at end of file + ) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 9a2f69eca6..b0ec69d7f0 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,6 +1,9 @@ # WRF CMake Build set( FOLDER_COMPILE_TARGETS ) +add_compile_options ( "${PROJECT_COMPILE_OPTIONS}" ) +add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" ) + # First make true executables if ( ${WRF_CORE} STREQUAL "PLUS" ) add_executable( diff --git a/phys/CMakeLists.txt b/phys/CMakeLists.txt index d7d85e1c12..d3df6a28e0 100644 --- a/phys/CMakeLists.txt +++ b/phys/CMakeLists.txt @@ -5,14 +5,13 @@ # Quickly preprocess some files so that cmake can understand the module dependencies # ######################################################################################################################## -get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS ) wrf_c_preproc_fortran( TARGET_NAME module_ra_rrtmg_preproc OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/preproc/ EXTENSION ".f90" INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} DEPENDENCIES registry_code - DEFINITIONS ${DIR_DEFS} + DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS} SOURCES module_ra_rrtmg_lwk.F module_ra_rrtmg_lwf.F module_ra_rrtmg_swk.F diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 1181ab0af4..a261177f1a 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,4 +1,6 @@ # WRF CMake Build +add_compile_options ( "${PROJECT_COMPILE_OPTIONS}" ) +add_compile_definitions( "${PROJECT_COMPILE_DEFINITIONS}" ) #!TODO ORGANIZE THIS FOLDER set( FOLDER_COMPILE_TARGET registry ) @@ -99,10 +101,9 @@ elseif ( ${WRF_CORE} STREQUAL "DA" OR ${WRF_CORE} STREQUAL "DA_4D_VAR" ) endif() -get_directory_property( DIR_DEFS DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS ) wrf_expand_definitions( RESULT_VAR REGISTRY_DEFS - DEFINITIONS ${DIR_DEFS} + DEFINITIONS ${PROJECT_COMPILE_DEFINITIONS} ) # How this is not a bigger thing or not resolved is beyond me From 6b9d27ea71fe9a544d2a2f0136716e78821d1679 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Tue, 30 Jul 2024 16:20:31 -0700 Subject: [PATCH 04/13] Make sure hydro gets all the flags similar to original cmake build --- hydro/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hydro/CMakeLists.txt b/hydro/CMakeLists.txt index ee756e71ac..63f6f59bf0 100644 --- a/hydro/CMakeLists.txt +++ b/hydro/CMakeLists.txt @@ -1,4 +1,6 @@ # additions that WRF-Hydro's top CMakeLists.txt handles +add_compile_options( ${PROJECT_COMPILE_OPTIONS} ) +add_compile_definitions( ${PROJECT_COMPILE_DEFINITIONS} ) set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/hydro/mods) add_definitions(-DMPP_LAND) if (WRF_HYDRO_NUDGING STREQUAL "1") From 4dda1098f96384309a466b8d8b376e71d4ea5958 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Wed, 31 Jul 2024 17:47:42 -0700 Subject: [PATCH 05/13] Prepare cmake build to not have core selection --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bdbbdaf32..4f42c8f374 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,6 +127,9 @@ set( WRF_CASE_OPTIONS EM_CONVRAD EM_SQUALL2D_X EM_SQUALL2D_Y + + # No case selected, for situations where we are not compiling ARW + NONE ) set( WRF_CASE "" CACHE STRING "WRF_CASE" ) From bee8ddd2075a80305cf1c9e9f6045522307f2cba Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Wed, 31 Jul 2024 17:48:44 -0700 Subject: [PATCH 06/13] Make sure appropriate selection of option for non-ARW cores --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f42c8f374..70e1a06f91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,6 +223,11 @@ if ( NOT ${WRF_CORE} IN_LIST WRF_CORE_OPTIONS ) message( FATAL_ERROR "WRF Core option not recognized : ${WRF_CORE}" ) endif() +if ( NOT ${WRF_CORE} STREQUAL "ARW" ) + message( STATUS "All non-ARW Cores requires using pointers in grid state struct" ) + set( USE_ALLOCATABLES OFF CACHE BOOL "Required by configuration" FORCE ) +endif() + if ( NOT ${WRF_NESTING} IN_LIST WRF_NESTING_OPTIONS ) message( FATAL_ERROR "WRF Nesting option not recognized : ${WRF_NESTING}" ) endif() From 4e30de19ea998be194979d6ab91ce96b3045a5e3 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Wed, 31 Jul 2024 17:49:02 -0700 Subject: [PATCH 07/13] Shortcut selections for other cores --- arch/configure_reader.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/configure_reader.py b/arch/configure_reader.py index fb89bfca80..2668a86f1f 100755 --- a/arch/configure_reader.py +++ b/arch/configure_reader.py @@ -575,8 +575,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" ] From 5598e7c314626883567cc9d76215187c0c7225f5 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Wed, 31 Jul 2024 17:54:07 -0700 Subject: [PATCH 08/13] Generalize the sanitization logic for stanzas --- arch/configure_reader.py | 52 ++++------------------------------------ 1 file changed, 5 insertions(+), 47 deletions(-) diff --git a/arch/configure_reader.py b/arch/configure_reader.py index 2668a86f1f..98f758e0b8 100755 --- a/arch/configure_reader.py +++ b/arch/configure_reader.py @@ -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(): @@ -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 From 96930f52e5596256f13ae8bca9b171d453c6877d Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Mon, 29 Jul 2024 18:42:50 -0700 Subject: [PATCH 09/13] Create properties for flag and defines organization --- CMakeLists.txt | 25 +++++++ cmake/target_source_properties.cmake | 107 +++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 cmake/target_source_properties.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 70e1a06f91..7321125eb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,12 +26,15 @@ list( APPEND CMAKE_C_PREPROCESSOR_FLAGS -P -nostdinc -traditional ) include( CMakePackageConfigHelpers ) include( CheckIPOSupported ) + +# WRF helper scripts include( c_preproc ) include( m4_preproc ) include( target_copy ) include( confcheck ) include( gitinfo ) include( printOption ) +include( target_source_properties ) include( wrf_case_setup ) include( wrf_get_version ) @@ -311,6 +314,28 @@ if ( ${USE_IPO} ) endif() endif() + +################################################################################ +## +## Create our flags / defines properties and variables to carry our information +## +################################################################################ +define_target_source_properties( + PROPERTIES + FLAGS_OPTIMIZATION # Control of optimization flags + FLAGS_CONFCHECK # Originate from system configuration checks + FLAGS_Fortran_PRECISION # Fortran floating point precision control + FLAGS_Fortran_LINE_LENGTH # Fortran line length for compilers that need it + FLAGS_DIAGNOSTICS # Extra flags for diagnostics + FLAGS_SUPPRESS_ERRORS # EXPLICITLY suppress errors, USE SPARINGLY!!! + FLAGS_SUPPRESS_WARNINGS # Suppress warnings, try to fix before they become errs + FLAGS_STANZA # Any remaining flags imported via stanza + + DEFINE_CONFCHECK # Originate from system configuration checks + DEFINE_OPTIONS # Anything that is derived from options + DEFINE_STANZA # Any remaining defines imported via stanza + ) + ################################################################################ ## ## Now find packages that cross-compilation is potentially handled diff --git a/cmake/target_source_properties.cmake b/cmake/target_source_properties.cmake new file mode 100644 index 0000000000..c6ce9d4d00 --- /dev/null +++ b/cmake/target_source_properties.cmake @@ -0,0 +1,107 @@ +# +# These two functions together allow greater control of propagating flags within +# a target on a per-source basis with the ability to "inherit" those properties +# from the target if not set. This allows a target to defing its own flags, but +# then if a file needs different settings those can be directly overridden without +# relying on compiler-specific flag order precedence. Additionally this allows a +# project to organize grouping of flags within a target +# + + +# +# A simple function to create properties for targets and sources quickly +# +function( define_target_source_properties ) + set( options ) + set( oneValueArgs ) + set( multiValueArgs PROPERTIES ) + + cmake_parse_arguments( + FUNC_PROP + "${options}" "${oneValueArgs}" "${multiValueArgs}" + ${ARGN} + ) + + foreach( PROPERTY ${FUNC_PROP_PROPERTIES} ) + define_property( + SOURCE + PROPERTY ${PROPERTY} + # INHERITED # they will be "inherited" via target to source + ) + + define_property( + TARGET + PROPERTY ${PROPERTY} + # INHERITED # they will be "inherited" via target to source + ) + endforeach() +endfunction() + + +# +# The bulk of the functionality exists in this function. It will loop over each +# provided target, gathering sources and their respective properties listed, using +# the target's property if not defined for this source else nothing, and finally +# applies it to that source. +# +function( apply_target_source_properties ) + set( options ) + set( oneValueArgs AS_PROPERTY ) + set( multiValueArgs TARGETS PROPERTIES ) + + cmake_parse_arguments( + FUNC_PROP + "${options}" "${oneValueArgs}" "${multiValueArgs}" + ${ARGN} + ) + + foreach( TARGET ${FUNC_PROP_TARGETS} ) + # get target sources + get_target_property( TARGET_SOURCES ${TARGET} SOURCES ) + + # get default "inherited" value from target + foreach( PROPERTY ${FUNC_PROP_PROPERTIES} ) + get_target_property( TARGET_PROPERTY_${PROPERTY} ${TARGET} ${PROPERTY} ) + if ( "${TARGET_PROPERTY_${PROPERTY}}" STREQUAL "TARGET_PROPERTY_${PROPERTY}-NOTFOUND" ) + # unset it + set( TARGET_PROPERTY_${PROPERTY} ) + endif() + endforeach() + + foreach( SOURCE ${TARGET_SOURCES} ) + + # We need to accumulate properties since a call to set property will + # override what was there before + set( SOURCE_PROPERTY_ALL ) + + foreach( PROPERTY ${FUNC_PROP_PROPERTIES} ) + # first try source + get_source_file_property( + SOURCE_PROPERTY_${PROPERTY} + ${SOURCE} + TARGET_DIRECTORY ${TARGET} + ${PROPERTY} + ) + if ( "${SOURCE_PROPERTY_${PROPERTY}}" STREQUAL "NOTFOUND" ) + # use target + set( SOURCE_PROPERTY_${PROPERTY} ${TARGET_PROPERTY_${PROPERTY}} ) + endif() + + # Now apply these as prop + if ( NOT "${SOURCE_PROPERTY_${PROPERTY}}" STREQUAL "" ) + list( APPEND SOURCE_PROPERTY_ALL ${SOURCE_PROPERTY_${PROPERTY}} ) + endif() + endforeach() # properties + + # Apply properties to source + if ( NOT "${SOURCE_PROPERTY_ALL}" STREQUAL "" ) + set_source_files_properties( + ${SOURCE} + TARGET_DIRECTORY ${TARGET} + PROPERTIES + ${FUNC_PROP_AS_PROPERTY} ${SOURCE_PROPERTY_ALL} + ) + endif() + endforeach() # sources + endforeach() # targets +endfunction() \ No newline at end of file From 0203d612bdda8e7bdf6378cb44c0cb5373f9ea6a Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Wed, 31 Jul 2024 17:35:01 -0700 Subject: [PATCH 10/13] Fine-tuned control of compile flags --- CMakeLists.txt | 340 ++++++++++++++++----------- arch/configure_reader.py | 3 +- cmake/target_source_properties.cmake | 49 +++- cmake/template/arch_config.cmake | 21 +- frame/CMakeLists.txt | 2 +- 5 files changed, 257 insertions(+), 158 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7321125eb1..d5fa55a4a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -322,20 +322,43 @@ endif() ################################################################################ define_target_source_properties( PROPERTIES - FLAGS_OPTIMIZATION # Control of optimization flags - FLAGS_CONFCHECK # Originate from system configuration checks - FLAGS_Fortran_PRECISION # Fortran floating point precision control - FLAGS_Fortran_LINE_LENGTH # Fortran line length for compilers that need it - FLAGS_DIAGNOSTICS # Extra flags for diagnostics - FLAGS_SUPPRESS_ERRORS # EXPLICITLY suppress errors, USE SPARINGLY!!! - FLAGS_SUPPRESS_WARNINGS # Suppress warnings, try to fix before they become errs - FLAGS_STANZA # Any remaining flags imported via stanza + COMPILE_OPTIONS_OPTIMIZATION # Control of optimization flags + COMPILE_OPTIONS_CONFCHECK # Originate from system configuration checks + COMPILE_OPTIONS_OPTIONS # Derived from options + COMPILE_OPTIONS_Fortran_PRECISION # Fortran floating point precision control + COMPILE_OPTIONS_Fortran_LINE_LENGTH # Fortran line length for compilers that need it + COMPILE_OPTIONS_DIAGNOSTICS # Extra flags for diagnostics + COMPILE_OPTIONS_SUPPRESS_ERRORS # EXPLICITLY suppress errors, USE SPARINGLY!!! + COMPILE_OPTIONS_SUPPRESS_WARNINGS # Suppress warnings, try to fix before they become errs + COMPILE_OPTIONS_STANZA # Any remaining flags imported via stanza - DEFINE_CONFCHECK # Originate from system configuration checks - DEFINE_OPTIONS # Anything that is derived from options - DEFINE_STANZA # Any remaining defines imported via stanza + COMPILE_DEFINITIONS_CONFCHECK # Originate from system configuration checks + COMPILE_DEFINITIONS_OPTIONS # Anything that is derived from options + COMPILE_DEFINITIONS_STANZA # Any remaining defines imported via stanza ) +# These will be the cumulative set for quicker reference +set( PROJECT_COMPILE_OPTIONS "" ) +set( PROJECT_COMPILE_DEFINITIONS "" ) + +# Recreate these as project variables so that they may be re-used generically +set( PROJECT_COMPILE_OPTIONS_OPTIMIZATION "" ) +set( PROJECT_COMPILE_OPTIONS_CONFCHECK "" ) +set( PROJECT_COMPILE_OPTIONS_OPTIONS "" ) +set( PROJECT_COMPILE_OPTIONS_Fortran_PRECISION "" ) +set( PROJECT_COMPILE_OPTIONS_Fortran_LINE_LENGTH "" ) +set( PROJECT_COMPILE_OPTIONS_DIAGNOSTICS "" ) +set( PROJECT_COMPILE_OPTIONS_SUPPRESS_ERRORS "" ) +set( PROJECT_COMPILE_OPTIONS_SUPPRESS_WARNINGS "" ) +set( PROJECT_COMPILE_OPTIONS_STANZA "" ) +set( PROJECT_COMPILE_DEFINITIONS_CONFCHECK "" ) +set( PROJECT_COMPILE_DEFINITIONS_OPTIONS "" ) +set( PROJECT_COMPILE_DEFINITIONS_STANZA ${WRF_ARCH_LOCAL} ) + +# Make these imported variables easier to use in genexp +separate_arguments( WRF_FCOPTIM ) +separate_arguments( WRF_FCNOOPT ) + ################################################################################ ## ## Now find packages that cross-compilation is potentially handled @@ -355,19 +378,19 @@ if ( ${USE_MPI} ) # It still technically finds MPI but the output is nonintuitive # saying things like hdf5 or pthread find_package( MPI REQUIRED COMPONENTS Fortran C ) - list( APPEND PROJECT_COMPILE_DEFINITIONS + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS USE_MPI=1 DM_PARALLEL ) if ( DEFINED WRF_MPI_Fortran_FLAGS AND NOT "${WRF_MPI_Fortran_FLAGS}" STREQUAL "" ) - list( APPEND PROJECT_COMPILE_OPTIONS + list( APPEND PROJECT_COMPILE_OPTIONS_OPTIONS $<$:${WRF_MPI_Fortran_FLAGS}> ) endif() if ( DEFINED WRF_MPI_C_FLAGS AND NOT "${WRF_MPI_C_FLAGS}" STREQUAL "" ) - list( APPEND PROJECT_COMPILE_OPTIONS + list( APPEND PROJECT_COMPILE_OPTIONS_OPTIONS $<$:${WRF_MPI_C_FLAGS}> ) endif() @@ -398,7 +421,7 @@ if ( ${USE_MPI} ) set( USE_RSL_LITE ON ) # We know NONE is the zero index so compare against that elseif( ${CURRENT_NESTING_IDX} GREATER 0 ) - list( APPEND PROJECT_COMPILE_DEFINITIONS + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS DM_PARALLEL STUBMPI ) @@ -407,7 +430,7 @@ endif() if ( ${USE_OPENMP} ) find_package( OpenMP REQUIRED COMPONENTS Fortran C ) - list( APPEND PROJECT_COMPILE_DEFINITIONS + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS USE_OPENMP=1 SM_PARALLEL ) @@ -540,44 +563,18 @@ add_subdirectory( confcheck ) ## ################################################################################ -# https://stackoverflow.com/a/47927921 -# Define compile options to be inherited for directories -define_property( - SOURCE - PROPERTY COMPILE_FLAGS - INHERITED - BRIEF_DOCS "brief-doc" - FULL_DOCS "full-doc" - ) - -define_property( - DIRECTORY - PROPERTY COMPILE_FLAGS - INHERITED - BRIEF_DOCS "brief-doc" - FULL_DOCS "full-doc" - ) - # Get current build type flags and put them in there if ( "${CMAKE_BUILD_TYPE}" STREQUAL "Release" ) - set_directory_properties( - PROPERTIES - COMPILE_FLAGS - $<$:${WRF_FCOPTIM}> - ) + set( PROJECT_COMPILE_OPTIONS_OPTIMIZATION $<$:${WRF_FCOPTIM}> ) # else() # # Assume no optimization -# set_directory_properties( -# PROPERTIES -# COMPILE_FLAGS -# $<$:${WRF_FCNOOPT}> -# ) +# set( PROJECT_COMPILE_OPTIONS_OPTIMIZATION $<$:${WRF_FCNOOPT}> ) endif() # This is really ugly but such is the cost of supporting many ways to say the same thing # https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html -list( APPEND PROJECT_COMPILE_OPTIONS +list( APPEND PROJECT_COMPILE_OPTIONS_Fortran_PRECISION # Use "" and ; specifically to evaluate correctly # "$<$:>" #@ Absoft Fortran # "$<$:>" #@ Analog VisualDSP++ @@ -617,7 +614,9 @@ list( APPEND PROJECT_COMPILE_OPTIONS # "$<$:>" #@ IBM LLVM-based Compiler # Todo find how to handle default selection or add new compiler IDs # unknown how to add support for sxf90 + ) +list( APPEND PROJECT_COMPILE_OPTIONS_Fortran_LINE_LENGTH # line lengths "$<$:-ffree-line-length-none>" #@ GNU Compiler Collection ) @@ -628,24 +627,23 @@ list( APPEND PROJECT_COMPILE_OPTIONS # message( STATUS "Set Fortran_COMPILER_ID to : ${Fortran_COMPILER_ID}" ) -# Whole project flags -list( APPEND PROJECT_COMPILE_OPTIONS - # $<$:-cpp> +list( APPEND PROJECT_COMPILE_OPTIONS_SUPPRESS_WARNINGS # Use "" and ; specifically to evaluate correctly "$<$:-diag-disable;6843>" + ) + +list( APPEND PROJECT_COMPILE_OPTIONS_SUPPRESS_ERRORS $<$,$>:-fallow-argument-mismatch> $<$,$>:-fallow-invalid-boz> $<$,$>:-ffree-line-length-none> - - # $,$:-diag-disable;6843> ) if ( ${PROFILE_COMPILATION} ) message( STATUS "Attemping to add compilation profiling..." ) - list( APPEND PROJECT_COMPILE_OPTIONS $<$:-ftime-report> ) + list( APPEND PROJECT_COMPILE_OPTIONS_DIAGNOSTICS $<$:-ftime-report> ) endif() -list( APPEND PROJECT_COMPILE_DEFINITIONS +list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS MAX_DOMAINS_F=${MAX_DOMAINS_F} CONFIG_BUF_LEN=${CONFIG_BUF_LEN} MAX_HISTORY=${MAX_HISTORY} @@ -671,56 +669,56 @@ list( APPEND PROJECT_COMPILE_DEFINITIONS # in code since cmake cannot handle basically any others :( # https://gitlab.kitware.com/cmake/cmake/-/issues/17398 if ( ${ENABLE_CHEM} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_CHEM=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_CHEM=1 ) if ( ${ENABLE_KPP} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_KPP=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_KPP=1 ) endif() endif() if ( ${ENABLE_CHEM} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_CHEM=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS BUILD_CHEM=1 ) endif() if ( ${ENABLE_CMAQ} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_CMAQ=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_CMAQ=1 ) endif() if ( ${ENABLE_DFI_RADAR} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_DFI_RADAR=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_DFI_RADAR=1 ) endif() if ( ${ENABLE_TITAN} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_TITAN=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_TITAN=1 ) endif() if ( ${ENABLE_MARS} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_MARS=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_MARS=1 ) endif() if ( ${ENABLE_VENUS} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_VENUS=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_VENUS=1 ) endif() if ( ${ENABLE_HYDRO} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_HYDRO=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_HYDRO=1 ) endif() # Because once again we need two defines to control one thing if ( ${ENABLE_CTSM} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_USE_CTSM ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_USE_CTSM ) else() #!TODO there are some files that rely on this being 1, but that is never set by the legacy make system - list( APPEND PROJECT_COMPILE_DEFINITIONS WRF_USE_CLM ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRF_USE_CLM ) endif() # If force classic or no nc-4 support enable classic if ( ${FORCE_NETCDF_CLASSIC} OR ( NOT ${netCDF_NC4} ) ) - list( APPEND PROJECT_COMPILE_DEFINITIONS NETCDF_classic=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS NETCDF_classic=1 ) endif() if ( ${WRFIO_NCD_NO_LARGE_FILE_SUPPORT} OR ( NOT ${netCDF_LARGE_FILE_SUPPORT} ) ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRFIO_NCD_NO_LARGE_FILE_SUPPORT=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRFIO_NCD_NO_LARGE_FILE_SUPPORT=1 ) endif() # May need a check for WRFIO_ncdpar_LARGE_FILE_SUPPORT # Now set the opposite in different defines, because why not :) if ( ( NOT ${FORCE_NETCDF_CLASSIC} ) AND ${netCDF_NC4} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS USE_NETCDF4_FEATURES=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS USE_NETCDF4_FEATURES=1 ) endif() if ( ( NOT ${WRFIO_NCD_NO_LARGE_FILE_SUPPORT} ) AND ${netCDF_LARGE_FILE_SUPPORT} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRFIO_NCD_LARGE_FILE_SUPPORT=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRFIO_NCD_LARGE_FILE_SUPPORT=1 ) endif() # Could simplify logic to just check if RPC is available but to be explicit @@ -728,115 +726,139 @@ endif() # not enable terran or not rpc_found do # not ( enable terrain and rpc_found ) # if ( NOT ( ${ENABLE_TERRAIN} AND ${RPC_FOUND} ) ) # this is wrong, needs fixing -# list( APPEND PROJECT_COMPILE_DEFINITIONS LANDREAD_STUB ) +# list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS LANDREAD_STUB ) # endif() if ( ${ENABLE_TERRAIN} AND ${MOVE_NESTS} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS TERRAIN_AND_LANDUSE ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS TERRAIN_AND_LANDUSE ) else () - list( APPEND PROJECT_COMPILE_DEFINITIONS LANDREAD_STUB ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS LANDREAD_STUB ) endif() if ( ${USE_ALLOCATABLES} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS USE_ALLOCATABLES ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS USE_ALLOCATABLES ) endif() if ( ${wrfmodel} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS wrfmodel ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS wrfmodel ) endif() if ( ${GRIB1} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS GRIB1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS GRIB1 ) endif() if ( ${INTIO} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS INTIO ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS INTIO ) endif() if ( ${KEEP_INT_AROUND} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS KEEP_INT_AROUND ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS KEEP_INT_AROUND ) endif() if ( ${LIMIT_ARGS} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS LIMIT_ARGS ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS LIMIT_ARGS ) endif() if ( ${BUILD_RRTMG_FAST} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_RRTMG_FAST=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS BUILD_RRTMG_FAST=1 ) else() - list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_RRTMG_FAST=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS BUILD_RRTMG_FAST=0 ) endif() if ( ${BUILD_RRTMK} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_RRTMK=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS BUILD_RRTMK=1 ) else() - list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_RRTMK=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS BUILD_RRTMK=0 ) endif() if ( ${BUILD_SBM_FAST} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_SBM_FAST=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS BUILD_SBM_FAST=1 ) else() - list( APPEND PROJECT_COMPILE_DEFINITIONS BUILD_SBM_FAST=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS BUILD_SBM_FAST=0 ) endif() if ( ${SHOW_ALL_VARS_USED} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS SHOW_ALL_VARS_USED=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS SHOW_ALL_VARS_USED=1 ) else() - list( APPEND PROJECT_COMPILE_DEFINITIONS SHOW_ALL_VARS_USED=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS SHOW_ALL_VARS_USED=0 ) endif() if ( ${NMM_CORE} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS NMM_CORE=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS NMM_CORE=1 ) else() - list( APPEND PROJECT_COMPILE_DEFINITIONS NMM_CORE=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS NMM_CORE=0 ) endif() if ( "${WRF_CORE}" STREQUAL "PLUS" ) - list( APPEND PROJECT_COMPILE_DEFINITIONS WRFPLUS=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRFPLUS=1 ) else() - list( APPEND PROJECT_COMPILE_DEFINITIONS WRFPLUS=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS WRFPLUS=0 ) endif() if ( "${WRF_CORE}" STREQUAL "DA_CORE" OR "${WRF_CORE}" STREQUAL "DA_4D_VAR" ) - list( APPEND PROJECT_COMPILE_DEFINITIONS DA_CORE=1 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS DA_CORE=1 ) else() - list( APPEND PROJECT_COMPILE_DEFINITIONS DA_CORE=0 ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS DA_CORE=0 ) endif() # DFI_RADAR=$ # Nesting options if ( ${MOVE_NESTS} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS MOVE_NESTS ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS MOVE_NESTS ) endif() if ( "${WRF_NESTING}" STREQUAL "VORTEX" ) - list( APPEND PROJECT_COMPILE_DEFINITIONS VORTEX_CENTER ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS VORTEX_CENTER ) endif() # Configuration checks if ( NOT ${Fortran_2003_IEEE} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS NO_IEEE_MODULE ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_CONFCHECK NO_IEEE_MODULE ) endif() if ( NOT ${Fortran_2003_ISO_C} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS NO_ISO_C_SUPPORT ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_CONFCHECK NO_ISO_C_SUPPORT ) endif() # If flush fails, check if we can fall back to fflush, and if not no support if ( NOT ${Fortran_2003_FLUSH} ) if ( "${Fortran_2003_FFLUSH}" ) - list( APPEND PROJECT_COMPILE_DEFINITIONS USE_FFLUSH ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_CONFCHECK USE_FFLUSH ) else() - list( APPEND PROJECT_COMPILE_DEFINITIONS NO_FLUSH_SUPPORT ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_CONFCHECK NO_FLUSH_SUPPORT ) endif() endif() if ( NOT ${Fortran_2003_GAMMA} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS NO_GAMMA_SUPPORT ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_CONFCHECK NO_GAMMA_SUPPORT ) endif() #!TODO Leaving as is in WRF for now but investigate why we don't do this # https://stackoverflow.com/a/1035713 # If fseeko64 succeeds, use that, else check if we can fall back to fseeko, and if not just use fseek if ( ${FSEEKO64} ) - list( APPEND PROJECT_COMPILE_DEFINITIONS FSEEKO64_OK ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_CONFCHECK FSEEKO64_OK ) elseif( "${FSEEKO}" ) - list( APPEND PROJECT_COMPILE_DEFINITIONS FSEEKO_OK ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_CONFCHECK FSEEKO_OK ) else() - list( APPEND PROJECT_COMPILE_DEFINITIONS FSEEK_OK ) + list( APPEND PROJECT_COMPILE_DEFINITIONS_CONFCHECK FSEEK_OK ) endif() # I don't believe these are used anymore... # $<$:MPI2_SUPPORT=$> # $<$:MPI2_THREAD_SUPPORT=$> +# Accumulate option and definitions +list( APPEND PROJECT_COMPILE_OPTIONS + ${PROJECT_COMPILE_OPTIONS_OPTIMIZATION} + ${PROJECT_COMPILE_OPTIONS_CONFCHECK} + ${PROJECT_COMPILE_OPTIONS_OPTIONS} + ${PROJECT_COMPILE_OPTIONS_Fortran_PRECISION} + ${PROJECT_COMPILE_OPTIONS_Fortran_LINE_LENGTH} + ${PROJECT_COMPILE_OPTIONS_DIAGNOSTICS} + ${PROJECT_COMPILE_OPTIONS_SUPPRESS_ERRORS} + ${PROJECT_COMPILE_OPTIONS_SUPPRESS_WARNINGS} + ${PROJECT_COMPILE_OPTIONS_STANZA} + ) +list( APPEND PROJECT_COMPILE_DEFINITIONS + ${PROJECT_COMPILE_DEFINITIONS_CONFCHECK} + ${PROJECT_COMPILE_DEFINITIONS_OPTIONS} + ${PROJECT_COMPILE_DEFINITIONS_STANZA} + ) + +################################################################################ +## +## DO NOT modify PROJECT_COMPILE_* beyond this point +## +################################################################################ + # Make core target add_library( @@ -844,18 +866,22 @@ add_library( STATIC ) -target_compile_options( - ${PROJECT_NAME}_Core - PRIVATE - ${PROJECT_COMPILE_OPTIONS} - ) - +set_target_properties( + ${PROJECT_NAME}_Core + PROPERTIES + COMPILE_OPTIONS_OPTIMIZATION "${PROJECT_COMPILE_OPTIONS_OPTIMIZATION}" + COMPILE_OPTIONS_CONFCHECK "${PROJECT_COMPILE_OPTIONS_CONFCHECK}" + COMPILE_OPTIONS_OPTIONS "${PROJECT_COMPILE_OPTIONS_OPTIONS}" + COMPILE_OPTIONS_Fortran_PRECISION "${PROJECT_COMPILE_OPTIONS_Fortran_PRECISION}" + COMPILE_OPTIONS_Fortran_LINE_LENGTH "${PROJECT_COMPILE_OPTIONS_Fortran_LINE_LENGTH}" + COMPILE_OPTIONS_DIAGNOSTICS "${PROJECT_COMPILE_OPTIONS_DIAGNOSTICS}" + COMPILE_OPTIONS_SUPPRESS_ERRORS "${PROJECT_COMPILE_OPTIONS_SUPPRESS_ERRORS}" + COMPILE_OPTIONS_SUPPRESS_WARNINGS "${PROJECT_COMPILE_OPTIONS_SUPPRESS_WARNINGS}" + COMPILE_OPTIONS_STANZA "${PROJECT_COMPILE_OPTIONS_STANZA}" + # We do not use compile definitions for CMake's lack of source file accounting + ) -target_compile_definitions( - ${PROJECT_NAME}_Core - PRIVATE - ${PROJECT_COMPILE_DEFINITIONS} - ) +# Do NOT apply these options or defines just yet, allow files to be added and set their own properties # Supplemental to core, or rather should be, some stuff in external is legitimately part of WRF and others # are source code from truly external repositories - albeit old versions @@ -868,6 +894,68 @@ add_dependencies( # So many things depend on this that I'm adding a dep here registry_code ) + +# Add directly to core +add_subdirectory( phys ) +add_subdirectory( share ) +add_subdirectory( frame ) +add_subdirectory( inc ) + +if ( ${WRF_CHEM} ) + add_subdirectory( chem ) +endif() + +if ( ${ENABLE_HYDRO} ) + add_subdirectory( hydro ) +endif() + +add_subdirectory( dyn_em ) + + +add_subdirectory( main ) + +################################################################################ +# Add subdirectory with case info +################################################################################ +if ( ${CURRENT_WRF_CORE_IDX} GREATER_EQUAL ${START_DA_IDX} ) + message( STATUS "DA or PLUS build, WRF_CASE selection ignored" ) +else() + add_subdirectory( test/${WRF_CASE_FOLDER} ) +endif() + + + +################################################################################ +## +## DO NOT add sources beyond this point +## +################################################################################ + +# gather compile info and apply +apply_target_source_properties( + TARGETS ${PROJECT_NAME}_Core + PROPERTIES + COMPILE_OPTIONS_OPTIMIZATION + COMPILE_OPTIONS_CONFCHECK + COMPILE_OPTIONS_OPTIONS + COMPILE_OPTIONS_Fortran_PRECISION + COMPILE_OPTIONS_Fortran_LINE_LENGTH + COMPILE_OPTIONS_DIAGNOSTICS + COMPILE_OPTIONS_SUPPRESS_ERRORS + COMPILE_OPTIONS_SUPPRESS_WARNINGS + COMPILE_OPTIONS_STANZA + AS_PROPERTY COMPILE_OPTIONS + ) + +target_compile_definitions( + ${PROJECT_NAME}_Core + PRIVATE + ${PROJECT_COMPILE_DEFINITIONS_CONFCHECK} + ${PROJECT_COMPILE_DEFINITIONS_OPTIONS} + ${PROJECT_COMPILE_DEFINITIONS_STANZA} + ) + + target_include_directories( ${PROJECT_NAME}_Core PUBLIC @@ -926,34 +1014,6 @@ target_include_directories( ${pnetCDF_INCLUDE_DIRS} ) -# Add directly to core -add_subdirectory( phys ) -add_subdirectory( share ) -add_subdirectory( frame ) -add_subdirectory( inc ) - -if ( ${WRF_CHEM} ) - add_subdirectory( chem ) -endif() - -if ( ${ENABLE_HYDRO} ) - add_subdirectory( hydro ) -endif() - -add_subdirectory( dyn_em ) - - -add_subdirectory( main ) - -################################################################################ -# Add subdirectory with case info -################################################################################ -if ( ${CURRENT_WRF_CORE_IDX} GREATER_EQUAL ${START_DA_IDX} ) - message( STATUS "DA or PLUS build, WRF_CASE selection ignored" ) -else() - add_subdirectory( test/${WRF_CASE_FOLDER} ) -endif() - # Configure core set_target_properties( ${PROJECT_NAME}_Core @@ -964,6 +1024,8 @@ set_target_properties( EXPORT_PROPERTIES Fortran_MODULE_DIRECTORY ) +target_link_options( ${PROJECT_NAME}_Core PRIVATE ${WRF_LINK_FLAGS} ) + # Because of the way netCDF provides its info and the way cmake auto-gens RPATH, we need to help it along target_link_directories( ${PROJECT_NAME}_Core diff --git a/arch/configure_reader.py b/arch/configure_reader.py index 98f758e0b8..c52d776af7 100755 --- a/arch/configure_reader.py +++ b/arch/configure_reader.py @@ -504,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"], @@ -587,4 +588,4 @@ def projectSpecificOptions( options, stanzaCfg ) : return additionalOptions if __name__ == '__main__' : - main() \ No newline at end of file + main() diff --git a/cmake/target_source_properties.cmake b/cmake/target_source_properties.cmake index c6ce9d4d00..55042a6263 100644 --- a/cmake/target_source_properties.cmake +++ b/cmake/target_source_properties.cmake @@ -6,6 +6,21 @@ # relying on compiler-specific flag order precedence. Additionally this allows a # project to organize grouping of flags within a target # +# Note that for compile defines on source files they are not used in the autogen +# dependency scanning. See : +# https://gitlab.kitware.com/cmake/cmake/-/issues/22519 +# and +# https://gitlab.kitware.com/cmake/cmake/-/blob/master/Source/cmDependsFortran.cxx#L84 +# functions cmDependsFortran::cmDependsFortran() and cmDependsFortran::WriteDependencies() +# +# The solution is to either use Ninja or preprocess the files (what Ninja internally does) +# This is probably the way to go as well since CMake native preprocessor directive +# parsing is... subpar and simplified : +# https://gitlab.kitware.com/cmake/cmake/-/issues/17398 +# +# Alternatively, set critical flags at the target level +# + # @@ -45,7 +60,7 @@ endfunction() # applies it to that source. # function( apply_target_source_properties ) - set( options ) + set( options DISCARD_PREVIOUS DEBUG ) set( oneValueArgs AS_PROPERTY ) set( multiValueArgs TARGETS PROPERTIES ) @@ -89,18 +104,38 @@ function( apply_target_source_properties ) # Now apply these as prop if ( NOT "${SOURCE_PROPERTY_${PROPERTY}}" STREQUAL "" ) + if ( ${FUNC_PROP_DEBUG} ) + message( STATUS "DEBUG : Adding '${SOURCE_PROPERTY_${PROPERTY}}' as SOURCE_PROPERTY_${PROPERTY}") + endif() list( APPEND SOURCE_PROPERTY_ALL ${SOURCE_PROPERTY_${PROPERTY}} ) endif() endforeach() # properties # Apply properties to source if ( NOT "${SOURCE_PROPERTY_ALL}" STREQUAL "" ) - set_source_files_properties( - ${SOURCE} - TARGET_DIRECTORY ${TARGET} - PROPERTIES - ${FUNC_PROP_AS_PROPERTY} ${SOURCE_PROPERTY_ALL} - ) + if ( NOT ${FUNC_PROP_DISCARD_PREVIOUS} ) + # get old value and append + get_source_file_property( + SOURCE_PROPERTY_ORIG + ${SOURCE} + TARGET_DIRECTORY ${TARGET} + ${FUNC_PROP_AS_PROPERTY} + ) + if ( "${SOURCE_PROPERTY_ORIG}" STREQUAL "NOTFOUND" ) + set( SOURCE_PROPERTY_ORIG ) + endif() + endif() + + if ( ${FUNC_PROP_DEBUG} ) + message( STATUS "DEBUG : ${FUNC_PROP_AS_PROPERTY} being set to '${SOURCE_PROPERTY_ORIG} ${SOURCE_PROPERTY_ALL}'") + endif() + + set_source_files_properties( + ${SOURCE} + TARGET_DIRECTORY ${TARGET} + PROPERTIES + ${FUNC_PROP_AS_PROPERTY} "${SOURCE_PROPERTY_ORIG};${SOURCE_PROPERTY_ALL}" + ) endif() endforeach() # sources endforeach() # targets diff --git a/cmake/template/arch_config.cmake b/cmake/template/arch_config.cmake index 42cba60287..0a655a4e32 100644 --- a/cmake/template/arch_config.cmake +++ b/cmake/template/arch_config.cmake @@ -15,15 +15,16 @@ set( CMAKE_Fortran_FLAGS_INIT "{SFC_FLAGS} {FCBASEOPTS} {BYTESWAPIO}" ) set( CMAKE_C_FLAGS_INIT "{SCC_FLAGS} {CFLAGS_LOCAL}" ) # https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS_CONFIG_INIT.html -set( CMAKE_Fortran_FLAGS_DEBUG_INIT "{FCDEBUG}" ) -set( CMAKE_Fortran_FLAGS_RELEASE_INIT "" ) -set( CMAKE_C_FLAGS_DEBUG_INIT "" ) -set( CMAKE_C_FLAGS_RELEASE_INIT "" ) +set( CMAKE_Fortran_FLAGS_Debug_INIT "{FCDEBUG}" ) +set( CMAKE_Fortran_FLAGS_Release_INIT "" ) +set( CMAKE_C_FLAGS_Debug_INIT "" ) +set( CMAKE_C_FLAGS_Release_INIT "" ) # Project specifics now -set( WRF_MPI_Fortran_FLAGS "{DM_FC_FLAGS}" ) -set( WRF_MPI_C_FLAGS "{DM_CC_FLAGS}" ) -set( WRF_ARCH_LOCAL "{ARCH_LOCAL}" ) -set( WRF_M4_FLAGS "{M4_FLAGS}" ) -set( WRF_FCOPTIM "{FCOPTIM}" ) -set( WRF_FCNOOPT "{FCNOOPT}" ) \ No newline at end of file +set( WRF_MPI_Fortran_FLAGS "{DM_FC_FLAGS}" ) +set( WRF_MPI_C_FLAGS "{DM_CC_FLAGS}" ) +set( WRF_ARCH_LOCAL "{ARCH_LOCAL}" ) +set( WRF_M4_FLAGS "{M4_FLAGS}" ) +set( WRF_FCOPTIM "{FCOPTIM}" ) +set( WRF_FCNOOPT "{FCNOOPT}" ) +set( WRF_LINK_FLAGS "{LDFLAGS_LOCAL}" ) diff --git a/frame/CMakeLists.txt b/frame/CMakeLists.txt index c322d84c9a..b923149edf 100644 --- a/frame/CMakeLists.txt +++ b/frame/CMakeLists.txt @@ -158,7 +158,7 @@ target_sources( set_source_files_properties( ${nl_dyn_source} PROPERTIES - COMPILE_FLAGS + COMPILE_OPTIONS_OPTIMIZATION $<$:${WRF_FCNOOPT}> ) From 86c370700dd7a437fd6dabefe24c481825d04f03 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Thu, 1 Aug 2024 12:01:57 -0700 Subject: [PATCH 11/13] Don't force specific define able to come from stanza --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5fa55a4a5..eef1cb7fde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -658,7 +658,7 @@ list( APPEND PROJECT_COMPILE_DEFINITIONS_OPTIONS NETCDF #!TODO Change this to a confcheck - NONSTANDARD_SYSTEM_SUBR + # NONSTANDARD_SYSTEM_SUBR # For now let this come from stanza EM_CORE=${EM_CORE} From 17694776910fe592d895ab7a647725b5a6e6da44 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Thu, 1 Aug 2024 13:16:52 -0700 Subject: [PATCH 12/13] Allow for regular defines to be passed in --- cmake/c_preproc.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/c_preproc.cmake b/cmake/c_preproc.cmake index 4de0a1e7a1..23ee44ddb0 100644 --- a/cmake/c_preproc.cmake +++ b/cmake/c_preproc.cmake @@ -117,6 +117,9 @@ macro( wrf_expand_definitions ) 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() From 812acda062ce5e6cf480ef70b50295cfe35d3811 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Mon, 5 Aug 2024 18:03:59 -0700 Subject: [PATCH 13/13] Reduce configuration check logic by using try_* functions --- cmake/confcheck.cmake | 133 +++++++++++---------------------------- confcheck/CMakeLists.txt | 29 ++++----- 2 files changed, 49 insertions(+), 113 deletions(-) diff --git a/cmake/confcheck.cmake b/cmake/confcheck.cmake index 5db8469519..4c4970bda8 100644 --- a/cmake/confcheck.cmake +++ b/cmake/confcheck.cmake @@ -1,18 +1,18 @@ # 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 @@ -20,102 +20,41 @@ macro( wrf_conf_check ) ${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 ) @@ -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() diff --git a/confcheck/CMakeLists.txt b/confcheck/CMakeLists.txt index 152aeeaa3a..c431a5c61c 100644 --- a/confcheck/CMakeLists.txt +++ b/confcheck/CMakeLists.txt @@ -2,24 +2,21 @@ wrf_conf_check( RUN RESULT_VAR Fortran_2003_IEEE - SOURCE ${PROJECT_SOURCE_DIR}/tools/fortran_2003_ieee_test.F - EXTENSION .F + SOURCES ${PROJECT_SOURCE_DIR}/tools/fortran_2003_ieee_test.F MESSAGE "Some IEEE Fortran 2003 features missing, removing usage of these features" ) wrf_conf_check( RUN RESULT_VAR Fortran_2003_ISO_C - SOURCE ${PROJECT_SOURCE_DIR}/tools/fortran_2003_iso_c_test.F - EXTENSION .F + SOURCES ${PROJECT_SOURCE_DIR}/tools/fortran_2003_iso_c_test.F MESSAGE "Some ISO_C Fortran 2003 features missing, removing usage ISO_C and stubbing code dependent on it" ) wrf_conf_check( RUN RESULT_VAR Fortran_2003_FLUSH - SOURCE ${PROJECT_SOURCE_DIR}/tools/fortran_2003_flush_test.F - EXTENSION .F + SOURCES ${PROJECT_SOURCE_DIR}/tools/fortran_2003_flush_test.F MESSAGE "Standard FLUSH routine Fortran 2003 features missing, checking for alternate Fortran_2003_FFLUSH" ) @@ -27,8 +24,7 @@ if ( NOT ${Fortran_2003_FLUSH} ) wrf_conf_check( RUN RESULT_VAR Fortran_2003_FFLUSH - SOURCE ${PROJECT_SOURCE_DIR}/tools/fortran_2003_fflush_test.F - EXTENSION .F + SOURCES ${PROJECT_SOURCE_DIR}/tools/fortran_2003_fflush_test.F MESSAGE "Standard FFLUSH routine Fortran 2003 features missing, no alternate to FLUSH found, feature stubbed out" ) endif() @@ -36,8 +32,7 @@ endif() wrf_conf_check( RUN RESULT_VAR Fortran_2003_GAMMA - SOURCE ${PROJECT_SOURCE_DIR}/tools/fortran_2008_gamma_test.F - EXTENSION .F + SOURCES ${PROJECT_SOURCE_DIR}/tools/fortran_2008_gamma_test.F MESSAGE "Some Fortran 2003 features missing, removing usage gamma function intrinsic and stubbing code dependent on it" ) @@ -45,22 +40,20 @@ wrf_conf_check( wrf_conf_check( RUN - SOURCE_TYPE C RESULT_VAR FSEEKO64 - SOURCE ${PROJECT_SOURCE_DIR}/tools/fseek_test.c - EXTENSION .c - ADDITIONAL_DEFINITIONS -DTEST_FSEEKO64 -DFILE_TO_TEST="${PROJECT_SOURCE_DIR}/CMakeLists.txt" + SOURCES ${PROJECT_SOURCE_DIR}/tools/fseek_test.c + OPTIONS + COMPILE_DEFINITIONS -DTEST_FSEEKO64 -DFILE_TO_TEST="${PROJECT_SOURCE_DIR}/CMakeLists.txt" MESSAGE "fseeko64 not supported, checking alternate fseeko" ) if ( NOT "${FSEEKO64}" ) wrf_conf_check( RUN - SOURCE_TYPE C RESULT_VAR FSEEKO - SOURCE ${PROJECT_SOURCE_DIR}/tools/fseek_test.c - EXTENSION .c - ADDITIONAL_DEFINITIONS -DTEST_FSEEKO -DFILE_TO_TEST="${PROJECT_SOURCE_DIR}/CMakeLists.txt" + SOURCES ${PROJECT_SOURCE_DIR}/tools/fseek_test.c + OPTIONS + COMPILE_DEFINITINOS -DTEST_FSEEKO -DFILE_TO_TEST="${PROJECT_SOURCE_DIR}/CMakeLists.txt" MESSAGE "fseeko not supported, compiling with fseek (caution with large files)" ) endif()