# Getting the c++ standard if ROOT\_CXX\_STANDARD is not set

**URL:** <https://root-forum.cern.ch/t/getting-the-c-standard-if-root-cxx-standard-is-not-set/59439>\
**Category:** ROOT\
**Tags:** cmake\
**Created:** [May 23, 2024, 3:17pm UTC](https://root-forum.cern.ch/t/getting-the-c-standard-if-root-cxx-standard-is-not-set/59439 "2024-05-23T15:17:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaubee](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/v/ecb155/32.png) [@vaubee](https://root-forum.cern.ch/u/vaubee)\
**Post date:** [May 23, 2024, 3:17pm UTC](https://root-forum.cern.ch/t/getting-the-c-standard-if-root-cxx-standard-is-not-set/59439/1 "2024-05-23T15:17:12Z")

</div>

The original topic got closed, but in case anyone else encounters this problem:

If the ROOT\_CXX\_STANDARD variable is not set in cmake (ROOT versions 6.30.06 and earlier), I found the code can be used to get the c++ standard used to compile the ROOT version in use:

```auto
if(NOT ROOT_CXX_VERSION)
   string(REGEX REPLACE ".*-std=.+\\+\\+([0-9][0-9]).*" "\\1" ROOT_CXX_VERSION ${ROOT_CXX_FLAGS})
   if(${CMAKE_MATCH_COUNT} EQUAL "1")
      message("Got ROOT_CXX_VERSION=${ROOT_CXX_VERSION} from \"${ROOT_CXX_FLAGS}\"")
   else()
      message(FATAL_ERROR "The ROOT cxx flags seem to be misformed (${ROOT_CXX_FLAGS}) (CMAKE_MATCH_COUNT=${CMAKE_MATCH_COUNT}), consider providing a cxx version by hand using \"-DROOT_CXX_VERSION=??\"")
   endif()
else()
   message("Got user provided ROOT_CXX_VERSION=${ROOT_CXX_VERSION}")
endif()

```

---

<div class="post-metadata">

**Author:** ![devajith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/devajith/32/37165_2.png) [@devajith](https://root-forum.cern.ch/u/devajith)\
**Post date:** [May 24, 2024, 11:51am UTC](https://root-forum.cern.ch/t/getting-the-c-standard-if-root-cxx-standard-is-not-set/59439/2 "2024-05-24T11:51:14Z")

</div>

Hi @vaubee, thanks for providing your solution.

Original post for future reference: [CMake variable ROOT\_CXX\_STANDARD not set](https://root-forum.cern.ch/t/cmake-variable-root-cxx-standard-not-set/59207)

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [June 7, 2024, 11:52am UTC](https://root-forum.cern.ch/t/getting-the-c-standard-if-root-cxx-standard-is-not-set/59439/3 "2024-06-07T11:52:06Z")

</div>

Closed on June 7, 2024, 11:52am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
