Commit 713e254
authored
Fix the static library might failed to link on Windows (#251)
### Motivation
Currently the CI in master is broken, here is an example failure:
https://github.com/apache/pulsar-client-cpp/actions/runs/4688588681/jobs/8309495018?pr=249
The reason is that the latest Windows runner image is already integrated
with the OpenSSL library to link, i.e. the `COMMON_LIBS` list variable
might have an element like:
```
debug;C:/Program Files/OpenSSL/lib/VC/libcrypto64MDd.lib
```
The list above have two elements:
1. `debug`
2. `C:/Program Files/OpenSSL/lib/VC/libcrypto64MDd.lib`
When building the static library, the list above will be converted to a
space-separated string like:
```
C:/Program Files/OpenSSL/lib/VC/libcrypto64MDd.lib
```
i.e. the `debug` and `optimized` elements are removed, the rest elements
that follows `debug` or `optimized` (determined by the build mode) will
be retained.
See https://github.com/apache/pulsar-client-cpp/blob/a57bb072ce6140757917353cc1d5a0007ddc353d/lib/CMakeLists.txt#L109
However, since there is a blank in `Program Files`, the string above is
unexpectedly treated as two elements:
- `C:/Program`
- `Files/OpenSSL/lib/VC/libcrypto64MDd.lib`
Then, the CI failed when linking to `pulsarWithDeps.lib`:
> fatal error LNK1181: cannot open input file 'C:\Program'
### Modifications
Instead of setting the `STATIC_LIBRARY_FLAGS` property, set the
`STATIC_LIBRARY_OPTIONS` property, which is a list rather than a string.
So the blank in the list element won't affect. Then in `remove_libtype`,
return a list instead of a string.
References:
- https://cmake.org/cmake/help/latest/prop_tgt/STATIC_LIBRARY_OPTIONS.html#prop_tgt:STATIC_LIBRARY_OPTIONS
- https://cmake.org/cmake/help/latest/prop_tgt/STATIC_LIBRARY_FLAGS.html#prop_tgt:STATIC_LIBRARY_FLAGS1 parent a57bb07 commit 713e254
1 file changed
Lines changed: 9 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
110 | 112 | | |
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
114 | 116 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
119 | 123 | | |
120 | 124 | | |
121 | 125 | | |
| |||
0 commit comments