CMake error with AOCC flang compiler

Hi all,

I’m installing HDF5 using aocc@3.2.0 with fortran support by spack. And cmake complains about the flang compiler Failed to find available REAL KINDs for Fortran. The cmake log is attached below, where the Flang version is also somewhat strange

-- The Fortran compiler identification is Flang 99.99.1
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler: /data/apps/hpcx/v2.11/rebuild-aocc-3.2.0/bin/mpif90 - skipped
-- Detecting Fortran/C Interface
-- Detecting Fortran/C Interface - Found GLOBAL and MODULE mangling
-- Performing Test H5_FORTRAN_HAVE_SIZEOF
-- Performing Test H5_FORTRAN_HAVE_SIZEOF - Success
-- Performing Test H5_FORTRAN_HAVE_C_SIZEOF
-- Performing Test H5_FORTRAN_HAVE_C_SIZEOF - Success
-- Performing Test H5_FORTRAN_HAVE_STORAGE_SIZE
-- Performing Test H5_FORTRAN_HAVE_STORAGE_SIZE - Success
-- Performing Test H5_HAVE_ISO_FORTRAN_ENV
-- Performing Test H5_HAVE_ISO_FORTRAN_ENV - Success
-- Performing Test H5_FORTRAN_DEFAULT_REAL_NOT_DOUBLE
-- Performing Test H5_FORTRAN_DEFAULT_REAL_NOT_DOUBLE - Success
-- Performing Test H5_FORTRAN_HAVE_ISO_C_BINDING
-- Performing Test H5_FORTRAN_HAVE_ISO_C_BINDING - Success
-- Performing Test FORTRAN_HAVE_C_LONG_DOUBLE
-- Performing Test FORTRAN_HAVE_C_LONG_DOUBLE - Success
-- Performing Test FORTRAN_C_LONG_DOUBLE_IS_UNIQUE
-- Performing Test FORTRAN_C_LONG_DOUBLE_IS_UNIQUE - Failed
CMake Error at config/cmake/HDF5UseFortran.cmake:148 (list):
  list index: 2 out of range (-2, 1)
Call Stack (most recent call first):
  CMakeLists.txt:1069 (include)


CMake Error at config/cmake/HDF5UseFortran.cmake:155 (message):
  Failed to find available REAL KINDs for Fortran
Call Stack (most recent call first):
  CMakeLists.txt:1069 (include)


-- Configuring incomplete, errors occurred!

The detailed cmake errors goes like this:

Performing Fortran SOURCE FILE Test FORTRAN_C_LONG_DOUBLE_IS_UNIQUE failed with the following output:
Change Dir: /tmp/root/spack-stage/spack-stage-hdf5-1.12.2-rsyp7nrnoou2pdhycmcag63htkrbk5oi/spack-build-rsyp7nr/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make -f Makefile cmTC_049af/fast && /usr/bin/make  -f CMakeFiles/cmTC_049af.dir/build.make CMakeFiles/cmTC_049af.dir/build
make[1]: Entering directory '/tmp/root/spack-stage/spack-stage-hdf5-1.12.2-rsyp7nrnoou2pdhycmcag63htkrbk5oi/spack-build-rsyp7nr/CMakeFiles/CMakeTmp'
Building Fortran object CMakeFiles/cmTC_049af.dir/src.f90.o
/data/apps/hpcx/v2.11/rebuild-aocc-3.2.0/bin/mpif90 -DFORTRAN_C_LONG_DOUBLE_IS_UNIQUE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE  -O3 -DNDEBUG -fPIE -c /tmp/root/spack-stage/spack-stage-hdf5-1.12.2-rsyp7nrnoou2pdhycmcag63htkrbk5oi/spack-build-rsyp7nr/CMakeFiles/CMakeTmp/src.f90 -o CMakeFiles/cmTC_049af.dir/src.f90.o
F90-S-0155-Ambiguous interfaces for generic procedure h5t (/tmp/root/spack-stage/spack-stage-hdf5-1.12.2-rsyp7nrnoou2pdhycmcag63htkrbk5oi/spack-build-rsyp7nr/CMakeFiles/CMakeTmp/src.f90: 20)
F90-S-0155-Ambiguous interfaces for generic procedure h5t (/tmp/root/spack-stage/spack-stage-hdf5-1.12.2-rsyp7nrnoou2pdhycmcag63htkrbk5oi/spack-build-rsyp7nr/CMakeFiles/CMakeTmp/src.f90: 21)
  0 inform,   0 warnings,   2 severes, 0 fatal for prog_fc_c_long_double_eq_c_double
make[1]: *** [CMakeFiles/cmTC_049af.dir/build.make:78: CMakeFiles/cmTC_049af.dir/src.f90.o] Error 1
make[1]: Leaving directory '/tmp/root/spack-stage/spack-stage-hdf5-1.12.2-rsyp7nrnoou2pdhycmcag63htkrbk5oi/spack-build-rsyp7nr/CMakeFiles/CMakeTmp'
make: *** [Makefile:127: cmTC_049af/fast] Error 2


Source file was:
MODULE type_mod
  USE ISO_C_BINDING
  INTERFACE h5t
     MODULE PROCEDURE h5t_c_double
     MODULE PROCEDURE h5t_c_long_double
  END INTERFACE
CONTAINS
  SUBROUTINE h5t_c_double(r)
    REAL(KIND=C_DOUBLE) :: r
  END SUBROUTINE h5t_c_double
  SUBROUTINE h5t_c_long_double(d)
    REAL(KIND=C_LONG_DOUBLE) :: d
  END SUBROUTINE h5t_c_long_double
END MODULE type_mod
PROGRAM PROG_FC_C_LONG_DOUBLE_EQ_C_DOUBLE
  USE ISO_C_BINDING
  USE type_mod
  REAL(KIND=C_DOUBLE)      :: r
  REAL(KIND=C_LONG_DOUBLE) :: d
  CALL h5t(r)
  CALL h5t(d)
END PROGRAM PROG_FC_C_LONG_DOUBLE_EQ_C_DOUBLE
Determining if the Fortran REAL and INTEGER KINDs exists failed: 127

FYI, I’m using Ubuntu 20.04 and the cmake command is:

/data/apps/mambaforge/bin/cmake
-GUnix Makefiles
-DCMAKE_INSTALL_PREFIX:STRING=${SPACK}/aocc-3.2.0/hdf5-1.12.2-rsyp7nrnoou2pdhycmcag63htkrbk5oi
-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo
-DBUILD_TESTING:BOOL=OFF
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=ON
-DCMAKE_INSTALL_RPATH:STRING=${SPACK}/aocc-3.2.0/hdf5-1.12.2-rsyp7nrnoou2pdhycmcag63htkrbk5oi/lib;${SPACK}/aocc-3.2.0/hdf5-1.12.2-rsyp7nrnoou2pdhycmcag63htkrbk5oi/lib64;/data/apps/hpcx/v2.11/rebuild-aocc-3.2.0/lib;${SPACK}/aocc-3.2.0/zlib-1.2.12-jdzjtycok3kfe6ekxpfk24wys7ih6kbo/lib
-DCMAKE_PREFIX_PATH:STRING=${SPACK}/aocc-3.2.0/zlib-1.2.12-jdzjtycok3kfe6ekxpfk24wys7ih6kbo;/data/apps/hpcx/v2.11/rebuild-aocc-3.2.0;/data/apps/mambaforge
-DALLOW_UNSUPPORTED:BOOL=ON
-DHDF5_BUILD_EXAMPLES:BOOL=OFF
-DBUILD_TESTING:BOOL=OFF
-DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=ON
-DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF
-DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF
-DBUILD_SHARED_LIBS:BOOL=ON
-DONLY_SHARED_LIBS:BOOL=OFF
-DHDF5_ENABLE_PARALLEL:BOOL=ON
-DHDF5_ENABLE_THREADSAFE:BOOL=OFF
-DHDF5_BUILD_HL_LIB:BOOL=ON
-DHDF5_BUILD_CPP_LIB:BOOL=OFF
-DHDF5_BUILD_FORTRAN:BOOL=ON
-DHDF5_BUILD_JAVA:BOOL=OFF
-DHDF5_BUILD_TOOLS:BOOL=ON
-DCMAKE_C_COMPILER:STRING=/data/apps/hpcx/v2.11/rebuild-aocc-3.2.0/bin/mpicc
-DCMAKE_Fortran_COMPILER:STRING=/data/apps/hpcx/v2.11/rebuild-aocc-3.2.0/bin/mpif90
/tmp/root/spack-stage/spack-stage-hdf5-1.12.2-rsyp7nrnoou2pdhycmcag63htkrbk5oi/spack-src

After digging into the config/cmake/HDF5UseFortran.cmake and do some message print. The actully error message was like libomp.so not found.

It turns out that the module setting in compiler.yaml of spack only works during build/make stage and when it is needed in cmake stage to do some flag check, things goes wrong.

After using environment attribute to add the aocc library path to LD_LIBRARY_PATH, problem is solved.