diff options
author | Michal Klocek <michal.klocek@qt.io> | 2021-08-20 10:33:57 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2021-08-30 19:47:56 +0200 |
commit | 68e724bf48eab90aca310d700b4aad0127b61d35 (patch) | |
tree | 7ac33f0adf9d38fd4b639ee75192cf8748f9ee8b /src/core/CMakeLists.txt | |
parent | add4dd7c1f50e09677f968a47c75309351e16743 (diff) |
Rewrite gn-cmake integration
The previous gn-cmake integration was driven towards having the
complete cmake build tree which included gn build artifacts.
These were marked as IMPORTED in cmake build files, this way
cmake "knew" all object files and static libs coming from gn.
To achieve that we needed to run the cmake configure twice.
First to feed gn with the build information from cmake and
then the second run to import all the build information to
cmake based on gn run.
As a side effect of this the first run cmake was creating incomplete
targets, so we could use generator expressions to gather all the data
needed for gn run. The second run of cmake was able to create fully
initialized targets. We used 'external project' to run cmake the second
time.
This approach worked well when doing "module" builds and having two
targets, one in the main project and one in external was not an issue.
Moreover, this approach could be integrated nicely since CI does only
"module" builds.
Unfortunately "top level" builds are implemented to import all qt
targets into one build tree. This created issue for qtwebengine since
fully initialized targets were 'hidden' by 'external project' and
including half baked (dummy) targets from the main project resulted
in bunch of issues related to the dependency tracking and build race
conditions. Also using 'external project' complicated installation
rules and in the end installation worked differently than in other
modules.
With current approach we use response files, so we hide all build
artifacts coming from gn and feed cmake with those response files.
This way we run the cmake configure once and we create all the targets
once. Using rsp files hacks linker options in cmake, so this approach
is sub-optimal, however allows to have working "top level" builds.
It is worth mentioning here that the final module linking has to take
place with cmake's part of build since doing one static lib in gn is
not possible due to the toolchain limitation (msvc is not able to
process static libs over 4Gb and has no support for thin archives,
so only a shared lib is doable at time of writing)
Following changes are made:
* remove 'external project' for qtwebengine target, we keep it however
for ninja ,gn and a host project
* call gn from cmake in a scripting mode during build and not configure
run, this way BUILD.gn is assembled as a build step so after
generator expressions are executed
* BUILD.gn is assembled now from 4 files:
- root template BUILD.root.gn.in
- compiler data gn_config_c.cmake, gn_config_cxx.cmake
- sources data gn_cofnig_target.cmake
* since we use gn wrapper script use gn.args file to pass arguments
instead of a command line, so this file can be now easily modified
when running gn and ninja 'manually'
* since a script mode does not support handling of properties with
TARGET as such, use the DIRECTORY scope in some of our functions
which handle GN_TARGET
* use qt_build_repo() in main CMakeFile and remove all coin and top
level build hacks
* remove 'external project' for examples and tests, this is no longer
required as all qt targets are not hidden by external project
* remove leftovers from gn feedback call used for GN_TARGET
* improve installation rules, WebEgineCore target is not by default
installed during build, therefore we need to copy resources and
translations to root so tests and examples still can be built without
a module being installed first
* adjust GN lookup paths, we look for gn in main configure and during
scripting mode when gn is executed
Fixes: QTBUG-94349
Fixes: QTBUG-94709
Fixes: QTBUG-94922
Fixes: QTBUG-94997
Fixes: QTBUG-95051
Fixes: QTBUG-95152
Fixes: QTBUG-95158
Fixes: QTBUG-95972
Task-number: QTBUG-95231
Task-number: QTBUG-95590
Change-Id: I5e7a34287ee59d904103fe310fc7c6a36a8dfbc9
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
(cherry picked from commit bd75c51f2a7f7384d3303e86764211cb3e32f03d)
Diffstat (limited to 'src/core/CMakeLists.txt')
-rw-r--r-- | src/core/CMakeLists.txt | 171 |
1 files changed, 39 insertions, 132 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index ffb327c2e..74ae345dc 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,32 +1,19 @@ cmake_minimum_required(VERSION 3.19) -if(NOT DEFINED WEBENGINE_ROOT_SOURCE_DIR) - get_filename_component(WEBENGINE_ROOT_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." REALPATH) -endif() -if (NOT DEFINED WEBENGINE_ROOT_BUILD_DIR) - get_filename_component(WEBENGINE_ROOT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/../.." REALPATH) -endif() - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${WEBENGINE_ROOT_SOURCE_DIR}/cmake") -set(buildDir "${CMAKE_CURRENT_BINARY_DIR}") - -include(${WEBENGINE_ROOT_SOURCE_DIR}/cmake/Functions.cmake) -assertRunAsTopLevelBuild(TRUE) - -add_subdirectory(api) -add_subdirectory(tools) - -find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core) -find_package(Gn ${QT_REPO_MODULE_VERSION} EXACT REQUIRED) find_package(Ninja 1.7.2 REQUIRED) find_package(Python2 2.7.5 REQUIRED) find_package(Nodejs 10.19 REQUIRED) find_package(PkgConfig) if(PkgConfig_FOUND) pkg_check_modules(XSCRNSAVER xscrnsaver) - create_pkg_config_host_wrapper() + create_pkg_config_host_wrapper(${CMAKE_CURRENT_BINARY_DIR}) endif() +set(buildDir "${CMAKE_CURRENT_BINARY_DIR}") + +add_subdirectory(api) +add_subdirectory(tools) + ## # TOOLCHAIN SETUP ## @@ -36,9 +23,11 @@ if(LINUX) endif() ## -# MULTICONFIG SETUP +# GN BUILD SETUP ## +addSyncTargets(core) + get_configs(configs) get_architectures(archs) @@ -49,13 +38,14 @@ foreach(arch ${archs}) # BUILD.gn SETUP ## - unset(buildGn) set(buildGn core_${config}_${arch}) - add_gn_target(${buildGn} ${config} ${arch} SOURCES DEFINES CXX_COMPILE_OPTIONS C_COMPILE_OPTIONS INCLUDES) - + add_gn_target(${buildGn} ${config} ${arch} + SOURCES DEFINES CXX_COMPILE_OPTIONS C_COMPILE_OPTIONS INCLUDES MOC_PATH RSP_PREFIX + ) resolve_target_includes(gnIncludes WebEngineCore) get_forward_declaration_macro(forwardDeclarationMacro) get_target_property(qtWebEngineProcessName WebEngineCore QTWEBENGINEPROCESS_NAME) + get_target_property(mocFilePath Qt6::moc IMPORTED_LOCATION) if(QT_FEATURE_debug_and_release AND ("${config}" STREQUAL "Debug")) set(qtWebEngineProcessName "${qtWebEngineProcessName}${CMAKE_DEBUG_POSTFIX}") @@ -74,15 +64,19 @@ foreach(arch ${archs}) endif() extend_gn_target(${buildGn} + MOC_PATH + ${mocFilePath} + RSP_PREFIX + src/core/${config}/${arch} INCLUDES ${gnIncludes} DEFINES QT_NO_KEYWORDS QT_USE_QSTRINGBUILDER - QTWEBENGINECORE_VERSION_STR=\\\\\"${QT_REPO_MODULE_VERSION}\\\\\" - QTWEBENGINEPROCESS_NAME=\\\\\"${qtWebEngineProcessName}\\\\\" + QTWEBENGINECORE_VERSION_STR=\\\\\\\\\"${QT_REPO_MODULE_VERSION}\\\\\\\\\" + QTWEBENGINEPROCESS_NAME=\\\\\\\\\"${qtWebEngineProcessName}\\\\\\\\\" BUILDING_CHROMIUM - ${forwardDeclarationMacro} + "${forwardDeclarationMacro}" CXX_COMPILE_OPTIONS ${gnCxxCompileOptions} SOURCES @@ -267,13 +261,6 @@ foreach(arch ${archs}) renderer/extensions/resource_request_policy_qt.cpp renderer/extensions/resource_request_policy_qt.h ) - read_gn_target(${buildGn} ${WEBENGINE_ROOT_BUILD_DIR}/src/core/api/${config}/gn_config.cxx.cmake) - read_gn_target(${buildGn} ${WEBENGINE_ROOT_BUILD_DIR}/src/core/api/${config}/gn_config.c.cmake) - configure_gn_target(${buildGn} ${config} - ${WEBENGINE_ROOT_SOURCE_DIR}/src/core/configure/BUILD.root.gn.in "${buildDir}/${config}/${arch}/BUILD.gn" - core/${config}/${arch} - ) - ## # GN PARAMETERS SETUP ## @@ -449,17 +436,22 @@ foreach(arch ${archs}) ) endif() - ## - # GN CALL - ## - - execute_gn(gnArgArg) + add_gn_command( + CMAKE_TARGET WebEngineCore + NINJA_TARGETS QtWebEngineCore convert_dict + GN_TARGET ${buildGn} + GN_ARGS "${gnArgArg}" + BUILDDIR ${buildDir}/${config}/${arch} + MODULE core + ) endforeach() + create_cxx_configs(WebEngineCore ${arch}) endforeach() + ## -# WEBENGINECORE +# WEBENGINECORE SETUP ## set(arch ${CMAKE_SYSTEM_PROCESSOR}) @@ -469,7 +461,8 @@ target_include_directories(WebEngineCore PRIVATE ${buildDir}/$<CONFIG>/${arch}/gen/third_party/perfetto/build_config ) -add_gn_build_aritfacts_to_target(WebEngineCore QtWebEngineCore ${buildDir}) +add_gn_build_aritfacts_to_target(WebEngineCore QtWebEngineCore core ${buildDir}) +add_dependencies(WebEngineCore run_core_NinjaDone) ## # SANDBOX @@ -483,6 +476,7 @@ if(WIN32) TARGET QtWebEngineCoreSandbox OUTPUT QtWebEngineCoreSandbox.lib BUILDDIR ${buildDir}/${config}/${arch} + MODULE core ) set(sandboxLibraryPath ${buildDir}/${config}/${arch}/QtWebEngineCoreSandbox.lib) set_property(TARGET WebEngineCoreSandbox @@ -490,101 +484,12 @@ if(WIN32) ) add_custom_target(sandboxLibrary_${config} DEPENDS ${buildDir}/${config}/${arch}/QtWebEngineCoreSandbox.lib) - add_dependencies(WebEngineCoreSandbox sandboxLibrary_${config}) + add_dependencies(run_core_NinjaDone sandboxLibrary_${config}) add_dependencies(WebEngineCoreSandbox WebEngineCore) endforeach() endif() ## -# WEBENGINECORE RESOURCES -## - -#TODO: use simply filter / globbing-expressions -set(localeList am ar bg bn ca cs da de el en-GB en-US es-419 es et fa fi fil fr - gu he hi hr hu id it ja kn ko lt lv ml mr ms nb nl pl pt-BR pt-PT ro ru sk - sl sr sv sw ta te th tr uk vi zh-CN zh-TW) - -set(resourceList qtwebengine_resources.pak - qtwebengine_resources_100p.pak - qtwebengine_resources_200p.pak - qtwebengine_devtools_resources.pak) - -get_install_config(config) - -foreach(loc ${localeList}) - get_filename_component(locSourcePath ${buildDir}/${config}/${arch}/qtwebengine_locales/${loc}.pak REALPATH) - list(APPEND localeFiles ${locSourcePath}) -endforeach() - -foreach(res ${resourceList}) - get_filename_component(resSourcePath ${buildDir}/${config}/${arch}/${res} REALPATH) - list(APPEND resourceFiles ${resSourcePath}) -endforeach() - -if (NOT QT_FEATURE_webengine_system_icu) - get_filename_component(icuFile ${buildDir}/${config}/${arch}/icudtl.dat REALPATH) - list(APPEND resourceFiles ${icuFile}) -endif() - -if(QT_FEATURE_framework) - set(allResourceFiles ${localeFiles} ${resourceFiles}) - target_sources(WebEngineCore PRIVATE ${allResourceFiles}) - - set_source_files_properties(${localeFiles} - TARGET_DIRECTORY WebEngineCore - PROPERTIES MACOSX_PACKAGE_LOCATION Resources/qtwebengine_locales - GENERATED TRUE - ) - set_source_files_properties(${resourceFiles} - TARGET_DIRECTORY WebEngineCore - PROPERTIES MACOSX_PACKAGE_LOCATION Resources - GENERATED TRUE - ) - - add_custom_command(OUTPUT ${allResourceFiles} DEPENDS ${buildDir}/${config}/${arch}/QtWebEngineCore.stamp) - add_custom_target(generate_resources_${config} DEPENDS ${allResourceFiles}) -else() - install(FILES ${localeFiles} - DESTINATION translations/qtwebengine_locales - CONFIGURATIONS ${config} - ) - install(FILES ${resourceFiles} - DESTINATION resources - CONFIGURATIONS ${config} - ) -# install (again) for superbuild - install(FILES ${localeFiles} - DESTINATION ${WEBENGINE_ROOT_BUILD_DIR}/translations/qtwebengine_locales - CONFIGURATIONS ${config} - ) - install(FILES ${resourceFiles} - DESTINATION ${WEBENGINE_ROOT_BUILD_DIR}/resources - CONFIGURATIONS ${config} - ) - if(NOT QT_WILL_INSTALL) - # TODO: Could we get rid of ALL? - add_custom_target( - install_resources_${config} - ALL - DEPENDS ${buildDir}/${config}/${arch}/QtWebEngineCore.stamp - COMMAND ${CMAKE_COMMAND} -E make_directory - ${CMAKE_INSTALL_PREFIX}/resources - COMMAND ${CMAKE_COMMAND} -E copy - ${resourceFiles} - ${CMAKE_INSTALL_PREFIX}/resources) - add_custom_target( - install_locales_${config} - ALL - DEPENDS ${buildDir}/${config}/${arch}/QtWebEngineCore.stamp - COMMAND ${CMAKE_COMMAND} -E make_directory - ${CMAKE_INSTALL_PREFIX}/translations/qtwebengine_locales - COMMAND ${CMAKE_COMMAND} -E copy - ${localeFiles} - ${CMAKE_INSTALL_PREFIX}/translations/qtwebengine_locales) - endif() -endif() - -## # WEBENGINECORE DICT TOOL SETUP ## @@ -593,8 +498,10 @@ if(QT_FEATURE_webengine_spellchecker) target_include_directories(${dict_target_name} PRIVATE ../3rdparty/chromium ../3rdparty/chromium/third_party/boringssl/src/include - ${buildDir}/${config}/${arch}/gen + ${buildDir}/$<CONFIG>/${arch}/gen ) - add_gn_build_aritfacts_to_target(${dict_target_name} convert_dict ${buildDir}) + add_gn_build_aritfacts_to_target(${dict_target_name} convert_dict core ${buildDir}) + add_dependencies(${dict_target_name} run_core_NinjaDone) + add_dependencies(${dict_target_name} WebEngineCore) endif() |