Skip to content

cmake: Show error instead of invoking cross-compiled mpgen binary #171

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ryanofsky
Copy link
Collaborator

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.

# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants