Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the projection build with CMake #319

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ else()
execute_process(
COMMAND ${CMAKE_COMMAND}
-S "${CMAKE_CURRENT_SOURCE_DIR}"
-B "${CMAKE_CURRENT_BINARY_DIR}"
-B "${CMAKE_CURRENT_BINARY_DIR}/Build"
-G "${CMAKE_GENERATOR}"
-D "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
-D "CMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
Expand All @@ -25,10 +25,10 @@ else()

message(STATUS "Building Generator as subproject...")
execute_process(
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_CURRENT_BINARY_DIR}"
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_CURRENT_BINARY_DIR}/Build"
COMMAND_ERROR_IS_FATAL ANY)

# Now build InteropTests, which depends on SWIFTWINRT_EXE
set(SWIFTWINRT_EXE "${CMAKE_CURRENT_BINARY_DIR}/Sources/SwiftWinRT/SwiftWinRT.exe")
set(SWIFTWINRT_EXE "${CMAKE_CURRENT_BINARY_DIR}/Build/Sources/SwiftWinRT/SwiftWinRT.exe")
add_subdirectory(InteropTests)
endif()
5 changes: 1 addition & 4 deletions Generator/InteropTests/WinRTComponent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,4 @@ ExternalProject_Add(WinRTComponent
TEST_COMMAND "")

# Define the projection build
# TODO(https://github.com/tristanlabelle/swift-winrt/issues/302): Fix linking issues
# add_subdirectory(
# ${CMAKE_CURRENT_BINARY_DIR}/Projection/Sources
# ${CMAKE_CURRENT_BINARY_DIR}/Projection/Build)
add_subdirectory("${PROJECTION_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/Projection/Build")
14 changes: 12 additions & 2 deletions Generator/Sources/SwiftWinRT/writeProjectionFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ fileprivate func writeSwiftModuleFiles(_ module: Module, directoryPath: String,
writer.writeSingleLineCommand(
"set_target_properties", .autoquote(targetName),
"PROPERTIES", "Swift_MODULE_NAME", .autoquote(module.name))
// Workaround CMake error with mismatching module names:
// "CMake can not determine linker language for target: <blah>"
// writer.writeSingleLineCommand(
// "set_target_properties", .autoquote(targetName),
// "PROPERTIES", "LINKER_LANGUAGE", "Swift")
}
writer.writeTargetLinkLibraries(targetName, .public,
[ cmakeOptions.getTargetName(moduleName: module.abiModuleName), SupportModules.WinRT.moduleName ]
Expand Down Expand Up @@ -136,8 +141,13 @@ fileprivate func writeNamespaceModuleFiles(_ module: Module, directoryPath: Stri
writer.writeAddLibrary(targetName, .static, ["Aliases.swift"])
if targetName != namespaceModuleName {
writer.writeSingleLineCommand(
"set_target_properties", .unquoted(targetName),
"PROPERTIES", "Swift_MODULE_NAME", .unquoted(namespaceModuleName))
"set_target_properties", .autoquote(targetName),
"PROPERTIES", "Swift_MODULE_NAME", .autoquote(namespaceModuleName))
// Workaround CMake error with mismatching module names:
// "CMake can not determine linker language for target: <blah>"
// writer.writeSingleLineCommand(
// "set_target_properties", .autoquote(targetName),
// "PROPERTIES", "LINKER_LANGUAGE", "Swift")
}
writer.writeTargetLinkLibraries(targetName, .public, [ cmakeOptions.getTargetName(moduleName: module.name) ])
}
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let package = Package(
targets: ["COM_ABI", "WindowsRuntime_ABI"]),
.library(
name: "WindowsRuntime",
targets: ["COM", "WindowsRuntime"]),
targets: ["ABIBindings", "COM", "WindowsRuntime"]),
],
targets: [
.target(
Expand Down
6 changes: 5 additions & 1 deletion Support/Sources/WindowsRuntime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
file(GLOB_RECURSE SOURCES *.swift)
add_library(WindowsRuntime STATIC ${SOURCES})
target_link_libraries(WindowsRuntime PUBLIC COM WindowsRuntime_ABI)
target_link_libraries(WindowsRuntime PRIVATE SWRT_InternalABI)
target_link_libraries(WindowsRuntime PRIVATE SWRT_InternalABI)

# Workaround for CMake not propagating include dirs
# target_include_directories(WindowsRuntime INTERFACE "$<TARGET_FILE_DIR:ABIBindings>")
# target_include_directories(WindowsRuntime INTERFACE "$<TARGET_PROPERTY:SWRT_InternalABI,INCLUDE_DIRECTORIES>")
Loading