如何只在Linux环境下编写CMakeLists.txt
以有条件地链接到系统范围的librt
库?
答案 0 :(得分:19)
cmake有几个对环境检测有用的预定义变量(WIN32,UNIX,APPLE,CYGWIN)。以下是完整列表:http://www.cmake.org/cmake/help/cmake-2-8-docs.html#section_VariablesThatDescribetheSystem
所以你可以写点像
if(UNIX AND NOT APPLE)
target_link_libraries(target_name rt)
endif()