对于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时,我如何传入不同的编译标志?
2条答案
按热度按时间vxqlmq5t1#
您似乎在寻找
CMAKE_OSX_ARCHITECTURES
:或
当编译不同的archs时,我如何传入不同的编译标志?
Xcode/xcodebuild无法做到,你必须建立单个的拱门目标,然后用
lipo -create -output universal_app x86_app arm_app
合并它们。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)