Skip to content

Allow compilation with NVIDIA nvc++ #16975

Open
@cgleggett

Description

@cgleggett

Explain what you would like to see improved and how.

The main obstacle to compiling root with nvc++ is the extraction of the system headers by cling. With gcc, this is done via g++ -xc++ -E -v /dev/null and then a sed script to extract the paths in interpreter/cling/lib/Interpreter/CMakeLists.cxx. This doesn't work with nvc++, but a new flag in hpc sdk version 24.11 was added explicitly for this: -drygccinc. I can offer a patch for this file, but there are a LOT of different code paths through it, and I'm not certain of what they all do, so I probably haven't covered all use cases:

diff --git a/interpreter/cling/lib/Interpreter/CMakeLists.txt b/interpreter/cling/lib/Interpreter/CMakeLists.txt
index e397da97f6..7639cbc58e 100644
--- a/interpreter/cling/lib/Interpreter/CMakeLists.txt
+++ b/interpreter/cling/lib/Interpreter/CMakeLists.txt
@@ -242,24 +242,34 @@ if (UNIX)
   endif()
 
   if(NOT CLING_CXX_HEADERS)
-    if (CLING_CXX_PATH)
-      execute_process(COMMAND ${CLING_CXX_PATH} ${CLING_CXX_PATH_ARGS} -xc++ -E -v /dev/null
+    
+    if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "NVHPC")
+        execute_process(COMMAND ${CLING_CXX_RLTV} -drygccinc
                       OUTPUT_QUIET ERROR_VARIABLE CLING_CXX_HEADERS)
-      set(CLING_CXX_PATH "${CLING_CXX_PATH} ${CLING_CXX_PATH_ARGS}")
+        execute_process(
+          COMMAND echo ${CLING_CXX_HEADERS}
+          COMMAND sed s/:/\\\n/g
+        OUTPUT_VARIABLE CLING_CXX_HEADERS)
     else()
-      # convert CMAKE_CXX_FLAGS to a list for execute_process
-      string(REPLACE "-fdiagnostics-color=always" "" cling_tmp_arg_list ${CMAKE_CXX_FLAGS})
-      string(REPLACE "-fcolor-diagnosics" "" cling_tmp_arg_list ${cling_tmp_arg_list})
-      string(REPLACE " " ";" cling_tmp_arg_list ${cling_tmp_arg_list})
-      execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} ${cling_tmp_arg_list} -xc++ -E -v /dev/null
-                      OUTPUT_QUIET ERROR_VARIABLE CLING_CXX_HEADERS)
+       if (CLING_CXX_PATH)
+         execute_process(COMMAND ${CLING_CXX_PATH} ${CLING_CXX_PATH_ARGS} -xc++ -E -v /dev/null
+                         OUTPUT_QUIET ERROR_VARIABLE CLING_CXX_HEADERS)
+         set(CLING_CXX_PATH "${CLING_CXX_PATH} ${CLING_CXX_PATH_ARGS}")
+       else()
+         # convert CMAKE_CXX_FLAGS to a list for execute_process
+         string(REPLACE "-fdiagnostics-color=always" "" cling_tmp_arg_list ${CMAKE_CXX_FLAGS})
+         string(REPLACE "-fcolor-diagnosics" "" cling_tmp_arg_list ${cling_tmp_arg_list})
+         string(REPLACE " " ";" cling_tmp_arg_list ${cling_tmp_arg_list})
+         execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} ${cling_tmp_arg_list} -xc++ -E -v /dev/null
+                         OUTPUT_QUIET ERROR_VARIABLE CLING_CXX_HEADERS)
+       endif()
+
+       execute_process(
+         COMMAND echo ${CLING_CXX_HEADERS}
+         COMMAND sed -n -e /^.include/,\$\{ -e /^\\\ \\\/.*++/p -e \}
+         OUTPUT_VARIABLE CLING_CXX_HEADERS)
     endif()
 
-    execute_process(
-      COMMAND echo ${CLING_CXX_HEADERS}
-      COMMAND sed -n -e /^.include/,\$\{ -e /^\\\ \\\/.*++/p -e \}
-      OUTPUT_VARIABLE CLING_CXX_HEADERS)
-
     stripNewLine("${CLING_CXX_HEADERS}" CLING_CXX_HEADERS)
   endif()

Also, we can add NVHPC to the list of supported compilers in cmake/modules/CheckCompiler.cmake:

diff --git a/cmake/modules/CheckCompiler.cmake b/cmake/modules/CheckCompiler.cmake
index 4efd0b5946..64ed9761ff 100644
--- a/cmake/modules/CheckCompiler.cmake
+++ b/cmake/modules/CheckCompiler.cmake
@@ -8,7 +8,7 @@
 #  CheckCompiler.cmake
 #---------------------------------------------------------------------------------------------------
 
-if(NOT CMAKE_CXX_COMPILER_ID MATCHES "(Apple|)Clang|GNU|Intel|MSVC")
+if(NOT CMAKE_CXX_COMPILER_ID MATCHES "(Apple|)Clang|GNU|Intel|MSVC|NVHPC")
   message(WARNING "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}.")
 endif()

ROOT version

tried with 6.33.01

Installation method

build from source

Operating system

linux alma9

Additional context

requires at least v24.11 of NVIDIA nvc++

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions