Use _qt_internal_path_is_prefix

Change-Id: I3eeb514c33340956328eff33409dfa2899023eb5
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Cristian Le 2025-02-04 13:56:23 +01:00
parent 0630f055b8
commit 3f31f210d5
5 changed files with 15 additions and 23 deletions

View File

@ -199,8 +199,8 @@ function(qt_make_output_file infile prefix suffix source_dir binary_dir result)
get_filename_component(outfilename "${infile}" NAME_WE) get_filename_component(outfilename "${infile}" NAME_WE)
set(base_dir "${source_dir}") set(base_dir "${source_dir}")
string(FIND "${infile}" "${binary_dir}/" in_binary) _qt_internal_path_is_prefix(binary_dir "${infile}" in_binary)
if (in_binary EQUAL 0) if(in_binary)
set(base_dir "${binary_dir}") set(base_dir "${binary_dir}")
endif() endif()

View File

@ -199,8 +199,9 @@ function(qt_internal_add_executable name)
set(exclude_from_all FALSE) set(exclude_from_all FALSE)
if(__qt_exclude_tool_directories) if(__qt_exclude_tool_directories)
foreach(absolute_dir ${__qt_exclude_tool_directories}) foreach(absolute_dir ${__qt_exclude_tool_directories})
string(FIND "${CMAKE_CURRENT_SOURCE_DIR}" "${absolute_dir}" dir_starting_pos) _qt_internal_path_is_prefix(absolute_dir "${CMAKE_CURRENT_SOURCE_DIR}"
if(dir_starting_pos EQUAL 0) in_current_source)
if(in_current_source)
set(exclude_from_all TRUE) set(exclude_from_all TRUE)
set_target_properties("${name}" PROPERTIES set_target_properties("${name}" PROPERTIES
EXCLUDE_FROM_ALL TRUE EXCLUDE_FROM_ALL TRUE

View File

@ -239,8 +239,8 @@ function(qt_internal_add_headersclean_target module_target module_headers)
set(possible_base_dirs "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}") set(possible_base_dirs "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}")
foreach(dir IN LISTS possible_base_dirs) foreach(dir IN LISTS possible_base_dirs)
string(FIND "${input_path}" "${dir}" idx) _qt_internal_path_is_prefix(dir "${input_path}" dir_is_prefix)
if(idx EQUAL "0") if(dir_is_prefix)
set(input_base_dir "${dir}") set(input_base_dir "${dir}")
break() break()
endif() endif()

View File

@ -1619,16 +1619,11 @@ function(qt_internal_collect_module_headers out_var target)
get_filename_component(file_path "${file_path}" ABSOLUTE) get_filename_component(file_path "${file_path}" ABSOLUTE)
string(FIND "${file_path}" "${source_dir}" source_dir_pos) _qt_internal_path_is_prefix(source_dir "${file_path}" is_inside_module_source_dir)
if(source_dir_pos EQUAL 0)
set(is_outside_module_source_dir FALSE)
else()
set(is_outside_module_source_dir TRUE)
endif()
get_source_file_property(is_generated "${file_path}" GENERATED) get_source_file_property(is_generated "${file_path}" GENERATED)
# Skip all header files outside the module source directory, except the generated files. # Skip all header files outside the module source directory, except the generated files.
if(is_outside_module_source_dir AND NOT is_generated) if(NOT is_inside_module_source_dir AND NOT is_generated)
continue() continue()
endif() endif()
@ -1640,10 +1635,10 @@ function(qt_internal_collect_module_headers out_var target)
"\nCondition:\n ${condition_string}") "\nCondition:\n ${condition_string}")
endif() endif()
if(is_outside_module_source_dir) if(is_inside_module_source_dir)
set(base_dir "${binary_dir}")
else()
set(base_dir "${source_dir}") set(base_dir "${source_dir}")
else()
set(base_dir "${binary_dir}")
endif() endif()
file(RELATIVE_PATH file_path_rel "${base_dir}" "${file_path}") file(RELATIVE_PATH file_path_rel "${base_dir}" "${file_path}")

View File

@ -771,13 +771,9 @@ function(_qt_internal_sbom_map_path_to_reproducible_relative_path out_var)
if(IS_ABSOLUTE "${path}") if(IS_ABSOLUTE "${path}")
set(path_in "${path}") set(path_in "${path}")
string(FIND "${path}" "${PROJECT_SOURCE_DIR}/" src_idx) _qt_internal_path_is_prefix(PROJECT_SOURCE_DIR "${path}" is_in_source_dir)
string(FIND "${path}" "${PROJECT_BINARY_DIR}/" dest_idx) if(NOT is_in_source_dir)
_qt_internal_path_is_prefix(PROJECT_BINARY_DIR "${path}" is_in_build_dir)
if(src_idx EQUAL "0")
set(is_in_source_dir TRUE)
elseif(dest_idx EQUAL "0")
set(is_in_build_dir TRUE)
endif() endif()
else() else()
# We consider relative paths to be relative to the current source dir. # We consider relative paths to be relative to the current source dir.