保护码取决于CMake版本 [英] Guard code depending on CMake version

查看:67
本文介绍了保护码取决于CMake版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的项目有一个 CMakeList.txt ,但它不是我们的主要构建系统。在Mac OS X上,使用 Cmake生成警告(此处无新内容):

Our project has a CMakeList.txt, but its not our primary build system. On Mac OS X, using Cmake generates a warning (nothing new here):

MACOSX_RPATH is not specified for the following targets...

引用的问题/答案指出使用 set(CMAKE_MACOSX_RPATH 0) set(CMAKE_MACOSX_RPATH 1)。我们的问题是此功能太新了,它会破坏现有的Cmake安装,例如在Ubuntu LTS或CentOS上找到的安装。我们需要保护其在Cmake> = 2.8.12中的使用,但是博客文章没有讨论如何做。

The cited question/answer states to use either set(CMAKE_MACOSX_RPATH 0) or set(CMAKE_MACOSX_RPATH 1). Our problem is, the feature is too new and it breaks existing Cmake installations, like those found on Ubuntu LTS's or CentOS. We need to guard its use for Cmake >= 2.8.12, but the blog post does not discuss how to do it.

搜索没有产生有用的结果:如何保护cmake指令。我无法找到相关结果可能是由于我对Cmake缺乏经验(应该由其他人维护)。

Searching is not producing useful results: how to guard cmake directive. My inability to find relevant results is probably due to my inexperience with Cmake (others were supposed to maintain it).

我们如何保护 set( CMAKE_MACOSX_RPATH 0) set(CMAKE_MACOSX_RPATH 1)

请注意,我不是不是正在寻找 cmake_minimum_required(版本2.8.5致命错误)。我所能告诉的最好的事情不是该死的事情。通过测试,我们知道它不会拒绝 target_include_directories ,即使 target_include_directories 不满足最低要求并导致下层客户端失败像Ubuntu LTS一样。

Please note, I'm not looking for cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR). The best I can tell it does not do a damn thing. From testing we know it does not reject target_include_directories even though target_include_directories does not meet minimum requirements and causes failures in down level clients like Ubuntu LTS's.

我认为我正在寻找的对象更接近C预处理程序宏:

I think what I'm looking for is closer to a C preprocessor macro:

#define 2_8_12 ...
#if CMAKE_VERSION >= 2_8_12
set(CMAKE_MACOSX_RPATH 0)
#endif


推荐答案

if (CMAKE_VERSION VERSION_LESS 2.8.12)
  message("Not setting RPATH")
else()
  set(CMAKE_MACOSX_RPATH 0)
endif()

此处提供2.8.10的文档: https://cmake.org/cmake/help/v2.8.10/cmake.html#variable:CMAKE_VERSION

Docs for 2.8.10 here: https://cmake.org/cmake/help/v2.8.10/cmake.html#variable:CMAKE_VERSION

这篇关于保护码取决于CMake版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆