Skip to content

Commit

Permalink
CMake: Don't use check_language for Objective-C/C++
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Amir Masoud Abdol <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Joerg Bornemann <[email protected]>
  • Loading branch information
alcroito committed Jun 29, 2023
1 parent b249a8a commit 961ff0c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 961ff0c

Please sign in to comment.