CMake: Adjust PCH support for multi-arch iOS builds

Starting with CMake 3.18, there is PCH support for darwin multi-arch
builds, like iOS simulator_and_device builds.

Also enable PCH for Objective-C++ files when the support is there.

To enable PCH for Objective-C++, we need to do enable the OBJCXX
language as well, but conditionally, because on non-darwin platforms
the language is probably not available.

Introduce the qt_enable_cmake_languages() macro which is called
automatically by qt_build_repo_begin().

Change-Id: I0e7f44be6577ac54ce940470036626409920e272
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexandru Croitor 2020-04-03 14:23:18 +02:00
parent 9121829916
commit 430232e44d
3 changed files with 27 additions and 6 deletions

View File

@ -205,10 +205,10 @@ endfunction()
function(qt_auto_detect_pch)
set(default_value "ON")
if(CMAKE_OSX_ARCHITECTURES)
if(CMAKE_OSX_ARCHITECTURES AND CMAKE_VERSION VERSION_LESS 3.18.0 AND NOT QT_FORCE_PCH)
list(LENGTH CMAKE_OSX_ARCHITECTURES arch_count)
# CMake doesn't currently support PCH when multiple architecture are set. This is the
# case for simulator_and_device builds.
# CMake versions lower than 3.18 don't support PCH when multiple architectures are set.
# This is the case for simulator_and_device builds.
if(arch_count GREATER 1)
set(default_value "OFF")
message(WARNING "PCH support disabled due to usage of multiple architectures.")

View File

@ -1092,7 +1092,7 @@ endfunction()
function(qt_update_precompiled_header target precompiled_header)
if (precompiled_header AND BUILD_WITH_PCH)
set_property(TARGET "${target}" APPEND PROPERTY "PRECOMPILE_HEADERS" "$<$<COMPILE_LANGUAGE:CXX>:${precompiled_header}>")
set_property(TARGET "${target}" APPEND PROPERTY "PRECOMPILE_HEADERS" "$<$<OR:$<COMPILE_LANGUAGE:CXX>,$<COMPILE_LANGUAGE:OBJCXX>>:${precompiled_header}>")
endif()
endfunction()
@ -1113,8 +1113,11 @@ function(qt_update_ignore_pch_source target sources)
endfunction()
function(qt_ignore_pch_obj_c_sources target sources)
list(FILTER sources INCLUDE REGEX "\\.mm$")
qt_update_ignore_pch_source("${target}" "${sources}")
# No obj-cxx PCH support for versions lower than 3.16.
if(CMAKE_VERSION VERSION_LESS 3.16.0)
list(FILTER sources INCLUDE REGEX "\\.mm$")
qt_update_ignore_pch_source("${target}" "${sources}")
endif()
endfunction()
# This function can be used to add sources/libraries/etc. to the specified CMake target

View File

@ -65,8 +65,26 @@ macro(qt_build_internals_set_up_private_api)
qt_check_if_tools_will_be_built()
endmacro()
macro(qt_enable_cmake_languages)
include(CheckLanguage)
set(__qt_required_language_list C CXX)
set(__qt_optional_language_list OBJC OBJCXX)
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()
endforeach()
endmacro()
macro(qt_build_repo_begin)
qt_build_internals_set_up_private_api()
qt_enable_cmake_languages()
# Add global docs targets that will work both for per-repo builds, and super builds.
if(NOT TARGET docs)