CMake: Pass qt-configured linker flag when building examples
If Qt is configured to build with lld, our examples should use it as well. But we want to do it without forcing the same linker on user projects. Normally if we wanted to do it for all user projects, we would propagate the linker flag via the Platform target, but we can't. In case of in-tree examples, we propagate the flags using add_link_options which is directory-scoped, and will apply to all targets created under the examples directory. For out-of-tree examples, we pass the flags via the equivalent CMAKE_<type>_LINKER_FLAGS_INIT variable to the external project. Fixes: QTBUG-137882 Change-Id: Iade8ee2f37032b4a7801e5a628c9cc177d478129 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> Reviewed-by: Moss Heim <moss.heim@qt.io> (cherry picked from commit 2293fe9de819ebc6b31eef334dd94112d71fe663) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit ecefe63b8d5608ba648c6e355bd15a0f1eb368c5) (cherry picked from commit 74a05a5027249f86b5c094127d027237e7532530)
This commit is contained in:
committed by
Qt Cherry-pick Bot
parent
29497f5222
commit
dac30f073b
@@ -83,6 +83,12 @@ macro(qt_examples_build_begin)
|
||||
if(NOT QT_BUILD_EXAMPLES_BY_DEFAULT)
|
||||
set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
||||
endif()
|
||||
|
||||
# Add active linker flags to all targets created below this subdirectory.
|
||||
qt_internal_get_active_linker_flags(active_linker_flags)
|
||||
if(active_linker_flags)
|
||||
add_link_options(${active_linker_flags})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# TODO: Change this to TRUE when all examples in all repos are ported to use
|
||||
@@ -500,6 +506,15 @@ function(qt_internal_add_example_external_project subdir)
|
||||
list(APPEND var_defs -DCMAKE_AUTOGEN_VERBOSE:BOOL=TRUE)
|
||||
endif()
|
||||
|
||||
# Pass active linker flags.
|
||||
qt_internal_get_active_linker_flags(active_linker_flags)
|
||||
if(active_linker_flags)
|
||||
foreach(item_type EXE MODULE SHARED)
|
||||
list(APPEND var_defs
|
||||
"-DCMAKE_${item_type}_LINKER_FLAGS_INIT:STRING=${active_linker_flags}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
set(deps "")
|
||||
list(REMOVE_DUPLICATES QT_EXAMPLE_DEPENDENCIES)
|
||||
foreach(dep IN LISTS QT_EXAMPLE_DEPENDENCIES)
|
||||
|
||||
Reference in New Issue
Block a user