flavorjones / mini_portile

mini_portile and mini_portile2 - Simple autoconf and cmake builder for developers
MIT License
114 stars 51 forks source link

[cmake] Automatically add required cross-compilation variables #130

Closed stanhu closed 1 year ago

stanhu commented 1 year ago

For the standard make, mini_portile provides the configure script with the --host parameter, and the script figures out the target compilers to use. With CMake, we don't have that benefit so we need to set the C and C++ compilers ourselves.

This commit uses a simple heuristic to find the target compilers:

  1. For macOS, use clang and clang++. Otherwise use gcc and gcc++.
  2. We search the PATH for <host>-compiler. Use that if we find it. Otherwise default to the base compilers.

To make CMake work with cross-compilation, a number of variables have to be set:

Closes #128

flavorjones commented 1 year ago

This looks great! Thank you!

flavorjones commented 1 year ago

Released in https://github.com/flavorjones/mini_portile/releases/tag/v2.8.4

larskanis commented 1 year ago

Great addition! Thank you!

flavorjones commented 4 months ago

@stanhu I'm curious why we're not using RbConfig::CONFIG["CC"] and ["CXX"] here ... would that simplify things?

Asking because OpenBSD and FreeBSD support have been ... interesting.

stanhu commented 4 months ago

I'm curious why we're not using RbConfig::CONFIG["CC"] and ["CXX"] here ... would that simplify things?

@flavorjones Yeah, that could would work. It looks like mini_portile2 uses RbConfig::CONFIG['CC'] here, so maybe we can simplify this further by using gcc_cmd and introducing something like gxx_cmd: https://github.com/flavorjones/mini_portile/blob/af3f9d2a8359f31bcfa64e40492357f7d07bce30/lib/mini_portile2/mini_portile.rb#L376

stanhu commented 4 months ago

I think I might have been focused on ENV["CC"] because that's what configure uses. I think I defaulted to clang for macOS because the cross-compile images for macOS has compilers with clang-#{host} (e.g. clang-arm64-apple-darwin22). But I think the cross-compile images should have reasonable values for RbConfig::CONFIG["CC"] that match with the image, so that approach should work.

flavorjones commented 3 months ago

I've opened a PR to simplify compiler detection at https://github.com/flavorjones/mini_portile/pull/144