2c49f85380
In MSVC static build, if we build Qt with 3rdparty library (e.g. zstd), cmake will add"zstd" (without "-l" prefix) to Qt6Core.prl. Then we use this Qt to build a qmake project, compilation will fail due to missing zstd.obj. Without "-l" prefix, qmake will treat "zstd" as an object file instead of a library. Library names in qt_module.pri and qt_lib_*_private.pri are also missing "-l" prefix. This is because on most compilers, CMAKE_LINK_LIBRARY_FLAG equals "-l". But on MSVC, it is an empty string. So we should pass "-DLINK_LIBRARY_FLAG=-l" for MSVC. Also add "-L/path/to/library" if the library path is not in default linker search directories. This will write un-relocatable paths to prl files only when using 3rdparty libraries to build Qt statically. Usually it's not a problem. In addition, CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES is also empty on MSVC. So The third argument of "$<FILTER>" is empty, it is an invalid generator expression. This means no include dir will be written to qt_module.pri and qt_lib_*_private.pri on MSVC. So only use "$<FILTER>" when CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES is not empty. Pick-to: 6.1 Change-Id: Ib66f95dc09cf920363a4b9338fb97747dd2f8ab7 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
120 lines
4.7 KiB
CMake
120 lines
4.7 KiB
CMake
# Given "/usr/lib/x86_64-linux-gnu/libcups.so"
|
|
# Returns "cups" or an empty string if the file is not an absolute library path.
|
|
# Aka it strips the "lib" prefix, the .so extension and the base path.
|
|
function(qt_get_library_name_without_prefix_and_suffix out_var file_path)
|
|
set(out_value "")
|
|
if(IS_ABSOLUTE "${file_path}")
|
|
get_filename_component(basename "${file_path}" NAME_WE)
|
|
get_filename_component(ext "${file_path}" EXT)
|
|
foreach(libsuffix ${LIBRARY_SUFFIXES})
|
|
# Handle weird prefix extensions like in the case of
|
|
# "/usr/lib/x86_64-linux-gnu/libglib-2.0.so"
|
|
# it's ".0.so".
|
|
if(ext MATCHES "^(\\.[0-9]+)*${libsuffix}(\\.[0-9]+)*")
|
|
set(is_linkable_library TRUE)
|
|
set(weird_numbered_extension "${CMAKE_MATCH_1}")
|
|
break()
|
|
endif()
|
|
endforeach()
|
|
if(is_linkable_library)
|
|
set(out_value "${basename}")
|
|
if(LIBRARY_PREFIXES)
|
|
foreach(libprefix ${LIBRARY_PREFIXES})
|
|
# Strip any library prefix like "lib" for a library that we will use with a link
|
|
# flag.
|
|
if(libprefix AND out_value MATCHES "^${libprefix}(.+)")
|
|
set(out_value "${CMAKE_MATCH_1}")
|
|
break()
|
|
endif()
|
|
endforeach()
|
|
endif()
|
|
if(weird_numbered_extension)
|
|
set(out_value "${out_value}${weird_numbered_extension}")
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
# Reverse the dependency order to be in sync with what qmake generated .pri files
|
|
# have.
|
|
list(REVERSE out_list)
|
|
|
|
set(${out_var} "${out_value}" PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
# Given "/usr/lib/x86_64-linux-gnu/libcups.so"
|
|
# Returns "-lcups" or an empty string if the file is not an absolute library path.
|
|
function(qt_get_library_with_link_flag out_var file_path)
|
|
qt_get_library_name_without_prefix_and_suffix(lib_name "${file_path}")
|
|
|
|
set(out_value "")
|
|
if(lib_name)
|
|
set(out_value "${lib_name}")
|
|
if(LINK_LIBRARY_FLAG)
|
|
string(PREPEND out_value "${LINK_LIBRARY_FLAG}")
|
|
endif()
|
|
endif()
|
|
|
|
set(${out_var} "${out_value}" PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
# Given a list of potential library paths, returns a transformed list where absolute library paths
|
|
# are replaced with library link flags.
|
|
function(qt_transform_absolute_library_paths_to_link_flags out_var library_path_list)
|
|
set(out_list "")
|
|
foreach(library_path ${library_path_list})
|
|
qt_get_library_with_link_flag(lib_name_with_link_flag "${library_path}")
|
|
if(lib_name_with_link_flag)
|
|
get_filename_component(dir "${library_path}" DIRECTORY)
|
|
# If library_path isn't in default link directories, we should add it to link flags.
|
|
list(FIND IMPLICIT_LINK_DIRECTORIES ${dir} index)
|
|
if(${index} EQUAL -1)
|
|
list(APPEND out_list "-L${dir} ")
|
|
endif()
|
|
list(APPEND out_list "${lib_name_with_link_flag}")
|
|
else()
|
|
list(APPEND out_list "${library_path}")
|
|
endif()
|
|
endforeach()
|
|
set(${out_var} "${out_list}" PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
function(qt_strip_library_version_suffix out_var file_path)
|
|
get_filename_component(dir "${file_path}" DIRECTORY)
|
|
get_filename_component(basename "${file_path}" NAME_WE)
|
|
get_filename_component(ext "${file_path}" EXT)
|
|
foreach(libsuffix ${LIBRARY_SUFFIXES})
|
|
if(ext MATCHES "^${libsuffix}(\\.[0-9]+)+")
|
|
set(ext ${libsuffix})
|
|
break()
|
|
endif()
|
|
endforeach()
|
|
set(final_value "${basename}${ext}")
|
|
if(dir)
|
|
set(final_value "${dir}/${final_value}")
|
|
endif()
|
|
set(${out_var} "${final_value}" PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
# Checks if `input_path` is relative to at least one path given in the list of `qt_lib_paths`.
|
|
# Sets TRUE or FALSE in `out_var_is_relative`.
|
|
# Assigns the relative path to `out_var_relative_path` if the path is relative, otherwise assigns
|
|
# the original path.
|
|
function(qt_internal_path_is_relative_to_qt_lib_path
|
|
input_path qt_lib_paths out_var_is_relative out_var_relative_path)
|
|
set(is_relative "FALSE")
|
|
set(relative_path_value "${input_path}")
|
|
|
|
foreach(qt_lib_path ${qt_lib_paths})
|
|
file(RELATIVE_PATH relative_path "${qt_lib_path}" "${input_path}")
|
|
if(IS_ABSOLUTE "${relative_path}" OR (relative_path MATCHES "^\\.\\."))
|
|
set(is_relative "FALSE")
|
|
else()
|
|
set(is_relative "TRUE")
|
|
set(relative_path_value "${relative_path}")
|
|
break()
|
|
endif()
|
|
endforeach()
|
|
set(${out_var_is_relative} "${is_relative}" PARENT_SCOPE)
|
|
set(${out_var_relative_path} "${relative_path_value}" PARENT_SCOPE)
|
|
endfunction()
|