Commit e3eefce
committed
Support linking static dependencies when building with MSVC
### Motivation
Currently it's impossible to build Pulsar C++ client on Windows with
`LINK_STATIC=ON`. It means users have to package all 3rd-party DLLs as
well as `pulsar.dll`, which harms the experience.
### Modifications
Enable `LINK_STATIC` when the Vcpkg triplet is `xxx-static`. In this
case, find the 3rd party libraries with correct names on Windows. And
replace `Threads::Threads` with `CMAKE_THREAD_LIB_INIT`.
The most important change is replacing the `/MD` compile option with
`/MT`. It should have been done by setting the
[`MSVC_RUNTIME_LIBRARY`](https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html)
property, but it seems not work. So this PR just modifies the
`CMAKE_CXX_FLAGS_<CONFIG>` variables.
For `pulsarWithAllDeps.lib`, add the actual library (`*.lib`) to
`COMMON_LIBS` instead of the target name (`dlfcn-win32::dl`).
Some warnings on Windows caused by incorrect compile options are fixed
as well.
A workflow is added to verify the static build for x64 and x86 Windows.
And a simple example is added as `win-examples` to show the
`pulsarWithAllDeps.lib` can be linked without any other dependency to
run an executable.
Change the existing release workflow to release two `*.zip` files:
- pulsar-client-cpp-x64-windows-static.zip
- pulsar-client-cpp-x86-windows-static.zip
Each zip file consists of:
```
bin/pulsar.dll - The dynamic library that links statically to dependencies
include/pulsar/ - Headers
lib/
pulsar.lib - The import library of pulsar.dll
pulsar-static.lib - The static library
pulsarWithDeps.lib - The static library with all dependnecies included
dependencies.txt - The vcpkg outputs, which contains the dependency versions
```
(cherry picked from commit 1c07678)1 parent 5ef4c11 commit e3eefce
File tree
6 files changed
+172
-48
lines changed- .github/workflows
- lib
- win-examples
6 files changed
+172
-48
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
99 | | - | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | | - | |
| 106 | + | |
108 | 107 | | |
109 | 108 | | |
110 | 109 | | |
| |||
145 | 144 | | |
146 | 145 | | |
147 | 146 | | |
148 | | - | |
| 147 | + | |
149 | 148 | | |
150 | 149 | | |
151 | 150 | | |
| |||
154 | 153 | | |
155 | 154 | | |
156 | 155 | | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 159 | + | |
| 160 | + | |
177 | 161 | | |
178 | 162 | | |
179 | 163 | | |
180 | | - | |
| 164 | + | |
181 | 165 | | |
182 | 166 | | |
183 | 167 | | |
184 | 168 | | |
185 | 169 | | |
186 | | - | |
187 | | - | |
| 170 | + | |
| 171 | + | |
188 | 172 | | |
189 | 173 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | | - | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
| |||
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
159 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
160 | 163 | | |
161 | 164 | | |
162 | 165 | | |
163 | 166 | | |
164 | 167 | | |
165 | 168 | | |
166 | 169 | | |
167 | | - | |
168 | | - | |
| 170 | + | |
| 171 | + | |
169 | 172 | | |
170 | 173 | | |
171 | 174 | | |
172 | | - | |
| 175 | + | |
173 | 176 | | |
174 | 177 | | |
175 | 178 | | |
176 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
177 | 201 | | |
178 | 202 | | |
179 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
47 | 53 | | |
| 54 | + | |
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
| |||
69 | 76 | | |
70 | 77 | | |
71 | 78 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | 79 | | |
76 | 80 | | |
77 | 81 | | |
| |||
93 | 97 | | |
94 | 98 | | |
95 | 99 | | |
96 | | - | |
| 100 | + | |
97 | 101 | | |
98 | 102 | | |
99 | 103 | | |
| |||
168 | 172 | | |
169 | 173 | | |
170 | 174 | | |
171 | | - | |
| 175 | + | |
172 | 176 | | |
173 | 177 | | |
174 | 178 | | |
| |||
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
198 | 225 | | |
199 | 226 | | |
200 | 227 | | |
| |||
211 | 238 | | |
212 | 239 | | |
213 | 240 | | |
214 | | - | |
| 241 | + | |
215 | 242 | | |
216 | 243 | | |
217 | 244 | | |
| |||
220 | 247 | | |
221 | 248 | | |
222 | 249 | | |
223 | | - | |
| 250 | + | |
224 | 251 | | |
225 | 252 | | |
226 | 253 | | |
227 | 254 | | |
228 | 255 | | |
229 | 256 | | |
230 | 257 | | |
231 | | - | |
| 258 | + | |
232 | 259 | | |
233 | 260 | | |
234 | 261 | | |
| |||
295 | 322 | | |
296 | 323 | | |
297 | 324 | | |
298 | | - | |
| 325 | + | |
299 | 326 | | |
300 | 327 | | |
301 | 328 | | |
| |||
307 | 334 | | |
308 | 335 | | |
309 | 336 | | |
310 | | - | |
311 | | - | |
312 | | - | |
| 337 | + | |
313 | 338 | | |
314 | | - | |
315 | | - | |
316 | | - | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
317 | 356 | | |
318 | 357 | | |
319 | 358 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
91 | | - | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments