Skip to content

Commit 7552ce3

Browse files
committed
Escape special characters before using source/build dirs in regex
If "^${CMAKE_SOURCE_DIR}" contains special characters, the regular expression will break with an error like this for Garfield++: RegularExpression::compile(): Nested *?+. RegularExpression::compile(): Error in compile. CMake Error at .../RootNewMacros.cmake:288 (if): if given arguments: "NOT" "IS_ABSOLUTE" "incdir" "OR" "incdir" "MATCHES" "^/<...>/src/Garfield++/HEAD" "OR" "incdir" "MATCHES" "^" "OR" "incdir" "MATCHES" "^" Regular expression "^/<...>/src/Garfield++/HEAD" cannot compile Call Stack (most recent call first): CMakeLists.txt:118 (ROOT_GENERATE_DICTIONARY) Also, the (current) build directory is CMAKE_(CURRENT_)BINARY_DIR. Related Jira issue: ROOT-10210.
1 parent e9968cd commit 7552ce3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cmake/modules/RootNewMacros.cmake

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,14 @@ function(ROOT_GENERATE_DICTIONARY dictionary)
290290
else()
291291
set(incdirs_in_build)
292292
set(incdirs_in_prefix)
293+
string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" _source_dir "${CMAKE_SOURCE_DIR}")
294+
string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" _binary_dir "${CMAKE_BINARY_DIR}")
295+
string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" _curr_binary_dir "${CMAKE_CURRENT_BINARY_DIR}")
293296
foreach(incdir ${incdirs})
294-
if(NOT IS_ABSOLUTE incdir
295-
OR incdir MATCHES "^${CMAKE_SOURCE_DIR}"
296-
OR incdir MATCHES "^${CMAKE_CURRENT_BUILD_DIR}"
297-
OR incdir MATCHES "^${CMAKE_BUILD_DIR}")
297+
if(NOT IS_ABSOLUTE ${incdir}
298+
OR ${incdir} MATCHES "^${_source_dir}"
299+
OR ${incdir} MATCHES "^${_binary_dir}"
300+
OR ${incdir} MATCHES "^${_curr_binary_dir}")
298301
list(APPEND incdirs_in_build
299302
${incdir})
300303
else()

0 commit comments

Comments
 (0)