Post

Replies

Boosts

Views

Activity

Get a list of swift's system libraries on macOS for different systems in CMake3.28
Preface: The C++ project links to a dynamic library that uses Swift, but CMake does not see this and does not put the necessary libs and i get many errors ld: warning: Could not find or use auto-linked framework 'libswiftCompatibility*' not found *link errors* What did I do: The first option to solve the problem is to add an empty .swift file to the sources, which will trigger xcodebuild and put the libs itself The second option I took it from Apple repository, but it only works for macOS. I need the same functionality for iOS. To get a list of libs for both macOS and iOS, just call the command swiftc -sdk /path/to/sdk/.sdk -target -print-target-info where <triple> is an arm64-apple-macos17.2, for example, and for different platforms, it is obviously different In CMake, I wrote such an implementation execute_process( COMMAND xcrun --show-sdk-path --sdk ${CMAKE_OSX_SYSROOT} OUTPUT_VARIABLE SDK_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process( COMMAND xcrun --show-sdk-platform-version --sdk ${CMAKE_OSX_SYSROOT} OUTPUT_VARIABLE SDK_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(TARGET_PLATFORM "macos") elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS") set(TARGET_PLATFORM "ios") endif() set(SDK_FLAGS "-sdk" "${SDK_PATH}" "-target" "${CMAKE_OSX_ARCHITECTURES}-apple-${TARGET_PLATFORM}${SDK_VERSION}" ) And the question is this: Is there some more beautiful/correct way to get a list of libs (in this case, the way to get <triple> bothers me, it seems to me at one point something will fall off) or maybe in the new CMake there is a way to link all libs without problems?
0
0
374
Feb ’24