-
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
CMake - TEST_BIG_ENDIAN #45270
Comments
This seems to be more of a bug in the CMake itself than the Zephyr build system.
The compilation of Note that the CMake try_compile(HAVE_${VARIABLE}
"${CMAKE_BINARY_DIR}"
${_test_file}
OUTPUT_VARIABLE OUTPUT
COPY_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin" ) For instance, the compilation of try_compile(HAVE_${var} ${CMAKE_BINARY_DIR} ${src}
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
CMAKE_FLAGS
"-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}"
... Note that zephyr/cmake/compiler/gcc/target.cmake Line 121 in 04836af
Applying the following patch to the CMake --- /usr/share/cmake-3.22/Modules/TestBigEndian.cmake 2022-01-25 22:45:06.000000000 +0900
+++ cmaketest/Modules/TestBigEndian.cmake 2022-05-02 17:45:40.429774864 +0900
@@ -91,6 +91,9 @@
try_compile(HAVE_${VARIABLE}
"${CMAKE_BINARY_DIR}"
${_test_file}
+ CMAKE_FLAGS
+ "-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}"
+ "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
OUTPUT_VARIABLE OUTPUT
COPY_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin" ) Output after applying the patch:
Of course, the upstream CMake developers may argue that it is the toolchain's fault for not being able to produce an executable as-is without some special arguments (i.e. Nevertheless, apart from the questionable toolchain issues, it is true that CMake has an inconsistency in its internal compiler checks that the When @tejlmand (or @SebastianBoe) comes back, he can further comment on this and maybe file a bug report to the upstream CMake repository. |
FMPOV, the interesting part of this issue seems to be, that the tool-chain is usually used for "cross-compiling". So I'm not sure, if that is a working solution at all, to compile & execute the test. Maybe, it's possible to provide an other approach, where somewhere in the board definition (or target arch), this could be provided and returned, instead of trying to do the test above. |
It only compiles and does not execute the test, so it can and does (as shown above) work for cross compilers. Note that it literally looks for a string in a compiled binary, without attempting to execute it: |
Thanks, then I was wrong, mislead by the "executable" in the error logs. |
I tried to apply your patch. Doing so, I found TestBigEndian.cmake - deprecated:: 3.20
I will try that. Maybe that works without patch. Edited: |
Thanks for raising this. There are a couple of reasons why this doesn't work out of the box with Zephyr. Secondly, even if trying to use the new endianess detecting for CMake >=3.20, then the next issue that arises is that CMake default in Zephyr context tries to compile for an executable, which fails as we haven't generated a valid linker script for the compiler. Therefore one must set STATIC_LIBRARY as compile target type. I have a working hack that correctly detects the endianess with no patching to CMake, as can be seen here:
going to clean up the hack and find a proper location for the code. This will mean that both the CMake |
Just to mention: |
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. |
Fixes: zephyrproject-rtos#45270 Zephyr Kconfig defines the settings BIG_ENDIAN. Propagate this setting to the corresponding CMAKE_C_BYTE_ORDER and CMAKE_CXX_BYTE_ORDER variables. This also ensures that the CMake function 'is_big_endian()' reports the correct endianess. Signed-off-by: Torsten Rasmussen <[email protected]>
Fixes: #45270 Zephyr Kconfig defines the settings BIG_ENDIAN. Propagate this setting to the corresponding CMAKE_C_BYTE_ORDER and CMAKE_CXX_BYTE_ORDER variables. This also ensures that the CMake function 'is_big_endian()' reports the correct endianess. Signed-off-by: Torsten Rasmussen <[email protected]>
Describe the bug
Adding
to the
CMakeLists.txt
fails. It reports:To Reproduce
Add
to the
CMakeLists.txt
. ExecuteExpected behavior
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
setsIS_BIG_ENDIAN
according the used processor.Impact
IS_BIG_ENDIAN
must be set manually,Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: