Scheduled Downtime
On Friday 21 April 2023 @ 5pm MT, this website will be down for maintenance and expected to return online the morning of 24 April 2023 at the latest

WRF configure_new.sh issue with cmake lists search function

William.Hatheway

Active member
When building WRF 4.6.1 with the configure_new.sh script, an issue arises when using libraries installed in non-standard locations. Although CMake tutorials and WRF documentation suggest exporting library paths with the LIBRARYNAME_ROOT format, I've encountered a situation where certain libraries require a different format to work properly. This was determined through trial and error.

Correct Environment Variables for Non-Standard Library Paths​

For example, the correct export statements for non-standard library locations should look like this:


Bash:
export ZLIB_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export JASPER_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export HDF5_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export PNETCDF_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2

These export statements set the required environment variables to point to the correct locations for each library.

Issue with PNETCDF_ROOT in All Uppercase​

However, a problem arises when using PNETCDF_ROOT in all uppercase, as this results in the following error:


Code:
CMake Warning (dev) at CMakeLists.txt:499 (find_package):
Policy CMP0144 is not set: find_package uses upper-case <PACKAGENAME>_ROOT
variables. Run "cmake --help-policy CMP0144" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.

Environment variable PNETCDF_ROOT is set to:

/home/workhorse/WRFHYDRO_COUPLED/Libs/grib2

For compatibility, find_package is ignoring the variable, but code in a
.cmake module might still use it.
This warning is for project developers. Use -Wno-dev to suppress it.

The issue here is that CMake is treating uppercase variables like PNETCDF_ROOT as reserved and does not use them, leading to compatibility warnings. This happens because of the way the find_package logic in CMakeLists.txt handles uppercase variables.

Solution: Use pnetCDF_ROOT in Lowercase​

To resolve this issue, the environment variable PNETCDF_ROOT should be written in lowercase (pnetCDF_ROOT). This change allows the CMake script to properly find and link the pnetCDF library. So, the corrected export statement is:

Bash:
export pnetCDF_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2

Summary of Correct Configuration​

To configure your environment with non-standard library locations, you should set the following environment variables:


Bash:
export ZLIB_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export JASPER_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export HDF5_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export pnetCDF_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2

This setup ensures that the build system can correctly find and use the libraries from their custom locations.

By making sure that pnetCDF_ROOT is in lowercase, the CMake configuration will work without the compatibility warning.


Why the CMakeLists.txt is the Problem​

The issue with the PNETCDF_ROOT variable arises due to how the CMakeLists.txt script in the WRF build system processes environment variables (line 499) , particularly those related to finding external libraries. Specifically, the CMake find_package command used in CMakeLists.txt has a particular way of handling uppercase and lowercase variables.

Here’s why the problem occurs:

  1. CMake's Handling of Uppercase Package Variables:
    • The find_package function in CMake uses a case-sensitive approach to locate packages. By default, CMake expects variables like PNETCDF_ROOT to be lowercase. However, in the WRF build system, the find_package function checks for PNETCDF_ROOT as an uppercase variable.
  2. Compatibility Policy (CMP0144):
    • CMake introduced the CMP0144 policy, which governs how find_package handles package root variables. The policy affects whether uppercase or lowercase versions of these variables are used.
    • When PNETCDF_ROOT is written in all uppercase, as the default in many tutorials and guides, the build system may ignore this variable. CMake’s behavior, in combination with the find_package directive, causes it to overlook the environment variable, leading to a warning that it is being ignored. This results in the issue where pnetCDF cannot be found, even though the library is installed and available.
  3. The CMake find_package Logic:
    • In the specific version of CMakeLists.txt used by WRF, the find_package(pnetCDF) function is searching for the pnetCDFConfig.cmake file using the lowercase naming convention (i.e., pnetCDF instead of PNETCDF). Therefore, if the environment variable is set in uppercase, CMake will not use it as expected, resulting in the error and the failure to find pnetCDF.
  4. Workaround Through Trial and Error:
    • After noticing this issue, we determined through trial and error that the correct approach is to set the environment variable in lowercase (pnetCDF_ROOT). This aligns with how CMake expects to handle package paths and resolves the conflict caused by the uppercase setting.

 

Attachments

  • CMakeLists.txt
    45.5 KB · Views: 1
  • CMakeLists_Modified.txt
    45.5 KB · Views: 0
Bash:
workhorse@workhorse-MS-7D91:~/WRFHYDRO_COUPLED/WRFV4.6.1$ export ZLIB_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export jasper_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export HDF5_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export pnetCDF_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2


./configure_new -x -p "GNU" -- -DCMAKE_Fortran_COMPILER=gfortran -DMPI_Fortran_COMPILER=mpifort -DMPI_C_COMPILER=mpicc -DWRF_CORE=ARW -DWRF_NESTING=BASIC -DWRF_CASE=EM_REAL -DWRFIO_NCD_LARGE_FILE_SUPPORT=1 -DUSE_MPI=ON -DENABLE_HYDRO=ON -DSPATIAL_SOIL=1 -DWRF_HYDRO_NUDGING=1 -DUSE_JASPER=1 -DUSE_HDF5=1
Using default build directory : _build
Using default install directory : /home/workhorse/WRFHYDRO_COUPLED/WRFV4.6.1/install
Using preselected config GNU
Linux         gfortran    /    gcc         /    mpif90      /    mpicc      GNU (gfortran/gcc)
-- The C compiler identification is GNU 13.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- The CXX compiler identification is GNU 13.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is GNU 13.3.0
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler: /usr/bin/gfortran - skipped
-- Retrieving git information...
-- git SHA  : v4.6.1-0-gd66e442fccc04111067e29274c9f9eaccc3cef28-dirty
-- git diff :  151 files changed, 1099 insertions(+), 64730 deletions(-)
-- Setting project version to 4.6.1
-- Set default build type to Release
-- netCDF large file support not suppressed, if available it will be used
-- Found MPI_C: /home/workhorse/WRFHYDRO_COUPLED/Libs/MPICH/lib/libmpi.so (found version "4.1")
-- Found MPI_Fortran: /home/workhorse/WRFHYDRO_COUPLED/Libs/MPICH/lib/libmpifort.so (found version "4.1")
-- Found MPI: TRUE (found version "4.1") found components: Fortran C
-- Checking if MPI requires IPO
-- Found HDF5: /home/workhorse/WRFHYDRO_COUPLED/Libs/grib2/lib/libhdf5.so;/home/workhorse/WRFHYDRO_COUPLED/Libs/grib2/lib/libz.so;/usr/lib/x86_64-linux-gnu/libdl.a;/usr/lib/x86_64-linux-gnu/libm.so (found version "1.14.4-3") 
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1")
-- Found Jasper: /home/workhorse/WRFHYDRO_COUPLED/Libs/grib2/lib/libjasper.a (found suitable version "1.900.1", required range is "1.900.1...<1.900.24")
-- Found NETCDF_PROGRAM : /home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/bin/nc-config
-- Found netCDF: /home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/include (found version "4.9.2")
-- Found NETCDF-FORTRAN_PROGRAM : /home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/bin/nf-config
-- Found netCDF-Fortran: /home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/include (found version "4.6.1")
-- Found PNETCDF_PROGRAM : /home/workhorse/WRFHYDRO_COUPLED/Libs/grib2/bin/pnetcdf-config
-- Found ZLIB: /home/workhorse/WRFHYDRO_COUPLED/Libs/grib2/lib/libz.so (found version "1.3.1") 
-- Found CURL: /usr/lib/x86_64-linux-gnu/libcurl.so (found version "8.5.0") 
-- WRF_CONFIG           : /home/workhorse/WRFHYDRO_COUPLED/WRFV4.6.1/_build/wrf_config.cmake
-- CMAKE_BUILD_TYPE     : Release
-- WRF_CORE             : ARW
-- WRF_NESTING          : BASIC
-- WRF_CASE             : EM_REAL
-- USE_DOUBLE           : OFF
-- USE_MPI              : ON
-- USE_OPENMP           : OFF
-- USE_IPO              : OFF
-- ENABLE_CHEM          : OFF
-- ENABLE_CLM           :
-- ENABLE_CMAQ          : OFF
-- ENABLE_DFI_RADAR     : OFF
-- ENABLE_HYDRO         : ON
-- ENABLE_KPP           : OFF
-- ENABLE_MARS          : OFF
-- ENABLE_TERRAIN       : OFF
-- ENABLE_TITAN         : OFF
-- ENABLE_VENUS         : OFF
-- USE_ALLOCATABLES     : ON
-- wrfmodel             : ON
-- GRIB1                : ON
-- INTIO                : ON
-- KEEP_INT_AROUND      : ON
-- LIMIT_ARGS           : ON
-- FORCE_NETCDF_CLASSIC  : OFF
-- BUILD_RRTMG_FAST     : OFF
-- BUILD_RRTMK          : OFF
-- BUILD_SBM_FAST       : ON
-- SHOW_ALL_VARS_USED   : OFF
-- WRFIO_NCD_NO_LARGE_FILE_SUPPORT      : OFF
-- Performing Test Fortran_2003_IEEE
-- Performing Test Fortran_2003_IEEE - Success
-- Performing Test Fortran_2003_ISO_C
-- Performing Test Fortran_2003_ISO_C - Success
-- Performing Test Fortran_2003_FLUSH
-- Performing Test Fortran_2003_FLUSH - Success
-- Performing Test Fortran_2003_GAMMA
-- Performing Test Fortran_2003_GAMMA - Success
-- Performing Test FSEEKO64
-- Performing Test FSEEKO64 - Success
-- Adding [io_netcdfpar] to configuration
-- Adding [io_pnetcdf] to configuration
-- Adding [io_phdf5] to configuration
-- Adding [io_grib2] to configuration
-- Setting gen_comms to RSL_LITE
-- Setting module_dm to RSL_LITE
-- Found MPI_CXX: /home/workhorse/WRFHYDRO_COUPLED/Libs/MPICH/lib/libmpicxx.so (found version "4.1")
-- Found MPI: TRUE (found version "4.1") 
-- Found NetCDF: /home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/lib/libnetcdff.so;/home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/lib/libnetcdf.so;-L/home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/lib -lnetcdf 
-- NetCDF Include Dir(s): /home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/include /home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/include
-- Setting LSM to: NoahMP
=============================================================
-- Start of WRF-Hydro Env VARIABLES
WRF_HYDRO = 1
HYDRO_D = 0
WRF_HYDRO_RAPID = 0
SPATIAL_SOIL = 1
WRFIO_NCD_LARGE_FILE_SUPPORT = 1
NCEP_WCOSS = 0
NWM_META = 0
WRF_HYDRO_NUDGING = 1
OUTPUT_CHAN_CONN = 0
PRECIP_DOUBLE = 0
WRF_HYDRO_NUOPC = 0
=============================================================
-- Using gfortran
-- CMAKE_Fortran_COMPILER full path: /usr/bin/gfortran
-- Building NoahMP LSM
-- Configuring done (2.1s)
-- Generating done (0.1s)
-- Build files have been written to: /home/workhorse/WRFHYDRO_COUPLED/WRFV4.6.1/_build
 
Bash:
workhorse@workhorse-MS-7D91:~/WRFHYDRO_COUPLED/WRFV4.6.1$
export ZLIB_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export JASPER_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export HDF5_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2
export pnetCDF_ROOT=$HOME/WRFHYDRO_COUPLED/Libs/grib2


./configure_new -x -p "GNU" -- -DCMAKE_Fortran_COMPILER=gfortran -DMPI_Fortran_COMPILER=mpifort -DMPI_C_COMPILER=mpicc -DWRF_CORE=ARW -DWRF_NESTING=BASIC -DWRF_CASE=EM_REAL -DWRFIO_NCD_LARGE_FILE_SUPPORT=1 -DUSE_MPI=ON -DENABLE_HYDRO=ON -DSPATIAL_SOIL=1 -DWRF_HYDRO_NUDGING=1 -DUSE_JASPER=1 -DUSE_HDF5=1
Using default build directory : _build
Using default install directory : /home/workhorse/WRFHYDRO_COUPLED/WRFV4.6.1/install
Using preselected config GNU
Linux         gfortran    /    gcc         /    mpif90      /    mpicc      GNU (gfortran/gcc)
-- Retrieving git information...
-- git SHA  : v4.6.1-0-gd66e442fccc04111067e29274c9f9eaccc3cef28-dirty
-- git diff :  151 files changed, 1099 insertions(+), 64730 deletions(-)
-- Setting project version to 4.6.1
-- Set default build type to Release
-- netCDF large file support not suppressed, if available it will be used
-- Found MPI: TRUE (found version "4.1") found components: Fortran C
-- Checking if MPI requires IPO
CMake Warning (dev) at CMakeLists.txt:458 (find_package):
  Policy CMP0144 is not set: find_package uses upper-case <PACKAGENAME>_ROOT
  variables.  Run "cmake --help-policy CMP0144" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  Environment variable JASPER_ROOT is set to:

    /home/workhorse/WRFHYDRO_COUPLED/Libs/grib2

  For compatibility, find_package is ignoring the variable, but code in a
  .cmake module might still use it.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found NETCDF_PROGRAM : /home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/bin/nc-config
-- Found NETCDF-FORTRAN_PROGRAM : /home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/bin/nf-config
-- Found PNETCDF_PROGRAM : /home/workhorse/WRFHYDRO_COUPLED/Libs/grib2/bin/pnetcdf-config
-- WRF_CONFIG           : _build/wrf_config.cmake
-- CMAKE_BUILD_TYPE     : Release
-- WRF_CORE             : ARW
-- WRF_NESTING          : BASIC
-- WRF_CASE             : EM_REAL
-- USE_DOUBLE           : OFF
-- USE_MPI              : ON
-- USE_OPENMP           : OFF
-- USE_IPO              : OFF
-- ENABLE_CHEM          : OFF
-- ENABLE_CLM           :
-- ENABLE_CMAQ          : OFF
-- ENABLE_DFI_RADAR     : OFF
-- ENABLE_HYDRO         : ON
-- ENABLE_KPP           : OFF
-- ENABLE_MARS          : OFF
-- ENABLE_TERRAIN       : OFF
-- ENABLE_TITAN         : OFF
-- ENABLE_VENUS         : OFF
-- USE_ALLOCATABLES     : ON
-- wrfmodel             : ON
-- GRIB1                : ON
-- INTIO                : ON
-- KEEP_INT_AROUND      : ON
-- LIMIT_ARGS           : ON
-- FORCE_NETCDF_CLASSIC  : OFF
-- BUILD_RRTMG_FAST     : OFF
-- BUILD_RRTMK          : OFF
-- BUILD_SBM_FAST       : ON
-- SHOW_ALL_VARS_USED   : OFF
-- WRFIO_NCD_NO_LARGE_FILE_SUPPORT      : OFF
-- Adding [io_netcdfpar] to configuration
-- Adding [io_pnetcdf] to configuration
-- Adding [io_phdf5] to configuration
-- Adding [io_grib2] to configuration
-- Setting gen_comms to RSL_LITE
-- Setting module_dm to RSL_LITE
-- Found MPI: TRUE (found version "4.1") 
-- NetCDF Include Dir(s): /home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/include /home/workhorse/WRFHYDRO_COUPLED/Libs/NETCDF/include
-- Setting LSM to: NoahMP
=============================================================
-- Start of WRF-Hydro Env VARIABLES
WRF_HYDRO = 1
HYDRO_D = 0
WRF_HYDRO_RAPID = 0
SPATIAL_SOIL = 1
WRFIO_NCD_LARGE_FILE_SUPPORT = 1
NCEP_WCOSS = 0
NWM_META = 0
WRF_HYDRO_NUDGING = 1
OUTPUT_CHAN_CONN = 0
PRECIP_DOUBLE = 0
WRF_HYDRO_NUOPC = 0
=============================================================
-- Using gfortran
-- CMAKE_Fortran_COMPILER full path: /usr/bin/gfortran
-- Building NoahMP LSM
-- Configuring done (1.4s)
-- Generating done (0.1s)
-- Build files have been written to: /home/workhorse/WRFHYDRO_COUPLED/WRFV4.6.1/_build
 
This is the intended behavior (that package roots must specify case-sensitive <PackageName>). There is currently (as far as I'm aware) no official WRF documentation that suggests exporting library paths with uppercase PACKAGENAME_ROOT syntax for the CMake build. If using thirdparty tutorials and guides, there is a chance of incompatibility, especially for packages where we provide our own find module (see cmake/modules/ in WRF).

For PnetCDF support specifically, please see : CMake PnetCDF Find Package by islas · Pull Request #2145 · wrf-model/WRF

Note: With the incoming changes, the root path for PnetCDF should be provided as PnetCDF_ROOT. This is a deliberate change as all the modules have been written to accurately use the official name of the project rather than arbitrary casing schemes.

RE: Why the CMakeLists.txt is the Problem
1. I'm not sure I understand the last two sentences. Without enabling CMP1044, *_ROOT variables must be case sensitive to the find_package() call. The WRF build system follows the default documentation for this call for CMake v3.20 (find_package — CMake 3.20.6 Documentation). This is to ensure backward compatibility for the minimum CMake version the build supports.
2. As stated, thirdparty tutorials especially for differing implementations of finding PnetCDF within CMake, may work differently and not work. The most compatible way to find a package throughout all CMake versions is to provide <PackageName>_ROOT case sensitive to match the find_package() call. In order to avoid users needing to sift through the top-level CMakeLists.txt, however, the names of these can and should be provided in the doc/README.cmake_build
3. This is the desired behavior

I'm surprised jasper_ROOT worked as it should have been Jasper_ROOT
 
This is the intended behavior (that package roots must specify case-sensitive <PackageName>). There is currently (as far as I'm aware) no official WRF documentation that suggests exporting library paths with uppercase PACKAGENAME_ROOT syntax for the CMake build. If using thirdparty tutorials and guides, there is a chance of incompatibility, especially for packages where we provide our own find module (see cmake/modules/ in WRF).
This was based on some of your comments on other threads about how to use the package names. Perhaps I misunderstood the context

I found it pnetCDF_ROOT
https://github.com/wrf-model/WRF/pull/2145
Note: With the incoming changes, the root path for PnetCDF should be provided as PnetCDF_ROOT. This is a deliberate change as all the modules have been written to accurately use the official name of the project rather than arbitrary casing schemes.
I will keep an eye on this

RE: Why the CMakeLists.txt is the Problem
1. I'm not sure I understand the last two sentences. Without enabling CMP1044, *_ROOT variables must be case sensitive to the find_package() call. The WRF build system follows the default documentation for this call for CMake v3.20 (find_package — CMake 3.20.6 Documentation). This is to ensure backward compatibility for the minimum CMake version the build supports.
Well if the cmake lists had all the similar package names in all caps for root that would make thing easier for users to just do PACKAGENAME_ROOT instead of looking in Cmake lists file for the case sensative version. Lots of users seem to have custom paths for their installations and the *_ROOT directories are going to be needed.

2. As stated, thirdparty tutorials especially for differing implementations of finding PnetCDF within CMake, may work differently and not work. The most compatible way to find a package throughout all CMake versions is to provide <PackageName>_ROOT case sensitive to match the find_package() call. In order to avoid users needing to sift through the top-level CMakeLists.txt, however, the names of these can and should be provided in the doc/README.cmake_build
okay thank you

3. This is the desired behavior

I'm surprised jasper_ROOT worked as it should have been Jasper_ROOT
So was I
 
Top