-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support generating CMakeLists.txt files (#238)
Fixes #229
- Loading branch information
1 parent
5e1db60
commit 7d367c9
Showing
9 changed files
with
172 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public enum CMakeLibraryType: String { | ||
case `static` = "STATIC" | ||
case shared = "SHARED" | ||
case interface = "INTERFACE" | ||
} |
38 changes: 38 additions & 0 deletions
38
Generator/Sources/CodeWriters/CMake/CMakeListsWriter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
public final class CMakeListsWriter { | ||
private let output: IndentedTextOutputStream | ||
|
||
public init(output: some TextOutputStream) { | ||
self.output = .init(inner: output) | ||
} | ||
|
||
public func writeAddLibrary(_ name: String, _ type: CMakeLibraryType? = nil, _ sources: [String] = []) { | ||
let typeSuffix = type.map { " \($0)" } ?? "" | ||
output.writeIndentedBlock(grouping: .never, header: "add_library(\(name)\(typeSuffix)", footer: ")") { | ||
for source in sources { | ||
output.writeFullLine(source) | ||
} | ||
} | ||
} | ||
|
||
public func writeTargetIncludeDirectories(_ target: String, _ visibility: CMakeVisibility, _ directories: [String]) { | ||
guard !directories.isEmpty else { return } | ||
output.writeIndentedBlock(grouping: .never, header: "target_include_directories(\(target) \(visibility)", footer: ")") { | ||
for directory in directories { | ||
output.writeFullLine(directory) | ||
} | ||
} | ||
} | ||
|
||
public func writeTargetLinkLibraries(_ target: String, _ visibility: CMakeVisibility, _ libraries: [String]) { | ||
guard !libraries.isEmpty else { return } | ||
output.writeIndentedBlock(grouping: .never, header: "target_link_libraries(\(target) \(visibility)", footer: ")") { | ||
for library in libraries { | ||
output.writeFullLine(library) | ||
} | ||
} | ||
} | ||
|
||
public func writeAddSubdirectory(_ subdirectory: String) { | ||
output.writeFullLine(grouping: .withName("add_subdirectory"), "add_subdirectory(\(subdirectory))") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public enum CMakeVisibility: String { | ||
case `public` = "PUBLIC" | ||
case `private` = "PRIVATE" | ||
case `interface` = "INTERFACE" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters