cmake跨平台编译之判断操作系统平台、32位64位系统_谁吃薄荷糖的博客-CSDN博客
if(CMAKE_CROSSCOMPILING)
message(STATUS "Cross Comliling!!!, ARM")
set(CURRENT_SYSTEM "Arm")
else()
message(STATUS "No Cross Comliling!!!")
endif()
if(CMAKE_CL_64)
set(CURRENT_PLATFORM "x64")
message(STATUS "Current Platform is ${CURRENT_PLATFORM}")
else(CMAKE_CL_64)
set(CURRENT_PLATFORM "x86")
message(STATUS "Current Platform is ${CURRENT_PLATFORM}")
endif(CMAKE_CL_64)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CURRENT_SYSTEM "Linux")
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CURRENT_SYSTEM "Windows")
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(CURRENT_SYSTEM "FreeBSD")
endif()
CMakeLists.txt文件节选:
message(STATUS "===============================")
MESSAGE(STATUS "current operation system is ${CMAKE_SYSTEM}")
message(STATUS "current operation system name is ${CMAKE_SYSTEM_NAME}")
if(CMAKE_CL_64)
set(CURRENT_PLATFORM "x64")
message(STATUS "Current Platform is ${CURRENT_PLATFORM}")
else(CMAKE_CL_64)
set(CURRENT_PLATFORM "x86")
message(STATUS "Current Platform is ${CURRENT_PLATFORM}")
endif(CMAKE_CL_64)
if(CMAKE_CROSSCOMPILING)
message(STATUS "Cross Comliling!!!, ARM")
set(CURRENT_SYSTEM "Arm")
else()
message(STATUS "No Cross Comliling!!!")
#根据不同平台给CURRENT_SYSTEM命名
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CURRENT_SYSTEM "Linux")
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CURRENT_SYSTEM "Windows")
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(CURRENT_SYSTEM "FreeBSD")
endif()
endif()
cmake打印信息(Ubuntu20系统x86测试测试):
root@root:/home/root123/testdemo/demo1/build
-- ===============================
-- current operation system is Linux-5.11.0-41-generic
-- current operation system name is Linux
-- Current Platform is x86
-- No Cross Comliling!!!
-- ===============================
-- /home/root123/testdemo/demo1/Lib/Debug/Linux/x86
-- ===============================