project_options icon indicating copy to clipboard operation
project_options copied to clipboard

Cross-compiling

Open aminya opened this issue 1 year ago • 10 comments

  • [x] Merge #171 by @abeimler
  • [ ] Test cross-compiling with Conan @aminya
  • [x] Test cross-compiling without using Conan NOR vcpkg, just plain C++ #188
    • [x] by just using enable_cross_compiler() and CMAKE_TOOLCHAIN_FILE #188
  • [ ] May add a more specific (cross-compile) example for windows
    • [ ] So it can compile with both MSVC AND MinGW
  • [x] Update setup-cpp (toolchain) examples in project-options https://github.com/aminya/setup-cpp/pull/103
  • [x] After adding cross-compiler to setup-cpp, update Dockerfile.mingw so setup-cpp can install the cross-compiler (MinGW) #233
  • [x] Update Taskfile in https://github.com/aminya/cpp_vcpkg_project/pull/15

Future Ideas

  • add more specific project_options for emscripten
  • add cross-compiler for ARM
  • Maybe Android (toolchain)

Usage

The best you can do is add this to your cmake file:

# opt-in cross-compiling
option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF)
if(ENABLE_CROSS_COMPILING)
  enable_cross_compiler()
endif()
run_vcpkg() # run_vcpkg AFTER enable_cross_compiler, when using vcpkg

and run cmake with these additional arguments:

-DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=x64-mingw-dynamic

See Taskfile and docker examples

Notes

  • This feature isn't a magic switch to enable cross-compiling
    • vcpkg Community triplets are not guaranteed to succeed.
    • emscripten can be more of a specific use case and you may need to add some flags
  • The toolchain files are more of a basic setup and examples
  • enable_cross_compiler() and run_vcpkg() can help you set up Community triplets easier
  • Best way to experiment with cross-compiling is by using docker and in a closed environment

Originally posted by @abeimler in https://github.com/aminya/project_options/issues/171#issuecomment-1345251104

Upvote & Fund

  • I am using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.

  • Thank you in advance for helping prioritize & fund our backlog.

Fund with Polar

aminya avatar Dec 28 '22 06:12 aminya