# Best practice for a library with multiple language bindings: target definitions with compile\_features

**URL:** <https://discourse.cmake.org/t/best-practice-for-a-library-with-multiple-language-bindings-target-definitions-with-compile-features/2168>\
**Category:** Code\
**Created:** [November 12, 2020, 6:35pm UTC](https://discourse.cmake.org/t/best-practice-for-a-library-with-multiple-language-bindings-target-definitions-with-compile-features/2168 "2020-11-12T18:35:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![relliott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/relliott/32/790_2.png) [@relliott](https://discourse.cmake.org/u/relliott)\
**Post date:** [November 12, 2020, 6:35pm UTC](https://discourse.cmake.org/t/best-practice-for-a-library-with-multiple-language-bindings-target-definitions-with-compile-features/2168/1 "2020-11-12T18:35:00Z")

</div>

I develop a library with language bindings for c, c++, and Fortran. The library c++ bindings require cxx\_std\_17 features.

If I create the shared library target and use `target_compile_features(XYZ PUBLIC cxx_std_17)` and export the target for use by other projects, then those projects must activate the CXX language even if they are pure Fortran. That is, a pure Fortran project must use

```auto
project(my-fortran-app LANGUAGES Fortran CXX)
find_package(XYZ)

```

where `XYZ` is my library. It seems like the `CXX` in the `project` command should not be necessary. However, it if is not there CMake gives the error: `Cannot use features from non-enabled language CXX`

Am I missing something? How should the `XYZ` package create and export its targets to avoid this? Should multiple targets, one for each language binding, be created?

---

<div class="post-metadata">

**Author:** ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)\
**Post date:** [November 13, 2020, 7:08am UTC](https://discourse.cmake.org/t/best-practice-for-a-library-with-multiple-language-bindings-target-definitions-with-compile-features/2168/2 "2020-11-13T07:08:50Z")

</div>

If the C++17 requirement is for the library itself only, then you should set the compile feature privately: `target_compile_features(XYZ PRIVATE cxx_std_17)`

---

<div class="post-metadata">

**Author:** ![relliott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/relliott/32/790_2.png) [@relliott](https://discourse.cmake.org/u/relliott)\
**Post date:** [November 13, 2020, 7:23pm UTC](https://discourse.cmake.org/t/best-practice-for-a-library-with-multiple-language-bindings-target-definitions-with-compile-features/2168/3 "2020-11-13T19:23:30Z")

</div>

I now see that this issues has been identified and discussed on the gitlab issues:

[https://gitlab.kitware.com/cmake/cmake/-/issues/20438](https://gitlab.kitware.com/cmake/cmake/-/issues/20438)

It seems there is currently no fix for this, but it is a known issue.
