# Programmatically select cxx\_std\_\<yy\> meta features

**URL:** https://discourse.cmake.org/t/programmatically-select-cxx-std-yy-meta-features/5143
**Category:** Usage
**Created:** [March 2, 2022, 3:28am UTC](https://discourse.cmake.org/t/programmatically-select-cxx-std-yy-meta-features/5143 "2022-03-02T03:28:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![h-vetinari](https://discourse.cmake.org/user_avatar/discourse.cmake.org/h-vetinari/32/2207_2.png) [@h-vetinari](https://discourse.cmake.org/u/h-vetinari)
#### Post date: [March 2, 2022, 3:28am UTC](https://discourse.cmake.org/t/programmatically-select-cxx-std-yy-meta-features/5143/1 "2022-03-02T03:28:10Z")

</div>

Hey all

I’m working on packaging abseil-cpp for conda-forge; abseil already [uses](https://github.com/abseil/abseil-cpp/blob/20211102.0/CMake/AbseilHelpers.cmake#L257-L261) `target_compile_features`, but sets it only to `cxx_std_11`, which is to my understanding not correct if abseil itself is compiled with a newer C++ standard (the API changes based on the C++ version, e.g. whether it’s using `std::string_view` or `absl::string_view`).

In the “old world” (see else-clause in link above), the feature level could be set dynamically, à la:

```auto
      set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
      set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)

```

But I’m wondering how to dynamically set the meta feature in the new world, à la:

```auto
target_compile_features(${_NAME} PUBLIC cxx_std_<MY_STANDARD>)

```

Is this possible, and if yes, how? If no, it would seem like a feature gap in the “new world” to me, but maybe I’m looking at this wrong…?

Thanks,  
H.

---

<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 2, 2022, 1:58pm UTC](https://discourse.cmake.org/t/programmatically-select-cxx-std-yy-meta-features/5143/2 "2022-03-02T13:58:39Z")

</div>

> [@h-vetinari](#):
>
> `target_compile_features(${_NAME} PUBLIC cxx_std_<MY_STANDARD>)`

`target_compile_features(${_NAME} PUBLIC cxx_std_${ABSL_CXX_STANDARD})`

should work.

---

<div class="post-metadata">

### Author: ![h-vetinari](https://discourse.cmake.org/user_avatar/discourse.cmake.org/h-vetinari/32/2207_2.png) [@h-vetinari](https://discourse.cmake.org/u/h-vetinari)
#### Post date: [March 3, 2022, 10:15pm UTC](https://discourse.cmake.org/t/programmatically-select-cxx-std-yy-meta-features/5143/3 "2022-03-03T22:15:52Z")

</div>

Thanks for the quick response. Wasn’t sure that would work. 🙂
