flavorjones / mini_portile

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

[cmake] Support cross-compiling out of the box #128

Closed stanhu closed 1 year ago

stanhu commented 1 year ago

While working on https://github.com/mudge/re2/pull/67, I had to add a number of configuration options to make cross-compiling work properly.

For the standard make, mini_portile2 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.

I used 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:

I was surprised that CMAKE_SYSTEM_NAME has to be set, or cmake won't try to cross-compile.

I think mini_portile2 should provide these options by default.

stanhu commented 1 year ago

In order to build a C extension against a library, we may also want to add:

flavorjones commented 1 year ago

Ack. CMake is still "experimental" and you may be the first person to really try to use it for something. Will take a look, but prioritizing it behind some other work at the moment.