diff --git a/cmake/QtHeadersClean.cmake b/cmake/QtHeadersClean.cmake index a1ebfcef28a..adcf868f5ad 100644 --- a/cmake/QtHeadersClean.cmake +++ b/cmake/QtHeadersClean.cmake @@ -237,12 +237,14 @@ function(qt_internal_add_headersclean_target module_target module_headers) get_filename_component(input_file_name ${input_path} NAME) set(artifact_path "${CMAKE_CURRENT_BINARY_DIR}/header_check/${input_file_name}.o") - unset(input_base_dir) - if(input_path MATCHES "${CMAKE_BINARY_DIR}") - set(input_base_dir "${CMAKE_BINARY_DIR}") - elseif(input_path MATCHES "${CMAKE_SOURCE_DIR}") - set(input_base_dir "${CMAKE_SOURCE_DIR}") - endif() + set(possible_base_dirs "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}") + foreach(dir IN LISTS possible_base_dirs) + string(FIND "${input_path}" "${dir}" idx) + if(idx EQUAL "0") + set(input_base_dir "${dir}") + break() + endif() + endforeach() if(input_base_dir AND IS_ABSOLUTE "${input_base_dir}" AND IS_ABSOLUTE "${input_path}") file(RELATIVE_PATH comment_header_path "${input_base_dir}" "${input_path}")