I have a project which uses cmake, one target is set to only build with MSVC:
if (MSVC) add_library(test SHARED source.cpp) endif()
The optional solution is to build the condition base on used compiler name.
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")