cmake: Show error instead of invoking cross-compiled mpgen binary#171
cmake: Show error instead of invoking cross-compiled mpgen binary#171ryanofsky wants to merge 1 commit intobitcoin-core:masterfrom
Conversation
Suggested by Cory Fields <cory-nospam-@coryfields.com> in bitcoin/bitcoin#31741 (comment)
| # should trigger a more readable attempting to run a cross compiled executable. | ||
| if(CMAKE_CROSSCOMPILING AND NOT MPGEN_EXECUTABLE) | ||
| include(CheckCXXSourceRuns) | ||
| check_cxx_source_runs("int main() { return 0; }" EXECUTABLES_CAN_RUN) |
There was a problem hiding this comment.
Nice. While looking for something like this, I stumbled upon try_run which takes CMAKE_CROSSCOMPILING into account, which is why I suggested just testing against the var itself. But it seems check_cxx_source_runs is more sane.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
🐙 This pull request conflicts with the target branch and needs rebase. |
|
⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
|
⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
Idea here is to avoid potentially confusing errors if cross compiling and forgetting to set the MPGEN_EXECUTABLE.
Idea came from theuni in bitcoin/bitcoin#31741 (comment) with suggestion to show a warning whenever CMAKE_CROSSCOMPILING was set and MPGEN_EXECUTABLE wasn't set, but this would show a warning in the default build which excludes tests and examples and does not need to run the code generator. Also it could warn spuriously if cross-compiled binaries were actually executable.
Avoid these problems by using check_cxx_source_runs instead of CMAKE_CROSSCOMPILING to see if binaries can run and triggering an error at build time instead of configure time to avoid showing warnings when code generator is not actually needed.
This is currently a draft PR, because I haven't tested it on a cross-compiled system so not actually sure it is a significant improvement. Also not sure if this is the best approach.