CMake似乎忽略了CMAKE_OSX_DEPLOYMENT_TARGET [英] CMake seems to ignore CMAKE_OSX_DEPLOYMENT_TARGET
问题描述
我在OS X 10.10.5上使用CMake 3.3.2和Xcode 7.1。
I'm using CMake 3.3.2 and Xcode 7.1 on OS X 10.10.5.
我有一个使用CMake的小型C ++项目。我希望它在OS X 10.9或更高版本上运行。因此,我修改了CMakeLists.txt以开始以下操作:
I have a small C++ project that uses CMake. I want it to run on OS X 10.9 or later. So I modified my CMakeLists.txt to look start this:
cmake_minimum_required(VERSION 3.3)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9")
project(...
然后我创建了Xcode项目像这样:
Then I create the Xcode project like this:
cmake -G Xcode <path>
但是,生成的xcodeproj捆绑包似乎没有设置部署目标。当我在文本编辑器中打开所包含的project.pbxproj文件时,没有任何行提及 MACOSX_DEPLOYMENT_TARGET
。
However, the resulting xcodeproj bundle doesn't seem to have a deployment target set. When I open the contained project.pbxproj file in a text editor, there is no line mentioning MACOSX_DEPLOYMENT_TARGET
.
因此,当我在Xcode中打开项目设置>部署> OS X部署目标下的项目时,无论我在CMakeLists.txt中指定什么,Xcode始终显示默认值 OS X 10.11。在Xcode中手动更改设置然后在文本编辑器中重新打开项目文件时,行 MACOSX_DEPLOYMENT_TARGET = 10.9;
已正确添加。
Accordingly, when I open the project in Xcode, under Build Settings > Deployment > OS X Deployment Target, Xcode always displays the default value "OS X 10.11", no matter what I specify in CMakeLists.txt. When I manually change the setting in Xcode and then re-open the project file in a text editor, the line MACOSX_DEPLOYMENT_TARGET = 10.9;
has correctly been added.
我在做什么吗?错了吗?谷歌搜索问题没有得到任何最新结果。
Am I doing something wrong? Googling the problem didn't give any recent results.
推荐答案
变量 CMAKE_OSX_DEPLOYMENT_TARGET
必须在第一个 project()
命令之前初始化为缓存变量,以便正确拾取Xcode项目生成:
The variable CMAKE_OSX_DEPLOYMENT_TARGET
must initialized as a cache variable prior to the first project()
command in order for the Xcode project generation to be picked up properly:
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")
如果未显式设置为 cache 变量,则会由
环境变量。 CMAKE_OSX_DEPLOYMENT_TARGET
> MACOSX_DEPLOYMENT_TARGET
If not set explicitly as a cache variable the CMAKE_OSX_DEPLOYMENT_TARGET
is initialized by the MACOSX_DEPLOYMENT_TARGET
environment variable.
像上面的赋值一样,初始化缓存变量也将覆盖非缓存变量的值。在相同范围内具有相同的名称。
The initialization of a cache variable like in the assignment above will also override the value of non-cache variables of the same name in the same scope.
这篇关于CMake似乎忽略了CMAKE_OSX_DEPLOYMENT_TARGET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!