Skip to content

Commit

Permalink
Fix build errors and codegened cmake target libs
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlabelle committed Sep 23, 2024
1 parent 9d7a210 commit ff5c43b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Generator/Sources/CodeWriters/CMake/CMakeListsWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public final class CMakeListsWriter {
output.beginLine()
argument.write(to: &output)
}
output.write(")")
}
output.write(")", endLine: true)
}
}

Expand Down
6 changes: 4 additions & 2 deletions Generator/Sources/SwiftWinRT/BuildSystemOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ struct SPMOptions {
public let excludeCMakeLists: Bool

public func getLibraryName(moduleName: String) -> String {
"\(libraryPrefix)\(module)\(librarySuffix)"
guard !libraryPrefix.isEmpty || !librarySuffix.isEmpty else { return moduleName }
return "\(libraryPrefix)\(moduleName)\(librarySuffix)"
}
}

Expand All @@ -16,6 +17,7 @@ struct CMakeOptions {
public let dynamicLibraries: Bool

public func getTargetName(moduleName: String) -> String {
"\(targetPrefix)\(module)\(targetSuffix)"
guard !targetPrefix.isEmpty || !targetSuffix.isEmpty else { return moduleName }
return "\(targetPrefix)\(moduleName)\(targetSuffix)"
}
}
4 changes: 3 additions & 1 deletion Generator/Sources/SwiftWinRT/Writing/SwiftPackageFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func writeSwiftPackageFile(_ projection: Projection, spmOptions: SPMOptions, toP

// Create products for the projections and the ABI
package.products.append(moduleProduct)
package.products.append(.library(name: module.abiModuleName, type: .static, targets: [abiModuleTarget.name]))
package.products.append(.library(
name: spmOptions.getLibraryName(moduleName: module.abiModuleName),
type: .static, targets: [abiModuleTarget.name]))
}

if spmOptions.excludeCMakeLists {
Expand Down
8 changes: 4 additions & 4 deletions Generator/Sources/SwiftWinRT/writeProjectionFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fileprivate func writeModuleFiles(
try writeNamespaceModuleFiles(module, directoryPath: "\(directoryPath)\\Namespaces", cmakeOptions: cmakeOptions)
}

if let cmakeOptions {
if cmakeOptions != nil {
let writer = CMakeListsWriter(output: FileTextOutputStream(
path: "\(directoryPath)\\CMakeLists.txt",
directoryCreation: .ancestors))
Expand Down Expand Up @@ -108,8 +108,8 @@ fileprivate func writeSwiftModuleFiles(_ module: Module, directoryPath: String,
"PROPERTIES", "Swift_MODULE_NAME", .autoquote(module.name))
}
writer.writeTargetLinkLibraries(targetName, .public,
[ SupportModules.WinRT.moduleName, SupportModules.WinRT.abiModuleName ]
+ module.references.map { cmakeOptions.getTargetName(moduleName: $0.abiModuleName) })
[ cmakeOptions.getTargetName(moduleName: module.abiModuleName), SupportModules.WinRT.moduleName ]
+ module.references.map { cmakeOptions.getTargetName(moduleName: $0.name) })
}
}

Expand Down Expand Up @@ -143,7 +143,7 @@ fileprivate func writeNamespaceModuleFiles(_ module: Module, directoryPath: Stri
}
}

if let cmakeOptions, !compactNamespaces.isEmpty {
if cmakeOptions != nil, !compactNamespaces.isEmpty {
let writer = CMakeListsWriter(output: FileTextOutputStream(
path: "\(directoryPath)\\CMakeLists.txt",
directoryCreation: .ancestors))
Expand Down

0 comments on commit ff5c43b

Please sign in to comment.