From 01bfed1d0abf438a7d5cd68cb4755377cd52b08a Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 5 Oct 2021 15:42:04 +0200 Subject: CMake: Generate relative #line directives in qlalr output When passing an absolute input file name to qlalr, the #line directives in the output will contain absolute paths. For reproducible builds, it's desirable to have relative paths. Pass the input file as relative path to qlalr to produce relative #line directives. Fixes: QTBUG-96267 Change-Id: I4ef1e4d5be7cbaf25a54a34ab7c2dbec06411a1d Reviewed-by: Alexandru Croitor --- cmake/QtLalrHelpers.cmake | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'cmake') diff --git a/cmake/QtLalrHelpers.cmake b/cmake/QtLalrHelpers.cmake index ce6f07007e..7c147b0597 100644 --- a/cmake/QtLalrHelpers.cmake +++ b/cmake/QtLalrHelpers.cmake @@ -39,13 +39,22 @@ function(qt_process_qlalr consuming_target input_file_list flags) qt_qlalr_find_option_in_list("${input_file_lines}" "^%impl(.+)" "impl") get_filename_component(base_file_name ${input_file} NAME_WE) + # Pass a relative input file path to qlalr to generate relative #line directives. + if(IS_ABSOLUTE "${input_file}") + set(absolute_input_file "${input_file}") + else() + get_filename_component(absolute_input_file "${input_file}" ABSOLUTE) + endif() + file(RELATIVE_PATH relative_input_file "${CMAKE_CURRENT_BINARY_DIR}" + "${absolute_input_file}") + set(cpp_file "${parser}.cpp") set(private_file "${parser}_p.h") set(decl_file "${decl}") set(impl_file "${impl}") add_custom_command( OUTPUT ${cpp_file} ${private_file} ${decl_file} ${impl_file} - COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::qlalr ${flags} ${input_file} + COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::qlalr ${flags} ${relative_input_file} DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::qlalr MAIN_DEPENDENCY ${input_file} ) -- cgit v1.2.3