AFAIK, there is no built-in support for something like this, but you could certainly write it yourself:
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "your.required.gcc.version")
message(FATAL_ERROR "Insufficient gcc version")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "your.required.msvc.version")
message(FATAL_ERROR "Insufficient msvc version")
endif()
elseif(...)
# etc.
endif()
However, I suggest you actually consider a feature-detection approach instead. That is, use try_compile()
to verify that the compiler supports the features you need, and FATAL_ERROR
if it doesn't. It's more idiomatic in CMake, and has the added benefit you don't have to discover the appropriate minimal version for all compilers out there.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…