Tests: Restore support for CMake 3.1 through 3.6 with MSVC
The change in !1302 (merged) introduced use of if()
conditions not supported until CMake 3.7, so while it was intended to restore support for CMake versions prior to 3.9, it actually only did so for 3.7 and 3.8. Backport the logic to work with CMake 3.1.
Fixes: #18987 (closed)