aminya / project_options

A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.

Home Page:https://aminya.github.io/project_options/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add toolchain support

abeimler opened this issue · comments

Add function to setup -DCMAKE_TOOLCHAIN_FILE/-DVCPKG_TOOLCHAIN_FILE and include() toolchain via -DOPT_TARGET_TRIPLET:STRING=x64-mingw-dynamic option.

Example:

project_options(
   TARGET_TRIPLET "x64-mingw-dynamic"
)

or with cmake arguments:

# for custom toolchains
cmake ... -DOPT_TOOLCHAIN_FILE:STRING="..." -DOPT_TARGET_TRIPLET:STRING="..."
## setup vcpkg and more

# use project_options toolchains
cmake ... -DOPT_TARGET_TRIPLET:STRING="..."
## setup vcpkg and more

# use vcpkg arguments
cmake ... -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="..." -DVCPKG_TARGET_TRIPLET="..."
## read vcpkg triplet and set OPT_TARGET_TRIPLET etc.

Notes

  • Cross compiler must setup by user
  • Maybe addition arguments must be pass for cross-compiler root path or other paths like Android NDK, emscripten SDK (emsdk), ...

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

I have taken the automated approach to the toolchains; the user should not need to specify the toolchains manually. We detect the proper toolchain based on the compiler settings and the target system.

For example, for the msvc toolchain:

if(# if on windows and the generator is not Visual Studio
WIN32
AND NOT
CMAKE_GENERATOR
MATCHES
"Visual Studio*")
is_msvc(_is_msvc)

We already detect MinGW and apply some fixes for it for VCPKG. You can use the same function to detect MinGW and include its toolchain.

function(is_mingw value)