cotire icon indicating copy to clipboard operation
cotire copied to clipboard

improve robustness against CMake bug 17079

Open SoongJr opened this issue 8 years ago • 0 comments

CMake has a bug where CMAKE_MATCH_# may not be empty if the capture group of a regex matched an empty string. See https://gitlab.kitware.com/cmake/cmake/issues/17079

Found these regexes that can provoke issues:

  • elseif ("${_compileFlag}" MATCHES "^(${_flagPrefix})(${_flagFilter})$")
  • if (_line MATCHES "^(\\.+) (.*)$")
  • if (_maxIncludes MATCHES "(-j|--parallel|--jobs) ?([0-9]*)")

It is suggested to prelude these matches by explicitly setting the CMAKE_MATCH_# variables used to empty:

	set (CMAKE_MATCH_2)  # reset capturing variable as an empty capture below does not reset the according variable!
	if (_maxIncludes MATCHES "(-j|--parallel|--jobs) ?([0-9]*)")
		set (_numberOfThreads "${CMAKE_MATCH_2}")

This issue is only provoked if the user of cotire does a STRING(REGEX REPLACE) or STRING(REGEX MATCHALL) right before using cotire. And even then the regex they used must be of a certain format (match two capture groups at first pass of the regex, then match fewer groups at the second pass), making this an exotic issue.

SoongJr avatar Jul 20 '17 12:07 SoongJr