diff --git a/cmake/scripts/FindFiles.cmake b/cmake/scripts/FindFiles.cmake
index d474989cce5452e9b2d5a42f21db0c7f6c25efa5..df7440ed8696ea76a38bffb79c42ccfcb2080f42 100644
--- a/cmake/scripts/FindFiles.cmake
+++ b/cmake/scripts/FindFiles.cmake
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0009 NEW)
 file(GLOB_RECURSE makefiles RELATIVE ${RELPATH} "CMakeLists.txt")
 foreach(_file ${makefiles})
   # path contains "/test" or is directly "test"
-  string(REGEX MATCH "(.*/)*test" _testdir ${_file})
+  string(REGEX MATCH "^(.*/)*test" _testdir ${_file})
   # path end with "/test" and not "/testFoo" or "/test/foo"
   string(REGEX MATCH "(.*/)*test/CMakeLists.txt$" _testdirensured ${_file})
   if(_testdir AND _testdirensured)