From 9a013c9e9d344f9703f339c6aeab9dcc303b53c0 Mon Sep 17 00:00:00 2001 From: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com> Date: Fri, 13 Jan 2023 13:34:16 +0000 Subject: Swift: Use macOS-style linker flags on iOS, tvOS, and watchOS too Without this, building a shared Swift library with `CMAKE_SYSTEM_NAME=iOS` produces the error `ld: unknown option: -soname`. iOS is an Apple platform, and so should use the `-install_name` option. --- Modules/CMakeSwiftInformation.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake index 62f7ef2..707635b 100644 --- a/Modules/CMakeSwiftInformation.cmake +++ b/Modules/CMakeSwiftInformation.cmake @@ -20,7 +20,8 @@ endif() set(CMAKE_EXE_EXPORTS_Swift_FLAG "-emit-module -emit-module-path ${CMAKE_Swift_IMPLIB_LINKER_FLAGS}") set(CMAKE_INCLUDE_FLAG_Swift "-I ") -if(CMAKE_SYSTEM_NAME STREQUAL Darwin) +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS" + OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "watchOS") set(CMAKE_SHARED_LIBRARY_SONAME_Swift_FLAG "-Xlinker -install_name -Xlinker ") elseif(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) set(CMAKE_SHARED_LIBRARY_SONAME_Swift_FLAG "-Xlinker -soname -Xlinker ") @@ -29,7 +30,8 @@ endif() if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) set(CMAKE_EXECUTABLE_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ") set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ") - if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS" + OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "watchOS") set(CMAKE_EXECUTABLE_RUNTIME_Swift_FLAG_SEP "") set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG_SEP "") else() -- cgit v0.12 From 44abf248486fca72e59a5a94f5c79b4914d2cfd8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 13 Jan 2023 12:06:22 -0500 Subject: Swift: Add comment about where platform-specific flags should go --- Modules/CMakeSwiftInformation.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake index 707635b..64c7519 100644 --- a/Modules/CMakeSwiftInformation.cmake +++ b/Modules/CMakeSwiftInformation.cmake @@ -20,13 +20,14 @@ endif() set(CMAKE_EXE_EXPORTS_Swift_FLAG "-emit-module -emit-module-path ${CMAKE_Swift_IMPLIB_LINKER_FLAGS}") set(CMAKE_INCLUDE_FLAG_Swift "-I ") + +# FIXME: Move compiler- and platform-specific flags to the above-included modules. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "watchOS") set(CMAKE_SHARED_LIBRARY_SONAME_Swift_FLAG "-Xlinker -install_name -Xlinker ") elseif(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) set(CMAKE_SHARED_LIBRARY_SONAME_Swift_FLAG "-Xlinker -soname -Xlinker ") endif() - if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) set(CMAKE_EXECUTABLE_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ") set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ") -- cgit v0.12