Skip to contentSkip to conversation

cmake: add CMAKE_SYSROOT to generated toolchain file

PATCH New Poonam Jadhav 1 participant 1 message Apr 21, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmake: add CMAKE_SYSROOT to generated toolchain file

From: Pascal Bach <[email protected]>

This already got fixed in the toolchain file that is used during development
in https://github.com/openembedded/openembedded-core/commit/cb42802f2fe1760f894a435b07286bca3a220364

The toolchain file generated by the cmake.bbclass however does not set CMAKE_SYSROOT. Under certain circumstances this also leads to the error:
"stdlib.h: No such file or directory #include_next <stdlib.h>" during the build of a recipe.

An example where this accured was during the upgrade of the Apache Thrift recipe in meta-openembedded to 0.11.0. With this change the build works out of the box.

CMAKE_SYSROOT must only be set when crosscompiling, otherwise it will interfere with the native compiler headers.

(from http://lists.openembedded.org/pipermail/openembedded-core/2018-August/154791.html )

---
 meta/classes-recipe/cmake.bbclass | 4 ++++
 1 file changed, 4 insertions(+)
meta/classes-recipe/cmake.bbclass +4 -0
index 554b948c32..301367b515 100644
@@ -94,6 +94,8 @@ def map_host_arch_to_uname_arch(host_arch):
 cmake_do_generate_toolchain_file() {
 	if [ "${BUILD_SYS}" = "${HOST_SYS}" ]; then
 		cmake_crosscompiling="set( CMAKE_CROSSCOMPILING FALSE )"
+       else
+               cmake_sysroot="set( CMAKE_SYSROOT \"${RECIPE_SYSROOT}\" )"
 	fi
 	cat > ${WORKDIR}/toolchain.cmake <<EOF
 # CMake system name must be something like "Linux".
@@ -126,6 +128,8 @@ set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
 set( CMAKE_PROGRAM_PATH "/" )
 
+$cmake_sysroot
+
 # Use qt.conf settings
 set( ENV{QT_CONF_PATH} ${WORKDIR}/qt.conf )
 
Signature · 1 line
2.25.1