Avoid using add_custom_command with PRE_LINK for version script

add_custom_command with PRE_LINK doesn't work correctly with
Multi-Config builds. The better solution is to introduce a custom
target that generates the final version script and link the target to
the library target as the dependency.

Change-Id: Ib7420af752a6a46f29f411f9f0dc8557410b4f22
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2022-05-18 18:14:12 +02:00
parent 04a60bb033
commit 38bb294fb7

View File

@ -32,13 +32,26 @@ function(qt_internal_add_linker_version_script target)
qt_ensure_perl()
add_custom_command(TARGET "${target}" PRE_LINK
COMMAND "${HOST_PERL}" "${QT_MKSPECS_DIR}/features/data/unix/findclasslist.pl" < "${infile}" > "${outfile}"
BYPRODUCTS "${outfile}" DEPENDS "${infile}"
set(generator_command "${HOST_PERL}"
"${QT_MKSPECS_DIR}/features/data/unix/findclasslist.pl"
"<" "${infile}" ">" "${outfile}"
)
set(generator_dependencies
"${infile}"
"${QT_MKSPECS_DIR}/features/data/unix/findclasslist.pl"
)
add_custom_command(
OUTPUT "${outfile}"
COMMAND ${generator_command}
DEPENDS ${generator_dependencies}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Generating version linker script"
VERBATIM)
target_link_options("${target}" PRIVATE "-Wl,--version-script,${outfile}")
COMMENT "Generating version linker script for target ${target}"
VERBATIM
)
add_custom_target(${target}_version_script DEPENDS ${outfile})
add_dependencies(${target} ${target}_version_script)
target_link_options(${target} PRIVATE "-Wl,--version-script,${outfile}")
endif()
endfunction()