NVHPC & CMake issues : CMAKE_LIBRARY_ARCHITECTURE is not set and hence system libraries are not found


Here is a small example to demonstrate the issue: if I create an empty CMake project that tries to find and use system Readline library:

$ cat CMakeLists.txt

    project (TestCase C)
    cmake_minimum_required (VERSION 2.8)
    find_path(Readline_ROOT_DIR NAMES include/readline/readline.h)
    find_path(Readline_INCLUDE_DIR NAMES readline/readline.h HINTS ${Readline_ROOT_DIR}/include)
    message(INFO "--> ${Readline_INCLUDE_DIR} :: ${CMAKE_LIBRARY_ARCHITECTURE}")
    find_library(Readline_LIBRARY NAMES readline HINTS ${Readline_ROOT_DIR}/lib)
    message(INFO "--> ${Readline_LIBRARY} :: ${Readline_LIBRARY}")

Compiling with GCC gives:

$ cmake . -DCMAKE_C_COMPILER=gcc
   -- CMAKE_LIBRARY_ARCHITECTURE :: x86_64-linux-gnu
   INFO--> /usr/include :: x86_64-linux-gnu
   INFO--> /usr/lib/x86_64-linux-gnu/libreadline.so :: /usr/lib/x86_64-linux-gnu/libreadline.so

But with NVHPC compilers we get following:

$ cmake . -DCMAKE_C_COMPILER=nvc
   INFO--> /usr/include ::

i.e. CMAKE_LIBRARY_ARCHITECTURE is not and libraries are not found correctly.

This has been reported earlier on stackoverflow[1] and this readhat issue describes how subdir triplets from compiler is used to detect CMAKE_LIBRARY_ARCHITECTURE.

As this causes issue only with NVHPC compilers, this is something could be improved?

By the way, I am not able to reproduce this issue with CMake 3.21 but with CMake <=3.19 which is common on many platforms including Ubuntu 20.

[1] linux - CMake: find_library result depends on selected compiler? - Stack Overflow
[2] 1531678 – CMAKE_LIBRARY_ARCHITECTURE is empty

We have been working with Kitware, the makers of CMake, to get it to better recognize the NV HPC compilers. I believe most of these changes went in CMake 3.20. Not much we can do about older versions of CMake except suggest to update to a more current version.