Skip to content
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: Not possible to cross-compile due to settinsgen/strgen #8249

Closed
JGRennison opened this issue Jun 29, 2020 · 10 comments · Fixed by #8350
Closed

CMake: Not possible to cross-compile due to settinsgen/strgen #8249

JGRennison opened this issue Jun 29, 2020 · 10 comments · Fixed by #8350

Comments

@JGRennison
Copy link
Contributor

Cross-compiling (i.e. using CMAKE_TOOLCHAIN_FILE such that CMAKE_CROSSCOMPILING is ON) does not work because settingsgen and strgen are built for the target platform but executed on the host platform as part of the build.
In the case where the host and target are different, the settingsgen/strgen executables cannot be found/executed.

The configure script handled this correctly.

Unfortunately cmake doesn't seem to support the standard host/build distinction.
Stackoverflow suggest various convoluted and ugly workarounds, which I haven't been able to get working.
It'd be useful to get an "official" take on how this is supposed to work.

I'm attempting to use MinGW, but I can imagine that similar issues would arise when cross-building for other architectures like ARM, etc.

@nielsmh
Copy link
Contributor

nielsmh commented Jun 29, 2020

I'm not sure if it's a great solution, but I suppose it'd be possible to have settings pointing to strgen and settingsgen executables to use instead of those built.

@glx22
Copy link
Contributor

glx22 commented Jun 29, 2020

https://stackoverflow.com/a/61385572 seems to be a good option.

@glx22
Copy link
Contributor

glx22 commented Jun 29, 2020

I tried something using the link in my previous comment in master...glx22:cross_compile

@JGRennison
Copy link
Contributor Author

I tried something using the link in my previous comment in master...glx22:cross_compile

This fixes the issue for me, many thanks :)

@orudge
Copy link
Contributor

orudge commented Jun 30, 2020

Hm, I assume this works for gcc or similar, but doesn't appear to work when trying to cross-compile ARM64 on x64 with MSVC 2019. I'll have a dig around and see if I can work out a solution.

@glx22
Copy link
Contributor

glx22 commented Jun 30, 2020

Yeah, for now I hardcoded host compiler, but I think it can be configurable.
@orudge maybe try without https://github.com/glx22/OpenTTD/blob/fdaf0d0b2f82701c8ea1e9a1125415351cf49e57/CMakeLists.txt#L143 I added these when testing mingw target on my debian VM, because it kept using mingw compiler even for the native part.

@glx22
Copy link
Contributor

glx22 commented Jun 30, 2020

Ok I tried ARM64 on x64 with VS2019, it's not detected as cross-compiling (CMAKE_CROSSCOMPILING is false)

@orudge
Copy link
Contributor

orudge commented Jun 30, 2020

It's not particularly elegant, but master...orudge:msvc-crosscompile works for me when crosscompiling for ARM64 on x64. Compiling x64 and x86 on x64 work too in the conventional manner, and building with mingw-w64/msys2 also looks OK.

@glx22
Copy link
Contributor

glx22 commented Jul 2, 2020

Alternate option in master...glx22:cross_compile_alt.
It requires more manual steps (and 2 build directories):

  • create a directory for native
  • run cmake for native
  • build at least tools target
  • create a directory for cross-compile
  • run cmake for cross-compile, passing the full path to native directory in HOST_BINARY_DIR
  • build cross-compile

@TrueBrain
Copy link
Member

I like your solution @glx22, and it works very well. Did you already make a PR out of this?

There is one change in your commit I am not sure is correct, the one where you add a WIN32 line .. feels a bit out-of-place.

To make it an official option in CMake, might be good to set HOST_BINARY_DIR somewhere, with a description? So people who use the CMake GUI know about it too :)

@glx22 glx22 linked a pull request Dec 3, 2020 that will close this issue
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 a pull request may close this issue.

5 participants