#判断系统 message(STATUS "CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME} ") message(STATUS "CMAKE_HOST_SYSTEM : ${CMAKE_HOST_SYSTEM} ") message(STATUS "CMAKE_SYSTEM_NAME : ${CMAKE_SYSTEM_NAME} ") message(STATUS "CMAKE_SYSTEM : ${CMAKE_SYSTEM} ") message(STATUS "CMAKE_HOST_UNIX : ${CMAKE_HOST_UNIX} ") message(STATUS "CMAKE_HOST_WIN32 : ${CMAKE_HOST_WIN32} ")
执行结果
# 在 Linux 平台 CMAKE_HOST_SYSTEM_NAME = "Linux" CMAKE_HOST_UNIX = 1 CMAKE_HOST_WIN32 = 空 UNIX = 1 WIN32 = 空 # 在 Windows 平台 CMAKE_HOST_SYSTEM_NAME = "Windows" CMAKE_HOST_UNIX = 空 CMAKE_HOST_WIN32 = 1 UNIX = 空 WIN32 = 1
三种判断方法:
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux") message("platform: Linux ") elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") message("platform: Windows ") else() message("platform: unkonw ") endif()
if(CMAKE_HOST_UNIX) message("platform: Linux ") elseif(CMAKE_HOST_WIN32) message("platform: Windows ") else() message("platform: unkonw ") endif()
if(UNIX) message("platform: Linux ") elseif(WIN32) message("platform: Windows ") else() message("platform: unkonw ") endif()
但其他情况,当在windows下使用CYGwin时:
-- platform: platform -- CMAKE_HOST_SYSTEM_NAME: CYGWIN -- CMAKE_HOST_SYSTEM : CYGWIN-3.3.6-341.x86_64 -- CMAKE_SYSTEM_NAME : CYGWIN -- CMAKE_SYSTEM : CYGWIN-3.3.6-341.x86_64 -- CMAKE_HOST_UNIX : 1 -- CMAKE_HOST_WIN32 :
所以,此处建议根据项目实际情况考虑
还没有评论,来说两句吧...