CMake: Improve .prl dependency tracking

Previously .prl files were created via add_custom_command with a
POST_BUILD command. This means they were only created after linking
the libraries, and that whenever a relinking happened, dependees had
to rebuild many parts of their target.

Ideally we would use generator expressions in the OUTPUT argument, but
versions up-to CMake 3.18 don't support doing that.

A workaround is to create and depend on a .prl file name without
generator expressions, and as a side effect also create a .prl file
that does use generator expressions, but don't specify it as an
OUTPUT.

This seems to work well, and improves the dependency tracking issue,
at the cost of one more file copy per .prl file whenever it changes.

Change-Id: I7dd99777fec5a08552503bdbafb6116f93ebe66b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Alexandru Croitor 2020-06-17 18:35:56 +02:00
parent f04cb9ed63
commit 06557312d2

View File

@ -3003,18 +3003,35 @@ QMAKE_PRL_LIBS_FOR_CMAKE = ${prl_libs}
)
# Add a custom command that prepares the .prl file for installation
qt_path_join(prl_file_path "${QT_BUILD_DIR}/${install_dir}" "${prl_file_name}")
qt_path_join(final_prl_file_path "${QT_BUILD_DIR}/${install_dir}" "${prl_file_name}")
qt_path_join(fake_dependency_prl_file_path
"${CMAKE_CURRENT_BINARY_DIR}" "fake_dep_prl_for_${target}.prl")
set(library_suffixes ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX})
add_custom_command(
TARGET ${target} POST_BUILD
OUTPUT "${fake_dependency_prl_file_path}"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${prl_file_name}"
"${QT_CMAKE_DIR}/QtFinishPrlFile.cmake"
COMMAND ${CMAKE_COMMAND} "-DIN_FILE=${prl_file_name}"
"-DOUT_FILE=${prl_file_path}"
"-DOUT_FILE=${fake_dependency_prl_file_path}"
"-DLIBRARY_SUFFIXES=${library_suffixes}"
"-DQT_BUILD_LIBDIR=${QT_BUILD_DIR}/${INSTALL_LIBDIR}"
-P "${QT_CMAKE_DIR}/QtFinishPrlFile.cmake"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${fake_dependency_prl_file_path}"
"${final_prl_file_path}"
VERBATIM
COMMENT "Generating prl file for target ${target}"
)
# Tell the target to depend on the fake dependency prl file, to ensure the custom command
# is executed. As a side-effect, this will also create the final_prl_file_path that uses
# generator expressions. It should not be specified as a BYPRODUCT.
# This allows proper per-file dependency tracking, without having to resort on a POST_BUILD
# step, which means that relinking would happen as well as transitive rebuilding of any
# dependees.
# This is inspired by https://gitlab.kitware.com/cmake/cmake/-/issues/20842
target_sources(${target} PRIVATE "${fake_dependency_prl_file_path}")
# Installation of the .prl file happens globally elsewhere,
# because we have no clue here what the actual file name is.
# What we know however, is the directory where the prl file is created.