From 430232e44d5e6c7d7fd7ca3ebebb06d74e21ce2f Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 3 Apr 2020 14:23:18 +0200 Subject: [PATCH] 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 Reviewed-by: Alexandru Croitor --- cmake/QtAutoDetect.cmake | 6 +++--- cmake/QtBuild.cmake | 9 ++++++--- .../QtBuildInternalsConfig.cmake | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/cmake/QtAutoDetect.cmake b/cmake/QtAutoDetect.cmake index 6f06c489849..d5d93007baf 100644 --- a/cmake/QtAutoDetect.cmake +++ b/cmake/QtAutoDetect.cmake @@ -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.") diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index dfe88d7da49..09ac0d0bb84 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -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" "$<$:${precompiled_header}>") + set_property(TARGET "${target}" APPEND PROPERTY "PRECOMPILE_HEADERS" "$<$,$>:${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 diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index cff3abb97b1..3265fea7b23 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -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)