From 8b478431a77a58b0200e5df33e4480a07b4e562a Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 12 Sep 2023 11:05:58 +0200 Subject: [PATCH] Help the Skia build to find clang ..even if cmake sets CC/CXX to GCC. --- api/cpp/CMakeLists.txt | 82 +++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/api/cpp/CMakeLists.txt b/api/cpp/CMakeLists.txt index 95cf11f94..e368cb848 100644 --- a/api/cpp/CMakeLists.txt +++ b/api/cpp/CMakeLists.txt @@ -204,39 +204,57 @@ else(SLINT_STYLE) set_property(GLOBAL PROPERTY SLINT_STYLE ${SLINT_STYLE_DEFAULT}) endif(SLINT_STYLE) -# The Skia cross-build requires a host C compiler (due to some build dependencies of rust-skia), -# so cc.rs will first look for CC_ 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 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_. -# Finally, we set CC_ to clang or gcc and empty CFLAGS_ -if((SLINT_FEATURE_RENDERER_SKIA OR SLINT_FEATURE_RENDERER_SKIA_OPENGL OR SLINT_FEATURE_RENDERER_SKIA_VULKAN) AND CMAKE_CROSSCOMPILING AND Rust_CARGO_HOST_TARGET) - find_program(CLANG clang) - if(CLANG) - set(host_cc "${CLANG}") - else() - find_program(GCC gcc) - if (GCC) - set(host_cc "${GCC}") - endif() +if(SLINT_FEATURE_RENDERER_SKIA OR SLINT_FEATURE_RENDERER_SKIA_OPENGL OR SLINT_FEATURE_RENDERER_SKIA_VULKAN) + find_program(CLANGCC clang) + find_program(CLANGCXX clang++) + if(CLANGCC AND CLANGCXX) + set_property( + TARGET slint-cpp + APPEND + PROPERTY CORROSION_ENVIRONMENT_VARIABLES + CLANGCC=${CLANGCC} + ) + set_property( + TARGET slint-cpp + APPEND + PROPERTY CORROSION_ENVIRONMENT_VARIABLES + CLANGCXX=${CLANGCXX} + ) endif() - if(host_cc) - string(REPLACE "-" "_" cargo_host_target_underscore "${Rust_CARGO_HOST_TARGET}") - set_property( - TARGET slint-cpp - APPEND - 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}= - ) + + # The Skia cross-build requires a host C compiler (due to some build dependencies of rust-skia), + # so cc.rs will first look for CC_ 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 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_. + # Finally, we set CC_ to clang or gcc and empty CFLAGS_ + if(CMAKE_CROSSCOMPILING AND Rust_CARGO_HOST_TARGET) + if(CLANGCC) + set(host_cc "${CLANGCC}") + else() + find_program(GCC gcc) + if (GCC) + set(host_cc "${GCC}") + endif() + endif() + if(host_cc) + string(REPLACE "-" "_" cargo_host_target_underscore "${Rust_CARGO_HOST_TARGET}") + set_property( + TARGET slint-cpp + APPEND + 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() endif()