Skip to content

Commit

Permalink
Detect __cplusplus with nvc++
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Nov 29, 2023
1 parent 8c0a2d2 commit e4c3a59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions cmake/modules/RootConfiguration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,13 @@ if(PYTHON_VERSION_STRING_Development_Other)
endif()

#---RConfigure.h---------------------------------------------------------------------------------------------
try_compile(has__cplusplus "${CMAKE_BINARY_DIR}" SOURCES "${CMAKE_SOURCE_DIR}/config/__cplusplus.cxx"
if (CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dM -E /dev/null OUTPUT_VARIABLE __cplusplus_PPout)
else()
try_compile(has__cplusplus "${CMAKE_BINARY_DIR}" SOURCES "${CMAKE_SOURCE_DIR}/config/__cplusplus.cxx"
OUTPUT_VARIABLE __cplusplus_PPout)
string(REGEX MATCH "__cplusplus=([0-9]+)" __cplusplus "${__cplusplus_PPout}")
endif()
string(REGEX MATCH "__cplusplus[=| ]([0-9]+)" __cplusplus "${__cplusplus_PPout}")
set(__cplusplus ${CMAKE_MATCH_1}L)

configure_file(${PROJECT_SOURCE_DIR}/config/RConfigure.in ginclude/RConfigure.h NEWLINE_STYLE UNIX)
Expand Down
2 changes: 1 addition & 1 deletion config/__cplusplus.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define _STRINGIFY(x) #x
#define STRINGIFY(x) _STRINGIFY(x)

// `#pragma message` is supported in well-known compilers including gcc, clang, icc, and MSVC
// `#pragma message` is supported in well-known compilers including gcc, clang, icc, and MSVC. But not nvc++.
#pragma message("__cplusplus=" STRINGIFY(__cplusplus))

int main(void)
Expand Down

0 comments on commit e4c3a59

Please sign in to comment.