Skip to content

Commit d04b60c

Browse files
committed
CMake: Exclude no direct extern flags on Linux with Swift language
Otherwise, the Swift linker failed to build a Swift library that links to a Qt module. Pick-to: 6.10 6.11 Change-Id: I5c170916050c1e2041300ae4c90ae736063eaafa Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
1 parent 782799d commit d04b60c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

cmake/QtPlatformTargetHelpers.cmake

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ function(qt_internal_setup_public_platform_target)
4545
endif()
4646
target_link_options(Platform INTERFACE "${libc_link_option}")
4747
endif()
48-
if (QT_FEATURE_no_direct_extern_access)
49-
target_compile_options(Platform INTERFACE "$<$<CXX_COMPILER_ID:GNU>:-mno-direct-extern-access>")
50-
target_compile_options(Platform INTERFACE "$<$<CXX_COMPILER_ID:Clang>:-fno-direct-access-external-data>")
48+
if(QT_FEATURE_no_direct_extern_access)
49+
# Swift compiler doesn't understand these options on Linux.
50+
set(not_swift_cond "$<NOT:$<COMPILE_LANGUAGE:Swift>>")
51+
52+
set(no_direct_extern_gnu "$<$<CXX_COMPILER_ID:GNU>:-mno-direct-extern-access>")
53+
set(no_direct_extern_gnu_wrapped "$<${not_swift_cond}:${no_direct_extern_gnu}>")
54+
55+
set(no_direct_extern_clang "$<$<CXX_COMPILER_ID:Clang>:-fno-direct-access-external-data>")
56+
set(no_direct_extern_clang_wrapped "$<${not_swift_cond}:${no_direct_extern_clang}>")
57+
58+
target_compile_options(Platform INTERFACE "${no_direct_extern_gnu_wrapped}")
59+
target_compile_options(Platform INTERFACE "${no_direct_extern_clang_wrapped}")
5160
endif()
5261

5362
qt_set_msvc_cplusplus_options(Platform INTERFACE)

0 commit comments

Comments
 (0)