如何在CMake中为Xcode项目的特定目标更改OSX_DEPLOYMENT_TARGET。

huangapple go评论56阅读模式
英文:

How to alter OSX_DEPLOYMENT_TARGET for a specific target in CMake for xcode project

问题

以下是您要翻译的代码部分:

For make project, the below minimal example will allow me to alter `OSX_DEPLOYMENT_TARGET` for a specific target successfully:
set(CMAKE_OSX_DEPLOYMENT_TARGET
    "11.0"
    CACHE STRING "osx deployment target")

# the osx deployment target of mylib is 11.0
add_subdirectory(mylib)

# but one of the external library the test links to is built with 12.0, so I want the test to be compiled with 12.0
find_package(external)

set_property(
  TARGET external
  APPEND
  PROPERTY INTERFACE_COMPILE_OPTIONS -mmacosx-version-min=12.0
  PROPERTY INTERFACE_LINK_OPTIONS -mmacosx-version-min=12.0)

add_executable(mytest main.cpp)

target_link_libraries(mytest PUBLIC mylibs external)

对于 Xcode 项目,OSX_DEPLOYMENT_TARGET-target x86_64-apple-macos12.0-target arm64-apple-macos12.0 控制。mytest 是一个具有 x86_64 和 arm64 的通用二进制文件,我很难弄清楚如何在 CMake 中将 -target x86_64-apple-macos12.0 传递给 x86_64 切片,并将 -target arm64-apple-macos12.0 传递给 arm64 切片。我的最佳尝试看起来像下面这样:

set_property(
  TARGET external
  APPEND
  PROPERTY
    INTERFACE_COMPILE_OPTIONS
    -target
    $<${STREQUAL:$<TARGET_PROPERTY:OSX_ARCHITECTURES>,x86_64:x86_64-apple-macos12.0>}
    $<${STREQUAL:$<TARGET_PROPERTY:OSX_ARCHITECTURES>,arm64:arm64-apple-macos12.0>}
  PROPERTY
    INTERFACE_LINK_OPTIONS
    -target
    $<${STREQUAL:$<TARGET_PROPERTY:OSX_ARCHITECTURES>,x86_64:x86_64-apple-macos12.0>}
    $<${STREQUAL:$<TARGET_PROPERTY:OSX_ARCHITECTURES>,arm64:arm64-apple-macos12.0>}
)

但不幸的是,这不起作用。一个更一般的问题是,如何在编译不同架构时传递不同的编译标志?

英文:

For make project, the below minimal example will allow me to alter OSX_DEPLOYMENT_TARGET for a specific target successfully:

set(CMAKE_OSX_DEPLOYMENT_TARGET
    &quot;11.0&quot;
    CACHE STRING &quot;osx deployment target&quot;)

# the osx deployment target of mylib is 11.0
add_subdirectory(mylib)

# but one of the external library the test links to is built with 12.0, so I want the test to be compiled with 12.0
find_package(external)

set_property(
  TARGET external
  APPEND
  PROPERTY INTERFACE_COMPILE_OPTIONS -mmacosx-version-min=12.0
  PROPERTY INTERFACE_LINK_OPTIONS -mmacosx-version-min=12.0)

add_executable(mytest main.cpp)

target_link_libraries(mytest PUBLIC mylibs external)

However, for xcode project, the OSX_DEPLOYMENT_TARGET is controlled by -target x86_64-apple-macos12.0 and -target arm64-apple-macos12.0. mytest is a universal binary with x86_64 and arm64, and I am having difficulties to figure out how to pass -target x86_64-apple-macos12.0 to the x86_64 slice and -target arm64-apple-macos12.0 to the arm64 slice in cmake. My best attempt looks like the below:

set_property(
  TARGET external
  APPEND
  PROPERTY
    INTERFACE_COMPILE_OPTIONS
    -target
    $&lt;$&lt;STREQUAL:$&lt;TARGET_PROPERTY:OSX_ARCHITECTURES&gt;,x86_64:x86_64-apple-macos12.0&gt;&gt;
    $&lt;$&lt;STREQUAL:$&lt;TARGET_PROPERTY:OSX_ARCHITECTURES&gt;,arm64:arm64-apple-macos12.0&gt;&gt;
  PROPERTY
    INTERFACE_LINK_OPTIONS
    -target
    $&lt;$&lt;STREQUAL:$&lt;TARGET_PROPERTY:OSX_ARCHITECTURES&gt;,x86_64:x86_64-apple-macos12.0&gt;&gt;
    $&lt;$&lt;STREQUAL:$&lt;TARGET_PROPERTY:OSX_ARCHITECTURES&gt;,arm64:arm64-apple-macos12.0&gt;&gt;
)

but unfortunately this doesn't work. A more general question is that how can I pass in different compilation flags when compiling different archs?

答案1

得分: 0

你似乎在寻找CMAKE_OSX_ARCHITECTURES

cmake ... -DCMAKE_OSX_ARCHITECTURES=arm64

或者

set(CMAKE_OSX_ARCHITECTURES arm64)

> 在编译不同的架构时,如何传递不同的编译标志?

Xcode/xcodebuild 无法做到。您必须构建单个架构目标,然后使用lipo -create -output universal_app x86_app arm_app将它们合并。

英文:

You seem to be looking for CMAKE_OSX_ARCHITECTURES:

cmake ... -DCMAKE_OSX_ARCHITECTURES=arm64

or

set(CMAKE_OSX_ARCHITECTURES arm64)

> how can I pass in different compilation flags when compiling different archs?

Xcode/xcodebuild can't do it. You have to build single arch targets and merge them with lipo -create -output universal_app x86_app arm_app.

答案2

得分: 0

我从https://github.com/eyalamirmusic/JUCECmakeRepoPrototype/issues/5#issuecomment-747082201找到了答案。

这是 set_target_properties(mytest PROPERTIES XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET 12.0)

英文:

I found the answer from https://github.com/eyalamirmusic/JUCECmakeRepoPrototype/issues/5#issuecomment-747082201.

It's set_target_properties(mytest PROPERTIES XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET 12.0)

huangapple
  • 本文由 发表于 2023年2月16日 09:14:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466923.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定