forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
215 lines (188 loc) · 9.73 KB
/
Copy pathCMakeLists.txt
File metadata and controls
215 lines (188 loc) · 9.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
cmake_minimum_required(VERSION 3.24)
if(NOT WIN32)
message(FATAL_ERROR
"Context for Claude's Windows host can only be configured on Windows. "
"Build the portable core on this host instead: cmake -S ../core -B <build-dir>")
endif()
project(context_for_claude_windows LANGUAGES CXX)
if(NOT MSVC)
message(FATAL_ERROR
"Context for Claude's Windows host requires MSVC. Open a Visual Studio Developer PowerShell "
"with the Desktop development with C++ workload installed, then rerun CMake.")
endif()
find_program(CONTEXT_FOR_CLAUDE_SWIFTC_EXECUTABLE NAMES swiftc)
if(NOT CONTEXT_FOR_CLAUDE_SWIFTC_EXECUTABLE)
message(FATAL_ERROR
"Context for Claude's Windows host requires a Swift toolchain with swiftc on PATH. "
"Install the Windows toolchain recommended by swift-winrt, then rerun CMake.")
endif()
execute_process(
COMMAND "${CONTEXT_FOR_CLAUDE_SWIFTC_EXECUTABLE}" --version
RESULT_VARIABLE CONTEXT_FOR_CLAUDE_SWIFTC_RESULT
)
if(NOT CONTEXT_FOR_CLAUDE_SWIFTC_RESULT EQUAL 0)
message(FATAL_ERROR "swiftc was found but could not run. Repair the Windows Swift toolchain, then rerun CMake.")
endif()
include(CheckIncludeFileCXX)
check_include_file_cxx(windows.h CONTEXT_FOR_CLAUDE_HAS_WINDOWS_SDK)
if(NOT CONTEXT_FOR_CLAUDE_HAS_WINDOWS_SDK)
message(FATAL_ERROR
"The Windows SDK headers are unavailable. Install a Windows SDK, including its C++ headers, "
"through the Visual Studio Installer, then rerun CMake from a Developer PowerShell.")
endif()
# Swift/WinRT consumes Windows metadata, not C headers. Resolve the SDK metadata
# before fetching it so a missing SDK stops with a useful diagnostic.
set(CONTEXT_FOR_CLAUDE_WINDOWS_SDK_VERSION "${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
if(NOT CONTEXT_FOR_CLAUDE_WINDOWS_SDK_VERSION)
set(CONTEXT_FOR_CLAUDE_WINDOWS_SDK_VERSION "$ENV{WindowsSDKVersion}")
endif()
string(REGEX REPLACE "[\\\\/]$" "" CONTEXT_FOR_CLAUDE_WINDOWS_SDK_VERSION "${CONTEXT_FOR_CLAUDE_WINDOWS_SDK_VERSION}")
set(CONTEXT_FOR_CLAUDE_WINDOWS_SDK_ROOT "$ENV{WindowsSdkDir}")
set(CONTEXT_FOR_CLAUDE_WINDOWS_WINMD
"${CONTEXT_FOR_CLAUDE_WINDOWS_SDK_ROOT}/UnionMetadata/${CONTEXT_FOR_CLAUDE_WINDOWS_SDK_VERSION}/Windows.winmd")
if(NOT CONTEXT_FOR_CLAUDE_WINDOWS_SDK_VERSION OR NOT EXISTS "${CONTEXT_FOR_CLAUDE_WINDOWS_WINMD}")
message(FATAL_ERROR
"Windows SDK metadata was not found at '${CONTEXT_FOR_CLAUDE_WINDOWS_WINMD}'. "
"Run from a Visual Studio Developer PowerShell with WindowsSdkDir and WindowsSDKVersion set.")
endif()
include(CTest)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../core" "${CMAKE_CURRENT_BINARY_DIR}/core")
# Build the real upstream generator at a reproducible revision. Its output is
# Swift bindings for Windows metadata; Context core remains a separate C ABI
# static library that a future Windows Swift host imports through a module map.
include(FetchContent)
FetchContent_Declare(
swift_winrt
GIT_REPOSITORY https://github.com/thebrowsercompany/swift-winrt.git
GIT_TAG 79ffa65c
GIT_SUBMODULES_RECURSE TRUE
SOURCE_SUBDIR swiftwinrt
)
FetchContent_MakeAvailable(swift_winrt)
# Use Windows.Foundation as the smallest real Windows API namespace that every
# WinRT host needs. The response-file shape follows swift-winrt's own tests.
set(CONTEXT_FOR_CLAUDE_WINRT_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated/windows-foundation")
file(MAKE_DIRECTORY "${CONTEXT_FOR_CLAUDE_WINRT_OUTPUT_DIR}")
set(CONTEXT_FOR_CLAUDE_SWIFTWINRT_RESPONSE_FILE
"${CMAKE_CURRENT_BINARY_DIR}/ContextForClaudeWindowsFoundation.rsp")
file(WRITE "${CONTEXT_FOR_CLAUDE_SWIFTWINRT_RESPONSE_FILE}"
"-include\nWindows.Foundation\n"
"-input\n${CONTEXT_FOR_CLAUDE_WINDOWS_WINMD}\n"
"-reference\n${CONTEXT_FOR_CLAUDE_WINDOWS_SDK_VERSION}\n"
"-output\n${CONTEXT_FOR_CLAUDE_WINRT_OUTPUT_DIR}\n")
add_custom_target(generate_windows_foundation_projection
COMMAND $<TARGET_FILE:swiftwinrt> "@${CONTEXT_FOR_CLAUDE_SWIFTWINRT_RESPONSE_FILE}"
DEPENDS swiftwinrt
COMMENT "Generating Windows.Foundation Swift bindings with upstream swift-winrt"
VERBATIM
)
# --- Swift host ---------------------------------------------------------------
#
# A real Windows Swift host that links the portable C++ core through a module
# map and imports WinRT bindings generated by swift-winrt. The projection is
# generated into swift-host/projection/ and consumed by the SwiftPM package at
# swift-host/Package.swift. The build runs `swift build` after the projection
# is generated, following the same pattern as swift-winrt's own test_app.
set(CONTEXT_FOR_CLAUDE_SWIFT_HOST_DIR "${CMAKE_CURRENT_LIST_DIR}/swift-host")
set(CONTEXT_FOR_CLAUDE_SWIFT_HOST_PROJECTION_DIR "${CONTEXT_FOR_CLAUDE_SWIFT_HOST_DIR}/projection")
# The projection package needs a Sources/ tree with the generated bindings and
# a Package.swift that exposes them as a library target. swift-winrt writes
# flat .swift files into the output directory; we stage them into the SPM
# layout that Package.swift expects.
set(CONTEXT_FOR_CLAUDE_PROJECTION_PACKAGE_FILE
"${CONTEXT_FOR_CLAUDE_SWIFT_HOST_PROJECTION_DIR}/Package.swift")
set(CONTEXT_FOR_CLAUDE_PROJECTION_SOURCES_DIR
"${CONTEXT_FOR_CLAUDE_SWIFT_HOST_PROJECTION_DIR}/Sources/WindowsFoundation")
file(WRITE "${CONTEXT_FOR_CLAUDE_PROJECTION_PACKAGE_FILE}"
"// swift-tools-version: 5.9
// Generated by CMake — do not hand-edit.
import PackageDescription
let package = Package(
name: \"WinRTProjection\",
products: [
.library(name: \"WindowsFoundation\", type: .dynamic, targets: [\"WindowsFoundation\"]),
],
targets: [
.target(
name: \"CWinRT\",
path: \"Sources/CWinRT\"
),
.target(
name: \"WindowsFoundation\",
dependencies: [\"CWinRT\"],
path: \"Sources/WindowsFoundation\"
),
]
)
")
# CWinRT is the C shim that swift-winrt's generated bindings link against.
# On Windows it wraps the RoActivateInstance / RoGetActivationFactory calls.
file(MAKE_DIRECTORY "${CONTEXT_FOR_CLAUDE_SWIFT_HOST_PROJECTION_DIR}/Sources/CWinRT/include")
file(WRITE "${CONTEXT_FOR_CLAUDE_SWIFT_HOST_PROJECTION_DIR}/Sources/CWinRT/include/module.modulemap"
"module CWinRT {
header \"shim.h\"
export *
}
")
file(WRITE "${CONTEXT_FOR_CLAUDE_SWIFT_HOST_PROJECTION_DIR}/Sources/CWinRT/include/shim.h"
"#pragma once
#include <windows.h>
")
file(WRITE "${CONTEXT_FOR_CLAUDE_SWIFT_HOST_PROJECTION_DIR}/Sources/CWinRT/shim.c"
"#include \"shim.h\"
")
# Generate the Windows.Foundation projection into the SPM sources directory.
# The response file already targets the right namespace; we redirect the output
# to the projection's Sources/WindowsFoundation directory.
set(CONTEXT_FOR_CLAUDE_HOST_PROJECTION_RESPONSE_FILE
"${CMAKE_CURRENT_BINARY_DIR}/ContextForClaudeHostProjection.rsp")
file(WRITE "${CONTEXT_FOR_CLAUDE_HOST_PROJECTION_RESPONSE_FILE}"
"-include\nWindows.Foundation\n"
"-input\n${CONTEXT_FOR_CLAUDE_WINDOWS_WINMD}\n"
"-reference\n${CONTEXT_FOR_CLAUDE_WINDOWS_SDK_VERSION}\n"
"-output\n${CONTEXT_FOR_CLAUDE_PROJECTION_SOURCES_DIR}\n")
file(MAKE_DIRECTORY "${CONTEXT_FOR_CLAUDE_PROJECTION_SOURCES_DIR}")
add_custom_target(generate_swift_host_projection
COMMAND $<TARGET_FILE:swiftwinrt> "@${CONTEXT_FOR_CLAUDE_HOST_PROJECTION_RESPONSE_FILE}"
DEPENDS swiftwinrt
COMMENT "Generating Windows.Foundation Swift bindings for the Swift host"
VERBATIM
)
# Build the Swift host package. The C++ core is linked through the CContextCore
# SPM target which points at ../core/include with a module map. The core static
# library is passed through SWIFT_LINK_FLAGS so `swift build` can find it.
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "ARM64")
set(CONTEXT_FOR_CLAUDE_SPM_BIN_DIR
"${CMAKE_CURRENT_BINARY_DIR}/swift-host/aarch64-unknown-windows-msvc/Release")
else()
set(CONTEXT_FOR_CLAUDE_SPM_BIN_DIR
"${CMAKE_CURRENT_BINARY_DIR}/swift-host/x86_64-unknown-windows-msvc/Release")
endif()
set(CONTEXT_FOR_CLAUDE_CORE_LIB_DIR "$<TARGET_FILE_DIR:context_core>")
add_custom_target(build_swift_host
COMMAND
${CONTEXT_FOR_CLAUDE_SWIFTC_EXECUTABLE} build
-c release
--scratch-path ${CMAKE_CURRENT_BINARY_DIR}/swift-host
-Xlinker ${CONTEXT_FOR_CLAUDE_CORE_LIB_DIR}/libcontext_core.lib
WORKING_DIRECTORY ${CONTEXT_FOR_CLAUDE_SWIFT_HOST_DIR}
COMMENT "Building Context for Claude Windows Swift host"
BYPRODUCTS ${CONTEXT_FOR_CLAUDE_SPM_BIN_DIR}/context-windows-host.exe
DEPENDS generate_swift_host_projection context_core
VERBATIM
)
add_executable(context_for_claude_windows_core_smoke src/core_smoke.cpp)
target_link_libraries(context_for_claude_windows_core_smoke PRIVATE ContextForClaude::core)
target_compile_features(context_for_claude_windows_core_smoke PRIVATE cxx_std_17)
target_compile_options(context_for_claude_windows_core_smoke PRIVATE /W4 /WX /permissive-)
add_test(NAME context_for_claude_windows_core_smoke COMMAND context_for_claude_windows_core_smoke)
add_executable(context_for_claude_windows_session_host src/session_host.cpp)
target_link_libraries(context_for_claude_windows_session_host PRIVATE ContextForClaude::core)
target_compile_features(context_for_claude_windows_session_host PRIVATE cxx_std_17)
target_compile_options(context_for_claude_windows_session_host PRIVATE /W4 /WX /permissive-)
add_test(NAME context_for_claude_windows_session_host COMMAND context_for_claude_windows_session_host)
add_executable(context_for_claude_windows_pcm_host src/pcm_host.cpp)
target_link_libraries(context_for_claude_windows_pcm_host PRIVATE ContextForClaude::core)
target_compile_features(context_for_claude_windows_pcm_host PRIVATE cxx_std_17)
target_compile_options(context_for_claude_windows_pcm_host PRIVATE /W4 /WX /permissive-)
add_test(NAME context_for_claude_windows_pcm_host COMMAND context_for_claude_windows_pcm_host)