有条件的CMAKE链接到rt-library

时间:2011-10-08 08:21:27

标签: c++ c cmake

如何只在Linux环境下编写CMakeLists.txt以有条件地链接到系统范围的librt库?

1 个答案:

答案 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()