# Clean way to detect if compiler supports enum deprecation

**URL:** https://discourse.cmake.org/t/clean-way-to-detect-if-compiler-supports-enum-deprecation/5169
**Category:** Code
**Created:** [March 4, 2022, 10:41pm UTC](https://discourse.cmake.org/t/clean-way-to-detect-if-compiler-supports-enum-deprecation/5169 "2022-03-04T22:41:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![szhorvat](https://discourse.cmake.org/user_avatar/discourse.cmake.org/szhorvat/32/1906_2.png) [@szhorvat](https://discourse.cmake.org/u/szhorvat)
#### Post date: [March 4, 2022, 10:41pm UTC](https://discourse.cmake.org/t/clean-way-to-detect-if-compiler-supports-enum-deprecation/5169/1 "2022-03-04T22:41:25Z")

</div>

GCC versions 6 and later, as well as all most Clang versions, support deprecating enum values in C like this:

```auto
enum Foo {
    A = 1,
    B __attribute__ ((deprecated)) = A /* B is deprecated in favour of A */ 
};

```

However, several other compilers that claim compatibility with GCC 6 (by setting ` __GCC__ ` to a value greater than 6) do not support this. For example, neither the Intel compiler nor PGI do.

Is there a clean way to detect the availability of this feature with CMake? How should I go about it? I was looking at `try_compile`, but it seemed quite complicated, and couldn’t quite make it work.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [March 4, 2022, 11:01pm UTC](https://discourse.cmake.org/t/clean-way-to-detect-if-compiler-supports-enum-deprecation/5169/2 "2022-03-04T23:01:32Z")

</div>

You can use the CMake compiler detection for this. Something like:

```auto
set(enum_variant_deprecation_supported 0)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" # gcc
     OR …)
  set(enum_variant_deprecation_supported 1)
endif ()

# use the detection

```

Note that the consuming compiler also matters here, so some other detection may be required in that case. Here, you can use genexes to do this `if` condition to set the value to 1 or 0 that way.

See how VTK does this for Intel detection [here](https://gitlab.kitware.com/vtk/vtk/-/blob/e0123b361d2eaafef60ed46de5cd1760fd7c3ca7/CMake/vtkCompilerExtraFlags.cmake#L41).
