diff --git a/cmake/modules/RootMacros.cmake b/cmake/modules/RootMacros.cmake
index 856a48ed77f422c986a03a1fa94cb224ee65417c..8665de187c1cbcd7e6081a622f1883e793b3cf01 100644
--- a/cmake/modules/RootMacros.cmake
+++ b/cmake/modules/RootMacros.cmake
@@ -257,6 +257,17 @@ function(ROOT_GET_INSTALL_DIR result)
   SET(${result} "${shared_lib_install_dir}" PARENT_SCOPE)
 endfunction(ROOT_GET_INSTALL_DIR)
 
+#---------------------------------------------------------------------------------------------------
+#---ROOT_REPLACE_BUILD_INTERFACE( include_dir_var include_dir )
+# Update the `include_dir` variable after resolve the BUILD_INTERFACE
+function(ROOT_REPLACE_BUILD_INTERFACE include_dir_var include_dir)
+  string(REGEX REPLACE "^[$]<BUILD_INTERFACE:(.+)>" "\\1" include_dir ${include_dir})
+  # BUILD_INTERFACE might contain space-separated paths. They are split by
+  # foreach, leaving a trailing 'include/something>'. Remove the trailing '>'.
+  string(REGEX REPLACE ">$" "" include_dir ${include_dir})
+  set(${include_dir_var} ${include_dir} PARENT_SCOPE)
+endfunction(ROOT_REPLACE_BUILD_INTERFACE)
+
 #---------------------------------------------------------------------------------------------------
 #---ROOT_GENERATE_DICTIONARY( dictionary headerfiles NODEPHEADERS ghdr1 ghdr2 ...
 #                                                    MODULE module DEPENDENCIES dep1 dep2
@@ -298,17 +309,14 @@ function(ROOT_GENERATE_DICTIONARY dictionary)
     get_target_property(target_incdirs ${ARG_MODULE} INCLUDE_DIRECTORIES)
     if(target_incdirs)
        foreach(dir ${target_incdirs})
-          string(REGEX REPLACE "^[$]<BUILD_INTERFACE:(.+)>" "\\1" dir ${dir})
-          # BUILD_INTERFACE might contain space-separated paths. They are split by
-          # foreach, leaving a trailing 'include/something>'. Remove the trailing '>'.
-          string(REGEX REPLACE ">$" "" dir ${dir})
+          ROOT_REPLACE_BUILD_INTERFACE(dir ${dir})
           # check that dir not a empty dir like $<BUILD_INTERFACE:>
           if(NOT ${dir} MATCHES "^[$]")
-             list(APPEND incdirs ${dir})
-          endif()
-          string(FIND ${dir} "${CMAKE_SOURCE_DIR}" src_dir_in_dir)
-          if(${src_dir_in_dir} EQUAL 0)
-             list(APPEND headerdirs ${dir})
+            list(APPEND incdirs ${dir})
+            string(FIND ${dir} "${CMAKE_SOURCE_DIR}" src_dir_in_dir)
+            if(${src_dir_in_dir} EQUAL 0)
+              list(APPEND headerdirs ${dir})
+            endif()
           endif()
        endforeach()
     endif()
@@ -376,7 +384,7 @@ function(ROOT_GENERATE_DICTIONARY dictionary)
     if(TARGET ${ARG_MODULE})
       get_target_property(target_incdirs ${ARG_MODULE} INCLUDE_DIRECTORIES)
       foreach(dir ${target_incdirs})
-        string(REGEX REPLACE "^[$]<BUILD_INTERFACE:(.+)>" "\\1" dir ${dir})
+        ROOT_REPLACE_BUILD_INTERFACE(dir ${dir})
         if(NOT ${dir} MATCHES "^[$]")
           list(APPEND incdirs ${dir})
         endif()
@@ -929,8 +937,10 @@ function(ROOT_LINKER_LIBRARY library)
           endif()
           if(lib_incdirs)
             foreach(dir ${lib_incdirs})
-              string(REGEX REPLACE "^[$]<BUILD_INTERFACE:(.+)>" "\\1" dir ${dir})
-              list(APPEND dep_list ${dir})
+              ROOT_REPLACE_BUILD_INTERFACE(dir ${dir})
+              if(NOT ${dir} MATCHES "^[$]")
+                list(APPEND dep_list ${dir})
+              endif()
             endforeach()
           endif()
         endif()
@@ -959,8 +969,10 @@ function(ROOT_LINKER_LIBRARY library)
           endif()
           if(lib_incdirs)
             foreach(dir ${lib_incdirs})
-              string(REGEX REPLACE "^[$]<BUILD_INTERFACE:(.+)>" "\\1" dir ${dir})
-              list(APPEND dep_inc_list ${dir})
+              ROOT_REPLACE_BUILD_INTERFACE(dir ${dir})
+              if(NOT ${dir} MATCHES "^[$]")
+                list(APPEND dep_inc_list ${dir})
+              endif()
             endforeach()
           endif()
           if(lib_rpath)
@@ -1032,8 +1044,10 @@ function(ROOT_ADD_INCLUDE_DIRECTORIES library)
         get_target_property(lib_incdirs Core INCLUDE_DIRECTORIES)
         if(lib_incdirs)
           foreach(dir ${lib_incdirs})
-            string(REGEX REPLACE "^[$]<BUILD_INTERFACE:(.+)>" "\\1" dir ${dir})
-            target_include_directories(${library} BEFORE PRIVATE ${dir})
+            ROOT_REPLACE_BUILD_INTERFACE(dir ${dir})
+            if(NOT ${dir} MATCHES "^[$]")
+              target_include_directories(${library} BEFORE PRIVATE ${dir})
+            endif()
           endforeach()
         endif()
       endif()
@@ -1397,8 +1411,10 @@ function(ROOT_EXECUTABLE executable)
           get_target_property(lib_incdirs ${lib} INCLUDE_DIRECTORIES)
           if(lib_incdirs)
             foreach(dir ${lib_incdirs})
-              string(REGEX REPLACE "^[$]<BUILD_INTERFACE:(.+)>" "\\1" dir ${dir})
-              list(APPEND dep_list ${dir})
+              ROOT_REPLACE_BUILD_INTERFACE(dir ${dir})
+              if(NOT ${dir} MATCHES "^[$]")
+                list(APPEND dep_list ${dir})
+              endif()
             endforeach()
           endif()
         endif()