Fix build of CMake package inside Yocto build

When building against a Yocto SDK, CFLAGS isn't set, only CC. When
building inside Yocto, CC is set to just the target compiler and CFLAGS
contains the target specific options. Just like with commit
5bc56a3924 we need to cover also
HOST_CFLAGS by making them empty.
This commit is contained in:
Simon Hausmann 2022-08-19 17:02:30 +02:00
parent f7ed7cc3fc
commit c69437fe8f

View file

@ -168,11 +168,11 @@ endif(SLINT_STYLE)
# so cc.rs will first look for CC_<triplet> and then HOST_CC.
# When cross-compiling, CMake doesn't really know what the host compiler is. Corrosion will set
# HOST_CC to $CC, which is a good bet. Unfortunately in Yocto environments, CC will be set to
# the cross-compiler.
# the cross-compiler. The same applies to CFLAGS, which may contain target specific options.
# So the hack to solve this is two-fold:
# * We look for clang or gcc in PATH - unprefixed those are usually host compilers.
# * Through corrosion we know the correct host value of CC_<triplet>.
# Finally, we set CC_<host triplet> to clang or gcc.
# Finally, we set CC_<host triplet> to clang or gcc and empty CFLAGS_<host triplet>
if(SLINT_FEATURE_RENDERER_SKIA AND CMAKE_CROSSCOMPILING AND Rust_CARGO_HOST_TARGET)
find_program(CLANG clang)
if(CLANG)
@ -191,6 +191,12 @@ if(SLINT_FEATURE_RENDERER_SKIA AND CMAKE_CROSSCOMPILING AND Rust_CARGO_HOST_TARG
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
CC_${cargo_host_target_underscore}=${host_cc}
)
set_property(
TARGET slint-cpp
APPEND
PROPERTY CORROSION_ENVIRONMENT_VARIABLES
CFLAGS_${cargo_host_target_underscore}=""
)
endif()
endif()