获取正在编译的操作系统
?
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
MESSAGE(STATUS "current platform: Linux ")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
MESSAGE(STATUS "current platform: Windows")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
MESSAGE(STATUS "current platform: FreeBSD")
ELSE ()
MESSAGE(STATUS "other platform: ${CMAKE_SYSTEM_NAME}")
ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")
?
获取编译位数
?
if(CMAKE_CL_64) #CMAKE的内建变量,如果是true,就说明编译器的64位的,自然可以编译64bit的程序
MESSAGE(STATUS "current build compiler: x64")
else()
MESSAGE(STATUS "current build compiler: x86")
endif()
?
Windows Visual Studio 2019 默认为64位。
获取编译方式
if(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
MESSAGE("Debug mode:${CMAKE_C_FLAGS_DEBUG}")
elseif(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
MESSAGE(STATUS "Release mode:${CMAKE_C_FLAGS_RELEASE}")
else()
MESSAGE(STATUS "else:${CMAKE_BUILD_TYPE}")
MESSAGE(STATUS "else:${CMAKE_C_FLAGS_RELEASE}")
endif()
案例:Windows? ---visual studio 2019---x64----Release
CmakeList.txt在..目录中
?cmake .. -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release
?
|