diff options
author | Michal Klocek <michal.klocek@qt.io> | 2021-02-26 16:11:08 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2021-05-22 14:10:17 +0200 |
commit | 6d6037be24bcbff5efada34ed39331c7c8b28f3b (patch) | |
tree | 40febb3d86fa4742dcc2cebc9da80b1263456ba5 | |
parent | 68de090b1fce66f36743d31f384398af8c140a1d (diff) |
Add mac builds to cmake
We need to pass -F or -iframework to gn as a compiler flag, however
cmake keeps this parameter as include dir and adds internally
"-iframework QtFoo.framework/.." for the compiler call. This internal
handling can not be accessed with the genex. Add the manual conversion.
Task-number: QTBUG-91760
Change-Id: Id12831432ccb0516be52f79bd5f6cfcbe7e87d9c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | CMakeLists.txt | 16 | ||||
-rw-r--r-- | cmake/Functions.cmake | 67 | ||||
-rw-r--r-- | src/core/CMakeLists.txt | 71 | ||||
-rw-r--r-- | src/core/web_engine_library_info.cpp | 2 | ||||
-rw-r--r-- | src/gn/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/process/CMakeLists.txt | 27 |
6 files changed, 152 insertions, 33 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 876db610e..1a6bbfe9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,10 +163,12 @@ if(NOT Ninja_FOUND) externalproject_add_stepdependencies(gn install ninja) endif() -# install resources (again), coin calls install with DESTDIR -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/translations/qtwebengine_locales - DESTINATION ${CMAKE_INSTALL_PREFIX}/translations -) -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/resources - DESTINATION ${CMAKE_INSTALL_PREFIX} -) +if(NOT QT_FEATURE_framework) + # install resources (again), coin calls install with DESTDIR + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/translations/qtwebengine_locales + DESTINATION ${CMAKE_INSTALL_PREFIX}/translations + ) + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/resources + DESTINATION ${CMAKE_INSTALL_PREFIX} + ) +endif() diff --git a/cmake/Functions.cmake b/cmake/Functions.cmake index b63b96ed1..72069e015 100644 --- a/cmake/Functions.cmake +++ b/cmake/Functions.cmake @@ -159,8 +159,6 @@ function(configure_gn_target target configType inFilePath outFilePath) set(GN_SOURCES ${sourceList}) list(FILTER GN_HEADERS INCLUDE REGEX "^.+\\.h\"$") list(FILTER GN_SOURCES EXCLUDE REGEX "^.+\\.h\"$") - string(REPLACE ";" ",\n " GN_HEADERS "${GN_HEADERS}") - string(REPLACE ";" ",\n " GN_SOURCES "${GN_SOURCES}") # GN_DEFINES get_target_property(gnDefines ${target} GN_DEFINES) @@ -169,8 +167,6 @@ function(configure_gn_target target configType inFilePath outFilePath) list(APPEND GN_ARGS_DEFINES \"-D${gnDefine}\") list(APPEND GN_DEFINES \"${gnDefine}\") endforeach() - string(REPLACE ";" ",\n " GN_ARGS_DEFINES "${GN_ARGS_DEFINES}") - string(REPLACE ";" ",\n " GN_DEFINES "${GN_DEFINES}") # GN_INCLUDES get_target_property(gnIncludes ${target} GN_INCLUDES) @@ -180,8 +176,6 @@ function(configure_gn_target target configType inFilePath outFilePath) list(APPEND GN_ARGS_INCLUDES \"-I${gnInclude}\") list(APPEND GN_INCLUDE_DIRS \"${gnInclude}\") endforeach() - string(REPLACE ";" ",\n " GN_ARGS_INCLUDES "${GN_ARGS_INCLUDES}") - string(REPLACE ";" ",\n " GN_INCLUDE_DIRS "${GN_INCLUDE_DIRS}") # MOC get_target_property(GN_MOC_BIN_IN Qt6::moc IMPORTED_LOCATION) @@ -193,7 +187,6 @@ function(configure_gn_target target configType inFilePath outFilePath) list(APPEND GN_CFLAGS_CC \"${gnCxxCompileOption}\") endforeach() list(REMOVE_DUPLICATES GN_CFLAGS_CC) - string(REPLACE ";" ",\n " GN_CFLAGS_CC "${GN_CFLAGS_CC}") # GN_CFLAGS_C get_target_property(gnCCompileOptions ${target} GN_C_COMPILE_OPTIONS) @@ -201,7 +194,15 @@ function(configure_gn_target target configType inFilePath outFilePath) list(APPEND GN_CFLAGS_C \"${gnCCompileOption}\") endforeach() list(REMOVE_DUPLICATES GN_CFLAGS_C) - string(REPLACE ";" ",\n " GN_CFLAGS_C "${GN_CFLAGS_C}") + + if(MACOS) + recoverFrameworkBuild(GN_INCLUDE_DIRS GN_CFLAGS_C) + endif() + + foreach(item GN_HEADERS GN_SOURCES GN_ARGS_DEFINES GN_DEFINES GN_ARGS_INCLUDES + GN_INCLUDE_DIRS GN_CFLAGS_CC GN_CFLAGS_C) + string(REPLACE ";" ",\n " ${item} "${${item}}") + endforeach() configure_file(${inFilePath} ${outFilePath} @ONLY) endfunction() @@ -240,3 +241,53 @@ macro(assertRunAsTopLevelBuild condition) return() endif() endmacro() + +# we need to pass -F or -iframework in case of frameworks builds, which gn treats as +# compiler flag and cmake as include dir, so swap it. +function(recoverFrameworkBuild includeDirs compilerFlags) + foreach(includeDir ${${includeDirs}}) + if (includeDir MATCHES "^\"(.*/([^/]+)\\.framework)\"$") + list(APPEND frameworkDirs \"-iframework${CMAKE_MATCH_1}/..\") + else() + list(APPEND newIncludeDirs ${includeDir}) + endif() + endforeach() + set(${includeDirs} ${newIncludeDirs} PARENT_SCOPE) + set(${compilerFlags} ${${compilerFlags}} ${frameworkDirs} PARENT_SCOPE) +endfunction() + +# we need to fix namespace ambiguity issues between Qt and Chromium like +# forward declarations of NSString. +function(get_forward_declaration_macro result) + if(MACOS) + set(${result} "Q_FORWARD_DECLARE_OBJC_CLASS(name)=class name;" PARENT_SCOPE) +else() + set(${result} "Q_FORWARD_DECLARE_OBJC_CLASS=QT_FORWARD_DECLARE_CLASS" PARENT_SCOPE) +endif() +endfunction() + +function(get_darwin_sdk_version result) + if(APPLE) + if(IOS) + set(sdk_name "iphoneos") + elseif(TVOS) + set(sdk_name "appletvos") + elseif(WATCHOS) + set(sdk_name "watchos") + else() + # Default to macOS + set(sdk_name "macosx") + endif() + set(xcrun_version_arg "--show-sdk-version") + execute_process(COMMAND /usr/bin/xcrun --sdk ${sdk_name} ${xcrun_version_arg} + OUTPUT_VARIABLE sdk_version + ERROR_VARIABLE xcrun_error) + if(NOT sdk_version) + message(FATAL_ERROR + "Can't determine darwin ${sdk_name} SDK version. Error: ${xcrun_error}") + endif() + string(STRIP "${sdk_version}" sdk_version) + set(${result} "${sdk_version}" PARENT_SCOPE) + endif() +endfunction() + diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index ff38398d8..dc478ca05 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -11,7 +11,6 @@ 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) @@ -48,6 +47,7 @@ foreach(config ${configs}) add_gn_target(${buildGn} SOURCES DEFINES CXX_COMPILE_OPTIONS C_COMPILE_OPTIONS INCLUDES) resolve_target_includes(gnIncludes WebEngineCore) + get_forward_declaration_macro(forwardDeclarationMacro) extend_gn_target(${buildGn} INCLUDES @@ -58,6 +58,7 @@ foreach(config ${configs}) QTWEBENGINECORE_VERSION_STR=\\\\\"${QT_REPO_MODULE_VERSION}\\\\\" QTWEBENGINEPROCESS_NAME=\\\\\"${qtWebEngineProcessName}\\\\\" BUILDING_CHROMIUM + ${forwardDeclarationMacro} SOURCES accessibility_activation_observer.cpp accessibility_activation_observer.h accessibility_tree_formatter_qt.cpp @@ -462,6 +463,22 @@ foreach(config ${configs}) ) endif() + if(MACOS) + get_darwin_sdk_version(macSdkVersion) + get_filename_component(clangBasePath ${CMAKE_OBJCXX_COMPILER} DIRECTORY) + get_filename_component(clangBasePath ${clangBasePath} DIRECTORY) + list(APPEND gnArgArg + use_sysroot=false + use_system_xcode=true + clang_base_path="${clangBasePath}" + clang_use_chrome_plugins=false + mac_deployment_target="${CMAKE_OSX_DEPLOYMENT_TARGET}" + mac_sdk_min="${macSdkVersion}" + use_external_popup_menu=false + angle_enable_vulkan=false + ) + endif() + list(JOIN gnArgArg " " gnArgArg) list(APPEND gnArg "--args=${gnArgArg}") @@ -559,28 +576,56 @@ endforeach() get_filename_component(icuFiles ${buildDir}/${config}/icudtl.dat REALPATH) -install(FILES ${localeFiles} +if(QT_FEATURE_framework) + set(allResourceFiles ${localeFiles} ${resourceFiles} ${icuFiles}) + target_sources(WebEngineCore PRIVATE ${icuFiles} ${resourceFiles} ${localeFiles}) + + 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 + ) + set_source_files_properties(${icuFiles} + TARGET_DIRECTORY WebEngineCore + PROPERTIES MACOSX_PACKAGE_LOCATION Resources + GENERATED TRUE + ) + add_custom_command(OUTPUT ${localeFiles} ${resourceFiles} ${icuFiles} + DEPENDS QtWebEngineCore.stamp + ) + add_custom_target(generate_resources_${config} + DEPENDS ${localeFiles} ${resourcesFiles} ${icuFiles} + ) +else() + install(FILES ${localeFiles} DESTINATION translations/qtwebengine_locales CONFIGURATIONS ${config} -) -install(FILES ${resourceFiles} + ) + install(FILES ${resourceFiles} DESTINATION resources CONFIGURATIONS ${config} -) -install(FILES ${icuFiles} + ) + install(FILES ${icuFiles} DESTINATION resources CONFIGURATIONS ${config} -) + ) # install (again) for superbuild -install(FILES ${localeFiles} + install(FILES ${localeFiles} DESTINATION ${WEBENGINE_ROOT_BUILD_DIR}/translations/qtwebengine_locales CONFIGURATIONS ${config} -) -install(FILES ${resourceFiles} + ) + install(FILES ${resourceFiles} DESTINATION ${WEBENGINE_ROOT_BUILD_DIR}/resources CONFIGURATIONS ${config} -) -install(FILES ${icuFiles} + ) + install(FILES ${icuFiles} DESTINATION ${WEBENGINE_ROOT_BUILD_DIR}/resources CONFIGURATIONS ${config} -) + ) +endif() + diff --git a/src/core/web_engine_library_info.cpp b/src/core/web_engine_library_info.cpp index 407bd50bc..6eb90f2e6 100644 --- a/src/core/web_engine_library_info.cpp +++ b/src/core/web_engine_library_info.cpp @@ -80,7 +80,7 @@ QString fallbackDir() { #if defined(OS_MAC) && defined(QT_MAC_FRAMEWORK_BUILD) static inline CFBundleRef frameworkBundle() { - return CFBundleGetBundleWithIdentifier(CFSTR("org.qt-project.Qt.QtWebEngineCore")); + return CFBundleGetBundleWithIdentifier(CFSTR("org.qt-project.QtWebEngineCore")); } static QString getPath(CFBundleRef frameworkBundle) diff --git a/src/gn/CMakeLists.txt b/src/gn/CMakeLists.txt index bad9ffb08..7a419ec67 100644 --- a/src/gn/CMakeLists.txt +++ b/src/gn/CMakeLists.txt @@ -25,6 +25,8 @@ add_custom_command( --cc ${CMAKE_C_COMPILER} --cxx ${CMAKE_CXX_COMPILER} --ld ${CMAKE_CXX_COMPILER} + $<$<PLATFORM_ID:Darwin>:--isysroot> + $<$<PLATFORM_ID:Darwin>:${CMAKE_OSX_SYSROOT}> COMMAND Ninja::ninja -C ${GN_BINARY_DIR}/$<CONFIG> ${GN_EXECUTABLE} VERBATIM USES_TERMINAL diff --git a/src/process/CMakeLists.txt b/src/process/CMakeLists.txt index 742fecf0c..7f1b40b90 100644 --- a/src/process/CMakeLists.txt +++ b/src/process/CMakeLists.txt @@ -6,6 +6,7 @@ include(${WEBENGINE_ROOT_SOURCE_DIR}/cmake/Functions.cmake) find_package(Qt6 COMPONENTS Gui) get_target_property(qtWebEngineProcessName WebEngineCore QTWEBENGINEPROCESS_NAME) +get_target_property(isFramework WebEngineCore FRAMEWORK) qt_internal_add_executable(${qtWebEngineProcessName} SOURCES main.cpp) @@ -21,9 +22,27 @@ target_link_libraries(${qtWebEngineProcessName} target_include_directories(${qtWebEngineProcessName} PRIVATE ../core) get_install_config(config) -install(TARGETS ${qtWebEngineProcessName} - RUNTIME DESTINATION "${INSTALL_LIBEXECDIR}" - CONFIGURATIONS ${config} -) +if(isFramework) + set_target_properties(${qtWebEngineProcessName} PROPERTIES MACOSX_BUNDLE TRUE) + target_sources(${qtWebEngineProcessName} PRIVATE QtWebEngineProcess.entitlements) + set_source_files_properties(QtWebEngineProcess.entitlements PROPERTIES + MACOSX_PACKAGE_LOCATION Resources + ) + add_custom_command(TARGET ${qtWebEngineProcessName} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$<TARGET_BUNDLE_DIR:WebEngineCore>/Versions/A/Helpers/${qtWebEngineProcessName}.app" + COMMAND ${CMAKE_COMMAND} -E create_symlink "Versions/Current/Helpers" + "$<TARGET_BUNDLE_DIR:WebEngineCore>/Helpers" + ) + install(TARGETS ${qtWebEngineProcessName} + BUNDLE DESTINATION ./lib/QtWebEngineCore.framework/Versions/A/Helpers + COMPONENT Runtime + ) +else() + install(TARGETS ${qtWebEngineProcessName} + RUNTIME DESTINATION "${INSTALL_LIBEXECDIR}" + CONFIGURATIONS ${config} + ) +endif() make_install_only(${qtWebEngineProcessName}) |