-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Cross-compiling and toolchains #171
Conversation
* add mingw toolchains * add docker for testing
@@ -23,6 +23,37 @@ tasks: | |||
CWD: | |||
sh: git rev-parse --show-toplevel | |||
|
|||
test_docker: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add these to the CI in .github/workflows/CI.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm ... I mostly use this for development and testing on my machine.
I will try to add some github actions
docker/build.sh
Outdated
@@ -0,0 +1,7 @@ | |||
#!/bin/bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to have these bash script files? The point of Taskfile
is to collect these in a cross-platform file.
@@ -108,7 +108,24 @@ macro(run_vcpkg) | |||
list(APPEND VCPKG_FEATURE_FLAGS "versions") | |||
set(CMAKE_TOOLCHAIN_FILE | |||
${_vcpkg_args_VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake | |||
CACHE STRING "vcpkg toolchain file") | |||
CACHE STRING "vcpkg toolchain file" FORCE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be forced?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In enable_cross_compiler()
I'm already setting a toolchain (as default), so if you are not using vcpkg, this should be the default, otherwise vcpkg overrides it and sets VCPKG_CHAINLOAD_TOOLCHAIN_FILE
in addition.
but this case need also more testing
The compiler detection also uses CC/CXX environment variables. It calls |
The Mingw vcpkg code is continuously tested in the CI. So the error is related to the new code or something in the environment |
@@ -0,0 +1,133 @@ | |||
cmake_minimum_required(VERSION 3.16...3.21) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this helps you test the code easier, it is fine. We can merge and remove test_minimal
whenever the development is over.
@@ -102,7 +118,11 @@ macro(configure_mingw_vcpkg_after) | |||
include("${ProjectOptions_SRC_DIR}/Utilities.cmake") | |||
detect_architecture(_arch) | |||
string(TOLOWER "${_arch}" _arch) | |||
set(Z_VCPKG_TARGET_TRIPLET_ARCH ${_arch}) | |||
if(CROSSCOMPILING AND TARGET_ARCHITECTURE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this condition work? From my experience of working with CMake's confusing datatypes, an explicit "${variable}" STREQL ""
works better for making sure that the condition is correct.
* add docker-compose
* fix: detect cross compiler for em++
You can now set the cross-compiler (with
|
* fix path in toolchain
the minimal example seems to compile with mingw, but not the |
* update setup-cpp
* chore: code cleanup
Further TODOs
Future Ideas
UsageBest 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 this additional arguments: -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=x64-mingw-dynamic See Taskfile and docker examples Notes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will merge this for now. Let's open an issue for the TODOs you mentioned.
Hello,
I try to add some toolchain file (for mingw) and emscripten.
The compiler detection seems to work, but I can't fully build the test projects.
To enable Cross-compiling you need to set the cross-compiler via (environment variable)
CC
andCXX
, then call this cmake-macro:(before
run_vcpkg()
)There are also some TODOs and problem...
(I tried to detect the compiler with
detect_compiler()
, but it didn't work, so I fallback to$ENV{CXX}
)(when running
run_vcpkg()
)Test on Windowsdone by CIRight now, I have some problems building the test Project(s), seems like vcpkg didn't like the 3rd-party libs and throws an error:
Notes:
I'm using mostly docker for my Testing with setup-cpp and ubuntu-images.
Added
test_minimal
more for experimenting, would be nice to have onlytest
for cross-compiling and everything.I also run the
test
-project, on my native (Linux) machine and had some problem building it =|Environment:
OS: Linux 64-Bit (Arch Linux)
Compiler: gcc 12