判断操作系统

IF (CMAKE_SYSTEM_NAME MATCHES "Linux")

ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")

ELSEIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")

ELSE ()
MESSAGE(STATUS "other platform: ${CMAKE_SYSTEM_NAME}")
ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")

判断编译器

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")

using Clang

elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")

using GCC

elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")

using Intel C++

elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")

using Visual Studio C++

endif()

Reference

https://www.cnblogs.com/pandamohist/p/13556546.html

最后修改:2024 年 03 月 25 日
如果觉得我的文章对你有用,请随意赞赏