summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2023-02-15 15:36:44 +0100
committerAlexey Edelev <alexey.edelev@qt.io>2023-06-27 17:27:28 +0000
commita8cf976ce6c82192bdf2d4b310e9ba0ea75bd0b0 (patch)
tree6d325adb33aeef6ceb52fa2c3a4ca6af2f4e184a
parentb3f27f75b638c6eb8494d681cd4df50dd34bcac0 (diff)
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 Pick-to: 6.6 Change-Id: Ib61bda9546e58492be874a8591c37e100313d02c Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--cmake/QtExecutableHelpers.cmake2
-rw-r--r--cmake/QtSetup.cmake17
-rw-r--r--cmake/QtSyncQtHelpers.cmake2
-rw-r--r--src/tools/syncqt/CMakeLists.txt60
4 files changed, 55 insertions, 26 deletions
diff --git a/cmake/QtExecutableHelpers.cmake b/cmake/QtExecutableHelpers.cmake
index 768e1f1562..dc73f57844 100644
--- a/cmake/QtExecutableHelpers.cmake
+++ b/cmake/QtExecutableHelpers.cmake
@@ -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")
diff --git a/cmake/QtSetup.cmake b/cmake/QtSetup.cmake
index a973756d1d..f9ddd87313 100644
--- a/cmake/QtSetup.cmake
+++ b/cmake/QtSetup.cmake
@@ -205,6 +205,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})
@@ -225,11 +227,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)
diff --git a/cmake/QtSyncQtHelpers.cmake b/cmake/QtSyncQtHelpers.cmake
index b8eead1a9a..001ddee5f0 100644
--- a/cmake/QtSyncQtHelpers.cmake
+++ b/cmake/QtSyncQtHelpers.cmake
@@ -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(
diff --git a/src/tools/syncqt/CMakeLists.txt b/src/tools/syncqt/CMakeLists.txt
index 3740b1bd4d..9cdbec8841 100644
--- a/src/tools/syncqt/CMakeLists.txt
+++ b/src/tools/syncqt/CMakeLists.txt
@@ -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()