Skip to content

Commit

Permalink
CMake: Fix static build linkage with CMake version lower than 3.13
Browse files Browse the repository at this point in the history
After appropriate link flags are determined, they are added to the
INTERFACE_LINK_OPTIONS property. Unfortunately this property was added
in 3.13, and thus static builds on Windows for instance failed with
missing symbols due to missing system libraries on the link command
line, when the CMake version was lower.

When detecting a lower version, add the flags instead to
INTERFACE_LINK_LIBRARIES, which is a property that is available in
older CMake versions. To do this we have to strip the SHELL: prefix,
which means that the added link flags might get deduplicated, and thus
it can happen that the linking phase might still fail.

Nevertheless, on Windows this improves the situation when using an older
CMake version.

Amends 4460222

Task-number: QTBUG-38913
Change-Id: Ib710b8ea691d4a9281dcd5f5b9700b11df0a5c10
Reviewed-by: Kyle Edwards <[email protected]>
Reviewed-by: Simon Hausmann <[email protected]>
  • Loading branch information
alcroito committed Nov 25, 2019
1 parent 2e7c83e commit 8c6824f
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,20 @@ macro(_populate_$${CMAKE_MODULE_NAME}_target_properties Configuration LIB_LOCATI
endif()

set(_static_link_flags \"${_Qt5$${CMAKE_MODULE_NAME}_STATIC_${Configuration}_LINK_FLAGS}\")
if(NOT CMAKE_VERSION VERSION_LESS \"3.13\" AND _static_link_flags)
if(_static_link_flags)
set(_static_link_flags_genex \"$<${_genex_condition}:${_static_link_flags}>\")
set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY INTERFACE_LINK_OPTIONS
\"${_static_link_flags_genex}\"
)
if(NOT CMAKE_VERSION VERSION_LESS \"3.13\")
set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY INTERFACE_LINK_OPTIONS
\"${_static_link_flags_genex}\"
)
else()
# Abuse INTERFACE_LINK_LIBRARIES to add link flags when CMake version is too low.
# Strip out SHELL:, because it is not supported in this property. And hope for the best.
string(REPLACE \"SHELL:\" \"\" _static_link_flags_genex \"${_static_link_flags_genex}\")
set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY INTERFACE_LINK_LIBRARIES
\"${_static_link_flags_genex}\"
)
endif()
endif()
!!ENDIF

Expand Down Expand Up @@ -546,11 +555,20 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
endif()

set(_static_link_flags \"${_Qt5${Plugin}_STATIC_${Configuration}_LINK_FLAGS}\")
if(NOT CMAKE_VERSION VERSION_LESS \"3.13\" AND _static_link_flags)
if(_static_link_flags)
set(_static_link_flags_genex \"$<${_genex_condition}:${_static_link_flags}>\")
set_property(TARGET Qt5::${Plugin} APPEND PROPERTY INTERFACE_LINK_OPTIONS
\"${_static_link_flags_genex}\"
)
if(NOT CMAKE_VERSION VERSION_LESS \"3.13\")
set_property(TARGET Qt5::${Plugin} APPEND PROPERTY INTERFACE_LINK_OPTIONS
\"${_static_link_flags_genex}\"
)
else()
# Abuse INTERFACE_LINK_LIBRARIES to add link flags when CMake version is too low.
# Strip out SHELL:, because it is not supported in this property. And hope for the best.
string(REPLACE \"SHELL:\" \"\" _static_link_flags_genex \"${_static_link_flags_genex}\")
set_property(TARGET Qt5::${Plugin} APPEND PROPERTY INTERFACE_LINK_LIBRARIES
\"${_static_link_flags_genex}\"
)
endif()
endif()
!!ENDIF
endmacro()
Expand Down

0 comments on commit 8c6824f

Please sign in to comment.