-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Use of CMAKE_<lang>_COMPILER_FORCED on host-builds flag breaks third-party libraries #36558
Comments
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. |
The reason for this behavior is because Zephyr build infrastructure performs it's own toolchain testing regarding valid compiler flags. This is why CMake's own testing is disabled. What we should probably do is to tell CMake about the known compile features when we are testing the compiler.
This should probably be done in the compiler_flags.cmake for the compiler. @palchak-google before posting a fix, I would like to test it out on your use-case, so could you provide a small snippet and a reference to the testing framework you are using. Thanks in advance. |
might be better to link from #8827 BTW, is this really a bug? It sounds like an enhancement. |
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>
I would say it depends on the direction from where you see this. But better support for downstream users can be argued as an enhancement. But definitely not a medium bug, so I changed to low. But a fix is ready here: #39014 |
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>
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>
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>
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>
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. |
This is fixed. |
Describe the bug
When building for the "native_posix" target using the "host" toolchain, it's possible to use third-party libraries (e.g. unit test frameworks). Many such frameworks provide CMake build files, and some rely upon CMake's idiomatic, portable
target_compile_features()
function to ensure the compiler supports all the necessary language features.Zephyr's build system unconditionally sets the CMAKE_<lang>_COMPILER_FORCED global variables. This has the effect of inhibiting CMake's automatic discovery of compiler features. Without compiler feature discovery CMake generates an error at list time if
target_compile_features()
is used anywhere in the build.To Reproduce
Steps to reproduce the behavior:
zephyr/samples/basic/minimal/CMakeLists.txt
:target_compile_features(app PRIVATE cxx_std_17)
BOARD=native_posix
andZEPHYR_TOOLCHAIN_VARIANT=host
:Expected behavior
Build should complete normally and a valid
zephyr.elf
should be produced.Environment (please complete the following information):
Proposed Fix*
Zephyr should not set the CMAKE_<lang>_COMPILER_FORCED flags when the 'host' toolchain is used for the target. In such circumstances, the particulars of the host toolchain may not be known in advance (unlike what is typical with target-specific toolchains). Also the build may include third-party libraries that rely upon CMake's automatic discovery of compiler features.
The straightforward fix is as follows:
zephyr/cmake/boilerplate.cmake
:zephyr/cmake/target_toolchain.cmake
as follows:The text was updated successfully, but these errors were encountered: