Introduce QT_SYNC_HEADERS_AT_CONFIGURE_TIME flag

The syncqt tool was originally designed to run at build time, as a
part of dependency chain of Qt modules. This works well unless we need
the code model of the Qt project in IDE, since Qt source code actively
uses header aliases, and creating them at build time breaks the code
model until the initial build is done. So we made syncqt the configure
time tool to not break the developer experience.

It's more likely that developers build Qt using command line or don't
need the code model before the first build. So running the tool at
configure time should be optional.

QT_SYNC_HEADERS_AT_CONFIGURE_TIME switches the "mode" of the syncqt
tool from build time tool to the configure time tool. Without the
option enabled build procedure runs all the syncing targets at build
time only. The exception are the developer builds, if the
'-developer-build' option is enabled, QT_SYNC_HEADERS_AT_CONFIGURE_TIME
is set to TRUE by default. This gives better development experience for
the developers that don't use the code model in their IDE or don't
require it before the first build is finished. Also this build time
mode is preferred for the CI or similar build procedures where code
model is not required at all.

By default, the option initialized from the
QT_INTERNAL_CONFIGURE_FROM_IDE CMake variable.

TODO: The option is forced to TRUE for the static Ninja Multi-Config
builds. See QTBUG-113974 for details.

[ChangeLog][Build System] When building Qt from sources, syncqt and Qt
header files are now created at build time, not configure time. This
should speed up the configuration step. You can set the CMake variable
QT_CONFIGURE_TIME_SYNC_HEADERS to ON to use the previous behavior,
though. The old behavior is also preserved if cmake/configure is run
from inside an IDE - Qt Creator, Visual Studio Code, and CLion are
currently detected.

Task-number: QTBUG-111163
Task-number: QTBUG-109792
Change-Id: Ib61bda9546e58492be874a8591c37e100313d02c
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit a8cf976ce6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Alexey Edelev 2023-02-15 15:36:44 +01:00 committed by Qt Cherry-pick Bot
parent c73372b5fe
commit c131e159b0
4 changed files with 55 additions and 26 deletions

View File

@ -420,7 +420,7 @@ function(qt_internal_add_configure_time_executable target)
)
set(should_build_at_configure_time TRUE)
if(EXISTS "${target_binary_path}")
if(EXISTS "${target_binary_path}" AND EXISTS "${timestamp_file}")
set(last_ts 0)
foreach(source IN LISTS sources)
file(TIMESTAMP "${source}" ts "%s")

View File

@ -193,6 +193,8 @@ else()
set(QT_INTERNAL_CONFIGURE_FROM_IDE FALSE CACHE INTERNAL "Configuring Qt Project from IDE")
endif()
set(_qt_sync_headers_at_configure_time_default ${QT_INTERNAL_CONFIGURE_FROM_IDE})
if(FEATURE_developer_build)
if(DEFINED QT_CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_EXPORT_COMPILE_COMMANDS ${QT_CMAKE_EXPORT_COMPILE_COMMANDS})
@ -213,11 +215,26 @@ if(FEATURE_developer_build)
if (CMAKE_BUILD_TYPE AND CMAKE_BUILD_TYPE STREQUAL Debug)
set(__build_benchmarks OFF)
endif()
# Sync headers during the initial configuration of a -developer-build to facilitate code
# navigation for code editors that use an LSP-based code model.
set(_qt_sync_headers_at_configure_time_default TRUE)
else()
set(_qt_build_tests_default OFF)
set(__build_benchmarks OFF)
endif()
# Sync Qt header files at configure time
option(QT_SYNC_HEADERS_AT_CONFIGURE_TIME "Run syncqt at configure time already"
${_qt_sync_headers_at_configure_time_default})
unset(_qt_sync_headers_at_configure_time_default)
# In static Ninja Multi-Config builds the sync_headers dependencies(and other autogen dependencies
# are not added to '_autogen/timestamp' targets. See QTBUG-113974.
if(CMAKE_GENERATOR STREQUAL "Ninja Multi-Config" AND NOT QT_BUILD_SHARED_LIBS)
set(QT_SYNC_HEADERS_AT_CONFIGURE_TIME TRUE CACHE BOOL "" FORCE)
endif()
# Build Benchmarks
option(QT_BUILD_BENCHMARKS "Build Qt Benchmarks" ${__build_benchmarks})
if(QT_BUILD_BENCHMARKS)

View File

@ -251,7 +251,7 @@ function(qt_internal_target_sync_headers target module_headers module_headers_ge
# Run sync Qt first time at configure step to make all header files available for the code model
# of IDEs.
get_property(synced_modules GLOBAL PROPERTY _qt_synced_modules)
if(NOT "${module}" IN_LIST synced_modules)
if(NOT "${module}" IN_LIST synced_modules AND QT_SYNC_HEADERS_AT_CONFIGURE_TIME)
message(STATUS "Running syncqt.cpp for module: ${module}")
get_target_property(syncqt_location ${QT_CMAKE_EXPORT_NAMESPACE}::syncqt LOCATION)
execute_process(

View File

@ -11,29 +11,41 @@ set(compile_definitions
QT_NAMESPACE="${QT_NAMESPACE}"
)
set(config_type "")
if(NOT QT_INTERNAL_AVOID_OVERRIDING_SYNCQT_CONFIG)
set(config_type CONFIG RelWithDebInfo)
endif()
if(CMAKE_OSX_ARCHITECTURES)
set(osx_architectures "-DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}")
endif()
qt_get_tool_target_name(target_name syncqt)
# Note: configure-time tools reserve the original tool name for the imported executable.
# To re-build syncqt use 'syncqt_build' target.
qt_internal_add_configure_time_tool(${target_name}
DEFINES ${compile_definitions}
COMPILE_OPTIONS ${optimize_full_flags}
TOOLS_TARGET Core
INSTALL_DIRECTORY "${INSTALL_LIBEXECDIR}"
CMAKE_FLAGS
-DCMAKE_CXX_STANDARD_REQUIRED:BOOL=TRUE
-DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD}
# std::filesystem API is only available in macOS 10.15+
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.15
"${osx_architectures}"
SOURCES
if(NOT QT_SYNC_HEADERS_AT_CONFIGURE_TIME)
qt_internal_add_tool(${target_name}
DEFINES ${compile_definitions}
COMPILE_OPTIONS ${optimize_full_flags}
TOOLS_TARGET Core
CORE_LIBRARY None
INSTALL_DIR "${INSTALL_LIBEXECDIR}"
SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/main.cpp"
${config_type}
)
)
else()
set(config_type "")
if(NOT QT_INTERNAL_AVOID_OVERRIDING_SYNCQT_CONFIG)
set(config_type CONFIG RelWithDebInfo)
endif()
if(CMAKE_OSX_ARCHITECTURES)
set(osx_architectures "-DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}")
endif()
# Note: configure-time tools reserve the original tool name for the imported executable.
# To re-build syncqt use 'syncqt_build' target.
qt_internal_add_configure_time_tool(${target_name}
DEFINES ${compile_definitions}
COMPILE_OPTIONS ${optimize_full_flags}
TOOLS_TARGET Core
INSTALL_DIRECTORY "${INSTALL_LIBEXECDIR}"
CMAKE_FLAGS
-DCMAKE_CXX_STANDARD_REQUIRED:BOOL=TRUE
-DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD}
# std::filesystem API is only available in macOS 10.15+
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.15
"${osx_architectures}"
SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/main.cpp"
${config_type}
)
endif()