Skip to content

Commit

Permalink
CMake Build (#1896)
Browse files Browse the repository at this point in the history
TYPE: new feature

KEYWORDS: CMake, build, make

SOURCE: internal

DESCRIPTION OF CHANGES:
Problem:
The current WRF build system is fragile with many pitfalls making it difficult for users to build & add to it without perpetuating existing problems. Many options exist across various layers of files, languages, and option control-flow.

Solution:
*This requires CMake version 3.20 or newer*
A redesign of the build system from the ground up, maintaining the interfacing feel and knowledge accumulated in `arch/configure.defaults`. Condense option selection and control to single locations and as best as possible reduce the complexity of this control.

This will be a work in progress as gaps are identified in reproducing the full functionality of the makefile build system. Currently only `em_real` and `em_ideal` have limited supported


Brief how to use:
As this is a work in progress, the original `configure` and `compile` scripts have been left as-is. Alongside them are now `configure_new` and `compile_new` which walk a user through a slightly similar experience of configuring & compiling WRF.

A simple usage example would be:
```bash
# Ensure you have cmake 3.20+ and configuration environment set up
./configure_new
# Follow prompts to select configuration
./compile_new [-j N]
```

Notable differences are :
* Submodule code must be checked out beforehand and is not checked out during the compile process
* Stanzas presented to a user are only those for which the compiler exists in the current environment
* `!!` warnings appear for subconfigurations (MPI) that would not be supported in the current environment
* DM/SM selection is now done after selecting a base configuration rather than an individual configuration # within a family of compilers
* Compilation via `compile_new` does not take target to build as an argument - parallel `-j N` jobs still supported
* Users do not need to set `NETCDF` or `LD_LIBRARY_PATH` variables
* Base binaries do not have `.exe` extension, but symlinks are provided
* Binaries, test setups, and everything else generated from compilation is copy-placed (not softlinked) to a separate location - default is `./install`. This means the equivalent `test/em_real/wrf.exe` is now at `install/test/em_real/wrf.exe`


LIST OF MODIFIED FILES: 
A       CMakeLists.txt
A       arch/configure_reader.py
A       chem/CMakeLists.txt
A       cleanCMake.sh
A       cmake/c_preproc.cmake
A       cmake/confcheck.cmake
A       cmake/gitinfo.cmake
A       cmake/m4_preproc.cmake
A       cmake/modules/FindJasper.cmake
A       cmake/modules/FindRPC.cmake
A       cmake/modules/FindnetCDF-Fortran.cmake
A       cmake/modules/FindnetCDF.cmake
A       cmake/modules/FindpnetCDF.cmake
A       cmake/printOption.cmake
A       cmake/target_copy.cmake
A       cmake/template/WRFConfig.cmake.in
A       cmake/template/arch_config.cmake
A       cmake/template/commit_decl.cmake
A       cmake/wrf_case_setup.cmake
A       cmake/wrf_get_version.cmake
A       compile_new
A       confcheck/CMakeLists.txt
A       configure_new
A       dyn_em/CMakeLists.txt
A       external/CMakeLists.txt
A       external/RSL_LITE/CMakeLists.txt
A       external/atm_ocn/CMakeLists.txt
A       external/esmf_time_f90/CMakeLists.txt
A       external/fftpack/fftpack5/CMakeLists.txt
A       external/io_adios2/CMakeLists.txt
A       external/io_esmf/CMakeLists.txt
A       external/io_grib1/CMakeLists.txt
A       external/io_grib1/MEL_grib1/CMakeLists.txt
A       external/io_grib1/WGRIB/CMakeLists.txt
A       external/io_grib1/grib1_util/CMakeLists.txt
A       external/io_grib2/CMakeLists.txt
A       external/io_grib2/bacio-1.3/CMakeLists.txt
A       external/io_grib2/g2lib/CMakeLists.txt
A       external/io_grib2/g2lib/utest/CMakeLists.txt
A       external/io_grib_share/CMakeLists.txt
A       external/io_int/CMakeLists.txt
A       external/io_netcdf/CMakeLists.txt
A       external/io_netcdfpar/CMakeLists.txt
A       external/io_phdf5/CMakeLists.txt
A       external/io_pio/CMakeLists.txt
A       external/io_pnetcdf/CMakeLists.txt
A       external/ioapi_share/CMakeLists.txt
A       frame/CMakeLists.txt
A       inc/CMakeLists.txt
A       main/CMakeLists.txt
A       phys/CMakeLists.txt
A       share/CMakeLists.txt
A       test/em_b_wave/CMakeLists.txt
A       test/em_convrad/CMakeLists.txt
A       test/em_fire/CMakeLists.txt
A       test/em_grav2d_x/CMakeLists.txt
A       test/em_heldsuarez/CMakeLists.txt
A       test/em_hill2d_x/CMakeLists.txt
A       test/em_les/CMakeLists.txt
A       test/em_quarter_ss/CMakeLists.txt
A       test/em_real/CMakeLists.txt
A       test/em_scm_xy/CMakeLists.txt
A       test/em_seabreeze2d_x/CMakeLists.txt
A       test/em_squall2d_x/CMakeLists.txt
A       test/em_squall2d_y/CMakeLists.txt
A       test/em_tropical_cyclone/CMakeLists.txt
A       tools/CMakeLists.txt
A       tools/CodeBase/CMakeLists.txt
A       doc/README.cmake_build
M       tools/fseek_test.c
M       README
M       arch/configure.defaults


- Modified file include an adjustment to a compile test to allow the test to be conducted in an out-of-source build manner as prescribed by CMake. Default logic of this test to still test on the existence of `Makefile`

TESTS CONDUCTED: 
1. In various instances this build is faster and more reliable with meaningful diagnostics when errors occur

RELEASE NOTE: 
Introduction of a CMake build system for em_real and em_ideal
  • Loading branch information
islas authored Feb 16, 2024
1 parent 5db9f7f commit d66b399
Show file tree
Hide file tree
Showing 72 changed files with 5,908 additions and 11 deletions.
918 changes: 918 additions & 0 deletions CMakeLists.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This is the main directory for the WRF Version 4 source code release.
======================================

Other README files are located in the WRF/doc directory:
doc/README.cmake_build
doc/README.crtm
doc/README.CTSM
doc/README.cygwin.md
Expand Down
20 changes: 10 additions & 10 deletions arch/configure.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ CC_TOOLS = $(SCC)
NETCDFPAR_BUILD = CONFIGURE_NETCDFPAR_BUILD

###########################################################
#ARCH Darwin (MACOS) PGI compiler with pgcc #serial smpar dmpar dm+sm
#ARCH Darwin x86_64 arm64, (MACOS) PGI compiler with pgcc #serial smpar dmpar dm+sm
#
DESCRIPTION = PGI ($SFC/$SCC)
DMPARALLEL = # 1
Expand Down Expand Up @@ -862,7 +862,7 @@ CC_TOOLS = cc
NETCDFPAR_BUILD = CONFIGURE_NETCDFPAR_BUILD

###########################################################
#ARCH Darwin (MACOS) intel compiler with icc #serial smpar dmpar dm+sm
#ARCH Darwin x86_64 arm64, (MACOS) intel compiler with icc #serial smpar dmpar dm+sm
#
DESCRIPTION = INTEL ($SFC/$SCC)
DMPARALLEL = # 1
Expand Down Expand Up @@ -909,7 +909,7 @@ CC_TOOLS = cc
NETCDFPAR_BUILD = CONFIGURE_NETCDFPAR_BUILD

###########################################################
#ARCH Darwin (MACOS) intel compiler with clang EDIT FOR OPENMPI #serial smpar dmpar dm+sm
#ARCH Darwin x86_64 arm64, (MACOS) intel compiler with clang EDIT FOR OPENMPI #serial smpar dmpar dm+sm
#
DESCRIPTION = INTEL ($SFC/$SCC)
DMPARALLEL = # 1
Expand Down Expand Up @@ -955,7 +955,7 @@ CC_TOOLS = cc
NETCDFPAR_BUILD = CONFIGURE_NETCDFPAR_BUILD

###########################################################
#ARCH Darwin (MACOS) g95 with gcc #serial dmpar
#ARCH Darwin x86_64 arm64, (MACOS) g95 with gcc #serial dmpar
#
DESCRIPTION = GNU ($SFC/$SCC)
DMPARALLEL = # 1
Expand Down Expand Up @@ -1000,7 +1000,7 @@ CC_TOOLS = $(SCC)
NETCDFPAR_BUILD = CONFIGURE_NETCDFPAR_BUILD

###########################################################
#ARCH Darwin (MACOS) gfortran with gcc #serial smpar dmpar dm+sm
#ARCH Darwin x86_64 arm64, (MACOS) gfortran with gcc #serial smpar dmpar dm+sm
#
DESCRIPTION = GNU ($SFC/$SCC)
DMPARALLEL = # 1
Expand Down Expand Up @@ -1045,7 +1045,7 @@ CC_TOOLS = $(SCC)
NETCDFPAR_BUILD = CONFIGURE_NETCDFPAR_BUILD

###########################################################
#ARCH Darwin (MACOS) gfortran with clang #serial smpar dmpar dm+sm
#ARCH Darwin x86_64 arm64, (MACOS) gfortran with clang #serial smpar dmpar dm+sm
#
DESCRIPTION = GNU ($SFC/clang)
DMPARALLEL = # 1
Expand Down Expand Up @@ -1090,7 +1090,7 @@ CC_TOOLS = clang
NETCDFPAR_BUILD = CONFIGURE_NETCDFPAR_BUILD

###########################################################
#ARCH Darwin (MACOS) xlf #serial dmpar
#ARCH Darwin x86_64 arm64, (MACOS) xlf #serial dmpar
#
DESCRIPTION = IBM ($SFC/$SCC)
DMPARALLEL = # 1
Expand Down Expand Up @@ -1695,7 +1695,7 @@ CC_TOOLS = $(SCC)
NETCDFPAR_BUILD = CONFIGURE_NETCDFPAR_BUILD

###########################################################
#ARCH Darwin (MACOS) PGI compiler with pgcc -f90= #serial smpar dmpar dm+sm
#ARCH Darwin x86_64 arm64, (MACOS) PGI compiler with pgcc -f90= #serial smpar dmpar dm+sm
#
DESCRIPTION = PGI ($SFC/$SCC): -f90=pgf90
DMPARALLEL = # 1
Expand Down Expand Up @@ -1739,7 +1739,7 @@ CC_TOOLS = cc
NETCDFPAR_BUILD = CONFIGURE_NETCDFPAR_BUILD

###########################################################
#ARCH Darwin (MACOS) intel compiler with icc #serial smpar dmpar dm+sm
#ARCH Darwin x86_64 arm64, (MACOS) intel compiler with icc #serial smpar dmpar dm+sm
#
DESCRIPTION = INTEL ($SFC/$SCC): Open MPI
DMPARALLEL = # 1
Expand Down Expand Up @@ -1786,7 +1786,7 @@ CC_TOOLS = cc
NETCDFPAR_BUILD = CONFIGURE_NETCDFPAR_BUILD

###########################################################
#ARCH Darwin (MACOS) gfortran with gcc openmpi #serial smpar dmpar dm+sm
#ARCH Darwin x86_64 arm64, (MACOS) gfortran with gcc openmpi #serial smpar dmpar dm+sm
#
DESCRIPTION = GNU ($SFC/$SCC): Open MPI
DMPARALLEL = # 1
Expand Down
Loading

0 comments on commit d66b399

Please sign in to comment.