From 961ff0cc8a7408f59b2d0f9adfa980fd89bd3274 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 27 Jun 2023 15:25:50 +0200 Subject: [PATCH] CMake: Don't use check_language for Objective-C/C++ The check_language macro spawns a new cmake subprocess to detect availability of a language. We use that to detect availability of the Objective-C/C++ languages when targeting Apple platforms. That's problematic because the parent process CFLAGS / LDFLAGS env vars influences the result of the subprocess compiler detection, and in some cases that can fail the detection. An example of that is passing iOS specific flags which then get mixed with the default macOS flags added by CMake, resulting in a linker failure. Instead of using check_language, explicitly enable the Objective-C and C++ languages when targeting Apple platforms because we know that we need them for compiling Qt. This avoids the issue because enable_language is not spawning a separate cmake sub-process and thus passes more information to the underlying try_compile project to ensure a successful check. The change also means that CMake will error out earlier in case if the Objective-C compiler is not found, which was not the case before. Pick-to: 6.5 6.6 Fixes: QTBUG-114470 Change-Id: I1a16c1e5828dfe10b2d7da27cc9a8c787517ab8e Reviewed-by: Alexey Edelev Reviewed-by: Amir Masoud Abdol Reviewed-by: Qt CI Bot Reviewed-by: Joerg Bornemann --- cmake/QtBuildInternals/QtBuildInternalsConfig.cmake | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index e07c77c85a2..4ee68e92c8f 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -328,24 +328,19 @@ function(qt_build_internals_add_toplevel_targets) endfunction() macro(qt_enable_cmake_languages) - include(CheckLanguage) set(__qt_required_language_list C CXX) - set(__qt_optional_language_list ) + set(__qt_platform_required_language_list ) - # https://gitlab.kitware.com/cmake/cmake/-/issues/20545 if(APPLE) - list(APPEND __qt_optional_language_list OBJC OBJCXX) + list(APPEND __qt_platform_required_language_list OBJC OBJCXX) endif() foreach(__qt_lang ${__qt_required_language_list}) enable_language(${__qt_lang}) endforeach() - foreach(__qt_lang ${__qt_optional_language_list}) - check_language(${__qt_lang}) - if(CMAKE_${__qt_lang}_COMPILER) - enable_language(${__qt_lang}) - endif() + foreach(__qt_lang ${__qt_platform_required_language_list}) + enable_language(${__qt_lang}) endforeach() # The qtbase call is handled in qtbase/CMakeLists.txt.