mirror of https://github.com/qt/qtgrpc.git
Avoid storing absolute paths to protobuf module includes
Sanitize proto includes to ensure the generated <Module>ProtobufProperties.cmake is fully relocatable. Drive-by, ensure that includes do not contain duplicates. Task-number: QTBUG-130113 Change-Id: I64f56d497d412705f174a027f711b90ad7614abf Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
53f2963d56
commit
b8b8dd9fe2
|
@ -53,8 +53,8 @@ function(qt_internal_add_protobuf_module target)
|
|||
endif()
|
||||
|
||||
if(arg_PROTO_FILES)
|
||||
set(module_extra_properties_filename
|
||||
"${INSTALL_CMAKE_NAMESPACE}${target}ProtobufProperties.cmake")
|
||||
qt_internal_protobuf_get_module_properties_file_name(module_extra_properties_filename
|
||||
${target})
|
||||
endif()
|
||||
|
||||
qt_internal_add_module(${target}
|
||||
|
@ -104,16 +104,12 @@ function(qt_internal_add_protobuf_module target)
|
|||
|
||||
set_target_properties(${target} PROPERTIES QT_PROTO_INCLUDES "${proto_files_base_dir}")
|
||||
|
||||
set(proto_include_dirs "${module_install_interface_include_dir}")
|
||||
qt_internal_protobuf_generate_properties(${target}
|
||||
PROTO_INCLUDES "${module_install_interface_include_dir}")
|
||||
|
||||
set(export_name "${INSTALL_CMAKE_NAMESPACE}${target}")
|
||||
qt_path_join(config_build_dir ${QT_CONFIG_BUILD_DIR} ${export_name})
|
||||
qt_path_join(config_install_dir ${QT_CONFIG_INSTALL_DIR} ${export_name})
|
||||
set(module_extra_properties_file "${config_build_dir}/${module_extra_properties_filename}")
|
||||
configure_file("${__qt_protobuf_build_internals_base_dir}/QtProtobufProperties.cmake.in"
|
||||
"${module_extra_properties_file}" @ONLY)
|
||||
qt_install(FILES "${module_extra_properties_file}" DESTINATION "${config_install_dir}")
|
||||
if(generated_targets)
|
||||
set(export_name "${INSTALL_CMAKE_NAMESPACE}${target}")
|
||||
|
||||
list(REMOVE_DUPLICATES generated_targets)
|
||||
qt_install(TARGETS ${generated_targets}
|
||||
EXPORT "${export_name}Targets"
|
||||
|
@ -169,3 +165,49 @@ QT_END_NAMESPACE\n")
|
|||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Returns name of the protobuf module extra properties file
|
||||
function(qt_internal_protobuf_get_module_properties_file_name out_var target)
|
||||
set(${out_var} "${INSTALL_CMAKE_NAMESPACE}${target}ProtobufProperties.cmake" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Generates the protobuf module extra properties file
|
||||
#
|
||||
# Synopsys
|
||||
#
|
||||
# qt_internal_protobuf_generate_properties(target
|
||||
# [PROTO_INCLUDES path...]
|
||||
# )
|
||||
#
|
||||
# Arguments
|
||||
#
|
||||
# `target` the protobuf module target
|
||||
#
|
||||
# `PROTO_INCLUDES` list of the protobuf include paths to be stored in properties
|
||||
# file. All paths must be relative to the module install prefix.
|
||||
function(qt_internal_protobuf_generate_properties target)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 arg "" "" "PROTO_INCLUDES")
|
||||
|
||||
# Sanitize includes and ensure they only contain relative paths
|
||||
set(PROTO_INCLUDE_DIRS "")
|
||||
foreach(inc IN LISTS arg_PROTO_INCLUDES)
|
||||
if(IS_ABSOLUTE "${inc}")
|
||||
message(FATAL_ERROR "The ${target} protobuf include path is absolute, but should be"
|
||||
" relative to the target install prefix.")
|
||||
endif()
|
||||
if(NOT "${inc}" IN_LIST PROTO_INCLUDE_DIRS)
|
||||
list(APPEND PROTO_INCLUDE_DIRS "${inc}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
qt_internal_protobuf_get_module_properties_file_name(module_extra_properties_filename ${target})
|
||||
|
||||
set(export_name "${INSTALL_CMAKE_NAMESPACE}${target}")
|
||||
qt_path_join(config_build_dir ${QT_CONFIG_BUILD_DIR} ${export_name})
|
||||
qt_path_join(config_install_dir ${QT_CONFIG_INSTALL_DIR} ${export_name})
|
||||
set(module_extra_properties_file "${config_build_dir}/${module_extra_properties_filename}")
|
||||
configure_file("${__qt_protobuf_build_internals_base_dir}/QtProtobufProperties.cmake.in"
|
||||
"${module_extra_properties_file}" @ONLY)
|
||||
|
||||
qt_install(FILES "${module_extra_properties_file}" DESTINATION "${config_install_dir}")
|
||||
endfunction()
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
if(NOT QT_NO_CREATE_TARGETS)
|
||||
set(_@target@_proto_include_dirs "@proto_include_dirs@")
|
||||
set(_@target@_proto_include_dirs "@PROTO_INCLUDE_DIRS@")
|
||||
foreach(proto_include_dir IN LISTS _@target@_proto_include_dirs)
|
||||
if(IS_ABSOLUTE "${proto_include_dir}")
|
||||
set_property(TARGET ${QT_CMAKE_EXPORT_NAMESPACE}::@target@ APPEND PROPERTY
|
||||
QT_PROTO_INCLUDES "${proto_include_dir}")
|
||||
else()
|
||||
set_property(TARGET ${QT_CMAKE_EXPORT_NAMESPACE}::@target@ APPEND PROPERTY
|
||||
QT_PROTO_INCLUDES "${QT6_INSTALL_PREFIX}/${proto_include_dir}")
|
||||
if(CMAKE_STAGING_PREFIX)
|
||||
set_property(TARGET ${QT_CMAKE_EXPORT_NAMESPACE}::@target@ APPEND PROPERTY
|
||||
QT_PROTO_INCLUDES "${CMAKE_STAGING_PREFIX}/${proto_include_dir}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
unset(_@target@_proto_include_dirs)
|
||||
endif()
|
||||
|
|
Loading…
Reference in New Issue