diff options
-rw-r--r-- | Modules/CMakeSwiftInformation.cmake | 4 | ||||
-rw-r--r-- | Modules/Platform/Apple-Apple-Swift.cmake | 3 | ||||
-rw-r--r-- | Modules/Platform/Linux-Apple-Swift.cmake | 2 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 43 | ||||
-rw-r--r-- | Tests/SwiftOnly/CMakeLists.txt | 11 | ||||
-rw-r--r-- | Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/SwiftOnly/SwiftPlugin/main.swift | 3 | ||||
-rw-r--r-- | Tests/SwiftOnly/SwiftPlugin/plugin.swift | 2 |
8 files changed, 33 insertions, 37 deletions
diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake index 34ae751..60df6a2 100644 --- a/Modules/CMakeSwiftInformation.cmake +++ b/Modules/CMakeSwiftInformation.cmake @@ -138,7 +138,7 @@ if(CMAKE_Swift_COMPILATION_MODE_DEFAULT) endif() if(NOT CMAKE_Swift_CREATE_SHARED_MODULE) - set(CMAKE_Swift_CREATE_SHARED_MODULE ${CMAKE_Swift_CREATE_SHARED_LIBRARY}) + set(CMAKE_Swift_CREATE_SHARED_MODULE "${CMAKE_Swift_CREATE_SHARED_LIBRARY} <CMAKE_SHARED_MODULE_CREATE_Swift_FLAGS>") endif() if(NOT CMAKE_Swift_LINK_EXECUTABLE) @@ -162,7 +162,7 @@ else() endif() if(NOT CMAKE_Swift_CREATE_SHARED_MODULE) - set(CMAKE_Swift_CREATE_SHARED_MODULE ${CMAKE_Swift_CREATE_SHARED_LIBRARY}) + set(CMAKE_Swift_CREATE_SHARED_MODULE "${CMAKE_Swift_CREATE_SHARED_LIBRARY} <CMAKE_SHARED_MODULE_CREATE_Swift_FLAGS>") endif() if(NOT CMAKE_Swift_LINK_EXECUTABLE) diff --git a/Modules/Platform/Apple-Apple-Swift.cmake b/Modules/Platform/Apple-Apple-Swift.cmake index 237f6e4..9f27efa 100644 --- a/Modules/Platform/Apple-Apple-Swift.cmake +++ b/Modules/Platform/Apple-Apple-Swift.cmake @@ -7,8 +7,11 @@ if("${CMAKE_GENERATOR}" STREQUAL Xcode) set(CMAKE_Swift_USING_LINKER_APPLE_CLASSIC "-fuse-ld=ld" "LINKER:-ld_classic") set(CMAKE_Swift_USING_LINKER_LLD "-fuse-ld=lld") set(CMAKE_Swift_USING_LINKER_SYSTEM "-fuse-ld=ld") + set(CMAKE_SHARED_MODULE_LOADER_Swift_FLAG "-Wl,-bundle_loader,") else() set(CMAKE_Swift_USING_LINKER_APPLE_CLASSIC "-use-ld=ld" "LINKER:-ld_classic") set(CMAKE_Swift_USING_LINKER_LLD "-use-ld=lld") set(CMAKE_Swift_USING_LINKER_SYSTEM "-use-ld=ld") + set(CMAKE_SHARED_MODULE_LOADER_Swift_FLAG "-Xclang-linker -Wl,-bundle_loader,") + set(CMAKE_SHARED_MODULE_CREATE_Swift_FLAGS "-Xlinker -bundle") endif() diff --git a/Modules/Platform/Linux-Apple-Swift.cmake b/Modules/Platform/Linux-Apple-Swift.cmake index 22f0554..248d2de 100644 --- a/Modules/Platform/Linux-Apple-Swift.cmake +++ b/Modules/Platform/Linux-Apple-Swift.cmake @@ -1,3 +1,5 @@ +set(CMAKE_EXE_EXPORTS_Swift_FLAG "-Xclang-linker -Wl,--export-dynamic") + # Linker Selection # BFD is known to mislink Swift objects resulting in missing type info set(CMAKE_Swift_USING_LINKER_SYSTEM "") diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 684dfda..e04f505 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1478,7 +1478,7 @@ void cmLocalGenerator::GetTargetFlags( CM_FALLTHROUGH; case cmStateEnums::SHARED_LIBRARY: { std::string sharedLibFlags; - if (linkLanguage != "Swift") { + if (this->IsSplitSwiftBuild() || linkLanguage != "Swift") { sharedLibFlags = cmStrCat( this->Makefile->GetSafeDefinition(libraryLinkVariable), ' '); if (!configUpper.empty()) { @@ -1521,6 +1521,13 @@ void cmLocalGenerator::GetTargetFlags( } break; case cmStateEnums::EXECUTABLE: { std::string exeFlags; + if (linkLanguage.empty()) { + cmSystemTools::Error( + "CMake can not determine linker language for target: " + + target->GetName()); + return; + } + if (linkLanguage != "Swift") { exeFlags = this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS"); exeFlags += " "; @@ -1529,28 +1536,22 @@ void cmLocalGenerator::GetTargetFlags( cmStrCat("CMAKE_EXE_LINKER_FLAGS_", configUpper)); exeFlags += " "; } - if (linkLanguage.empty()) { - cmSystemTools::Error( - "CMake can not determine linker language for target: " + - target->GetName()); - return; - } + } - if (target->IsWin32Executable(config)) { - exeFlags += this->Makefile->GetSafeDefinition( - cmStrCat("CMAKE_", linkLanguage, "_CREATE_WIN32_EXE")); - exeFlags += " "; - } else { - exeFlags += this->Makefile->GetSafeDefinition( - cmStrCat("CMAKE_", linkLanguage, "_CREATE_CONSOLE_EXE")); - exeFlags += " "; - } + if (target->IsWin32Executable(config)) { + exeFlags += this->Makefile->GetSafeDefinition( + cmStrCat("CMAKE_", linkLanguage, "_CREATE_WIN32_EXE")); + exeFlags += " "; + } else { + exeFlags += this->Makefile->GetSafeDefinition( + cmStrCat("CMAKE_", linkLanguage, "_CREATE_CONSOLE_EXE")); + exeFlags += " "; + } - if (target->IsExecutableWithExports()) { - exeFlags += this->Makefile->GetSafeDefinition( - cmStrCat("CMAKE_EXE_EXPORTS_", linkLanguage, "_FLAG")); - exeFlags += " "; - } + if (target->IsExecutableWithExports()) { + exeFlags += this->Makefile->GetSafeDefinition( + cmStrCat("CMAKE_EXE_EXPORTS_", linkLanguage, "_FLAG")); + exeFlags += " "; } this->AddLanguageFlagsForLinking(flags, target, linkLanguage, config); diff --git a/Tests/SwiftOnly/CMakeLists.txt b/Tests/SwiftOnly/CMakeLists.txt index 3d2fe73..4754711 100644 --- a/Tests/SwiftOnly/CMakeLists.txt +++ b/Tests/SwiftOnly/CMakeLists.txt @@ -54,16 +54,7 @@ endif() add_library(SwiftIface INTERFACE) target_link_libraries(SwiftOnly PRIVATE SwiftIface) -# @_alwaysEmitIntoClient ensures that the function body is inserted into the -# swiftmodule instead of as a symbol in the binary itself. I'm doing this to -# avoid having to link the executable. There are some flags required in order to -# link an executable into a library that I didn't see CMake emitting for Swift -# on macOS. AEIC is the easiest workaround that still tests this functionality. -# Unfortunately, AEIC was only added recently (~Swift 5.2), so we need to check -# that it is available before using it. -if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.2) - add_subdirectory("SwiftPlugin") -endif() +add_subdirectory("SwiftPlugin") function(test_cmp0157_default mode) if(POLICY CMP0157) diff --git a/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt b/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt index 4069f16..2bfbc8a 100644 --- a/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt +++ b/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt @@ -1,5 +1,5 @@ add_executable(main main.swift) set_target_properties(main PROPERTIES ENABLE_EXPORTS TRUE) -add_library(plugin plugin.swift) +add_library(plugin MODULE plugin.swift) target_link_libraries(plugin PRIVATE main) diff --git a/Tests/SwiftOnly/SwiftPlugin/main.swift b/Tests/SwiftOnly/SwiftPlugin/main.swift index f5aac51..caba1fb 100644 --- a/Tests/SwiftOnly/SwiftPlugin/main.swift +++ b/Tests/SwiftOnly/SwiftPlugin/main.swift @@ -1,4 +1,3 @@ -@_alwaysEmitIntoClient -public func exported() -> Int { 32 } +public func exported() -> Int { return 32 } print(exported()) diff --git a/Tests/SwiftOnly/SwiftPlugin/plugin.swift b/Tests/SwiftOnly/SwiftPlugin/plugin.swift index e84f248..d00ca33 100644 --- a/Tests/SwiftOnly/SwiftPlugin/plugin.swift +++ b/Tests/SwiftOnly/SwiftPlugin/plugin.swift @@ -1,3 +1,3 @@ import main -public func importing() -> Int { main.exported() + 1 } +public func importing() -> Int { return main.exported() + 1 } |