I think 

    elseif(MSVC AND (CMAKE_GENERATOR MATCHES "Visual"))

will be more robust. Because other generators (for example, Ninja) are also affected.