# C++ language wrongly propagated through dependency chain

**URL:** https://discourse.cmake.org/t/c-language-wrongly-propagated-through-dependency-chain/3315
**Category:** Usage
**Created:** [May 13, 2021, 7:49pm UTC](https://discourse.cmake.org/t/c-language-wrongly-propagated-through-dependency-chain/3315 "2021-05-13T19:49:23Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [May 13, 2021, 7:49pm UTC](https://discourse.cmake.org/t/c-language-wrongly-propagated-through-dependency-chain/3315/1 "2021-05-13T19:49:23Z")

</div>

I have a library L (either a static lib or a headers only library) and an client application A.  
I set the required language level for L with :  
target\_compile\_features(L PUBLIC cxx\_std\_14) on a recent CMake  
target\_compile\_options(L PUBLIC $\<$\<COMPILE\_LANGUAGE:CXX\>:-std=c++14\>) on older CMake version  
NB I use INTERFACE if L is headers only  
for A:  
target\_compile\_features(L PUBLIC cxx\_std\_17) on a recent CMake  
target\_compile\_options(L PUBLIC $\<$\<COMPILE\_LANGUAGE:CXX\>:-std=c++17\>) on older CMake version

I configure/generate/build L then A

on windows/mingw everything works as expected, gcc is called with -std=c++14 for L (if static library) and -std=C++17 for A

on Ubuntu/gcc or clang I have two std options in A build command line: -std=c++14 and -std=c++17 and the language effectively used is c++14 while I expected to have c++17

I used PUBLIC/INTERFACE for L because, if the situation would be reversed (L requiring C++17 and A requiring C++14, I’d expected cmake to chose C++17 for A also).

To make it simpler, I’d like cmake to chose the highest language version in the dependency chain. What is wrong in the way I set the language? What’s the correct way?

Regards

---

<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: [May 13, 2021, 8:01pm UTC](https://discourse.cmake.org/t/c-language-wrongly-propagated-through-dependency-chain/3315/2 "2021-05-13T20:01:58Z")

</div>

It already does choose the highest level. Remove your manual `target_compile_options` flag selection and it should work.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [May 14, 2021, 8:35am UTC](https://discourse.cmake.org/t/c-language-wrongly-propagated-through-dependency-chain/3315/3 "2021-05-14T08:35:13Z")

</div>

Hum, sorry but it’s not what I observe  
I use only target\_compile\_features or target\_compile\_options according to the cmake version, not both, and I have the issue described.  
for recent CMake, I also add  
set\_target\_properties(L PROPERTIES CXX\_EXTENSIONS OFF) for L  
set\_target\_properties(A PROPERTIES CXX\_EXTENSIONS OFF) for A

I precise that the library and the application are not part of the same cmake project.

I’ve got a project for L that install it.  
I’ve got another one for A where I do a find\_package(L) followed by target\_link\_libraries(A PRIVATE L::L)

Doing so L config files contains  
set\_target\_properties(TestLib::TestLib PROPERTIES  
INTERFACE\_COMPILE\_FEATURES “cxx\_std\_14”  
…  
which seems OK

But in A, I find -std=c++17 AND -std=c++14 in CXX\_FLAGS on Linux only.  
I have the same behaviour with cmake 3.5 and 3.19

On windows with mingw I’ve got only -std=c++17

regards

---

<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: [May 14, 2021, 10:54am UTC](https://discourse.cmake.org/t/c-language-wrongly-propagated-through-dependency-chain/3315/4 "2021-05-14T10:54:17Z")

</div>

Ah, I see I missed the note at the end of the line.

Hmm. Does [this thread](https://discourse.cmake.org/t/cmake-does-not-set-the-compiler-option-std-to-gnu17-or-c-17-although-i-set-the-target-compile-features-to-cxx-std-17/3299) offer any insight here? Basically, is `CMAKE_CXX_STANDARD` being set anywhere?

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [May 14, 2021, 12:27pm UTC](https://discourse.cmake.org/t/c-language-wrongly-propagated-through-dependency-chain/3315/5 "2021-05-14T12:27:14Z")

</div>

Actually I had already read the thread before posting and nope, no CMAKE\_CXX\_STANDARD.  
The closest I can find is `set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "14")`  
in a CMakeCXXCompiler.cmake file.

---

<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: [May 14, 2021, 2:04pm UTC](https://discourse.cmake.org/t/c-language-wrongly-propagated-through-dependency-chain/3315/6 "2021-05-14T14:04:51Z")

</div>

Hmm. A small example that demonstrates the problem would be appreciated then.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [May 17, 2021, 7:24am UTC](https://discourse.cmake.org/t/c-language-wrongly-propagated-through-dependency-chain/3315/7 "2021-05-17T07:24:18Z")

</div>

Hi,

It seems I have rooted down the issue to cmake version.

with CMake 3.5 (a version that I must kept compliant with), language is set with target\_compile\_options(L PUBLIC $\<$\<COMPILE\_LANGUAGE:CXX\>:-std=c++14\>)  
and  
target\_compile\_options(A PUBLIC $\<$\<COMPILE\_LANGUAGE:CXX\>:-std=c++17\>)

my issue with CMake 3.19 was that I forgot to rebuild also L with 3.19 and L package was propagating L target\_compile\_options.

So the issues narrows down to how properly propagate language on CMake version that does not support target\_compile\_features(… cxx\_std\_17|cxx\_std\_14|…)?

Thanks

---

<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: [May 17, 2021, 1:54pm UTC](https://discourse.cmake.org/t/c-language-wrongly-propagated-through-dependency-chain/3315/8 "2021-05-17T13:54:08Z")

</div>

> [@adaldev](#):
>
> So the issues narrows down to how properly propagate language on CMake version that does not support target\_compile\_features(… cxx\_std\_17|cxx\_std\_14|…)?

Alas, I think the answer is “update your CMake”. CMake 3.5 just isn’t going to magically support standards or compilers that were released after it (though we do try to make that work as well as possible, it’s just not bullet-proof).
