C++ CMake检查Windows版本
如何向CMake检查我是否正在为Windows 7或Windows 8配置Visual Studio解决方案C++ CMake检查Windows版本,c++,windows-7,windows-8,visual-studio-2012,cmake,C++,Windows 7,Windows 8,Visual Studio 2012,Cmake,如何向CMake检查我是否正在为Windows 7或Windows 8配置Visual Studio解决方案 有什么方法可以做到这一点吗?您可以使用CMAKE\u系统\u名称和CMAKE\u系统\u版本 ## Check for Windows ## if( WIN32 ) # true if windows (32 and 64 bit) ## Check for Version ## if( ${CMAKE_SYSTEM_VERSION} EQUAL 6.1 ) # Win
有什么方法可以做到这一点吗?您可以使用
CMAKE\u系统\u名称
和CMAKE\u系统\u版本
## Check for Windows ##
if( WIN32 ) # true if windows (32 and 64 bit)
## Check for Version ##
if( ${CMAKE_SYSTEM_VERSION} EQUAL 6.1 ) # Windows 7
# Do something here
elseif( ${CMAKE_SYSTEM_VERSION} EQUAL 6.2 ) # Windows 8
# Do something here
else() # Some other Windows
# Do something here
endif()
endif()
您可以使用
execute\u process
和executever
来获取验证。这不会给出cmake正在运行的版本而不是目标系统吗?不,它返回您正在编译的系统的版本。我猜您的意思是CMAKE_VERSION
-此变量指定CMAKE可执行文件的版本。