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 /cmake | |
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>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/Functions.cmake | 67 |
1 files changed, 59 insertions, 8 deletions
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() + |