英文:
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
    "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)
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
    $<$<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>>
)
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论