CMake顶级Xcode项目属性 [英] CMake Top Level Xcode Project Properties

查看:317
本文介绍了CMake顶级Xcode项目属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有Xcode的Cmake来生成c ++ / c项目(my_project)和一些c ++ / c目标(一个是二进制文件,其余是库)

I am using Cmake with Xcode to generate a c++/c "project" (my_project) and some c++/c "targets" (one is a binary, the rest are libraries)

我的CMakeLists.txt看起来像这样:

My CMakeLists.txt looks something like this:

project(my_project)
add_subdirectory(library_projectA)
add_subdirectory(library_projectB)
add_subdirectory(binary_project) 

每个子目录都有一个CMakeLists .txt,其中之一:

Each Subdirectory has a CMakeLists.txt with either:

add_library(library_projectA)

add_executable(binary_project)

哪个会生成顶级my_project.xcodeproj,它引用子项目。

Which produces a top level my_project.xcodeproj, which references the subprojects.

Xcode具有以下层次结构属性继承(左字段优先于右字段):

Xcode has this Hierarchical property inheritance (left fields take precedence over right fields):

目标,项目,默认值

我想更改项目字段,即my_project。这应该会影响所有目标。

I would like to change the "Project" fields, i.e. for my_project. This should affect ALL Targets.

我已经尝试过:

add_custom_target(my_project)
add_target_properties(my_project PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO")

但这不是'

请注意,如果我将其放在目标之一中:

Note that if I put this in one of the "Targets":

add_target_properties(binary_project PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO")

然后此方法有效,但仅对于该目标

Then this works, but only for that "Target"

如果不清楚,我很乐意提供一个可行的示例,但这会花费一些时间...

If this isn't clear, I'd be happy to provide a working example, but this will take a bit of time...

在偶然的情况下,任何人都知道可以更快地解决整个问题,我希望全新安装Xcode不能提出这个问题(或其他问题)警告:

On the off-chance anyone knows of a quicker fix to the whole problem, I'd like a clean install of Xcode not not come up with this (or any other) warning:


项目 my_project会覆盖体系结构设置。
会删除该设置,并允许Xcode根据活动平台可用的硬件和
部署目标自动选择
体系结构。

Project 'my_project' overrides the Architectures setting. This will remove the setting and allow Xcode to automatically select Architectures based on hardware available for the active platform and deployment target.


推荐答案

我最近也需要做同样的事情,因此我不得不研究CMake的源代码。

I recently needed the same thing so I had to look into the source code of CMake.

当前,您只能为目标设置属性,无法在项目级别上设置它们。

Currently, you can set attributes only for the targets and there is no way to set them on the project level.

但是,可以更改 ONLY_ACTIVE_ARCH 在项目级别上以略有不同的方式。在cmake中实现的逻辑如下(对于版本2.8.12):

However, it is possible to change ONLY_ACTIVE_ARCH on the project level in a slightly different way. The implemented logic in cmake is the following (for version 2.8.12):


  1. 如果 CMAKE_OSX_ARCHITECTURES ,然后在项目级别将cmake将 ONLY_ACTIVE_ARCH 设置为 YES ,具体取决于xcode版本将默认体系结构设置为 $(ARCHS_STANDARD_32_64_BIT) $(ARCHS_STANDARD_32_BIT)

  2. 如果定义了 CMAKE_OSX_ARCHITECTURES ,则 ONLY_ACTIVE_ARCH 变为

  1. If CMAKE_OSX_ARCHITECTURES is not set, then cmake sets ONLY_ACTIVE_ARCH to YES on the project level, and depending on xcode version it sets default architectures to either $(ARCHS_STANDARD_32_64_BIT) or $(ARCHS_STANDARD_32_BIT)
  2. If CMAKE_OSX_ARCHITECTURES is defined, then ONLY_ACTIVE_ARCH becomes NO

我更喜欢设置CMAKE_OSX_ARCHITECTURES,以便XCode构建胖库,对于最大的库,我只是手动将ONLY_ACTIVE_ARCH设置为YES,仅用于Debug配置。看起来像这样:

I prefer to set CMAKE_OSX_ARCHITECTURES, so that XCode builds fat libraries and for the biggest libraries I just manually set ONLY_ACTIVE_ARCH to YES for Debug configuration only. This looks like that:

set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_64_BIT)")

...

set_target_properties(test PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH[variant=Debug] "YES")

这篇关于CMake顶级Xcode项目属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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