-
Notifications
You must be signed in to change notification settings - Fork 265
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
cmake: allow cross-CPU builds via LIBRESSL_CPU
#935
Conversation
If `LIBRESSL_CPU` is not set, honor existing `CMAKE_OSX_ARCHITECTURE` for Apple targets. Then fall back to `CMAKE_C_COMPILER_TARGET` if set. Otherwise fall back to the value that was used before this patch: `CMAKE_SYSTEM_PROCESSOR`. This allows customizing the target CPU, e.g. on Linux. I'm not certain of the exact CMake rules for this, but on some platforms (e.g. Linux) it is not possible to override the default `CMAKE_SYSTEM_PROCESSOR` value by passing it to cmake via `-DCMAKE_SYSTEM_PROCESSOR=...`. Meaning, before this patch it was not possible to build for a CPU other than the host one. Also: - simplify syntax in `STREQUAL` and `MATCH` expressions in the lines touched. - display the target CPU and ABI in the configuration phase.
Thanks. Does that mean the cross compile tests in this project, scripts/test, aren't doing what we thought they were with Cmake? |
I haven't tried that script, but after a quick look it seems to use FWIW when the CPU was mismatched in a cross-build with ASM enabled, it manifested in clear build failures in my Linux tests. |
After inspecting the CMake source code 1, it seems that if Footnotes |
Turns out `CMAKE_SYSTEM_PROCESSOR` is not overridable on Linux for example. Patch submitted upstream to fix cross-builds: libressl/portable#935
It was useful to take a second look, because the solution is to set I run into a separate issue where |
Thanks for digging into the logic here. This is potentially more convenient than what CMake provides out of the box. Just wanted to make sure this was solving the right problem. |
No worries, I was also happy to get to the root cause. I'm still not quite sure what is the CMake best-practice here though. No objection to merge this anyway, I agree it could improve the build UX. |
Looking into this more, a triplet doesn't work universally, because some conditions use I think maybe the best would be to move the CPU-selection logic to the C preprocessor. This would allow to drop all this (also in autotools), while automatically adding support for building universal (multi-CPU) Apple targets. |
If
LIBRESSL_CPU
is not set, honor existingCMAKE_OSX_ARCHITECTURE
for Apple targets. Then fall back toCMAKE_C_COMPILER_TARGET
(typically a triplet) if set. Otherwise fall back to the value that was used before this patch:CMAKE_SYSTEM_PROCESSOR
.This allows customizing the target CPU, e.g. on Linux.
I'm not certain of the exact CMake rules for this, but on some platforms (e.g. Linux) it is not possible to override the default
CMAKE_SYSTEM_PROCESSOR
value by passing it to cmake via-DCMAKE_SYSTEM_PROCESSOR=...
or-DCMAKE_TOOLCHAIN_FILE=..
. Meaning, before this patch it was not possible to build for a CPU other than the host one on Linux for example.Also:
STREQUAL
andMATCH
expressions in the lines touched.