Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target_compile_features in CMakeLists.txt triggers an error #32577

Closed
Thurnheer opened this issue Feb 23, 2021 · 10 comments
Closed

target_compile_features in CMakeLists.txt triggers an error #32577

Thurnheer opened this issue Feb 23, 2021 · 10 comments
Assignees
Labels
area: Build System Enhancement Changes/Updates/Additions to existing features

Comments

@Thurnheer
Copy link
Contributor

Thurnheer commented Feb 23, 2021

I am developing a framework. In the framework's CMakeLists.txt I've the following statement:
target_compile_features(myFramework PRIVATE cxx_std_17)

The application and the framework are developed using C++.

When I now run west build, I got the following error during cmake configuration:
target_compile_features no known features for CXX compiler "GNU" version 9.2.0

Using the toolchains from the zephyr SDK fails while trying to compile a simple test program.

I'm using the zephyr SDK for compilation, develop on Ubuntu LTS 20.04, use west version 0.8.0 and zephyr master.
cmake version 3.16.3

Is there a way out of this?

@Thurnheer Thurnheer added the bug The issue is a bug, or the PR is fixing a bug label Feb 23, 2021
@tejlmand
Copy link
Collaborator

this happens because Zephyr has it own toolchain handling and compiler verification scheme, which means the normal CMake check is not performed and therefore the target_compile_features won't work.

If you want to build using a specific language standard, you can do so by specifying: CONFIG_STD_CPP17=y either in prj.conf or on command line -DCONFIG_STD_CPP17=y.

See more here for possible settings:
https://docs.zephyrproject.org/latest/reference/kconfig/choice_359.html#choice-359

@Thurnheer
Copy link
Contributor Author

Thurnheer commented Feb 25, 2021

The problem is that the framework is targeting windows, linux and zephyr, so at least for windows and linux we need the target_compile_features. It would be convenient to just set it in the CmakeLists file so every project using the framework has automatically the correct settings, or is it possible to somehow set it for zepyr in the cmake file?
We also cross-compile it for yocto. There the cross-compilation toolchain can handle it.

@tejlmand
Copy link
Collaborator

The problem is that the framework is targeting windows, linux and zephyr, so at least for windows and linux we need the target_compile_features.

I see, and thanks for this additional info.
Although Zephyr itself has it's own toolchain handling, for sure this should not prevent users from using common CMake features in shared projects.
I will look into how this may be handled.

Note: there is a wish in community to also be able to use the common CMake toolchain functionality, but that is a bigger task to introduce this, as several compile options are handled through Kconfig and the toolchain infrastructure, so it must be ensure the two principles doesn't conflict.

@tejlmand tejlmand added the priority: low Low impact/importance bug label Feb 25, 2021
@github-actions
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Apr 27, 2021
@tejlmand tejlmand removed the Stale label Apr 27, 2021
@carlescufi carlescufi added Enhancement Changes/Updates/Additions to existing features and removed bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug labels May 19, 2021
@carlescufi
Copy link
Member

Changing to Enhancement to support CMake's CMAKE_TOOLCHAIN_FILE

@yashi
Copy link
Collaborator

yashi commented Sep 25, 2021

If the whole point is to workaround the error caused by target_compile_features(), how about setting CMAKE_C_COMPILE_FEATURES based on CSTD? Or, for c++ variant.

@Thurnheer, if it's just for you, you might want to set(CMAKE_CXX_COMPILE_FEATURES cxx_std_17) before going down to your framework.

@tejlmand
Copy link
Collaborator

The fix to this seems to be the same as I proposed here:
#36558 (comment)

but never got a reply on that message.
I would like to be sure it fixes the use-cases described and that they won't hit another obstacle afterwards.
(I prefer complete fixes, not partial fixes before sending a PR 😉 )

@yashi
Copy link
Collaborator

yashi commented Sep 27, 2021

Ah, I wasn't aware of the issue. Thanks!
(I think we can close this as a duplicate. The other has medium priority 😁).

FWIW, I'm using the same workaround when I integrate a CMake based project as a Zephyr module. So +1 for this.

tejlmand added a commit to tejlmand/zephyr that referenced this issue Sep 30, 2021
Fixes: zephyrproject-rtos#36558 zephyrproject-rtos#32577

This commit introduces CMAKE_C_COMPILE_FEATURES and
CMAKE_CXX_COMPILE_FEATURES.

This allows users to use the `target_compile_features()` in their own
code.

In Zephyr, the CMAKE_C/CXX_COMPILE_FEATURES are defined based on the
compiler and the Kconfig / CSTD setting.
Doing so ensures that a user compiling Zephyr with c99 and specifies
`target_compile_features(<target> ... c_std_11)` will get an error.
And similar if building Zephyr with C++ support and c++11, but testing
for `target_compile_features(<target> ... cxx_std_17)`.

For example in the C++ case, the user must ensure that Zephyr is
compiled with C++17, that is: CPLUSPLUS=y and STD_CPP17=y, in which case
the CMAKE_CXX_COMPILE_FEATURES will contain support for C++17 and thus
the `target_compile_features(<target> ... cxx_std_17)` will succeed.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
@tejlmand
Copy link
Collaborator

Fixed here: #39014

cfriedt pushed a commit that referenced this issue Oct 1, 2021
Fixes: #36558 #32577

This commit introduces CMAKE_C_COMPILE_FEATURES and
CMAKE_CXX_COMPILE_FEATURES.

This allows users to use the `target_compile_features()` in their own
code.

In Zephyr, the CMAKE_C/CXX_COMPILE_FEATURES are defined based on the
compiler and the Kconfig / CSTD setting.
Doing so ensures that a user compiling Zephyr with c99 and specifies
`target_compile_features(<target> ... c_std_11)` will get an error.
And similar if building Zephyr with C++ support and c++11, but testing
for `target_compile_features(<target> ... cxx_std_17)`.

For example in the C++ case, the user must ensure that Zephyr is
compiled with C++17, that is: CPLUSPLUS=y and STD_CPP17=y, in which case
the CMAKE_CXX_COMPILE_FEATURES will contain support for C++17 and thus
the `target_compile_features(<target> ... cxx_std_17)` will succeed.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
zephyrbot pushed a commit that referenced this issue Oct 1, 2021
Fixes: #36558 #32577

This commit introduces CMAKE_C_COMPILE_FEATURES and
CMAKE_CXX_COMPILE_FEATURES.

This allows users to use the `target_compile_features()` in their own
code.

In Zephyr, the CMAKE_C/CXX_COMPILE_FEATURES are defined based on the
compiler and the Kconfig / CSTD setting.
Doing so ensures that a user compiling Zephyr with c99 and specifies
`target_compile_features(<target> ... c_std_11)` will get an error.
And similar if building Zephyr with C++ support and c++11, but testing
for `target_compile_features(<target> ... cxx_std_17)`.

For example in the C++ case, the user must ensure that Zephyr is
compiled with C++17, that is: CPLUSPLUS=y and STD_CPP17=y, in which case
the CMAKE_CXX_COMPILE_FEATURES will contain support for C++17 and thus
the `target_compile_features(<target> ... cxx_std_17)` will succeed.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
nashif pushed a commit that referenced this issue Oct 19, 2021
Fixes: #36558 #32577

This commit introduces CMAKE_C_COMPILE_FEATURES and
CMAKE_CXX_COMPILE_FEATURES.

This allows users to use the `target_compile_features()` in their own
code.

In Zephyr, the CMAKE_C/CXX_COMPILE_FEATURES are defined based on the
compiler and the Kconfig / CSTD setting.
Doing so ensures that a user compiling Zephyr with c99 and specifies
`target_compile_features(<target> ... c_std_11)` will get an error.
And similar if building Zephyr with C++ support and c++11, but testing
for `target_compile_features(<target> ... cxx_std_17)`.

For example in the C++ case, the user must ensure that Zephyr is
compiled with C++17, that is: CPLUSPLUS=y and STD_CPP17=y, in which case
the CMAKE_CXX_COMPILE_FEATURES will contain support for C++17 and thus
the `target_compile_features(<target> ... cxx_std_17)` will succeed.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Rushybrook pushed a commit to Rushybrook/zephyr that referenced this issue Oct 21, 2021
Fixes: zephyrproject-rtos#36558 zephyrproject-rtos#32577

This commit introduces CMAKE_C_COMPILE_FEATURES and
CMAKE_CXX_COMPILE_FEATURES.

This allows users to use the `target_compile_features()` in their own
code.

In Zephyr, the CMAKE_C/CXX_COMPILE_FEATURES are defined based on the
compiler and the Kconfig / CSTD setting.
Doing so ensures that a user compiling Zephyr with c99 and specifies
`target_compile_features(<target> ... c_std_11)` will get an error.
And similar if building Zephyr with C++ support and c++11, but testing
for `target_compile_features(<target> ... cxx_std_17)`.

For example in the C++ case, the user must ensure that Zephyr is
compiled with C++17, that is: CPLUSPLUS=y and STD_CPP17=y, in which case
the CMAKE_CXX_COMPILE_FEATURES will contain support for C++17 and thus
the `target_compile_features(<target> ... cxx_std_17)` will succeed.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
@tejlmand
Copy link
Collaborator

tejlmand commented Nov 3, 2021

Fixed here: #39014 and #39060

@tejlmand tejlmand closed this as completed Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

No branches or pull requests

4 participants