如何在CMake for xcode项目中为特定目标更改OSX_DEPLOYMENT_TARGET

5anewei6  于 2023-03-02  发布在  其他
关注(0)|答案(2)|浏览(203)

对于make project,下面的最小示例将允许我成功地为特定目标修改OSX_DEPLOYMENT_TARGET

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>>
)

但不幸的是,这并不起作用。一个更普遍的问题是,当编译不同的archs时,我如何传入不同的编译标志?

vxqlmq5t

vxqlmq5t1#

您似乎在寻找CMAKE_OSX_ARCHITECTURES

cmake ... -DCMAKE_OSX_ARCHITECTURES=arm64

set(CMAKE_OSX_ARCHITECTURES arm64)

当编译不同的archs时,我如何传入不同的编译标志?
Xcode/xcodebuild无法做到,你必须建立单个的拱门目标,然后用lipo -create -output universal_app x86_app arm_app合并它们。

ecbunoof

ecbunoof2#

我在www.example.com上找到了答案https://github.com/eyalamirmusic/JUCECmakeRepoPrototype/issues/5#issuecomment-747082201。
set_target_properties(mytest PROPERTIES XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET 12.0)

相关问题