Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add files or define to different cpu when use SIMULATOR64COMBINED? #215

Open
SirLYC opened this issue Aug 22, 2024 · 3 comments
Open
Assignees
Labels

Comments

@SirLYC
Copy link

SirLYC commented Aug 22, 2024

My project contains separate code for different CPU architectures, such as x64/a.c for x64 and arm/a.c for arm64. How can I ensure that x64/a.c is compiled only for the x64 simulator and arm/a.c is compiled only for the arm64 target? I've observed that each file has both a compile command with -arch_only x86_64 and -arch_only arm64.

I tried compiling simulator64 and simulatorarm64 separately, but when I attempted to merge them into an xcframework, I encountered an error stating, "Both 'ios-x86_64-simulator' and 'ios-arm64-simulator' represent two equivalent library definitions."

I'm looking forward to your response and appreciate your help.

@kambala-decapitator
Copy link

try adding your files checking the CMAKE_SYSTEM_PROCESSOR variable, something like:

if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
  target_sources(your_target x64/a.c)
else()
  target_sources(your_target arm/a.c)
endif()

@SirLYC
Copy link
Author

SirLYC commented Aug 22, 2024

It's not working...According to https://github.com/leetal/ios-cmake/blob/ad96a372b168930c2a1ff9455e1a9ccb13021617/ios.toolchain.cmake#L815,the CMAKE_SYSTEM_PROCESSOR is always aarch64 when PLATFORM=SIMULATOR64COMBINED. And the Cmake config only once.

@kambala-decapitator
Copy link

kambala-decapitator commented Aug 22, 2024

then I guess the only way is to use xcodebuild's feature to exclude/include source files for a target: EXCLUDED_SOURCE_FILE_NAMES + INCLUDED_SOURCE_FILE_NAMES, see https://developer.apple.com/documentation/xcode/build-settings-reference#Excluded-Source-File-Names

so you'd exclude directory that contains your arch dirs and then include only the necessary arch dir using CURRENT_ARCH xcodebuild variable, e.g. in terms of xcconfig file that would be:

EXCLUDED_SOURCE_FILE_NAMES = x86_64/* arm64/*
INCLUDED_SOURCE_FILE_NAMES = $(CURRENT_ARCH)/*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants