From cd8e5453fce6942fb24170b2c65bd9d70b432e7a Mon Sep 17 00:00:00 2001 From: Anthony Islas <128631809+islas@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:40:49 -0700 Subject: [PATCH] Change internal flag organization in CMake build to not be global (#2053) TYPE: enhancement KEYWORDS: cmake, flags, compilation SOURCE: internal DESCRIPTION OF CHANGES: Problem: The current iteration of the cmake build places all configuration flags in the global properties of the project. While this works when just building WRF, integration with other projects' cmake builds if placed under WRF pollutes their respective build flags. Solution: Adjust the layout of the flags to instead carry them in a variable, and prefer using `target_*` calls for flag usage. LIST OF MODIFIED FILES: M CMakeLists.txt M chem/CMakeLists.txt M external/CMakeLists.txt M external/io_adios2/CMakeLists.txt M external/io_netcdf/CMakeLists.txt M external/io_netcdfpar/CMakeLists.txt M external/io_pnetcdf/CMakeLists.txt M frame/CMakeLists.txt M main/CMakeLists.txt M phys/CMakeLists.txt M tools/CMakeLists.txt RELEASE NOTE: Change internal flag organization in CMake build to not be global --- CMakeLists.txt | 289 ++++++++++++++++++----------------- 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 | 5 +- hydro/CMakeLists.txt | 2 + main/CMakeLists.txt | 3 + phys/CMakeLists.txt | 3 +- tools/CMakeLists.txt | 5 +- 12 files changed, 185 insertions(+), 153 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7195182..0951267f 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,122 +695,134 @@ 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... # $<$:MPI2_SUPPORT=$> # $<$:MPI2_THREAD_SUPPORT=$> - # Make core target add_library( ${PROJECT_NAME}_Core 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 9bfbf3d5..544b2532 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 7036a9de..e52b1c3f 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 dde531a7..2d8efd61 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 ac937928..b63a1ae4 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 8a0db9b9..9536023c 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 1717f713..8c7c1382 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 507678af..85264c7d 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 ) diff --git a/hydro/CMakeLists.txt b/hydro/CMakeLists.txt index ee756e71..63f6f59b 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") diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 9a2f69ec..b0ec69d7 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 d7d85e1c..d3df6a28 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 57bff48c..7f07eb25 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 ) @@ -117,10 +119,9 @@ foreach( n RANGE 0 31 ) ) endforeach() -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 -- 2.11.4.GIT